cleaned up GL_DepthTest and GL_CULL_FACE state management (by adding GL_CullFace...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 23 Nov 2006 19:35:52 +0000 (19:35 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 23 Nov 2006 19:35:52 +0000 (19:35 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6624 d7cf8633-e32d-0410-b094-e92efae38249

cl_particles.c
cl_screen.c
gl_backend.c
gl_backend.h
gl_draw.c
gl_rmain.c
gl_rsurf.c
r_explosion.c
r_shadow.c
todo

index 85ad184..cf1e271 100644 (file)
@@ -2033,6 +2033,7 @@ void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtligh
        R_Mesh_ColorPointer(particle_color4f);
        GL_DepthMask(false);
        GL_DepthTest(true);
+       GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
 
        // first generate all the vertices at once
        for (surfacelistindex = 0, v3f = particle_vertex3f, t2f = particle_texcoord2f, c4f = particle_color4f;surfacelistindex < numsurfaces;surfacelistindex++, v3f += 3*4, t2f += 2*4, c4f += 4*4)
index 164ed0c..6f9fd9a 100644 (file)
@@ -1614,7 +1614,6 @@ void SCR_UpdateLoadingScreen (void)
        qglColorMask(1,1,1,1);CHECKGLERROR
        //qglClearColor(0,0,0,0);CHECKGLERROR
        //qglClear(GL_COLOR_BUFFER_BIT);CHECKGLERROR
-       //qglCullFace(GL_FRONT);CHECKGLERROR
        //qglDisable(GL_CULL_FACE);CHECKGLERROR
        //R_ClearScreen();
        R_Textures_Frame();
index 96c341c..5770fb4 100644 (file)
@@ -341,6 +341,8 @@ gltextureunit_t;
 
 static struct gl_state_s
 {
+       int cullface;
+       int cullfaceenable;
        int blendfunc1;
        int blendfunc2;
        int blend;
@@ -467,6 +469,8 @@ void GL_Backend_ResetState(void)
        gl_state.lockrange_count = 0;
        gl_state.pointer_vertex = NULL;
        gl_state.pointer_color = NULL;
+       gl_state.cullface = GL_FRONT; // quake is backwards, this culls back faces
+       gl_state.cullfaceenable = true;
 
        CHECKGLERROR
 
@@ -475,7 +479,7 @@ void GL_Backend_ResetState(void)
        qglDisable(GL_ALPHA_TEST);CHECKGLERROR
        qglBlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);CHECKGLERROR
        qglDisable(GL_BLEND);CHECKGLERROR
-       qglCullFace(GL_FRONT);CHECKGLERROR
+       qglCullFace(gl_state.cullface);CHECKGLERROR
        qglEnable(GL_CULL_FACE);CHECKGLERROR
        qglDepthFunc(GL_LEQUAL);CHECKGLERROR
        qglEnable(GL_DEPTH_TEST);CHECKGLERROR
@@ -583,6 +587,35 @@ void GL_DepthTest(int state)
        }
 }
 
+void GL_CullFace(int state)
+{
+       if (gl_state.cullface != state)
+       {
+               CHECKGLERROR
+               if (state != GL_NONE)
+               {
+                       if (!gl_state.cullfaceenable)
+                       {
+                               gl_state.cullfaceenable = true;
+                               qglEnable(GL_CULL_FACE);CHECKGLERROR
+                       }
+                       if (gl_state.cullface != state)
+                       {
+                               gl_state.cullface = state;
+                               qglCullFace(state);CHECKGLERROR
+                       }
+               }
+               else
+               {
+                       if (gl_state.cullfaceenable)
+                       {
+                               gl_state.cullfaceenable = false;
+                               qglDisable(GL_CULL_FACE);CHECKGLERROR
+                       }
+               }
+       }
+}
+
 void GL_AlphaTest(int state)
 {
        if (gl_state.alphatest != state)
index 9a9be67..248c4ef 100644 (file)
@@ -17,6 +17,7 @@ void GL_SetupView_Mode_Ortho(double x1, double y1, double x2, double y2, double
 void GL_BlendFunc(int blendfunc1, int blendfunc2);
 void GL_DepthMask(int state);
 void GL_DepthTest(int state);
+void GL_CullFace(int state);
 void GL_AlphaTest(int state);
 void GL_ColorMask(int r, int g, int b, int a);
 void GL_Color(float cr, float cg, float cb, float ca);
index e918b88..a1374cd 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -542,6 +542,7 @@ static void _DrawQ_Setup(void)
        GL_SetupView_Mode_Ortho(0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100);
        qglDepthFunc(GL_LEQUAL);CHECKGLERROR
        qglDisable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
+       GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
        R_Mesh_Matrix(&identitymatrix);
 
        GL_DepthMask(true);
index c0f20c7..b43d665 100644 (file)
@@ -1179,7 +1179,7 @@ static void R_View_UpdateEntityVisible (void)
                for (i = 0;i < r_refdef.numentities;i++)
                {
                        ent = r_refdef.entities[i];
-                       r_viewcache.entityvisible[i] = !(ent->flags & renderimask) && !R_CullBox(ent->mins, ent->maxs) && (ent->effects & EF_NODEPTHTEST);
+                       r_viewcache.entityvisible[i] = !(ent->flags & renderimask) && !R_CullBox(ent->mins, ent->maxs);
                }
        }
 }
@@ -3309,10 +3309,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
        r_refdef.stats.entities_surfaces += texturenumsurfaces;
        CHECKGLERROR
        GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
-       if ((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE))
-       {
-               qglDisable(GL_CULL_FACE);CHECKGLERROR
-       }
+       GL_CullFace(((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE)) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
        if (r_showsurfaces.integer)
                R_DrawTextureSurfaceList_ShowSurfaces(texturenumsurfaces, texturesurfacelist);
        else if (rsurface_texture->currentmaterialflags & MATERIALFLAG_SKY)
@@ -3328,10 +3325,6 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
        }
        CHECKGLERROR
        GL_LockArrays(0, 0);
-       if ((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE))
-       {
-               qglEnable(GL_CULL_FACE);CHECKGLERROR
-       }
 }
 
 #define BATCHSIZE 256
