From dc779acdb5aafca183f74e09c5f5517800c701ea Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 5 Nov 2001 06:20:35 +0000 Subject: [PATCH] build the texture chains such that they get rendered front to back. seems to only get about 0.17% speedup in overkill (with just about every thing off), but it might make more of a difference in-game. --- include/QF/model.h | 1 + libs/video/renderer/gl/gl_rmisc.c | 11 +++---- libs/video/renderer/gl/gl_rsurf.c | 48 +++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/include/QF/model.h b/include/QF/model.h index b2bef5a79..16318170b 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -86,6 +86,7 @@ typedef struct texture_s int gl_texturenum; int gl_fb_texturenum; struct msurface_s *texturechain; // for gl_texsort drawing + struct msurface_s **texturechain_tail; int anim_total; // total tenths in sequence ( 0 = no) int anim_min, anim_max; // time for this frame min <=time< max struct texture_s *anim_next; // in the animation sequence diff --git a/libs/video/renderer/gl/gl_rmisc.c b/libs/video/renderer/gl/gl_rmisc.c index 3f88c81ae..451cfd2f2 100644 --- a/libs/video/renderer/gl/gl_rmisc.c +++ b/libs/video/renderer/gl/gl_rmisc.c @@ -194,14 +194,15 @@ R_NewMap (model_t *worldmodel, struct model_s **models, int num_models) skytexturenum = -1; mirrortexturenum = -1; for (i = 0; i < r_worldentity.model->numtextures; i++) { - if (!r_worldentity.model->textures[i]) + texture_t *tex = r_worldentity.model->textures[i]; + if (!tex) continue; - if (!strncmp (r_worldentity.model->textures[i]->name, "sky", 3)) + if (!strncmp (tex->name, "sky", 3)) skytexturenum = i; - if (!strncmp (r_worldentity.model->textures[i]->name, - "window02_1", 10)) + if (!strncmp (tex->name, "window02_1", 10)) mirrortexturenum = i; - r_worldentity.model->textures[i]->texturechain = NULL; + tex->texturechain = NULL; + tex->texturechain_tail = &tex->texturechain; } r_skyname = Cvar_FindVar ("r_skyname"); if (r_skyname != NULL) diff --git a/libs/video/renderer/gl/gl_rsurf.c b/libs/video/renderer/gl/gl_rsurf.c index 7044b4c92..440e7cb28 100644 --- a/libs/video/renderer/gl/gl_rsurf.c +++ b/libs/video/renderer/gl/gl_rsurf.c @@ -88,7 +88,28 @@ glpoly_t *lightmap_polys[MAX_LIGHTMAPS]; glRect_t lightmap_rectchange[MAX_LIGHTMAPS]; msurface_t *waterchain = NULL; +msurface_t **waterchain_tail = &waterchain; msurface_t *sky_chain; +msurface_t **sky_chain_tail; + +#define CHAIN_SURF_F2B(surf,chain) \ + do { \ + *(chain##_tail) = (surf); \ + (chain##_tail) = &(surf)->texturechain; \ + *(chain##_tail) = 0; \ + } while (0) + +#define CHAIN_SURF_B2F(surf,chain) \ + do { \ + (surf)->texturechain = (chain); \ + (chain) = (surf); \ + } while (0) + +#if 1 +# define CHAIN_SURF CHAIN_SURF_F2B +#else +# define CHAIN_SURF CHAIN_SURF_B2F +#endif // LordHavoc: place for gl_rsurf setup code @@ -582,6 +603,7 @@ R_DrawWaterSurfaces (void) } waterchain = NULL; + waterchain_tail = &waterchain; if (r_wateralpha->value < 1.0) { qfglDepthMask (GL_TRUE); @@ -598,12 +620,14 @@ DrawTextureChains (void) qfglDisable (GL_BLEND); for (i = 0; i < r_worldentity.model->numtextures; i++) { - if (!r_worldentity.model->textures[i]) + texture_t *tex = r_worldentity.model->textures[i]; + if (!tex) continue; - for (s = r_worldentity.model->textures[i]->texturechain; s; - s = s->texturechain) R_RenderBrushPoly (s); + for (s = tex->texturechain; s; s = s->texturechain) + R_RenderBrushPoly (s); - r_worldentity.model->textures[i]->texturechain = NULL; + tex->texturechain = NULL; + tex->texturechain_tail = &tex->texturechain; } qfglEnable (GL_BLEND); @@ -689,8 +713,7 @@ R_DrawBrushModel (entity_t *e) if (psurf->flags & SURF_DRAWTURB) { GL_WaterSurface (psurf); } else if (psurf->flags & SURF_DRAWSKY) { - psurf->texturechain = sky_chain; - sky_chain = psurf; + CHAIN_SURF (psurf, sky_chain); return; } else if (gl_mtex_active) { R_DrawMultitexturePoly (psurf); @@ -766,16 +789,16 @@ R_RecursiveWorldNode (mnode_t *node) continue; // wrong side if (surf->flags & SURF_DRAWTURB) { - surf->texturechain = waterchain; - waterchain = surf; + if (r_wateralpha->value < 1) + CHAIN_SURF_B2F (surf, waterchain); + else + CHAIN_SURF (surf, waterchain); } else if (surf->flags & SURF_DRAWSKY) { - surf->texturechain = sky_chain; - sky_chain = surf; + CHAIN_SURF (surf, sky_chain); } else if (gl_mtex_active) { R_DrawMultitexturePoly (surf); } else { - surf->texturechain = surf->texinfo->texture->texturechain; - surf->texinfo->texture->texturechain = surf; + CHAIN_SURF (surf, surf->texinfo->texture->texturechain); } } } @@ -799,6 +822,7 @@ R_DrawWorld (void) memset (fullbright_polys, 0, sizeof (fullbright_polys)); sky_chain = 0; + sky_chain_tail = &sky_chain; if (!gl_sky_clip->int_val) { R_DrawSky (); }