From 6a906fe49ae760f8a4096fd2171139e79ac3bf7a Mon Sep 17 00:00:00 2001 From: lordhavoc Date: Tue, 26 Mar 2002 00:47:44 +0000 Subject: [PATCH] minor speed increase in surface shaders, by splitting out surfaces with and without fullbrights into different shader code git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@1678 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rsurf.c | 163 ++++++++++++++++++++++++++++++++++++++++++++------ model_brush.c | 24 ++++++-- model_brush.h | 4 ++ 3 files changed, 169 insertions(+), 22 deletions(-) diff --git a/gl_rsurf.c b/gl_rsurf.c index 6a965011..ca1d14d9 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -874,8 +874,28 @@ static int RSurfShader_Water(int stage, msurface_t *s) RSurfShader_Water_Pass_Base(s); return false; case 1: - if (s->currenttexture->glowtexture) - RSurfShader_Water_Pass_Glow(s); + if (fogenabled) + { + if (currentrenderentity->alpha * (s->flags & SURF_DRAWNOALPHA ? 1 : r_wateralpha.value) >= 1.0f) + RSurfShader_Water_Pass_Fog(s); + return false; + } + else + return true; + default: + return true; + } +} + +static int RSurfShader_Water_Glow(int stage, msurface_t *s) +{ + switch(stage) + { + case 0: + RSurfShader_Water_Pass_Base(s); + return false; + case 1: + RSurfShader_Water_Pass_Glow(s); return false; case 2: if (fogenabled) @@ -1427,15 +1447,24 @@ static void RSurfShader_Wall_Pass_Fog(msurface_t *s) static int RSurfShader_Wall_Fullbright(int stage, msurface_t *s) { if (stage == 0) + { c_brush_polys++; + RSurfShader_Wall_Pass_BaseFullbright(s); + return false; + } + return true; +} + +static int RSurfShader_Wall_Fullbright_Glow(int stage, msurface_t *s) +{ switch(stage) { case 0: + c_brush_polys++; RSurfShader_Wall_Pass_BaseFullbright(s); return false; case 1: - if (s->currenttexture->glowtexture) - RSurfShader_Wall_Pass_Glow(s); + RSurfShader_Wall_Pass_Glow(s); return false; default: return true; @@ -1445,15 +1474,24 @@ static int RSurfShader_Wall_Fullbright(int stage, msurface_t *s) static int RSurfShader_Wall_Vertex(int stage, msurface_t *s) { if (stage == 0) + { c_brush_polys++; + RSurfShader_Wall_Pass_BaseVertex(s); + return false; + } + return true; +} + +static int RSurfShader_Wall_Vertex_Glow(int stage, msurface_t *s) +{ switch(stage) { case 0: + c_brush_polys++; RSurfShader_Wall_Pass_BaseVertex(s); return false; case 1: - if (s->currenttexture->glowtexture) - RSurfShader_Wall_Pass_Glow(s); + RSurfShader_Wall_Pass_Glow(s); return false; default: return true; @@ -1461,6 +1499,96 @@ static int RSurfShader_Wall_Vertex(int stage, msurface_t *s) } static int RSurfShader_Wall_Lightmap(int stage, msurface_t *s) +{ + if (r_vertexsurfaces.integer) + { + if (stage == 0) + { + c_brush_polys++; + RSurfShader_Wall_Pass_BaseVertex(s); + return false; + } + return true; + } + else if (r_multitexture.integer) + { + if (r_dlightmap.integer) + { + if (stage == 0) + { + c_brush_polys++; + RSurfShader_Wall_Pass_BaseMTex(s); + return false; + } + return true; + } + else + { + switch(stage) + { + case 0: + c_brush_polys++; + RSurfShader_Wall_Pass_BaseMTex(s); + return false; + case 1: + if (s->dlightframe == r_framecount) + RSurfShader_Wall_Pass_Light(s); + return false; + default: + return true; + } + } + } + else if (s->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1 || currentrenderentity->effects & EF_ADDITIVE) + { + if (stage == 0) + { + c_brush_polys++; + RSurfShader_Wall_Pass_BaseVertex(s); + return false; + } + return true; + } + else + { + if (r_dlightmap.integer) + { + switch(stage) + { + case 0: + c_brush_polys++; + RSurfShader_Wall_Pass_BaseTexture(s); + return false; + case 1: + RSurfShader_Wall_Pass_BaseLightmap(s); + return false; + default: + return true; + } + } + else + { + switch(stage) + { + case 0: + c_brush_polys++; + RSurfShader_Wall_Pass_BaseTexture(s); + return false; + case 1: + RSurfShader_Wall_Pass_BaseLightmap(s); + return false; + case 2: + if (s->dlightframe == r_framecount) + RSurfShader_Wall_Pass_Light(s); + return false; + default: + return true; + } + } + } +} + +static int RSurfShader_Wall_Lightmap_Glow(int stage, msurface_t *s) { if (stage == 0) c_brush_polys++; @@ -1472,8 +1600,7 @@ static int RSurfShader_Wall_Lightmap(int stage, msurface_t *s) RSurfShader_Wall_Pass_BaseVertex(s); return false; case 1: - if (s->currenttexture->glowtexture) - RSurfShader_Wall_Pass_Glow(s); + RSurfShader_Wall_Pass_Glow(s); return false; default: return true; @@ -1489,8 +1616,7 @@ static int RSurfShader_Wall_Lightmap(int stage, msurface_t *s) RSurfShader_Wall_Pass_BaseMTex(s); return false; case 1: - if (s->currenttexture->glowtexture) - RSurfShader_Wall_Pass_Glow(s); + RSurfShader_Wall_Pass_Glow(s); return false; default: return true; @@ -1508,8 +1634,7 @@ static int RSurfShader_Wall_Lightmap(int stage, msurface_t *s) RSurfShader_Wall_Pass_Light(s); return false; case 2: - if (s->currenttexture->glowtexture) - RSurfShader_Wall_Pass_Glow(s); + RSurfShader_Wall_Pass_Glow(s); return false; default: return true; @@ -1524,8 +1649,7 @@ static int RSurfShader_Wall_Lightmap(int stage, msurface_t *s) RSurfShader_Wall_Pass_BaseVertex(s); return false; case 1: - if (s->currenttexture->glowtexture) - RSurfShader_Wall_Pass_Glow(s); + RSurfShader_Wall_Pass_Glow(s); return false; default: return true; @@ -1544,8 +1668,7 @@ static int RSurfShader_Wall_Lightmap(int stage, msurface_t *s) RSurfShader_Wall_Pass_BaseLightmap(s); return false; case 2: - if (s->currenttexture->glowtexture) - RSurfShader_Wall_Pass_Glow(s); + RSurfShader_Wall_Pass_Glow(s); return false; default: return true; @@ -1566,8 +1689,7 @@ static int RSurfShader_Wall_Lightmap(int stage, msurface_t *s) RSurfShader_Wall_Pass_Light(s); return false; case 3: - if (s->currenttexture->glowtexture) - RSurfShader_Wall_Pass_Glow(s); + RSurfShader_Wall_Pass_Glow(s); return false; default: return true; @@ -1913,9 +2035,13 @@ loc1: } Cshader_t Cshader_wall_vertex = {{NULL, RSurfShader_Wall_Vertex, RSurfShader_Wall_Fog}, NULL}; +Cshader_t Cshader_wall_vertex_glow = {{NULL, RSurfShader_Wall_Vertex_Glow, RSurfShader_Wall_Fog}, NULL}; Cshader_t Cshader_wall_lightmap = {{NULL, RSurfShader_Wall_Lightmap, RSurfShader_Wall_Fog}, NULL}; +Cshader_t Cshader_wall_lightmap_glow = {{NULL, RSurfShader_Wall_Lightmap_Glow, RSurfShader_Wall_Fog}, NULL}; Cshader_t Cshader_wall_fullbright = {{NULL, RSurfShader_Wall_Fullbright, RSurfShader_Wall_Fog}, NULL}; +Cshader_t Cshader_wall_fullbright_glow = {{NULL, RSurfShader_Wall_Fullbright_Glow, RSurfShader_Wall_Fog}, NULL}; Cshader_t Cshader_water = {{NULL, RSurfShader_Water, NULL}, NULL}; +Cshader_t Cshader_water_glow = {{NULL, RSurfShader_Water_Glow, NULL}, NULL}; Cshader_t Cshader_sky = {{RSurfShader_Sky, NULL, NULL}, NULL}; int Cshader_count = 5; @@ -1975,6 +2101,7 @@ void R_DrawSurfaces (int type) { shader = Cshaders[i]; if (shader->chain && shader->shaderfunc[type]) + // shader->shaderfunc[type](shader->chain); for (stage = 0;stage < 1000;stage++) for (surf = shader->chain;surf;surf = surf->chain) if (shader->shaderfunc[type](stage, surf)) diff --git a/model_brush.c b/model_brush.c index 1760cb75..e42ec490 100644 --- a/model_brush.c +++ b/model_brush.c @@ -1244,7 +1244,10 @@ static void Mod_LoadFaces (lump_t *l) if (out->texinfo->texture->flags & SURF_DRAWTURB) { - out->shader = &Cshader_water; + if (out->texinfo->texture->glowtexture) + out->shader = &Cshader_water_glow; + else + out->shader = &Cshader_water; /* for (i=0 ; i<2 ; i++) { @@ -1262,6 +1265,10 @@ static void Mod_LoadFaces (lump_t *l) if (out->texinfo->flags & TEX_SPECIAL) { // qbsp couldn't find the texture for this surface, but it was either turb or sky... assume turb + if (out->texinfo->texture->glowtexture) + out->shader = &Cshader_water_glow; + else + out->shader = &Cshader_water; out->shader = &Cshader_water; out->samples = NULL; Mod_GenerateWarpMesh (out); @@ -1269,7 +1276,10 @@ static void Mod_LoadFaces (lump_t *l) else if ((out->extents[0]+1) > (256*16) || (out->extents[1]+1) > (256*16)) { Con_Printf ("Bad surface extents, converting to fullbright polygon"); - out->shader = &Cshader_wall_fullbright; + if (out->texinfo->texture->glowtexture) + out->shader = &Cshader_wall_fullbright_glow; + else + out->shader = &Cshader_wall_fullbright; out->samples = NULL; Mod_GenerateVertexMesh(out); } @@ -1281,12 +1291,18 @@ static void Mod_LoadFaces (lump_t *l) memset(out->stainsamples, 255, ssize * tsize * 3); if (out->extents[0] < r_vertexsurfacesthreshold.integer && out->extents[1] < r_vertexsurfacesthreshold.integer) { - out->shader = &Cshader_wall_vertex; + if (out->texinfo->texture->glowtexture) + out->shader = &Cshader_wall_vertex_glow; + else + out->shader = &Cshader_wall_vertex; Mod_GenerateVertexLitMesh(out); } else { - out->shader = &Cshader_wall_lightmap; + if (out->texinfo->texture->glowtexture) + out->shader = &Cshader_wall_lightmap_glow; + else + out->shader = &Cshader_wall_lightmap; Mod_GenerateLightmappedMesh(out); } } diff --git a/model_brush.h b/model_brush.h index cadbdcc8..0594fcd7 100644 --- a/model_brush.h +++ b/model_brush.h @@ -198,9 +198,13 @@ typedef struct Cshader_s Cshader_t; extern Cshader_t Cshader_wall_vertex; +extern Cshader_t Cshader_wall_vertex_glow; extern Cshader_t Cshader_wall_lightmap; +extern Cshader_t Cshader_wall_lightmap_glow; extern Cshader_t Cshader_wall_fullbright; +extern Cshader_t Cshader_wall_fullbright_glow; extern Cshader_t Cshader_water; +extern Cshader_t Cshader_water_glow; extern Cshader_t Cshader_sky; // warning: if this is changed, references must be updated in cpu_* assembly files -- 2.39.2