From 67fc35e7382c0b6a68b58a5e21a3077b6a63199d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 1 Feb 2016 01:49:49 +0100 Subject: [PATCH] - some cleanup of wall processing code. * removed SplitWall function * split PutWall into PutWall and PutPortal because none of the portal cases needs the overhead for normal walls. --- src/gl/scene/gl_sky.cpp | 22 ++++--- src/gl/scene/gl_wall.h | 20 +++--- src/gl/scene/gl_walls.cpp | 124 ++++++++++++++++---------------------- 3 files changed, 76 insertions(+), 90 deletions(-) diff --git a/src/gl/scene/gl_sky.cpp b/src/gl/scene/gl_sky.cpp index 7eeda5f3d..c020ab276 100644 --- a/src/gl/scene/gl_sky.cpp +++ b/src/gl/scene/gl_sky.cpp @@ -137,11 +137,12 @@ void GLSkyInfo::init(int sky1, PalEntry FadeColor) void GLWall::SkyPlane(sector_t *sector, int plane, bool allowreflect) { + int ptype = -1; FPortal *portal = sector->portals[plane]; if (portal != NULL) { if (GLPortal::instack[1 - plane]) return; - type = RENDERWALL_SECTORSTACK; + ptype = PORTALTYPE_SECTORSTACK; this->portal = portal; } else @@ -156,13 +157,13 @@ void GLWall::SkyPlane(sector_t *sector, int plane, bool allowreflect) if (!gl_noskyboxes && skyboxx && GLRenderer->mViewActor != skyboxx && !(skyboxx->flags&MF_JUSTHIT)) { - type = RENDERWALL_SKYBOX; + ptype = PORTALTYPE_SKYBOX; skybox = skyboxx; } else { skyinfo.init(sector->sky, Colormap.FadeColor); - type = RENDERWALL_SKY; + ptype = PORTALTYPE_SKY; sky = UniqueSkies.Get(&skyinfo); } } @@ -170,12 +171,14 @@ void GLWall::SkyPlane(sector_t *sector, int plane, bool allowreflect) { if ((plane == sector_t::ceiling && viewz > sector->ceilingplane.d) || (plane == sector_t::floor && viewz < -sector->floorplane.d)) return; - type = RENDERWALL_PLANEMIRROR; + ptype = PORTALTYPE_PLANEMIRROR; planemirror = plane == sector_t::ceiling ? §or->ceilingplane : §or->floorplane; } - else return; } - PutWall(0); + if (ptype != -1) + { + PutPortal(ptype); + } } @@ -189,22 +192,23 @@ void GLWall::SkyLine(line_t *line) { ASkyViewpoint * skyboxx = line->skybox; GLSkyInfo skyinfo; + int ptype; // JUSTHIT is used as an indicator that a skybox is in use. // This is to avoid recursion if (!gl_noskyboxes && skyboxx && GLRenderer->mViewActor != skyboxx && !(skyboxx->flags&MF_JUSTHIT)) { - type = RENDERWALL_SKYBOX; + ptype = PORTALTYPE_SKYBOX; skybox = skyboxx; } else { skyinfo.init(line->frontsector->sky, Colormap.FadeColor); - type = RENDERWALL_SKY; + ptype = PORTALTYPE_SKY; sky = UniqueSkies.Get(&skyinfo); } - PutWall(0); + PutPortal(ptype); } diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index 4d83e726b..d9ef91232 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -30,13 +30,7 @@ enum WallTypes RENDERWALL_M1S, RENDERWALL_M2S, RENDERWALL_BOTTOM, - RENDERWALL_SKY, RENDERWALL_FOGBOUNDARY, - RENDERWALL_HORIZON, - RENDERWALL_SKYBOX, - RENDERWALL_SECTORSTACK, - RENDERWALL_PLANEMIRROR, - RENDERWALL_MIRROR, RENDERWALL_MIRRORSURFACE, RENDERWALL_M2SNF, RENDERWALL_COLOR, @@ -44,6 +38,16 @@ enum WallTypes // Insert new types at the end! }; +enum PortalTypes +{ + PORTALTYPE_SKY, + PORTALTYPE_HORIZON, + PORTALTYPE_SKYBOX, + PORTALTYPE_SECTORSTACK, + PORTALTYPE_PLANEMIRROR, + PORTALTYPE_MIRROR, +}; + struct GLSeg { float x1,x2; @@ -159,7 +163,8 @@ public: private: void CheckGlowing(); - void PutWall(bool translucent); + void PutWall(sector_t *sec, bool translucent); + void PutPortal(int ptype); void CheckTexturePosition(); void SetupLights(); @@ -175,7 +180,6 @@ private: void SkyTop(seg_t * seg,sector_t * fs,sector_t * bs,vertex_t * v1,vertex_t * v2); void SkyBottom(seg_t * seg,sector_t * fs,sector_t * bs,vertex_t * v1,vertex_t * v2); - void SplitWall(sector_t * frontsector, bool translucent); void LightPass(); void SetHorizon(vertex_t * ul, vertex_t * ur, vertex_t * ll, vertex_t * lr); bool DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2); diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index ac90e6123..c8808e79b 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -96,57 +96,54 @@ void GLWall::CheckGlowing() // // //========================================================================== -void GLWall::PutWall(bool translucent) +void GLWall::PutWall(sector_t *sec, bool translucent) { - GLPortal * portal; int list; - static char passflag[]={ + static char passflag[] = { 0, //RENDERWALL_NONE, 1, //RENDERWALL_TOP, // unmasked 1, //RENDERWALL_M1S, // unmasked 2, //RENDERWALL_M2S, // depends on render and texture settings 1, //RENDERWALL_BOTTOM, // unmasked - 4, //RENDERWALL_SKYDOME, // special 3, //RENDERWALL_FOGBOUNDARY, // translucent - 4, //RENDERWALL_HORIZON, // special - 4, //RENDERWALL_SKYBOX, // special - 4, //RENDERWALL_SECTORSTACK, // special - 4, //RENDERWALL_PLANEMIRROR, // special - 4, //RENDERWALL_MIRROR, // special - 1, //RENDERWALL_MIRRORSURFACE, // only created here from RENDERWALL_MIRROR + 1, //RENDERWALL_MIRRORSURFACE, // only created from PORTALTYPE_MIRROR 2, //RENDERWALL_M2SNF, // depends on render and texture settings, no fog, used on mid texture lines with a fog boundary. 3, //RENDERWALL_COLOR, // translucent 2, //RENDERWALL_FFBLOCK // depends on render and texture settings }; - + + if (gltexture && gltexture->GetTransparent() && passflag[type] == 2) { translucent = true; } - if (gl_fixedcolormap) + if (gl_fixedcolormap) { // light planes don't get drawn with fullbright rendering - if (!gltexture && passflag[type]!=4) return; - + if (gltexture == NULL) return; Colormap.Clear(); } + else if (sec->e->XFloor.lightlist.Size() > 0 && gltexture != NULL) + { + lightlist = &sec->e->XFloor.lightlist; + } CheckGlowing(); if (translucent) // translucent walls { - viewdistance = P_AproxDistance( ((seg->linedef->v1->x+seg->linedef->v2->x)>>1) - viewx, - ((seg->linedef->v1->y+seg->linedef->v2->y)>>1) - viewy); + viewdistance = P_AproxDistance(((seg->linedef->v1->x + seg->linedef->v2->x) >> 1) - viewx, + ((seg->linedef->v1->y + seg->linedef->v2->y) >> 1) - viewy); gl_drawinfo->drawlists[GLDL_TRANSLUCENT].AddWall(this); } - else if (passflag[type]!=4) // non-translucent walls + else { bool masked; - masked = passflag[type]==1? false : (gltexture && gltexture->isMasked()); + masked = passflag[type] == 1 ? false : (gltexture && gltexture->isMasked()); if ((flags&GLWF_SKYHACK && type == RENDERWALL_M2S)) { @@ -159,18 +156,25 @@ void GLWall::PutWall(bool translucent) gl_drawinfo->drawlists[list].AddWall(this); } - else switch (type) + lightlist = NULL; +} + +void GLWall::PutPortal(int ptype) +{ + GLPortal * portal; + + switch (ptype) { // portals don't go into the draw list. // Instead they are added to the portal manager - case RENDERWALL_HORIZON: + case PORTALTYPE_HORIZON: horizon=UniqueHorizons.Get(horizon); portal=GLPortal::FindPortal(horizon); if (!portal) portal=new GLHorizonPortal(horizon); portal->AddLine(this); break; - case RENDERWALL_SKYBOX: + case PORTALTYPE_SKYBOX: portal = GLPortal::FindPortal(skybox); if (!portal) { @@ -181,12 +185,12 @@ void GLWall::PutWall(bool translucent) portal->AddLine(this); break; - case RENDERWALL_SECTORSTACK: + case PORTALTYPE_SECTORSTACK: portal = this->portal->GetGLPortal(); portal->AddLine(this); break; - case RENDERWALL_PLANEMIRROR: + case PORTALTYPE_PLANEMIRROR: if (GLPortal::PlaneMirrorMode * planemirror->c <=0) { //@sync-portal @@ -197,7 +201,7 @@ void GLWall::PutWall(bool translucent) } break; - case RENDERWALL_MIRROR: + case PORTALTYPE_MIRROR: portal=GLPortal::FindPortal(seg->linedef); if (!portal) portal=new GLMirrorPortal(seg->linedef); portal->AddLine(this); @@ -209,7 +213,7 @@ void GLWall::PutWall(bool translucent) } break; - case RENDERWALL_SKY: + case PORTALTYPE_SKY: portal=GLPortal::FindPortal(sky); if (!portal) portal=new GLSkyPortal(sky); portal->AddLine(this); @@ -217,26 +221,6 @@ void GLWall::PutWall(bool translucent) } } -//========================================================================== -// -// Splits a wall vertically if a 3D-floor -// creates different lighting across the wall -// -//========================================================================== - -void GLWall::SplitWall(sector_t * frontsector, bool translucent) -{ - - if (glseg.x1==glseg.x2 && glseg.y1==glseg.y2) - { - return; - } - lightlist=&frontsector->e->XFloor.lightlist; - PutWall(translucent); - lightlist = NULL; -} - - //========================================================================== // // @@ -262,7 +246,6 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) } else { - type = RENDERWALL_HORIZON; hi.plane.GetFromSector(fs, true); hi.lightlevel = gl_ClampLight(fs->GetCeilingLight()); hi.colormap = fs->ColorMap; @@ -277,7 +260,7 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) if (gl_fixedcolormap) hi.colormap.Clear(); horizon = &hi; - PutWall(0); + PutPortal(PORTALTYPE_HORIZON); } ztop[1] = ztop[0] = zbottom[0]; } @@ -291,7 +274,6 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) } else { - type = RENDERWALL_HORIZON; hi.plane.GetFromSector(fs, false); hi.lightlevel = gl_ClampLight(fs->GetFloorLight()); hi.colormap = fs->ColorMap; @@ -306,7 +288,7 @@ bool GLWall::DoHorizon(seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2) if (gl_fixedcolormap) hi.colormap.Clear(); horizon = &hi; - PutWall(0); + PutPortal(PORTALTYPE_HORIZON); } } return true; @@ -516,7 +498,7 @@ void GLWall::DoTexture(int _type,seg_t * seg, int peg, gltexture->GetTexCoordInfo(&tci, seg->sidedef->GetTextureXScale(texpos), seg->sidedef->GetTextureYScale(texpos)); - type = (seg->linedef->special == Line_Mirror && _type == RENDERWALL_M1S && gl_mirrors) ? RENDERWALL_MIRROR : _type; + type = _type; float floatceilingref = FIXED2FLOAT(ceilingrefheight + tci.RowOffset(seg->sidedef->GetTextureYOffset(texpos))); if (peg) floatceilingref += tci.mRenderHeight - FIXED2FLOAT(lh + v_offset); @@ -524,13 +506,16 @@ void GLWall::DoTexture(int _type,seg_t * seg, int peg, if (!SetWallCoordinates(seg, &tci, floatceilingref, topleft, topright, bottomleft, bottomright, seg->sidedef->GetTextureXOffset(texpos))) return; - CheckTexturePosition(); - - // Add this wall to the render list - sector_t * sec = sub? sub->sector : seg->frontsector; - - if (sec->e->XFloor.lightlist.Size()==0 || gl_fixedcolormap || !gltexture) PutWall(false); - else SplitWall(sec, false); + if (seg->linedef->special == Line_Mirror && _type == RENDERWALL_M1S && gl_mirrors) + { + PutPortal(PORTALTYPE_MIRROR); + } + else + { + CheckTexturePosition(); + // Add this wall to the render list + PutWall(sub ? sub->sector : seg->frontsector, false); + } glseg=glsave; flags&=~GLT_CLAMPY; @@ -728,12 +713,15 @@ void GLWall::DoMidTexture(seg_t * seg, bool drawfogboundary, { flags |= GLWF_NOSPLITUPPER|GLWF_NOSPLITLOWER; type=RENDERWALL_FOGBOUNDARY; - PutWall(true); - if (!gltexture) + FMaterial *savetex = gltexture; + gltexture = NULL; + PutWall(seg->frontsector, true); + if (!savetex) { flags &= ~(GLWF_NOSPLITUPPER|GLWF_NOSPLITLOWER); return; } + gltexture = savetex; type=RENDERWALL_M2SNF; } else type=RENDERWALL_M2S; @@ -818,8 +806,7 @@ void GLWall::DoMidTexture(seg_t * seg, bool drawfogboundary, // Draw the stuff // // - if (realfront->e->XFloor.lightlist.Size()==0 || gl_fixedcolormap || !gltexture) split.PutWall(translucent); - else split.SplitWall(realfront, translucent); + split.PutWall(realfront, translucent); t=1; } @@ -827,13 +814,7 @@ void GLWall::DoMidTexture(seg_t * seg, bool drawfogboundary, } else { - // - // - // Draw the stuff without splitting - // - // - if (realfront->e->XFloor.lightlist.Size()==0 || gl_fixedcolormap || !gltexture) PutWall(translucent); - else SplitWall(realfront, translucent); + PutWall(realfront, translucent); } alpha=1.0f; } @@ -941,11 +922,8 @@ void GLWall::BuildFFBlock(seg_t * seg, F3DFloor * rover, RenderStyle=STYLE_Normal; translucent=false; } - - sector_t * sec = sub? sub->sector : seg->frontsector; - if (sec->e->XFloor.lightlist.Size()==0 || gl_fixedcolormap || !gltexture) PutWall(translucent); - else SplitWall(sec, translucent); + PutWall(sub? sub->sector : seg->frontsector, translucent); alpha=1.0f; lightlevel = savelight; @@ -1573,7 +1551,7 @@ void GLWall::ProcessLowerMiniseg(seg_t *seg, sector_t * frontsector, sector_t * type = RENDERWALL_BOTTOM; gltexture->GetTexCoordInfo(&tci, FRACUNIT, FRACUNIT); SetWallCoordinates(seg, &tci, FIXED2FLOAT(bfh), bfh, bfh, ffh, ffh, 0); - PutWall(false); + PutWall(seg->frontsector, false); } } }