index 117e136..0a083ab 100644 (file)
@@ -338,7 +338,7 @@ static void R_DrawPortal_Callback(const entity_render_t *ent, const rtlight_t *r
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthMask(false);
        GL_DepthTest(true);
-       qglDisable(GL_CULL_FACE);CHECKGLERROR
+       GL_CullFace(GL_NONE);
        R_Mesh_Matrix(&identitymatrix);
 
        numpoints = min(portal->numpoints, POLYGONELEMENTS_MAXPOINTS);
@@ -355,7 +355,6 @@ static void R_DrawPortal_Callback(const entity_render_t *ent, const rtlight_t *r
        for (i = 0, v = vertex3f;i < numpoints;i++, v += 3)
                VectorCopy(portal->points[i].position, v);
        R_Mesh_Draw(0, numpoints, numpoints - 2, polygonelements);
-       qglEnable(GL_CULL_FACE);CHECKGLERROR
 }
 
 // LordHavoc: this is just a nice debugging tool, very slow
@@ -874,7 +873,6 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
                        R_Shadow_RenderSurfacesLighting(batchnumsurfaces, batchsurfacelist);
                batchnumsurfaces = 0;
        }
-       qglEnable(GL_CULL_FACE);CHECKGLERROR
 }
 
 //Made by [515]
index 283bbe8..a504dd3 100644 (file)
@@ -188,6 +188,7 @@ static void R_DrawExplosion_TransparentCallback(const entity_render_t *ent, cons
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
        GL_DepthMask(false);
        GL_DepthTest(true);
+       GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
        R_Mesh_Matrix(&identitymatrix);
 
        R_Mesh_ColorPointer(NULL);
index 1e69661..f89bef9 100644 (file)
@@ -715,11 +715,11 @@ void R_Shadow_RenderVolume(int numvertices, int numtriangles, const float *verte
        if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCIL)
        {
                // decrement stencil if backface is behind depthbuffer
-               qglCullFace(GL_BACK);CHECKGLERROR // quake is backwards, this culls front faces
+               GL_CullFace(GL_BACK); // quake is backwards, this culls front faces
                qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);CHECKGLERROR
                R_Mesh_Draw(0, numvertices, numtriangles, element3i);
                // increment stencil if frontface is behind depthbuffer
-               qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
+               GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
                qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);CHECKGLERROR
        }
        R_Mesh_Draw(0, numvertices, numtriangles, element3i);
@@ -821,10 +821,7 @@ void R_Shadow_RenderMode_Begin(void)
        R_Mesh_ResetTextureState();
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(false);
-       GL_DepthTest(true);
        GL_Color(0, 0, 0, 1);
