Skip to content

Commit

Permalink
- fixed remaining issues with portal refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Jun 23, 2018
1 parent 6ebec37 commit e7a0ccf
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 61 deletions.
3 changes: 2 additions & 1 deletion src/gl/scene/gl_drawinfo.cpp
Expand Up @@ -484,10 +484,11 @@ void FDrawInfo::FloodLowerGap(seg_t * seg)
// Same here for the dependency on the portal.
void FDrawInfo::AddSubsectorToPortal(FSectorPortalGroup *ptg, subsector_t *sub)
{
auto portal = GLRenderer->mPortalState.FindPortal(ptg);
auto portal = FindPortal(ptg);
if (!portal)
{
portal = new GLScenePortal(&GLRenderer->mPortalState, new HWSectorStackPortal(ptg));
Portals.Push(portal);
}
auto ptl = static_cast<HWSectorStackPortal*>(static_cast<GLScenePortal*>(portal)->mScene);
ptl->AddSubsector(sub);
Expand Down
8 changes: 4 additions & 4 deletions src/gl/scene/gl_portal.cpp
Expand Up @@ -149,11 +149,11 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw
else if (gl_noquery) doquery = false;

// Use occlusion query to avoid rendering portals that aren't visible
glBeginQuery(GL_SAMPLES_PASSED, GLRenderer->PortalQueryObject);
if (doquery) glBeginQuery(GL_SAMPLES_PASSED, GLRenderer->PortalQueryObject);

DrawPortalStencil();

glEndQuery(GL_SAMPLES_PASSED);
if (doquery) glEndQuery(GL_SAMPLES_PASSED);

// Clear Z-buffer
glStencilFunc(GL_EQUAL, mState->recursion + 1, ~0); // draw sky into stencil
Expand All @@ -170,9 +170,9 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw
gl_RenderState.SetEffect(EFF_NONE);
glDepthRange(0, 1);

GLuint sampleCount;
GLuint sampleCount = 1;

glGetQueryObjectuiv(GLRenderer->PortalQueryObject, GL_QUERY_RESULT, &sampleCount);
if (doquery) glGetQueryObjectuiv(GLRenderer->PortalQueryObject, GL_QUERY_RESULT, &sampleCount);

if (sampleCount == 0) // not visible
{
Expand Down
2 changes: 1 addition & 1 deletion src/gl/scene/gl_portal.h
Expand Up @@ -62,7 +62,6 @@ class GLPortal : public IPortal

bool Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDrawInfo **pDi) override;
void End(HWDrawInfo *di, bool usestencil) override;
void ClearClipper(HWDrawInfo *di);
void ClearScreen(HWDrawInfo *di);
};

Expand All @@ -88,6 +87,7 @@ class GLScenePortal : public GLPortal
static_cast<FDrawInfo*>(di)->DrawScene(DM_PORTAL);
mScene->Shutdown(di);
}
else ClearScreen(di);
}
virtual void RenderAttached(HWDrawInfo *di) { return mScene->RenderAttached(di); }
};
Expand Down
48 changes: 35 additions & 13 deletions src/gl/scene/gl_walls_draw.cpp
Expand Up @@ -347,27 +347,36 @@ void FDrawInfo::AddPortal(GLWall *wall, int ptype)
// Instead they are added to the portal manager
case PORTALTYPE_HORIZON:
wall->horizon = pstate.UniqueHorizons.Get(wall->horizon);
portal = pstate.FindPortal(wall->horizon);
if (!portal) portal = new GLHorizonPortal(&pstate, wall->horizon, Viewpoint);
portal = FindPortal(wall->horizon);
if (!portal)
{
portal = new GLHorizonPortal(&pstate, wall->horizon, Viewpoint);
Portals.Push(portal);
}
portal->AddLine(wall);
break;

case PORTALTYPE_SKYBOX:
portal = pstate.FindPortal(wall->secportal);
portal = FindPortal(wall->secportal);
if (!portal)
{
// either a regular skybox or an Eternity-style horizon
if (wall->secportal->mType != PORTS_SKYVIEWPOINT) portal = new GLEEHorizonPortal(&pstate, wall->secportal);
else portal = new GLScenePortal(&pstate, new HWSkyboxPortal(wall->secportal));
else
{
portal = new GLScenePortal(&pstate, new HWSkyboxPortal(wall->secportal));
Portals.Push(portal);
}
}
portal->AddLine(wall);
break;

