- remove some obsolete code from decal rendering.

- avoid rebinding the same texture multiple times, as there's considerable overhead in the texture manager.
- check gl_sort_textures only once per scene, not per draw list.
This commit is contained in:
Christoph Oelckers 2014-08-30 15:34:14 +02:00
parent 6a3cd6378a
commit 12160bd29c
7 changed files with 50 additions and 30 deletions

View file

@ -349,11 +349,15 @@ void GLWall::DrawDecal(DBaseDecal *decal)
//========================================================================== //==========================================================================
void GLWall::DoDrawDecals() void GLWall::DoDrawDecals()
{ {
DBaseDecal *decal = seg->sidedef->AttachedDecals; if (seg->sidedef && seg->sidedef->AttachedDecals)
while (decal)
{ {
DrawDecal(decal); gl_SetFog(lightlevel, rellight + getExtraLight(), &Colormap, false);
decal = decal->WallNext; DBaseDecal *decal = seg->sidedef->AttachedDecals;
while (decal)
{
DrawDecal(decal);
decal = decal->WallNext;
}
} }
} }

View file

@ -59,8 +59,6 @@
FDrawInfo * gl_drawinfo; FDrawInfo * gl_drawinfo;
CVAR(Bool, gl_sort_textures, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
//========================================================================== //==========================================================================
// //
// //
@ -811,6 +809,19 @@ void GLDrawList::DrawFlats(int pass)
RenderFlat.Unclock(); RenderFlat.Unclock();
} }
//==========================================================================
//
//
//
//==========================================================================
void GLDrawList::DrawDecals()
{
for(unsigned i=0;i<drawitems.Size();i++)
{
walls[drawitems[i].index].DoDrawDecals();
}
}
//========================================================================== //==========================================================================
// //
// Sorting the drawitems first by texture and then by light level. // Sorting the drawitems first by texture and then by light level.
@ -844,7 +855,7 @@ static int __cdecl difcmp (const void *a, const void *b)
void GLDrawList::SortWalls() void GLDrawList::SortWalls()
{ {
if (drawitems.Size()!=0 && gl_sort_textures) if (drawitems.Size() > 1)
{ {
sortinfo=this; sortinfo=this;
qsort(&drawitems[0], drawitems.Size(), sizeof(drawitems[0]), diwcmp); qsort(&drawitems[0], drawitems.Size(), sizeof(drawitems[0]), diwcmp);
@ -853,7 +864,7 @@ void GLDrawList::SortWalls()
void GLDrawList::SortFlats() void GLDrawList::SortFlats()
{ {
if (drawitems.Size()!=0 && gl_sort_textures) if (drawitems.Size() > 1)
{ {
sortinfo=this; sortinfo=this;
qsort(&drawitems[0], drawitems.Size(), sizeof(drawitems[0]), difcmp); qsort(&drawitems[0], drawitems.Size(), sizeof(drawitems[0]), difcmp);

View file

@ -32,7 +32,6 @@ enum Drawpasses
GLPASS_LIGHTSONLY, // only collect dynamic lights GLPASS_LIGHTSONLY, // only collect dynamic lights
GLPASS_PLAIN, // Main pass without dynamic lights GLPASS_PLAIN, // Main pass without dynamic lights
GLPASS_DECALS, // Draws a decal GLPASS_DECALS, // Draws a decal
GLPASS_DECALS_NOFOG,// Draws a decal without setting the fog (used for passes that need a fog layer)
GLPASS_TRANSLUCENT, // Draws translucent objects GLPASS_TRANSLUCENT, // Draws translucent objects
}; };
@ -130,6 +129,7 @@ public:
void Draw(int pass); void Draw(int pass);
void DrawWalls(int pass); void DrawWalls(int pass);
void DrawFlats(int pass); void DrawFlats(int pass);
void DrawDecals();
GLDrawList * next; GLDrawList * next;
} ; } ;

View file

@ -85,6 +85,7 @@ CVAR(Bool, gl_texture, true, 0)
CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Float, gl_mask_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_mask_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
EXTERN_CVAR (Int, screenblocks) EXTERN_CVAR (Int, screenblocks)
EXTERN_CVAR (Bool, cl_capfps) EXTERN_CVAR (Bool, cl_capfps)
@ -340,11 +341,14 @@ void FGLRenderer::RenderScene(int recursion)
gl_RenderState.EnableFog(true); gl_RenderState.EnableFog(true);
gl_RenderState.BlendFunc(GL_ONE,GL_ZERO); gl_RenderState.BlendFunc(GL_ONE,GL_ZERO);
gl_drawinfo->drawlists[GLDL_PLAINWALLS].SortWalls(); if (gl_sort_textures)
gl_drawinfo->drawlists[GLDL_PLAINFLATS].SortFlats(); {
gl_drawinfo->drawlists[GLDL_MASKEDWALLS].SortWalls(); gl_drawinfo->drawlists[GLDL_PLAINWALLS].SortWalls();
gl_drawinfo->drawlists[GLDL_MASKEDFLATS].SortFlats(); gl_drawinfo->drawlists[GLDL_PLAINFLATS].SortFlats();
gl_drawinfo->drawlists[GLDL_MASKEDWALLSOFS].SortWalls(); gl_drawinfo->drawlists[GLDL_MASKEDWALLS].SortWalls();
gl_drawinfo->drawlists[GLDL_MASKEDFLATS].SortFlats();
gl_drawinfo->drawlists[GLDL_MASKEDWALLSOFS].SortWalls();
}
// if we don't have a persistently mapped buffer, we have to process all the dynamic lights up front, // if we don't have a persistently mapped buffer, we have to process all the dynamic lights up front,
// so that we don't have to do repeated map/unmap calls on the buffer. // so that we don't have to do repeated map/unmap calls on the buffer.
@ -414,7 +418,7 @@ void FGLRenderer::RenderScene(int recursion)
glDepthMask(false); glDepthMask(false);
// this is the only geometry type on which decals can possibly appear // this is the only geometry type on which decals can possibly appear
gl_drawinfo->drawlists[GLDL_PLAINWALLS].Draw(GLPASS_DECALS); gl_drawinfo->drawlists[GLDL_PLAINWALLS].DrawDecals();
gl_RenderState.SetTextureMode(TM_MODULATE); gl_RenderState.SetTextureMode(TM_MODULATE);

View file

@ -395,18 +395,6 @@ void GLWall::Draw(int pass)
gl_RenderState.EnableGlow(false); gl_RenderState.EnableGlow(false);
break; break;
case GLPASS_DECALS:
case GLPASS_DECALS_NOFOG:
if (seg->sidedef && seg->sidedef->AttachedDecals)
{
if (pass==GLPASS_DECALS)
{
gl_SetFog(lightlevel, rellight + getExtraLight(), &Colormap, false);
}
DoDrawDecals();
}
break;
case GLPASS_TRANSLUCENT: case GLPASS_TRANSLUCENT:
switch (type) switch (type)
{ {

View file

@ -611,15 +611,27 @@ outl:
// //
//=========================================================================== //===========================================================================
static FMaterial *last;
static int lastclamp;
static int lasttrans;
static bool lastalpha;
void FMaterial::Bind(int clampmode, int translation, int overrideshader, bool alphatexture) void FMaterial::Bind(int clampmode, int translation, int overrideshader, bool alphatexture)
{ {
int usebright = false;
int shaderindex = overrideshader >= 0? overrideshader : mShaderIndex; int shaderindex = overrideshader >= 0? overrideshader : mShaderIndex;
gl_RenderState.SetShader(shaderindex, tex->gl_info.shaderspeed);
// avoid rebinding the same texture multiple times.
if (this == last && lastclamp == clampmode && translation == lasttrans && lastalpha == alphatexture) return;
last = this;
lastclamp = clampmode;
lastalpha = alphatexture;
lasttrans = translation;
int usebright = false;
int maxbound = 0; int maxbound = 0;
bool allowhires = tex->xScale == FRACUNIT && tex->yScale == FRACUNIT && clampmode <= CLAMP_XY && !mExpanded; bool allowhires = tex->xScale == FRACUNIT && tex->yScale == FRACUNIT && clampmode <= CLAMP_XY && !mExpanded;
gl_RenderState.SetShader(shaderindex, tex->gl_info.shaderspeed);
if (tex->bHasCanvas) clampmode = CLAMP_CAMTEX; if (tex->bHasCanvas) clampmode = CLAMP_CAMTEX;
else if (tex->bWarped && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; else if (tex->bWarped && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;

View file

@ -139,6 +139,7 @@ OptionMenu "GLTextureGLOptions"
Option "Precache GL textures", gl_precache, "YesNo" Option "Precache GL textures", gl_precache, "YesNo"
Option "Camera textures offscreen", gl_usefb, "OnOff" Option "Camera textures offscreen", gl_usefb, "OnOff"
Option "Trim sprite edges", gl_trimsprites, "OnOff" Option "Trim sprite edges", gl_trimsprites, "OnOff"
Option "Sort draw lists by texture", gl_sort_textures, "YesNo"
} }
OptionMenu "GLLightOptions" OptionMenu "GLLightOptions"