]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
reenabled R_UpdateAllTextureInfo calls when lighting the world model
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 20 Dec 2007 09:49:37 +0000 (09:49 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 20 Dec 2007 09:49:37 +0000 (09:49 +0000)
(necessary because of submodel entities sharing texture_t's with the
world model)
some tweaks and cleanup of R_UpdateAllTextureInfo calls
reworked texture_t->currentpolygonoffset stuff

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7827 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
gl_rsurf.c
model_shared.c
model_shared.h
r_shadow.c
render.h

index 06f94247868e656abaf228003fff5c051e397e87..1a8a4999e737b4534602db2671382da3278e4174 100644 (file)
@@ -4157,17 +4157,6 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                t->specularscale = 0;
        }
 
-       t->currentpolygonfactor = r_refdef.polygonfactor + t->basepolygonfactor;
-       t->currentpolygonoffset = r_refdef.polygonoffset + t->basepolygonoffset;
-       // submodels are biased to avoid z-fighting with world surfaces that they
-       // may be exactly overlapping (avoids z-fighting artifacts on certain
-       // doors and things in Quake maps)
-       if (ent->model->brush.submodel)
-       {
-               t->currentpolygonfactor += r_polygonoffset_submodel_factor.value;
-               t->currentpolygonoffset += r_polygonoffset_submodel_offset.value;
-       }
-
        VectorClear(t->dlightcolor);
        t->currentnumlayers = 0;
        if (!(t->currentmaterialflags & MATERIALFLAG_NODRAW))
@@ -4393,6 +4382,13 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q
        rsurface.frameblend[1] = ent->frameblend[1];
        rsurface.frameblend[2] = ent->frameblend[2];
        rsurface.frameblend[3] = ent->frameblend[3];
+       rsurface.basepolygonfactor = r_refdef.polygonfactor;
+       rsurface.basepolygonoffset = r_refdef.polygonoffset;
+       if (ent->model->brush.submodel)
+       {
+               rsurface.basepolygonfactor += r_polygonoffset_submodel_factor.value;
+               rsurface.basepolygonoffset += r_polygonoffset_submodel_offset.value;
+       }
        if (model->surfmesh.isanimated && (rsurface.frameblend[0].lerp != 1 || rsurface.frameblend[0].frame != 0))
        {
                if (wanttangents)
@@ -5376,12 +5372,20 @@ static void RSurf_DrawBatch_GL11_VertexShade(int texturenumsurfaces, msurface_t
        RSurf_DrawBatch_Simple(texturenumsurfaces, texturesurfacelist);
 }
 
-static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, msurface_t **texturesurfacelist)
+void RSurf_SetupDepthAndCulling(void)
 {
+       // submodels are biased to avoid z-fighting with world surfaces that they
+       // may be exactly overlapping (avoids z-fighting artifacts on certain
+       // doors and things in Quake maps)
        GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
-       GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
+       GL_PolygonOffset(rsurface.basepolygonfactor + rsurface.texture->biaspolygonfactor, rsurface.basepolygonoffset + rsurface.texture->biaspolygonoffset);
        GL_DepthTest(!(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
        GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : r_view.cullface_back);
+}
+
+static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, msurface_t **texturesurfacelist)
+{
+       RSurf_SetupDepthAndCulling();
        if (rsurface.mode != RSURFMODE_SHOWSURFACES)
        {
                rsurface.mode = RSURFMODE_SHOWSURFACES;
@@ -5414,10 +5418,7 @@ static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, msurface_t **te
                // restore entity matrix
                R_Mesh_Matrix(&rsurface.matrix);
        }
-       GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
-       GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
-       GL_DepthTest(!(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
-       GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : r_view.cullface_back);
+       RSurf_SetupDepthAndCulling();
        GL_DepthMask(true);
        // LordHavoc: HalfLife maps have freaky skypolys so don't use
        // skymasking on them, and Quake3 never did sky masking (unlike
@@ -5857,9 +5858,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
                        GL_ColorMask(0,0,0,0);
                        GL_Color(1,1,1,1);
                }
-               GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
-               GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
-               GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : r_view.cullface_back);
+               RSurf_SetupDepthAndCulling();
                GL_DepthTest(true);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_DepthMask(true);
@@ -5881,10 +5880,8 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
        {
                if (rsurface.mode != RSURFMODE_MULTIPASS)
                        rsurface.mode = RSURFMODE_MULTIPASS;
-               GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
-               GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
+               RSurf_SetupDepthAndCulling();
                GL_DepthTest(true);
-               GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : r_view.cullface_back);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_DepthMask(writedepth);
                GL_Color(1,1,1,1);
@@ -5928,10 +5925,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
                // write depth for anything we skipped on the depth-only pass earlier
                if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
                        writedepth = true;