case PORTALTYPE_SECTORSTACK:
portal = pstate.FindPortal(wall->portal);
portal = FindPortal(wall->portal);
if (!portal)
{
portal = new GLScenePortal(&pstate, new HWSectorStackPortal(wall->portal));
Portals.Push(portal);
}
portal->AddLine(wall);
break;
Expand All @@ -377,15 +386,23 @@ void FDrawInfo::AddPortal(GLWall *wall, int ptype)
{
//@sync-portal
wall->planemirror = pstate.UniquePlaneMirrors.Get(wall->planemirror);
portal = pstate.FindPortal(wall->planemirror);
if (!portal) portal = new GLScenePortal(&pstate, new HWPlaneMirrorPortal(wall->planemirror));
portal = FindPortal(wall->planemirror);
if (!portal)
{
portal = new GLScenePortal(&pstate, new HWPlaneMirrorPortal(wall->planemirror));
Portals.Push(portal);
}
portal->AddLine(wall);
}
break;

case PORTALTYPE_MIRROR:
portal = pstate.FindPortal(wall->seg->linedef);
if (!portal) portal = new GLScenePortal(&pstate, new HWMirrorPortal(wall->seg->linedef));
portal = FindPortal(wall->seg->linedef);
if (!portal)
{
portal = new GLScenePortal(&pstate, new HWMirrorPortal(wall->seg->linedef));
Portals.Push(portal);
}
portal->AddLine(wall);
if (gl_mirror_envmap)
{
Expand All @@ -395,23 +412,28 @@ void FDrawInfo::AddPortal(GLWall *wall, int ptype)
break;

case PORTALTYPE_LINETOLINE:
portal = pstate.FindPortal(wall->lineportal);
portal = FindPortal(wall->lineportal);
if (!portal)
{
line_t *otherside = wall->lineportal->lines[0]->mDestination;
if (otherside != NULL && otherside->portalindex < level.linePortals.Size())
if (otherside != nullptr && otherside->portalindex < level.linePortals.Size())
{
ProcessActorsInPortal(otherside->getPortal()->mGroup, in_area);
}
portal = new GLScenePortal(&pstate, new HWLineToLinePortal(wall->lineportal));
Portals.Push(portal);
}
portal->AddLine(wall);
break;

case PORTALTYPE_SKY:
wall->sky = pstate.UniqueSkies.Get(wall->sky);
portal = pstate.FindPortal(wall->sky);
if (!portal) portal = new GLSkyPortal(&pstate, wall->sky);
portal = FindPortal(wall->sky);
if (!portal)
{
portal = new GLSkyPortal(&pstate, wall->sky);
Portals.Push(portal);
}
portal->AddLine(wall);
break;
}
Expand Down
16 changes: 15 additions & 1 deletion src/hwrenderer/scene/hw_drawinfo.cpp
Expand Up @@ -32,6 +32,7 @@
#include "g_levellocals.h"
#include "hw_fakeflat.h"
#include "hw_drawinfo.h"
#include "hw_portal.h"
#include "hwrenderer/utility/hw_clock.h"
#include "hwrenderer/utility/hw_cvars.h"

Expand Down Expand Up @@ -256,6 +257,20 @@ void HWDrawInfo::SetupView(float vx, float vy, float vz, bool mirror, bool plane
//
//-----------------------------------------------------------------------------

IPortal * HWDrawInfo::FindPortal(const void * src)
{
int i = Portals.Size() - 1;

while (i >= 0 && Portals[i] && Portals[i]->GetSource() != src) i--;
return i >= 0 ? Portals[i] : nullptr;
}

//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------

void HWViewpointUniforms::SetDefaults()
{
mProjectionMatrix.loadIdentity();
Expand All @@ -267,4 +282,3 @@ void HWViewpointUniforms::SetDefaults()
mClipLine.X = -10000000.0f;

}

3 changes: 3 additions & 0 deletions src/hwrenderer/scene/hw_drawinfo.h
Expand Up @@ -110,6 +110,7 @@ struct HWDrawInfo
Clipper *mClipper;
FRenderViewpoint Viewpoint;
HWViewpointUniforms VPUniforms; // per-viewpoint uniform state
TArray<IPortal *> Portals;

TArray<MissingTextureInfo> MissingUpperTextures;
TArray<MissingTextureInfo> MissingLowerTextures;
Expand Down Expand Up @@ -149,6 +150,7 @@ struct HWDrawInfo

sector_t fakesec; // this is a struct member because it gets used in recursively called functions so it cannot be put on the stack.


void UnclipSubsector(subsector_t *sub);
void AddLine(seg_t *seg, bool portalclip);
void PolySubsector(subsector_t * sub);
Expand Down Expand Up @@ -183,6 +185,7 @@ struct HWDrawInfo
return (screen->hwcaps & RFL_NO_CLIP_PLANES) && VPUniforms.mClipLine.X > -1000000.f;
}

IPortal * FindPortal(const void * src);
void RenderBSPNode(void *node);

void ClearBuffers();
Expand Down

0 comments on commit e7a0ccf

Please sign in to comment.