-       qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
-       qglEnable(GL_CULL_FACE);CHECKGLERROR
        GL_Scissor(r_view.x, r_view.y, r_view.width, r_view.height);
 
        r_shadow_rendermode = R_SHADOW_RENDERMODE_NONE;
@@ -870,16 +867,14 @@ void R_Shadow_RenderMode_StencilShadowVolumes(void)
        GL_ColorMask(0, 0, 0, 0);
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(false);
-       GL_DepthTest(true);
        qglPolygonOffset(r_refdef.shadowpolygonfactor, r_refdef.shadowpolygonoffset);CHECKGLERROR
        qglDepthFunc(GL_LESS);CHECKGLERROR
-       qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
        qglEnable(GL_STENCIL_TEST);CHECKGLERROR
        qglStencilFunc(GL_ALWAYS, 128, ~0);CHECKGLERROR
        r_shadow_rendermode = r_shadow_shadowingrendermode;
        if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCILTWOSIDE)
        {
-               qglDisable(GL_CULL_FACE);CHECKGLERROR
+               GL_CullFace(GL_NONE);
                qglEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);CHECKGLERROR
                qglActiveStencilFaceEXT(GL_BACK);CHECKGLERROR // quake is backwards, this is front faces
                qglStencilMask(~0);CHECKGLERROR
@@ -890,7 +885,7 @@ void R_Shadow_RenderMode_StencilShadowVolumes(void)
        }
        else
        {
-               qglEnable(GL_CULL_FACE);CHECKGLERROR
+               GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
                qglStencilMask(~0);CHECKGLERROR
                // this is changed by every shadow render so its value here is unimportant
                qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);CHECKGLERROR
@@ -905,7 +900,6 @@ void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent)
        R_Shadow_RenderMode_Reset();
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
        GL_DepthMask(false);
-       GL_DepthTest(true);
        qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
        //qglDisable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
        GL_Color(1, 1, 1, 1);
@@ -918,8 +912,6 @@ void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent)
        {
                qglDepthFunc(GL_EQUAL);CHECKGLERROR
        }
-       qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
-       qglEnable(GL_CULL_FACE);CHECKGLERROR
        if (stenciltest)
        {
                qglEnable(GL_STENCIL_TEST);CHECKGLERROR
@@ -960,13 +952,10 @@ void R_Shadow_RenderMode_VisibleShadowVolumes(void)
        R_Shadow_RenderMode_Reset();
        GL_BlendFunc(GL_ONE, GL_ONE);
        GL_DepthMask(false);
-       GL_DepthTest(!r_showdisabledepthtest.integer);
        qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
        GL_Color(0.0, 0.0125 * r_view.colorscale, 0.1 * r_view.colorscale, 1);
        GL_ColorMask(r_view.colormask[0], r_view.colormask[1], r_view.colormask[2], 1);
        qglDepthFunc(GL_GEQUAL);CHECKGLERROR
-       qglCullFace(GL_FRONT);CHECKGLERROR // this culls back
-       qglDisable(GL_CULL_FACE);CHECKGLERROR
        qglDisable(GL_STENCIL_TEST);CHECKGLERROR
        r_shadow_rendermode = R_SHADOW_RENDERMODE_VISIBLEVOLUMES;
 }