-               GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
-               GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
-               GL_DepthTest(!(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
-               GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : r_view.cullface_back);
+               RSurf_SetupDepthAndCulling();
                GL_BlendFunc(rsurface.texture->currentlayers[0].blendfunc1, rsurface.texture->currentlayers[0].blendfunc2);
                GL_DepthMask(writedepth && !(rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED));
                GL_AlphaTest((rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) != 0);
index 9dd089fed970d5449ce5a277eb8e8b8ed63b01d1..4afc3a07363060bc481539911a54baefae01bc4b 100644 (file)
@@ -899,8 +899,7 @@ void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
                info.pvs = info.model->brush.GetPVS(info.model, info.relativelightorigin);
        else
                info.pvs = NULL;
-       if (ent != r_refdef.worldentity)
-               R_UpdateAllTextureInfo(ent);
+       R_UpdateAllTextureInfo(ent);
 
        if (r_shadow_frontsidecasting.integer && r_shadow_compilingrtlight && r_shadow_realtime_world_compileportalculling.integer)
        {
@@ -963,8 +962,7 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
        // check the box in modelspace, it was already checked in worldspace
        if (!BoxesOverlap(model->normalmins, model->normalmaxs, lightmins, lightmaxs))
                return;
-       if (ent != r_refdef.worldentity)
-               R_UpdateAllTextureInfo(ent);
+       R_UpdateAllTextureInfo(ent);
        if (ent->model->brush.submodel)
                GL_PolygonOffset(r_refdef.shadowpolygonfactor + r_polygonoffset_submodel_factor.value, r_refdef.shadowpolygonoffset + r_polygonoffset_submodel_offset.value);
        if (model->brush.shadowmesh)
@@ -1031,7 +1029,7 @@ static void R_Q1BSP_DrawLight_TransparentCallback(const entity_render_t *ent, co
        R_Shadow_RenderMode_End();
 }
 
-#define RSURF_MAX_BATCHSURFACES 1024
+#define RSURF_MAX_BATCHSURFACES 8192
 
 void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surfacelist, const unsigned char *trispvs)
 {
@@ -1044,14 +1042,6 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
        int batchelements[BATCHSIZE*3];
        texture_t *tex;
        CHECKGLERROR
-       if (ent == r_refdef.worldentity)
-               RSurf_ActiveWorldEntity();
-       else
-       {
-               RSurf_ActiveModelEntity(ent, true, true);
-               R_UpdateAllTextureInfo(ent);
-       }
-       CHECKGLERROR
        culltriangles = r_shadow_culltriangles.integer && !(ent->flags & RENDER_NOSELFSHADOW);
        element3i = rsurface.modelelement3i;
        // this is a double loop because non-visible surface skipping has to be
index 4f046300aab2bffedb9222bf16621418ec2d94b0..9deebc5ab343e2eb448b66a2fba746329b738972 100644 (file)
@@ -1717,7 +1717,7 @@ qboolean Mod_LoadTextureFromQ3Shader(texture_t *texture, const char *name, qbool
                if (shader->textureflags & Q3TEXTUREFLAG_TWOSIDED)
                        texture->basematerialflags |= MATERIALFLAG_NOSHADOW | MATERIALFLAG_NOCULLFACE;
                if (shader->textureflags & Q3TEXTUREFLAG_POLYGONOFFSET)
-                       texture->basepolygonoffset -= 2;
+                       texture->biaspolygonoffset -= 2;
                if (shader->textureflags & Q3TEXTUREFLAG_REFRACTION)
                        texture->basematerialflags |= MATERIALFLAG_REFRACTION;
                if (shader->textureflags & Q3TEXTUREFLAG_REFLECTION)
index 4020b2b716a096a6c844819a8368d1fb38e733f5..9ec9bf16e545ab6f55af169b358b4aa83965546e 100644 (file)
@@ -429,11 +429,10 @@ typedef struct texture_s
        // current material flags (updated each bmodel render)
        int currentmaterialflags;
 
-       // current PolygonOffset values for rendering this material
-       float currentpolygonfactor;
-       float currentpolygonoffset;
-       float basepolygonfactor;
-       float basepolygonoffset;
+       // PolygonOffset values for rendering this material
+       // (these are added to the r_refdef values and submodel values)
+       float biaspolygonfactor;
+       float biaspolygonoffset;
 
        // textures to use when rendering this material
        skinframe_t *currentskinframe;
index ebcb4601810e1c8867123ebc888a1847a543749e..4964cf58e648f620326e08072102385e655f524e 100644 (file)
@@ -2332,10 +2332,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles,
        }
        if ((ambientscale + diffusescale) * VectorLength2(lightcolorbase) + specularscale * VectorLength2(lightcolorbase) < (1.0f / 1048576.0f))
                return;
-       GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
-       GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);
-       GL_DepthTest(!(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
-       GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : r_view.cullface_back);
+       RSurf_SetupDepthAndCulling();
        nmap = rsurface.texture->currentskinframe->nmap;
        if (gl_lightmaps.integer)
                nmap = r_texture_blanknormalmap;
@@ -2833,13 +2830,14 @@ void R_Shadow_DrawWorldLight(int numsurfaces, int *surfacelist, const unsigned c
        r_refdef.worldmodel->DrawLight(r_refdef.worldentity, numsurfaces, surfacelist, trispvs);
 }
 
-void R_Shadow_DrawEntityLight(entity_render_t *ent, int numsurfaces, int *surfacelist)
+void R_Shadow_DrawEntityLight(entity_render_t *ent)
 {
        model_t *model = ent->model;
        if (!model->DrawLight)
                return;
 
        R_Shadow_SetupEntityLight(ent);
+       R_UpdateAllTextureInfo(ent);
 
        model->DrawLight(ent, model->nummodelsurfaces, model->surfacelist, NULL);
 }
@@ -3060,7 +3058,7 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                        // draw lighting in the unmasked areas
                        R_Shadow_RenderMode_Lighting(true, false);
                        for (i = 0;i < numlightentities_noselfshadow;i++)
-                               R_Shadow_DrawEntityLight(lightentities_noselfshadow[i], numsurfaces, surfacelist);
+                               R_Shadow_DrawEntityLight(lightentities_noselfshadow[i]);
 
                        // optionally draw the illuminated areas
                        // for performance analysis by level designers
@@ -3068,7 +3066,7 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                        {
                                R_Shadow_RenderMode_VisibleLighting(!r_showdisabledepthtest.integer, false);
                                for (i = 0;i < numlightentities_noselfshadow;i++)
-                                       R_Shadow_DrawEntityLight(lightentities_noselfshadow[i], numsurfaces, surfacelist);
+                                       R_Shadow_DrawEntityLight(lightentities_noselfshadow[i]);
                        }
 
                        R_Shadow_RenderMode_StencilShadowVolumes(false);
@@ -3083,7 +3081,7 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                        if (numsurfaces)
                                R_Shadow_DrawWorldLight(numsurfaces, surfacelist, lighttrispvs);
                        for (i = 0;i < numlightentities;i++)
-                               R_Shadow_DrawEntityLight(lightentities[i], numsurfaces, surfacelist);
+                               R_Shadow_DrawEntityLight(lightentities[i]);
 
                        // optionally draw the illuminated areas
                        // for performance analysis by level designers
@@ -3093,7 +3091,7 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                                if (numsurfaces)
                                        R_Shadow_DrawWorldLight(numsurfaces, surfacelist, lighttrispvs);
                                for (i = 0;i < numlightentities;i++)
-                                       R_Shadow_DrawEntityLight(lightentities[i], numsurfaces, surfacelist);
+                                       R_Shadow_DrawEntityLight(lightentities[i]);
                        }
                }
        }
