From 369bccdb9b45de01e7d0ba4225e12884e0dc0951 Mon Sep 17 00:00:00 2001 From: divverent Date: Wed, 29 Sep 2010 07:10:49 +0000 Subject: [PATCH] fix lightmap switching/batching in fakelight git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10506 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 80 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 20 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index 52572fdf..bcdadb5e 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -12896,19 +12896,35 @@ static void R_DrawSurface_TransparentCallback(const entity_render_t *ent, const surface = rsurface.modelsurfaces + surfacelist[i]; texture = surface->texture; rsurface.texture = R_GetCurrentTexture(texture); - rsurface.lightmaptexture = FAKELIGHT_ENABLED ? NULL : surface->lightmaptexture; - rsurface.deluxemaptexture = surface->deluxemaptexture; - rsurface.uselightmaptexture = surface->lightmaptexture != NULL; // scan ahead until we find a different texture endsurface = min(i + MAXBATCH_TRANSPARENTSURFACES, numsurfaces); texturenumsurfaces = 0; texturesurfacelist[texturenumsurfaces++] = surface; - for (;j < endsurface;j++) + if(FAKELIGHT_ENABLED) { - surface = rsurface.modelsurfaces + surfacelist[j]; - if (texture != surface->texture || rsurface.lightmaptexture != surface->lightmaptexture) - break; - texturesurfacelist[texturenumsurfaces++] = surface; + rsurface.lightmaptexture = NULL; + rsurface.deluxemaptexture = NULL; + rsurface.uselightmaptexture = false; + for (;j < endsurface;j++) + { + surface = rsurface.modelsurfaces + surfacelist[j]; + if (texture != surface->texture) + break; + texturesurfacelist[texturenumsurfaces++] = surface; + } + } + else + { + rsurface.lightmaptexture = surface->lightmaptexture; + rsurface.deluxemaptexture = surface->deluxemaptexture; + rsurface.uselightmaptexture = surface->lightmaptexture != NULL; + for (;j < endsurface;j++) + { + surface = rsurface.modelsurfaces + surfacelist[j]; + if (texture != surface->texture || rsurface.lightmaptexture != surface->lightmaptexture) + break; + texturesurfacelist[texturenumsurfaces++] = surface; + } } // render the range of surfaces if (ent == r_refdef.scene.worldentity) @@ -13002,9 +13018,6 @@ void R_QueueWorldSurfaceList(int numsurfaces, const msurface_t **surfacelist, in // use skin 1 instead) texture = surfacelist[i]->texture; rsurface.texture = R_GetCurrentTexture(texture); - rsurface.lightmaptexture = FAKELIGHT_ENABLED ? NULL : surfacelist[i]->lightmaptexture; - rsurface.deluxemaptexture = surfacelist[i]->deluxemaptexture; - rsurface.uselightmaptexture = surfacelist[i]->lightmaptexture != NULL && !depthonly && !prepass; if (!(rsurface.texture->currentmaterialflags & flagsmask) || (rsurface.texture->currentmaterialflags & MATERIALFLAG_NODRAW)) { // if this texture is not the kind we want, skip ahead to the next one @@ -13012,9 +13025,24 @@ void R_QueueWorldSurfaceList(int numsurfaces, const msurface_t **surfacelist, in ; continue; } - // simply scan ahead until we find a different texture or lightmap state - for (;j < numsurfaces && texture == surfacelist[j]->texture && rsurface.lightmaptexture == surfacelist[j]->lightmaptexture;j++) - ; + if(FAKELIGHT_ENABLED) + { + rsurface.lightmaptexture = NULL; + rsurface.deluxemaptexture = NULL; + rsurface.uselightmaptexture = false; + // simply scan ahead until we find a different texture or lightmap state + for (;j < numsurfaces && texture == surfacelist[j]->texture;j++) + ; + } + else + { + rsurface.lightmaptexture = surfacelist[i]->lightmaptexture; + rsurface.deluxemaptexture = surfacelist[i]->deluxemaptexture; + rsurface.uselightmaptexture = surfacelist[i]->lightmaptexture != NULL && !depthonly && !prepass; + // simply scan ahead until we find a different texture or lightmap state + for (;j < numsurfaces && texture == surfacelist[j]->texture && rsurface.lightmaptexture == surfacelist[j]->lightmaptexture;j++) + ; + } // render the range of surfaces R_ProcessWorldTextureSurfaceList(j - i, surfacelist + i, writedepth, depthonly, prepass); } @@ -13066,9 +13094,6 @@ void R_QueueModelSurfaceList(entity_render_t *ent, int numsurfaces, const msurfa // use skin 1 instead) texture = surfacelist[i]->texture; rsurface.texture = R_GetCurrentTexture(texture); - rsurface.lightmaptexture = FAKELIGHT_ENABLED ? NULL : surfacelist[i]->lightmaptexture; - rsurface.deluxemaptexture = surfacelist[i]->deluxemaptexture; - rsurface.uselightmaptexture = surfacelist[i]->lightmaptexture != NULL && !depthonly && !prepass; if (!(rsurface.texture->currentmaterialflags & flagsmask) || (rsurface.texture->currentmaterialflags & MATERIALFLAG_NODRAW)) { // if this texture is not the kind we want, skip ahead to the next one @@ -13076,9 +13101,24 @@ void R_QueueModelSurfaceList(entity_render_t *ent, int numsurfaces, const msurfa ; continue; } - // simply scan ahead until we find a different texture or lightmap state - for (;j < numsurfaces && texture == surfacelist[j]->texture && rsurface.lightmaptexture == surfacelist[j]->lightmaptexture;j++) - ; + if(FAKELIGHT_ENABLED) + { + rsurface.lightmaptexture = NULL; + rsurface.deluxemaptexture = NULL; + rsurface.uselightmaptexture = false; + // simply scan ahead until we find a different texture or lightmap state + for (;j < numsurfaces && texture == surfacelist[j]->texture;j++) + ; + } + else + { + rsurface.lightmaptexture = surfacelist[i]->lightmaptexture; + rsurface.deluxemaptexture = surfacelist[i]->deluxemaptexture; + rsurface.uselightmaptexture = surfacelist[i]->lightmaptexture != NULL && !depthonly && !prepass; + // simply scan ahead until we find a different texture or lightmap state + for (;j < numsurfaces && texture == surfacelist[j]->texture && rsurface.lightmaptexture == surfacelist[j]->lightmaptexture;j++) + ; + } // render the range of surfaces R_ProcessModelTextureSurfaceList(j - i, surfacelist + i, writedepth, depthonly, ent, prepass); } -- 2.39.2