From 662d0d2715b6071545d9c55fd3c89a949760fdfd Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 2 Feb 2004 02:43:21 +0000 Subject: [PATCH] now always uses glPolygonOffset, and collision brush rendering has been fixed with better glPolygonOffset settings (no more flicker), also uses glPolygonOffset on shadow volumes now (but this probably has any effect in any cases I know of) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3851 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 6 ++++++ gl_rsurf.c | 39 +++++++++++++++++++++++++++++++++------ r_shadow.c | 29 ++++++++++++++++++----------- 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index 952078c1..1629ed36 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -865,6 +865,9 @@ void R_RenderView (void) R_MoveExplosions(); R_TimeReport("mexplosion"); + qglPolygonOffset(0, 0); + qglEnable(GL_POLYGON_OFFSET_FILL); + R_Textures_Frame(); R_SetupFrame(); R_SetFrustum(); @@ -943,6 +946,9 @@ void R_RenderView (void) R_Mesh_Finish(); R_TimeReport("meshfinish"); + + qglPolygonOffset(0, 0); + qglDisable(GL_POLYGON_OFFSET_FILL); } /* diff --git a/gl_rsurf.c b/gl_rsurf.c index 255a49b3..c05b8794 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -35,7 +35,8 @@ cvar_t r_testvis = {0, "r_testvis", "0"}; cvar_t r_floatbuildlightmap = {0, "r_floatbuildlightmap", "0"}; cvar_t r_detailtextures = {CVAR_SAVE, "r_detailtextures", "1"}; cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "1"}; -cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "-4"}; +cvar_t r_drawcollisionbrushes_polygonfactor = {0, "r_drawcollisionbrushes_polygonfactor", "-1"}; +cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "0"}; static int dlightdivtable[32768]; @@ -1888,7 +1889,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_Lightmap(entity_render_t *ent, q3mface_t * { rmeshstate_t m; memset(&m, 0, sizeof(m)); - GL_BlendFunc(GL_ONE, GL_SRC_COLOR); + GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR); GL_DepthMask(true); GL_DepthTest(true); m.tex[0] = R_GetTexture(face->lightmaptexture); @@ -2083,21 +2084,42 @@ void R_Q3BSP_RecursiveWorldNode(entity_render_t *ent, q3mnode_t *node, const vec { int i; q3mleaf_t *leaf; - while (node->isnode) + for (;;) { if (R_CullBox(node->mins, node->maxs)) return; + if (!node->plane) + break; c_nodes++; R_Q3BSP_RecursiveWorldNode(ent, node->children[0], modelorg, pvs, markframe); node = node->children[1]; } - if (R_CullBox(node->mins, node->maxs)) - return; - c_leafs++; leaf = (q3mleaf_t *)node; if (pvs[leaf->clusterindex >> 3] & (1 << (leaf->clusterindex & 7))) + { + c_leafs++; for (i = 0;i < leaf->numleaffaces;i++) leaf->firstleafface[i]->markframe = markframe; + } +} + +// FIXME: num_leafs needs to be recalculated at load time to include only +// node-referenced leafs, as some maps are incorrectly compiled with leafs for +// the submodels (which would render the submodels occasionally, as part of +// the world - not good) +void R_Q3BSP_MarkLeafPVS(entity_render_t *ent, qbyte *pvs, int markframe) +{ + int i, j; + q3mleaf_t *leaf; + for (j = 0, leaf = ent->model->brushq3.data_leafs;j < ent->model->brushq3.num_leafs;j++, leaf++) + { + if (pvs[leaf->clusterindex >> 3] & (1 << (leaf->clusterindex & 7))) + { + c_leafs++; + for (i = 0;i < leaf->numleaffaces;i++) + leaf->firstleafface[i]->markframe = markframe; + } + } } static int r_q3bsp_framecount = -1; @@ -2120,6 +2142,7 @@ void R_Q3BSP_DrawSky(entity_render_t *ent) { r_q3bsp_framecount = r_framecount; R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, r_framecount); + //R_Q3BSP_MarkLeafPVS(ent, pvs, r_framecount); } for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++) if (face->markframe == r_framecount && (face->texture->surfaceflags & Q3SURFACEFLAG_SKY) && !R_CullBox(face->mins, face->maxs)) @@ -2150,6 +2173,7 @@ void R_Q3BSP_Draw(entity_render_t *ent) { r_q3bsp_framecount = r_framecount; R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, r_framecount); + //R_Q3BSP_MarkLeafPVS(ent, pvs, r_framecount); } for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++) if (face->markframe == r_framecount && !R_CullBox(face->mins, face->maxs)) @@ -2167,9 +2191,11 @@ void R_Q3BSP_Draw(entity_render_t *ent) GL_DepthMask(false); GL_DepthTest(true); R_Mesh_State_Texture(&m); + qglPolygonOffset(r_drawcollisionbrushes_polygonfactor.value, r_drawcollisionbrushes_polygonoffset.value); for (i = 0;i < model->brushq3.data_thismodel->numbrushes;i++) if (model->brushq3.data_thismodel->firstbrush[i].colbrushf && model->brushq3.data_thismodel->firstbrush[i].colbrushf->numtriangles) R_DrawCollisionBrush(model->brushq3.data_thismodel->firstbrush[i].colbrushf); + qglPolygonOffset(0, 0); } } @@ -2262,6 +2288,7 @@ void GL_Surf_Init(void) Cvar_RegisterVariable(&r_floatbuildlightmap); Cvar_RegisterVariable(&r_detailtextures); Cvar_RegisterVariable(&r_surfaceworldnode); + Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor); Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset); R_RegisterModule("GL_Surf", gl_surf_start, gl_surf_shutdown, gl_surf_newmap); diff --git a/r_shadow.c b/r_shadow.c index 9a9071a8..fcfcfcb4 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -160,7 +160,8 @@ cvar_t r_shadow_debuglight = {0, "r_shadow_debuglight", "-1"}; cvar_t r_shadow_scissor = {0, "r_shadow_scissor", "1"}; cvar_t r_shadow_bumpscale_bumpmap = {0, "r_shadow_bumpscale_bumpmap", "4"}; cvar_t r_shadow_bumpscale_basetexture = {0, "r_shadow_bumpscale_basetexture", "0"}; -cvar_t r_shadow_polygonoffset = {0, "r_shadow_polygonoffset", "0"}; +cvar_t r_shadow_polygonfactor = {0, "r_shadow_polygonfactor", "0"}; +cvar_t r_shadow_polygonoffset = {0, "r_shadow_polygonoffset", "1"}; cvar_t r_shadow_portallight = {0, "r_shadow_portallight", "1"}; cvar_t r_shadow_projectdistance = {0, "r_shadow_projectdistance", "10000"}; cvar_t r_shadow_texture3d = {0, "r_shadow_texture3d", "1"}; @@ -249,6 +250,7 @@ void R_Shadow_Help_f(void) "r_shadow_scissor : use scissor optimization\n" "r_shadow_bumpscale_bumpmap : depth scale for bumpmap conversion\n" "r_shadow_bumpscale_basetexture : base texture as bumpmap with this scale\n" +"r_shadow_polygonfactor : nudge shadow volumes closer/further\n" "r_shadow_polygonoffset : nudge shadow volumes closer/further\n" "r_shadow_portallight : use portal visibility for static light precomputation\n" "r_shadow_projectdistance : shadow volume projection distance\n" @@ -275,6 +277,7 @@ void R_Shadow_Init(void) Cvar_RegisterVariable(&r_shadow_scissor); Cvar_RegisterVariable(&r_shadow_bumpscale_bumpmap); Cvar_RegisterVariable(&r_shadow_bumpscale_basetexture); + Cvar_RegisterVariable(&r_shadow_polygonfactor); Cvar_RegisterVariable(&r_shadow_polygonoffset); Cvar_RegisterVariable(&r_shadow_portallight); Cvar_RegisterVariable(&r_shadow_projectdistance); @@ -862,13 +865,14 @@ void R_Shadow_Stage_ShadowVolumes(void) GL_BlendFunc(GL_ONE, GL_ZERO); GL_DepthMask(false); GL_DepthTest(true); - if (r_shadow_polygonoffset.value != 0) - { - qglPolygonOffset(1.0f, r_shadow_polygonoffset.value); - qglEnable(GL_POLYGON_OFFSET_FILL); - } - else - qglDisable(GL_POLYGON_OFFSET_FILL); + qglPolygonOffset(r_shadow_polygonfactor.value, r_shadow_polygonoffset.value); + //if (r_shadow_polygonoffset.value != 0) + //{ + // qglPolygonOffset(r_shadow_polygonfactor.value, r_shadow_polygonoffset.value); + // qglEnable(GL_POLYGON_OFFSET_FILL); + //} + //else + // qglDisable(GL_POLYGON_OFFSET_FILL); qglDepthFunc(GL_LESS); qglCullFace(GL_FRONT); // quake is backwards, this culls back faces qglEnable(GL_STENCIL_TEST); @@ -894,7 +898,8 @@ void R_Shadow_Stage_LightWithoutShadows(void) GL_BlendFunc(GL_ONE, GL_ONE); GL_DepthMask(false); GL_DepthTest(true); - qglDisable(GL_POLYGON_OFFSET_FILL); + qglPolygonOffset(0, 0); + //qglDisable(GL_POLYGON_OFFSET_FILL); GL_Color(1, 1, 1, 1); qglColorMask(1, 1, 1, 1); qglDepthFunc(GL_EQUAL); @@ -914,7 +919,8 @@ void R_Shadow_Stage_LightWithShadows(void) GL_BlendFunc(GL_ONE, GL_ONE); GL_DepthMask(false); GL_DepthTest(true); - qglDisable(GL_POLYGON_OFFSET_FILL); + qglPolygonOffset(0, 0); + //qglDisable(GL_POLYGON_OFFSET_FILL); GL_Color(1, 1, 1, 1); qglColorMask(1, 1, 1, 1); qglDepthFunc(GL_EQUAL); @@ -936,7 +942,8 @@ void R_Shadow_Stage_End(void) GL_BlendFunc(GL_ONE, GL_ZERO); GL_DepthMask(true); GL_DepthTest(true); - qglDisable(GL_POLYGON_OFFSET_FILL); + qglPolygonOffset(0, 0); + //qglDisable(GL_POLYGON_OFFSET_FILL); GL_Color(1, 1, 1, 1); qglColorMask(1, 1, 1, 1); qglDisable(GL_SCISSOR_TEST); -- 2.39.2