From 204abab724d72c1acf68e1f0b68de0f0a0f638e8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 4 Oct 2019 18:25:18 +0200 Subject: [PATCH] glColor calls refactored. --- source/build/src/2d.cpp | 2 +- source/build/src/animvpx.cpp | 1 - source/build/src/common.cpp | 6 ++---- source/build/src/mdsprite.cpp | 12 ++---------- source/build/src/palette.cpp | 8 ++++---- source/build/src/polymost.cpp | 13 +++++-------- source/build/src/voxmodel.cpp | 4 +--- source/glbackend/glbackend.cpp | 5 +++++ source/glbackend/glbackend.h | 5 +++++ 9 files changed, 25 insertions(+), 31 deletions(-) diff --git a/source/build/src/2d.cpp b/source/build/src/2d.cpp index c1c5601d7..0e4b6d853 100644 --- a/source/build/src/2d.cpp +++ b/source/build/src/2d.cpp @@ -61,7 +61,7 @@ static void drawlinegl(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t GLInterface.EnableBlend(true); // When using line antialiasing, this is needed polymost_useColorOnly(true); - glColor4ub(p.r, p.g, p.b, 255); + GLInterface.SetColorub(p.r, p.g, p.b, 255); auto data = GLInterface.AllocVertices(2); data.second[0].Set((float) x1 * (1.f/4096.f), (float) y1 * (1.f/4096.f)); diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index 14b4efe7d..9aba6b4de 100644 --- a/source/build/src/animvpx.cpp +++ b/source/build/src/animvpx.cpp @@ -419,7 +419,6 @@ void animvpx_setup_glstate(int32_t animvpx_flags) GLInterface.SetMatrix(Matrix_Projection, &identity); GLInterface.SetMatrix(Matrix_Texture0, &identity); -// glPushAttrib(GL_ENABLE_BIT); GLInterface.EnableAlphaTest(false); GLInterface.EnableDepthTest(false); GLInterface.EnableBlend(false); diff --git a/source/build/src/common.cpp b/source/build/src/common.cpp index 49b849035..e8abac183 100644 --- a/source/build/src/common.cpp +++ b/source/build/src/common.cpp @@ -254,18 +254,16 @@ void COMMON_doclearbackground(int numcols, int height) # ifdef USE_OPENGL if (videoGetRenderMode() >= REND_POLYMOST && in3dmode()) { -// glPushAttrib(GL_FOG_BIT); polymost_setFogEnabled(false); polymost_useColorOnly(true); polymostSet2dView(); - glColor4f(0.f, 0.f, 0.f, 0.67f); + GLInterface.SetColor(0.f, 0.f, 0.f, 0.67f); GLInterface.EnableBlend(true); glRecti(0, 0, xdim, height); - glColor4f(0.f, 0.f, 0.f, 1.f); + GLInterface.SetColor(0.f, 0.f, 0.f, 1.f); glRecti(0, height-4, xdim, height); -// glPopAttrib(); polymost_useColorOnly(false); polymost_setFogEnabled(true); diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 8d71fcf17..4846ee01e 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1987,19 +1987,11 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) if (tspr->extra&TSPR_EXTRA_MDHACK) { -#ifdef __arm__ // GL ES has a glDepthRangef and the loss of precision is OK there - float f = (float) (tspr->owner + 1) * (std::numeric_limits::epsilon() * 8.0); - if (f != 0.0) f *= 1.f/(float) (sepldist(globalposx - tspr->x, globalposy - tspr->y)>>5); -#else double f = (double) (tspr->owner + 1) * (std::numeric_limits::epsilon() * 8.0); if (f != 0.0) f *= 1.0/(double) (sepldist(globalposx - tspr->x, globalposy - tspr->y)>>5); -// glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); -#endif glDepthFunc(GL_LEQUAL); -// glDepthRange(0.0 - f, 1.0 - f); } -// glPushAttrib(GL_POLYGON_BIT); if ((grhalfxdown10x >= 0) ^((globalorientation&8) != 0) ^((globalorientation&4) != 0)) glFrontFace(GL_CW); else glFrontFace(GL_CCW); GLInterface.SetCull(Cull_Back); @@ -2037,9 +2029,9 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) if ((tspr->cstat&2) || sext->alpha > 0.f || pc[3] < 1.0f) GLInterface.EnableBlend(true); //else GLInterface.EnableBlend(false); } - glColor4f(pc[0],pc[1],pc[2],pc[3]); + GLInterface.SetColor(pc[0],pc[1],pc[2],pc[3]); //if (MFLAGS_NOCONV(m)) - // glColor4f(0.0f, 0.0f, 1.0f, 1.0f); + // GLInterface.SetColor(0.0f, 0.0f, 1.0f, 1.0f); //------------ // PLAG: Cleaner model rotation code diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index eeaa3cedf..fd03b2a8d 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -62,7 +62,7 @@ void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GLInterface.EnableBlend(true); - glColor4ub(r, g, b, f); + GLInterface.SetColorub(r, g, b, f); polymost_useColorOnly(true); @@ -99,7 +99,7 @@ void fullscreen_tint_gl_blood(void) GLInterface.EnableBlend(true); polymost_useColorOnly(true); - glColor4ub(max(tint_blood_r, 0), max(tint_blood_g, 0), max(tint_blood_b, 0), 255); + GLInterface.SetColorub(max(tint_blood_r, 0), max(tint_blood_g, 0), max(tint_blood_b, 0), 255); auto data = GLInterface.AllocVertices(3); auto vt = data.second; vt[0].Set(-2.5f, 1.f); @@ -107,7 +107,7 @@ void fullscreen_tint_gl_blood(void) vt[2].Set(.0f, -2.5f); GLInterface.Draw(DT_TRIANGLES, data.first, 3); glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - glColor4ub(max(-tint_blood_r, 0), max(-tint_blood_g, 0), max(-tint_blood_b, 0), 255); + GLInterface.SetColorub(max(-tint_blood_r, 0), max(-tint_blood_g, 0), max(-tint_blood_b, 0), 255); data = GLInterface.AllocVertices(3); vt = data.second; vt[0].Set(-2.5f, 1.f); @@ -115,7 +115,7 @@ void fullscreen_tint_gl_blood(void) vt[2].Set(.0f, -2.5f); GLInterface.Draw(DT_TRIANGLES, data.first, 3); glBlendEquation(GL_FUNC_ADD); - glColor4ub(0,0,0,0); + GLInterface.SetColorub(0,0,0,0); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); polymost_useColorOnly(false); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 58b45fc97..e75503912 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -2204,7 +2204,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 if (skyzbufferhack_pass) pc[3] = 0.01f; - glColor4f(pc[0], pc[1], pc[2], pc[3]); + GLInterface.SetColor(pc[0], pc[1], pc[2], pc[3]); //POGOTODO: remove this, replace it with a shader implementation //Hack for walls&masked walls which use textures that are not a power of 2 @@ -7195,7 +7195,7 @@ void polymost_fillpolygon(int32_t npoints) if (maskprops > DAMETH_MASK) { GLInterface.EnableBlend(true); - glColor4f(f, f, f, float_trans(maskprops, 0)); + GLInterface.SetColor(f, f, f, float_trans(maskprops, 0)); } else { @@ -7296,7 +7296,6 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba GLInterface.EnableAlphaTest(false); glDepthMask(GL_FALSE); // disable writing to the z-buffer -// glPushAttrib(GL_POLYGON_BIT|GL_ENABLE_BIT); // XXX: Don't fogify the OSD text in Mapster32 with r_usenewshading >= 2. polymost_setFogEnabled(false); // We want to have readable text in wireframe mode, too: @@ -7307,7 +7306,7 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba { int const c = Bstrlen(name); - glColor4ub(b.r,b.g,b.b,255); + GLInterface.SetColorub(b.r,b.g,b.b,255); auto data = GLInterface.AllocVertices(4); auto vt = data.second; @@ -7321,7 +7320,7 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba } GLInterface.EnableBlend(true); - glColor4ub(p.r,p.g,p.b,255); + GLInterface.SetColorub(p.r,p.g,p.b,255); vec2f_t const tc = { fontsize ? (4.f / 256.f) : (8.f / 256.f), fontsize ? (6.f / 128.f) : (8.f / 128.f) }; @@ -7352,7 +7351,7 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba bricolor(&p, col); - glColor4ub(p.r, p.g, p.b, 255); + GLInterface.SetColorub(p.r, p.g, p.b, 255); continue; } @@ -7387,8 +7386,6 @@ int32_t polymost_printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t ba glDepthMask(GL_TRUE); // re-enable writing to the z-buffer -// glPopAttrib(); - if (!nofog) polymost_setFogEnabled(true); polymost_usePaletteIndexing(true); diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index 8c6f10cad..ed89a26b1 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1082,10 +1082,8 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) if (shadowHack) { glDepthFunc(GL_LEQUAL); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS -// glDepthRange(0.0, 0.9999); } -// glPushAttrib(GL_POLYGON_BIT); if ((grhalfxdown10x >= 0) ^ ((globalorientation&8) != 0) ^ ((globalorientation&4) != 0)) glFrontFace(GL_CW); @@ -1164,7 +1162,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) qstart += qdone * 4; qdone = 0; } - glColor4f(pc[0]*f, pc[1]*f, pc[2]*f, pc[3]*f); + GLInterface.SetColor(pc[0]*f, pc[1]*f, pc[2]*f, pc[3]*f); } const vert_t *const vptr = &m->quad[i].v[0]; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 930e2bcc2..c497d89f7 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -196,3 +196,8 @@ void GLInstance::SetCull(int type) glCullFace(GL_BACK); } } + +void GLInstance::SetColor(float r, float g, float b, float a) +{ + glColor4f(r, g, b, a); +} \ No newline at end of file diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index eba433950..fceb0cdeb 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -123,6 +123,11 @@ public: void EnableStencilWrite(int value); void EnableStencilTest(int value); void DisableStencil(); + void SetColor(float r, float g, float b, float a = 1.f); + void SetColorub(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) + { + SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f)); + } }; extern GLInstance GLInterface;