@@ -977,7 +966,6 @@ void R_Shadow_RenderMode_VisibleLighting(qboolean stenciltest, qboolean transpar
        R_Shadow_RenderMode_Reset();
        GL_BlendFunc(GL_ONE, GL_ONE);
        GL_DepthMask(false);
-       GL_DepthTest(!r_showdisabledepthtest.integer);
        qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
        GL_Color(0.1 * r_view.colorscale, 0.0125 * r_view.colorscale, 0, 1);
        GL_ColorMask(r_view.colormask[0], r_view.colormask[1], r_view.colormask[2], 1);
@@ -989,8 +977,6 @@ void R_Shadow_RenderMode_VisibleLighting(qboolean stenciltest, qboolean transpar
        {
                qglDepthFunc(GL_EQUAL);CHECKGLERROR
        }
-       qglCullFace(GL_FRONT);CHECKGLERROR // this culls back
-       qglEnable(GL_CULL_FACE);CHECKGLERROR
        if (stenciltest)
        {
                qglEnable(GL_STENCIL_TEST);CHECKGLERROR
@@ -1009,15 +995,12 @@ void R_Shadow_RenderMode_End(void)
        R_Shadow_RenderMode_ActiveLight(NULL);
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(true);
-       GL_DepthTest(true);
        qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
        //qglDisable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
        GL_Color(1, 1, 1, 1);
        GL_ColorMask(r_view.colormask[0], r_view.colormask[1], r_view.colormask[2], 1);
        GL_Scissor(r_view.x, r_view.y, r_view.width, r_view.height);
        qglDepthFunc(GL_LEQUAL);CHECKGLERROR
-       qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
-       qglEnable(GL_CULL_FACE);CHECKGLERROR
        qglDisable(GL_STENCIL_TEST);CHECKGLERROR
        qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);CHECKGLERROR
        if (gl_support_stenciltwoside)
@@ -1981,14 +1964,8 @@ void R_Shadow_RenderSurfacesLighting(int numsurfaces, msurface_t **surfacelist)
        lightcolorbase[2] = r_shadow_rtlight->currentcolor[2] * rsurface_entity->colormod[2] * rsurface_texture->currentalpha;
        if ((r_shadow_rtlight->ambientscale + r_shadow_rtlight->diffusescale) * VectorLength2(lightcolorbase) + (r_shadow_rtlight->specularscale * rsurface_texture->specularscale) * VectorLength2(lightcolorbase) < (1.0f / 1048576.0f))
                return;
-       if ((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE))
-       {
-               qglDisable(GL_CULL_FACE);CHECKGLERROR
-       }
-       else
-       {
-               qglEnable(GL_CULL_FACE);CHECKGLERROR
-       }
+       GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
+       GL_CullFace(((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE)) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
        if (rsurface_texture->colormapping)
        {
                qboolean dopants = rsurface_texture->skin.pants != NULL && VectorLength2(rsurface_entity->colormap_pantscolor) >= (1.0f / 1048576.0f);
@@ -2012,6 +1989,7 @@ void R_Shadow_RenderSurfacesLighting(int numsurfaces, msurface_t **surfacelist)
                switch (r_shadow_rendermode)
                {
                case R_SHADOW_RENDERMODE_VISIBLELIGHTING:
+                       GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST) && !r_showdisabledepthtest.integer);
                        R_Shadow_RenderSurfacesLighting_VisibleLighting(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->skin.pants, rsurface_texture->skin.shirt, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
                        break;
                case R_SHADOW_RENDERMODE_LIGHT_GLSL:
@@ -2033,6 +2011,7 @@ void R_Shadow_RenderSurfacesLighting(int numsurfaces, msurface_t **surfacelist)
                switch (r_shadow_rendermode)
                {
                case R_SHADOW_RENDERMODE_VISIBLELIGHTING:
+                       GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST) && !r_showdisabledepthtest.integer);
                        R_Shadow_RenderSurfacesLighting_VisibleLighting(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
                        break;
                case R_SHADOW_RENDERMODE_LIGHT_GLSL:
@@ -2209,11 +2188,11 @@ void R_Shadow_DrawEntityShadow(entity_render_t *ent, int numsurfaces, int *surfa
                                if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCIL)
                                {
                                        // decrement stencil if backface is behind depthbuffer
-                                       qglCullFace(GL_BACK);CHECKGLERROR // quake is backwards, this culls front faces
+                                       GL_CullFace(GL_BACK); // quake is backwards, this culls front faces
                                        qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);CHECKGLERROR
                                        R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i);
                                        // increment stencil if frontface is behind depthbuffer
-                                       qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
+                                       GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
                                        qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);CHECKGLERROR
                                }
                                R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i);
diff --git a/todo b/todo
index 9a71980..868cb5d 100644 (file)
--- a/todo
+++ b/todo
@@ -33,6 +33,7 @@
 -d (yummyluv) feature darkplaces protocol: add buttons 9-16 (yummyluv)
 -f (James D) bug darkplaces server: losing runes on episode completion, completing episode 1 then 2 then 3 causes it to forget 1, then 4 causes it to forget 2 and 3, making it impossible to open the boss gate (James D)
 -f (Wazat) bug darkplaces: client's slowmo detection (measuring packet times and comparing to game time changes) may be making the game unpleasant (Wazat)
+0 bug hmap2: handle \" properly in hmap2 cmdlib.c COM_Parse (sort)
 0 bug darkplaces client: GAME_NEHAHRA: make sure cutscenes and movies work, got a report of seeing a black screen (NightFright)
 0 bug darkplaces client: hipnotic: health is one character to the right on the sbar, covering up the key icons (M`Shacron)
 0 bug darkplaces client: it has been reported that sometimes level changes on quakeworld servers don't load a map, this may be related to downloading? (Baker)