@@ -3106,9 +3104,9 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                        if (numsurfaces)
                                R_Shadow_DrawWorldLight(numsurfaces, surfacelist, lighttrispvs);
                        for (i = 0;i < numlightentities;i++)
-                               R_Shadow_DrawEntityLight(lightentities[i], numsurfaces, surfacelist);
+                               R_Shadow_DrawEntityLight(lightentities[i]);
                        for (i = 0;i < numlightentities_noselfshadow;i++)
-                               R_Shadow_DrawEntityLight(lightentities_noselfshadow[i], numsurfaces, surfacelist);
+                               R_Shadow_DrawEntityLight(lightentities_noselfshadow[i]);
 
                        // optionally draw the illuminated areas
                        // for performance analysis by level designers
@@ -3118,9 +3116,9 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                                if (numsurfaces)
                                        R_Shadow_DrawWorldLight(numsurfaces, surfacelist, lighttrispvs);
                                for (i = 0;i < numlightentities;i++)
-                                       R_Shadow_DrawEntityLight(lightentities[i], numsurfaces, surfacelist);
+                                       R_Shadow_DrawEntityLight(lightentities[i]);
                                for (i = 0;i < numlightentities_noselfshadow;i++)
-                                       R_Shadow_DrawEntityLight(lightentities_noselfshadow[i], numsurfaces, surfacelist);
+                                       R_Shadow_DrawEntityLight(lightentities_noselfshadow[i]);
                        }
                }
        }
index d60e8e407ff9455ed41f904b113cf6c93a3bdfdf..49d3c3620aa4a2f1e203a11f78f90bf0e948b8be 100644 (file)
--- a/render.h
+++ b/render.h
@@ -307,6 +307,9 @@ typedef struct rsurfacestate_s
        vec3_t colormap_shirtcolor;
        // view location in model space
        vec3_t modelorg; // TODO: rename this
+       // polygon offset data for submodels
+       float basepolygonfactor;
+       float basepolygonoffset;
        // current texture in batching code
        texture_t *texture;
        // whether lightmapping is active on this batch
@@ -343,6 +346,7 @@ extern rsurfacestate_t rsurface;
 void RSurf_ActiveWorldEntity(void);
 void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, qboolean wanttangents);
 void RSurf_CleanUp(void);
+void RSurf_SetupDepthAndCulling(void);
 
 void R_Mesh_ResizeArrays(int newvertices);