diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 4846ee01e..17712e0f4 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1989,7 +1989,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) { 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); - glDepthFunc(GL_LEQUAL); + GLInterface.SetDepthFunc(Depth_LessEqual); } if ((grhalfxdown10x >= 0) ^((globalorientation&8) != 0) ^((globalorientation&4) != 0)) glFrontFace(GL_CW); else glFrontFace(GL_CCW); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index e75503912..b41e5969b 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -942,23 +942,20 @@ void calc_and_apply_fog(int32_t shade, int32_t vis, int32_t pal) fogresult2 = -GL_FOG_MAX; // hide fog behind the camera } - glFogf(GL_FOG_START, fogresult); - glFogf(GL_FOG_END, fogresult2); - glFogfv(GL_FOG_COLOR, (GLfloat *)&fogcol); - + GLInterface.SetFogLinear((float*)&fogcol, fogresult, fogresult2); return; } fogcalc(shade, vis, pal); - glFogfv(GL_FOG_COLOR, (GLfloat *)&fogcol); - if (r_usenewshading < 2) - glFogf(GL_FOG_DENSITY, fogresult); - else + if (r_usenewshading < 2) + { + GLInterface.SetFogExp2((float*)& fogcol, fogresult); + } + else { - glFogf(GL_FOG_START, fogresult); - glFogf(GL_FOG_END, fogresult2); - } + GLInterface.SetFogLinear((float*)& fogcol, fogresult, fogresult2); + } } void calc_and_apply_fog_factor(int32_t shade, int32_t vis, int32_t pal, float factor) @@ -987,25 +984,21 @@ void calc_and_apply_fog_factor(int32_t shade, int32_t vis, int32_t pal, float fa fogresult2 = -GL_FOG_MAX; // hide fog behind the camera } - glFogf(GL_FOG_START, fogresult); - glFogf(GL_FOG_END, fogresult2); - glFogfv(GL_FOG_COLOR, (GLfloat *)&fogcol); - - return; + GLInterface.SetFogLinear((float*)& fogcol, fogresult, fogresult2); + return; } // NOTE: for r_usenewshading >= 2, the fog beginning/ending distance results are // unused. fogcalc(shade, vis, pal); - glFogfv(GL_FOG_COLOR, (GLfloat *)&fogcol); - - if (r_usenewshading < 2) - glFogf(GL_FOG_DENSITY, fogresult*factor); - else - { - glFogf(GL_FOG_START, (GLfloat) FULLVIS_BEGIN); - glFogf(GL_FOG_END, (GLfloat) FULLVIS_END); - } + if (r_usenewshading < 2) + { + GLInterface.SetFogExp2((float*)& fogcol, fogresult*factor); + } + else + { + GLInterface.SetFogLinear((float*)& fogcol, FULLVIS_BEGIN, FULLVIS_END); + } } //////////////////// @@ -2397,11 +2390,11 @@ do polymost_setFogEnabled(false); - glDepthFunc(GL_EQUAL); + GLInterface.SetDepthFunc(Depth_Equal); polymost_drawpoly(dpxy, n, method_); - glDepthFunc(GL_LEQUAL); + GLInterface.SetDepthFunc(Depth_LessEqual); if (!nofog) polymost_setFogEnabled(true); @@ -5266,8 +5259,7 @@ void polymost_drawrooms() GLInterface.EnableBlend(false); GLInterface.EnableAlphaTest(false); GLInterface.EnableDepthTest(true); - glDepthFunc(GL_ALWAYS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS -// glDepthRange(0.0, 1.0); //<- this is more widely supported than glPolygonOffset + GLInterface.SetDepthFunc(Depth_Always); polymost_setBrightness(r_brightnesshack); @@ -5375,7 +5367,12 @@ void polymost_drawrooms() } } - if (n < 3) { glDepthFunc(GL_LEQUAL); videoEndDrawing(); return; } + if (n < 3) + { + GLInterface.SetDepthFunc(Depth_LessEqual); + videoEndDrawing(); + return; + } float sx[6], sy[6]; @@ -5506,9 +5503,8 @@ void polymost_drawrooms() bunchlast[closest] = bunchlast[numbunches]; } - glDepthFunc(GL_LEQUAL); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS -// glDepthRange(0.0, 1.0); //<- this is more widely supported than glPolygonOffset - polymost_identityrotmat(); + GLInterface.SetDepthFunc(Depth_LessEqual); + polymost_identityrotmat(); videoEndDrawing(); } @@ -7474,8 +7470,6 @@ static int osdcmd_cvar_set_polymost(osdcmdptr_t parm) gltexapplyprops(); else if (!Bstrcasecmp(parm->name, "r_texfilter")) gltexturemode(parm); - else if (!Bstrcasecmp(parm->name, "r_usenewshading")) - glFogi(GL_FOG_MODE, (r_usenewshading < 2) ? GL_EXP2 : GL_LINEAR); } return r; diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index ed89a26b1..f0d0da26c 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1081,8 +1081,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 - } + GLInterface.SetDepthFunc(Depth_LessEqual); + } if ((grhalfxdown10x >= 0) ^ ((globalorientation&8) != 0) ^ ((globalorientation&4) != 0)) @@ -1193,9 +1193,8 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) if (shadowHack) { - glDepthFunc(GL_LESS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS -// glDepthRange(0.0, 0.99999); - } + GLInterface.SetDepthFunc(Depth_Less); + } VSMatrix identity(0); GLInterface.SetMatrix(Matrix_ModelView, &identity); return 1; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index c497d89f7..17968b94d 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -22,7 +22,6 @@ void GLInstance::InitGLState(int fogmode, int multisample) glDisable(GL_DITHER); glEnable(GL_TEXTURE_2D); glHint(GL_FOG_HINT, GL_NICEST); - glFogi(GL_FOG_MODE, (fogmode < 2) ? GL_EXP2 : GL_LINEAR); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPixelStorei(GL_PACK_ALIGNMENT, 1); @@ -200,4 +199,25 @@ void GLInstance::SetCull(int type) void GLInstance::SetColor(float r, float g, float b, float a) { glColor4f(r, g, b, a); -} \ No newline at end of file +} + +void GLInstance::SetDepthFunc(int func) +{ + int f[] = { GL_ALWAYS, GL_LESS, GL_EQUAL, GL_LEQUAL }; + glDepthFunc(f[func]); +} + +void GLInstance::SetFogLinear(float* color, float start, float end) +{ + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogf(GL_FOG_START, start); + glFogf(GL_FOG_END, end); + glFogfv(GL_FOG_COLOR, color); +} + +void GLInstance::SetFogExp2(float* color, float coefficient) +{ + glFogi(GL_FOG_MODE, GL_EXP2); + glFogf(GL_FOG_DENSITY, coefficient); + glFogfv(GL_FOG_COLOR, color); +} diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index fceb0cdeb..a304072b2 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -68,6 +68,14 @@ enum ECull Cull_Back }; +enum EDepthFunc +{ + Depth_Always, + Depth_Less, + Depth_Equal, + Depth_LessEqual +}; + class GLInstance { enum @@ -128,6 +136,10 @@ public: { SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f)); } + + void SetDepthFunc(int func); + void SetFogLinear(float* color, float start, float end); + void SetFogExp2(float* color, float coefficient); }; extern GLInstance GLInterface;