- moved decal rendering from GLWall to FDrawInfo.

First step of turning GLWall into a pure data container.
This commit is contained in:
Christoph Oelckers 2018-04-25 22:09:12 +02:00
parent 306b630de2
commit 41d5bd76d4
5 changed files with 90 additions and 88 deletions

View file

@ -51,8 +51,9 @@ struct DecalVertex
//
//
//==========================================================================
void GLWall::DrawDecal(DBaseDecal *decal)
void FDrawInfo::DrawDecal(GLWall *wall, DBaseDecal *decal)
{
auto seg = wall->seg;
line_t * line = seg->linedef;
side_t * side = seg->sidedef;
int i;
@ -66,7 +67,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
if (decal->RenderFlags & RF_INVISIBLE) return;
if (type==RENDERWALL_FFBLOCK && gltexture->isMasked()) return; // No decals on 3D floors with transparent textures.
if (wall->type == RENDERWALL_FFBLOCK && wall->gltexture->isMasked()) return; // No decals on 3D floors with transparent textures.
//if (decal->sprite != 0xffff)
{
@ -111,7 +112,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
//break;
case RF_RELUPPER:
if (type!=RENDERWALL_TOP) return;
if (wall->type != RENDERWALL_TOP) return;
if (line->flags & ML_DONTPEGTOP)
{
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling);
@ -122,7 +123,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
}
break;
case RF_RELLOWER:
if (type!=RENDERWALL_BOTTOM) return;
if (wall->type != RENDERWALL_BOTTOM) return;
if (line->flags & ML_DONTPEGBOTTOM)
{
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling);
@ -133,7 +134,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
}
break;
case RF_RELMID:
if (type==RENDERWALL_TOP || type==RENDERWALL_BOTTOM) return;
if (wall->type == RENDERWALL_TOP || wall->type == RENDERWALL_BOTTOM) return;
if (line->flags & ML_DONTPEGBOTTOM)
{
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::floor);
@ -151,11 +152,11 @@ void GLWall::DrawDecal(DBaseDecal *decal)
}
else
{
light = lightlevel;
rel = rellight + getExtraLight();
light = wall->lightlevel;
rel = wall->rellight + getExtraLight();
}
FColormap p = Colormap;
FColormap p = wall->Colormap;
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)
{
@ -172,7 +173,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
float decallefto = tex->GetLeftOffset() * decal->ScaleX;
float decaltopo = tex->GetTopOffset() * decal->ScaleY;
auto &glseg = wall->glseg;
float leftedge = glseg.fracleft * side->TexelLength;
float linelength = glseg.fracright * side->TexelLength - leftedge;
@ -227,11 +228,10 @@ void GLWall::DrawDecal(DBaseDecal *decal)
dv[3].u = dv[2].u = tex->GetU(righttex / decal->ScaleX);
dv[0].v = dv[3].v = tex->GetVB();
// now clip to the top plane
float vzt=(ztop[1]-ztop[0])/linelength;
float topleft=this->ztop[0]+vzt*left;
float topright=this->ztop[0]+vzt*right;
float vzt = (wall->ztop[1] - wall->ztop[0]) / linelength;
float topleft = wall->ztop[0] + vzt * left;
float topright = wall->ztop[0] + vzt * right;
// completely below the wall
if (topleft < dv[0].z && topright < dv[3].z)
@ -248,9 +248,9 @@ void GLWall::DrawDecal(DBaseDecal *decal)
}
// now clip to the bottom plane
float vzb=(zbottom[1]-zbottom[0])/linelength;
float bottomleft=this->zbottom[0]+vzb*left;
float bottomright=this->zbottom[0]+vzb*right;
float vzb = (wall->zbottom[1] - wall->zbottom[0]) / linelength;
float bottomleft = wall->zbottom[0] + vzb * left;
float bottomright = wall->zbottom[0] + vzb * right;
// completely above the wall
if (bottomleft > dv[1].z && bottomright > dv[2].z)
@ -284,7 +284,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
// Note: This should be replaced with proper shader based lighting.
double x, y;
decal->GetXY(seg->sidedef, x, y);
gl_SetDynSpriteLight(nullptr, x, y, zpos - decalheight * 0.5f, sub);
gl_SetDynSpriteLight(nullptr, x, y, zpos - decalheight * 0.5f, wall->sub);
}
// alpha color only has an effect when using an alpha texture.
@ -321,30 +321,32 @@ void GLWall::DrawDecal(DBaseDecal *decal)
qd.Set(i, dv[i].x, dv[i].z, dv[i].y, dv[i].u, dv[i].v);
}
if (lightlist == NULL)
if (wall->lightlist == nullptr)
{
gl_RenderState.Apply();
qd.Render(GL_TRIANGLE_FAN);
}
else
{
for (unsigned k = 0; k < lightlist->Size(); k++)
auto &lightlist = *wall->lightlist;
for (unsigned k = 0; k < lightlist.Size(); k++)
{
secplane_t &lowplane = k == (*lightlist).Size() - 1 ? bottomplane : (*lightlist)[k + 1].plane;
secplane_t &lowplane = k == lightlist.Size() - 1 ? wall->bottomplane : lightlist[k + 1].plane;
float low1 = lowplane.ZatPoint(dv[1].x, dv[1].y);
float low2 = lowplane.ZatPoint(dv[2].x, dv[2].y);
if (low1 < dv[1].z || low2 < dv[2].z)
{
int thisll = (*lightlist)[k].caster != NULL ? gl_ClampLight(*(*lightlist)[k].p_lightlevel) : lightlevel;
int thisll = lightlist[k].caster != NULL ? gl_ClampLight(*lightlist[k].p_lightlevel) : wall->lightlevel;
FColormap thiscm;
thiscm.FadeColor = Colormap.FadeColor;
thiscm.CopyFrom3DLight(&(*lightlist)[k]);
thiscm.FadeColor = wall->Colormap.FadeColor;
thiscm.CopyFrom3DLight(&lightlist[k]);
mDrawer->SetColor(thisll, rel, thiscm, a);
if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) thiscm.Decolorize();
mDrawer->SetFog(thisll, rel, &thiscm, RenderStyle == STYLE_Add);
gl_RenderState.SetSplitPlanes((*lightlist)[k].plane, lowplane);
mDrawer->SetFog(thisll, rel, &thiscm, wall->RenderStyle == STYLE_Add);
gl_RenderState.SetSplitPlanes(lightlist[k].plane, lowplane);
gl_RenderState.Apply();
qd.Render(GL_TRIANGLE_FAN);
@ -365,27 +367,27 @@ void GLWall::DrawDecal(DBaseDecal *decal)
//
//
//==========================================================================
void GLWall::DoDrawDecals()
void FDrawInfo::DoDrawDecals(GLWall *wall)
{
if (seg->sidedef && seg->sidedef->AttachedDecals)
if (wall->seg->sidedef && wall->seg->sidedef->AttachedDecals)
{
if (lightlist != NULL)
if (wall->lightlist != nullptr)
{
gl_RenderState.EnableSplit(true);
}
else
{
mDrawer->SetFog(lightlevel, rellight + getExtraLight(), &Colormap, false);
mDrawer->SetFog(wall->lightlevel, wall->rellight + getExtraLight(), &wall->Colormap, false);
}
DBaseDecal *decal = seg->sidedef->AttachedDecals;
DBaseDecal *decal = wall->seg->sidedef->AttachedDecals;
while (decal)
{
DrawDecal(decal);
DrawDecal(wall, decal);
decal = decal->WallNext;
}
if (lightlist != NULL)
if (wall->lightlist != nullptr)
{
gl_RenderState.EnableSplit(false);
}

View file

@ -879,7 +879,7 @@ void GLDrawList::DrawDecals()
{
for(unsigned i=0;i<drawitems.Size();i++)
{
walls[drawitems[i].index]->DoDrawDecals();
gl_drawinfo->DoDrawDecals(walls[drawitems[i].index]);
}
}

View file

@ -183,6 +183,9 @@ struct FDrawInfo : public HWDrawInfo
bool PutWallCompat(GLWall *wall, int passflag); // Legacy GL only.
void DrawDecal(GLWall *wall, DBaseDecal *decal);
void DoDrawDecals(GLWall *wall);
void StartScene();
void SetupFloodStencil(wallseg * ws);

View file

@ -257,9 +257,6 @@ private:
float fch1, float fch2, float ffh1, float ffh2,
float bch1, float bch2, float bfh1, float bfh2);
void DrawDecal(DBaseDecal *actor);
void DoDrawDecals();
void RenderFogBoundary();
void RenderMirrorSurface();
void RenderTranslucentWall();

View file

@ -297,7 +297,7 @@ void GLWall::RenderMirrorSurface()
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(-1.0f, -128.0f);
glDepthMask(false);
DoDrawDecals();
gl_drawinfo->DoDrawDecals(this);
glDepthMask(true);
glPolygonOffset(0.0f, 0.0f);
glDisable(GL_POLYGON_OFFSET_FILL);