diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index ccd6567ce7..dc39e3ecbc 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -191,12 +191,13 @@ FDrawInfo::~FDrawInfo() // Sets up a new drawinfo struct // //========================================================================== -void FDrawInfo::StartDrawInfo(GLSceneDrawer *drawer) +FDrawInfo *FDrawInfo::StartDrawInfo(GLSceneDrawer *drawer) { FDrawInfo *di=di_list.GetNew(); di->mDrawer = drawer; di->FixedColormap = drawer->FixedColormap; di->StartScene(); + return di; } void FDrawInfo::StartScene() diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 05ca3dd8d9..a2bf52d1fb 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -135,7 +135,7 @@ struct FDrawInfo : public HWDrawInfo void AddSubsectorToPortal(FSectorPortalGroup *portal, subsector_t *sub) override; int ClipPoint(const DVector3 &pos) override; - static void StartDrawInfo(GLSceneDrawer *drawer); + static FDrawInfo *StartDrawInfo(GLSceneDrawer *drawer); static void EndDrawInfo(); gl_subsectorrendernode * GetOtherFloorPlanes(unsigned int sector) diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 12683c2d27..e6fdc54b7b 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -41,7 +41,6 @@ #include "gl/renderer/gl_renderstate.h" #include "gl/data/gl_vertexbuffer.h" #include "hwrenderer/scene/hw_clipper.h" -#include "gl/scene/gl_drawinfo.h" #include "gl/scene/gl_portal.h" #include "gl/scene/gl_scenedrawer.h" #include "gl/stereo3d/scoped_color_mask.h" @@ -160,8 +159,9 @@ void GLPortal::DrawPortalStencil() // //----------------------------------------------------------------------------- -bool GLPortal::Start(bool usestencil, bool doquery) +bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo **pDi) { + *pDi = nullptr; rendered_portals++; Clocker c(PortalAll); if (usestencil) @@ -228,7 +228,7 @@ bool GLPortal::Start(bool usestencil, bool doquery) return false; } } - FDrawInfo::StartDrawInfo(drawer); + *pDi = FDrawInfo::StartDrawInfo(drawer); } else { @@ -256,7 +256,7 @@ bool GLPortal::Start(bool usestencil, bool doquery) { if (NeedDepthBuffer()) { - FDrawInfo::StartDrawInfo(drawer); + *pDi = FDrawInfo::StartDrawInfo(drawer); } else { @@ -596,7 +596,7 @@ void GLPortal::RestoreMapSection() // //----------------------------------------------------------------------------- -void GLSkyboxPortal::DrawContents() +void GLSkyboxPortal::DrawContents(FDrawInfo *di) { int old_pm = PlaneMirrorMode; int saved_extralight = r_viewpoint.extralight; @@ -637,7 +637,7 @@ void GLSkyboxPortal::DrawContents() SaveMapSection(); drawer->CurrentMapSections.Set(mapsection); - drawer->DrawScene(DM_SKYPORTAL); + drawer->DrawScene(di, DM_SKYPORTAL); portal->mFlags &= ~PORTSF_INSKYBOX; inskybox = false; gl_RenderState.SetDepthClamp(oldclamp); @@ -698,7 +698,7 @@ static uint8_t SetCoverage(FDrawInfo *di, void *node) { node_t *bsp = (node_t *)node; uint8_t coverage = SetCoverage(di, bsp->children[0]) | SetCoverage(di, bsp->children[1]); - gl_drawinfo->no_renderflags[bsp->Index()] = coverage; + di->no_renderflags[bsp->Index()] = coverage; return coverage; } else @@ -718,7 +718,7 @@ void GLSectorStackPortal::SetupCoverage(FDrawInfo *di) { subsector_t *dsub = &::level.subsectors[sub->portalcoverage[plane].subsectors[j]]; drawer->CurrentMapSections.Set(dsub->mapsection); - gl_drawinfo->ss_renderflags[dsub->Index()] |= SSRF_SEEN; + di->ss_renderflags[dsub->Index()] |= SSRF_SEEN; } } SetCoverage(di, ::level.HeadNode()); @@ -729,7 +729,7 @@ void GLSectorStackPortal::SetupCoverage(FDrawInfo *di) // GLSectorStackPortal::DrawContents // //----------------------------------------------------------------------------- -void GLSectorStackPortal::DrawContents() +void GLSectorStackPortal::DrawContents(FDrawInfo *di) { FSectorPortalGroup *portal = origin; @@ -742,19 +742,19 @@ void GLSectorStackPortal::DrawContents() drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); SaveMapSection(); - SetupCoverage(gl_drawinfo); + SetupCoverage(di); ClearClipper(); // If the viewpoint is not within the portal, we need to invalidate the entire clip area. // The portal will re-validate the necessary parts when its subsectors get traversed. subsector_t *sub = R_PointInSubsector(r_viewpoint.Pos); - if (!(gl_drawinfo->ss_renderflags[sub->Index()] & SSRF_SEEN)) + if (!(di->ss_renderflags[sub->Index()] & SSRF_SEEN)) { drawer->clipper.SafeAddClipRange(0, ANGLE_MAX); drawer->clipper.SetBlocked(true); } - drawer->DrawScene(DM_PORTAL); + drawer->DrawScene(di, DM_PORTAL); RestoreMapSection(); if (origin->plane != -1) screen->instack[origin->plane]--; @@ -776,7 +776,7 @@ void GLSectorStackPortal::DrawContents() // //----------------------------------------------------------------------------- -void GLPlaneMirrorPortal::DrawContents() +void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di) { if (renderdepth > r_mirror_recursions) { @@ -801,7 +801,7 @@ void GLPlaneMirrorPortal::DrawContents() ClearClipper(); gl_RenderState.SetClipHeight(planez, PlaneMirrorMode < 0 ? -1.f : 1.f); - drawer->DrawScene(DM_PORTAL); + drawer->DrawScene(di, DM_PORTAL); gl_RenderState.SetClipHeight(0.f, 0.f); PlaneMirrorFlag--; PlaneMirrorMode = old_pm; @@ -897,7 +897,7 @@ int GLLinePortal::ClipPoint(const DVector2 &pos) // R_EnterMirror // //----------------------------------------------------------------------------- -void GLMirrorPortal::DrawContents() +void GLMirrorPortal::DrawContents(FDrawInfo *di) { if (renderdepth>r_mirror_recursions) { @@ -976,7 +976,7 @@ void GLMirrorPortal::DrawContents() gl_RenderState.SetClipLine(linedef); gl_RenderState.EnableClipLine(true); - drawer->DrawScene(DM_PORTAL); + drawer->DrawScene(di, DM_PORTAL); gl_RenderState.EnableClipLine(false); MirrorFlag--; @@ -997,7 +997,7 @@ void GLMirrorPortal::DrawContents() // // //----------------------------------------------------------------------------- -void GLLineToLinePortal::DrawContents() +void GLLineToLinePortal::DrawContents(FDrawInfo *di) { // TODO: Handle recursion more intelligently if (renderdepth>r_mirror_recursions) @@ -1049,14 +1049,14 @@ void GLLineToLinePortal::DrawContents() ClearClipper(); gl_RenderState.SetClipLine(glport->lines[0]->mDestination); gl_RenderState.EnableClipLine(true); - drawer->DrawScene(DM_PORTAL); + drawer->DrawScene(di, DM_PORTAL); gl_RenderState.EnableClipLine(false); RestoreMapSection(); } -void GLLineToLinePortal::RenderAttached() +void GLLineToLinePortal::RenderAttached(FDrawInfo *di) { - gl_drawinfo->ProcessActorsInPortal(glport, gl_drawinfo->mDrawer->in_area); + di->ProcessActorsInPortal(glport, di->mDrawer->in_area); } //----------------------------------------------------------------------------- @@ -1145,7 +1145,7 @@ GLHorizonPortal::GLHorizonPortal(GLHorizonInfo * pt, bool local) // GLHorizonPortal::DrawContents // //----------------------------------------------------------------------------- -void GLHorizonPortal::DrawContents() +void GLHorizonPortal::DrawContents(FDrawInfo *di) { Clocker c(PortalAll); @@ -1216,7 +1216,7 @@ void GLHorizonPortal::DrawContents() // //----------------------------------------------------------------------------- -void GLEEHorizonPortal::DrawContents() +void GLEEHorizonPortal::DrawContents(FDrawInfo *di) { sector_t *sector = portal->mOrigin; if (sector->GetTexture(sector_t::floor) == skyflatnum || @@ -1225,7 +1225,7 @@ void GLEEHorizonPortal::DrawContents() GLSkyInfo skyinfo; skyinfo.init(sector->sky, 0); GLSkyPortal sky(&skyinfo, true); - sky.DrawContents(); + sky.DrawContents(di); } if (sector->GetTexture(sector_t::ceiling) != skyflatnum) { @@ -1239,7 +1239,7 @@ void GLEEHorizonPortal::DrawContents() horz.plane.Texheight = r_viewpoint.Pos.Z + fabs(horz.plane.Texheight); } GLHorizonPortal ceil(&horz, true); - ceil.DrawContents(); + ceil.DrawContents(di); } if (sector->GetTexture(sector_t::floor) != skyflatnum) { @@ -1253,7 +1253,7 @@ void GLEEHorizonPortal::DrawContents() horz.plane.Texheight = r_viewpoint.Pos.Z - fabs(horz.plane.Texheight); } GLHorizonPortal floor(&horz, true); - floor.DrawContents(); + floor.DrawContents(di); } } diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index 5e5d023875..707c3d2a4c 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -89,9 +89,9 @@ protected: GLPortal(bool local = false) { if (!local) portals.Push(this); } virtual ~GLPortal() { } - bool Start(bool usestencil, bool doquery); + bool Start(bool usestencil, bool doquery, FDrawInfo **pDi); void End(bool usestencil); - virtual void DrawContents()=0; + virtual void DrawContents(FDrawInfo *di)=0; virtual void * GetSource() const =0; // GetSource MUST be implemented! void ClearClipper(); virtual bool IsSky() { return false; } @@ -111,9 +111,10 @@ public: // Start may perform an occlusion query. If that returns 0 there // is no need to draw the stencil's contents and there's also no // need to restore the affected area becasue there is none! - if (Start(usestencil, doquery)) + FDrawInfo *di; + if (Start(usestencil, doquery, &di)) { - DrawContents(); + DrawContents(di); End(usestencil); } } @@ -134,7 +135,7 @@ public: virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; } virtual int ClipPoint(const DVector2 &pos) { return PClip_Inside; } virtual line_t *ClipLine() { return NULL; } - virtual void RenderAttached() {} + virtual void RenderAttached(FDrawInfo *di) {} static void BeginScene(); static void StartFrame(); @@ -205,7 +206,7 @@ struct GLMirrorPortal : public GLLinePortal line_t * linedef; protected: - virtual void DrawContents(); + virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return linedef; } virtual const char *GetName(); @@ -223,11 +224,11 @@ struct GLLineToLinePortal : public GLLinePortal { FLinePortalSpan *glport; protected: - virtual void DrawContents(); + virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return glport; } virtual const char *GetName(); virtual line_t *ClipLine() { return line(); } - virtual void RenderAttached(); + virtual void RenderAttached(FDrawInfo *di); public: @@ -244,7 +245,7 @@ struct GLSkyboxPortal : public GLPortal FSectorPortal * portal; protected: - virtual void DrawContents(); + virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return portal; } virtual bool IsSky() { return true; } virtual const char *GetName(); @@ -266,7 +267,7 @@ struct GLSkyPortal : public GLPortal friend struct GLEEHorizonPortal; protected: - virtual void DrawContents(); + virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return origin; } virtual bool IsSky() { return true; } virtual bool NeedDepthBuffer() { return false; } @@ -290,7 +291,7 @@ struct GLSectorStackPortal : public GLPortal TArray subsectors; protected: virtual ~GLSectorStackPortal(); - virtual void DrawContents(); + virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return origin; } virtual bool IsSky() { return true; } // although this isn't a real sky it can be handled as one. virtual const char *GetName(); @@ -313,7 +314,7 @@ public: struct GLPlaneMirrorPortal : public GLPortal { protected: - virtual void DrawContents(); + virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return origin; } virtual const char *GetName(); virtual void PushState(); @@ -338,7 +339,7 @@ struct GLHorizonPortal : public GLPortal friend struct GLEEHorizonPortal; protected: - virtual void DrawContents(); + virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return origin; } virtual bool NeedDepthBuffer() { return false; } virtual bool NeedCap() { return false; } @@ -354,7 +355,7 @@ struct GLEEHorizonPortal : public GLPortal FSectorPortal * portal; protected: - virtual void DrawContents(); + virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return portal; } virtual bool NeedDepthBuffer() { return false; } virtual bool NeedCap() { return false; } diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 9b07196796..c3108a51b7 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -234,7 +234,7 @@ void GLSceneDrawer::SetupView(float vx, float vy, float vz, DAngle va, bool mirr // //----------------------------------------------------------------------------- -void GLSceneDrawer::CreateScene() +void GLSceneDrawer::CreateScene(FDrawInfo *di) { angle_t a1 = FrustumAngle(); InitClipper(r_viewpoint.Angles.Yaw.BAMs() + a1, r_viewpoint.Angles.Yaw.BAMs() - a1); @@ -254,26 +254,26 @@ void GLSceneDrawer::CreateScene() SetView(); validcount++; // used for processing sidedefs only once by the renderer. - gl_drawinfo->clipPortal = !!GLRenderer->mClipPortal; - gl_drawinfo->mAngles = GLRenderer->mAngles; - gl_drawinfo->mViewVector = GLRenderer->mViewVector; - gl_drawinfo->mViewActor = GLRenderer->mViewActor; - gl_drawinfo->mShadowMap = &GLRenderer->mShadowMap; + di->clipPortal = !!GLRenderer->mClipPortal; + di->mAngles = GLRenderer->mAngles; + di->mViewVector = GLRenderer->mViewVector; + di->mViewActor = GLRenderer->mViewActor; + di->mShadowMap = &GLRenderer->mShadowMap; RenderBSPNode (level.HeadNode()); - gl_drawinfo->PreparePlayerSprites(r_viewpoint.sector, in_area); + di->PreparePlayerSprites(r_viewpoint.sector, in_area); // Process all the sprites on the current portal's back side which touch the portal. - if (GLRenderer->mCurrentPortal != NULL) GLRenderer->mCurrentPortal->RenderAttached(); + if (GLRenderer->mCurrentPortal != NULL) GLRenderer->mCurrentPortal->RenderAttached(di); Bsp.Unclock(); // And now the crappy hacks that have to be done to avoid rendering anomalies. // These cannot be multithreaded when the time comes because all these depend // on the global 'validcount' variable. - gl_drawinfo->HandleMissingTextures(in_area); // Missing upper/lower textures - gl_drawinfo->HandleHackedSubsectors(); // open sector hacks for deep water - gl_drawinfo->ProcessSectorStacks(in_area); // merge visplanes of sector stacks + di->HandleMissingTextures(in_area); // Missing upper/lower textures + di->HandleHackedSubsectors(); // open sector hacks for deep water + di->ProcessSectorStacks(in_area); // merge visplanes of sector stacks GLRenderer->mLights->Finish(); GLRenderer->mVBO->Unmap(); @@ -412,7 +412,7 @@ void GLSceneDrawer::RenderScene(FDrawInfo *di, int recursion) // //----------------------------------------------------------------------------- -void GLSceneDrawer::RenderTranslucent() +void GLSceneDrawer::RenderTranslucent(FDrawInfo *di) { RenderAll.Clock(); @@ -424,8 +424,8 @@ void GLSceneDrawer::RenderTranslucent() gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.EnableBrightmap(true); - gl_drawinfo->drawlists[GLDL_TRANSLUCENTBORDER].Draw(gl_drawinfo, GLPASS_TRANSLUCENT); - gl_drawinfo->DrawSorted(GLDL_TRANSLUCENT); + di->drawlists[GLDL_TRANSLUCENTBORDER].Draw(di, GLPASS_TRANSLUCENT); + di->DrawSorted(GLDL_TRANSLUCENT); gl_RenderState.EnableBrightmap(false); @@ -445,7 +445,7 @@ void GLSceneDrawer::RenderTranslucent() // //----------------------------------------------------------------------------- -void GLSceneDrawer::DrawScene(int drawmode) +void GLSceneDrawer::DrawScene(FDrawInfo *di, int drawmode) { static int recursion=0; static int ssao_portals_available = 0; @@ -469,16 +469,16 @@ void GLSceneDrawer::DrawScene(int drawmode) if (r_viewpoint.camera != nullptr) { ActorRenderFlags savedflags = r_viewpoint.camera->renderflags; - CreateScene(); + CreateScene(di); r_viewpoint.camera->renderflags = savedflags; } else { - CreateScene(); + CreateScene(di); } GLRenderer->mClipPortal = NULL; // this must be reset before any portal recursion takes place. - RenderScene(gl_drawinfo, recursion); + RenderScene(di, recursion); if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS) { @@ -495,7 +495,7 @@ void GLSceneDrawer::DrawScene(int drawmode) recursion++; GLPortal::EndFrame(); recursion--; - RenderTranslucent(); + RenderTranslucent(di); } //----------------------------------------------------------------------------- @@ -572,7 +572,7 @@ void GLSceneDrawer::DrawEndScene2D(FDrawInfo *di, sector_t * viewsector) // //----------------------------------------------------------------------------- -void GLSceneDrawer::ProcessScene(bool toscreen) +void GLSceneDrawer::ProcessScene(FDrawInfo *di, bool toscreen) { iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; GLPortal::BeginScene(); @@ -581,7 +581,7 @@ void GLSceneDrawer::ProcessScene(bool toscreen) CurrentMapSections.Resize(level.NumMapSections); CurrentMapSections.Zero(); CurrentMapSections.Set(mapsection); - DrawScene(toscreen ? DM_MAINVIEW : DM_OFFSCREEN); + DrawScene(di, toscreen ? DM_MAINVIEW : DM_OFFSCREEN); } @@ -694,13 +694,13 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl SetViewMatrix(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, false, false); gl_RenderState.ApplyMatrices(); - FDrawInfo::StartDrawInfo(this); - ProcessScene(toscreen); - if (mainview && toscreen) EndDrawScene(gl_drawinfo, lviewsector); // do not call this for camera textures. + FDrawInfo *di = FDrawInfo::StartDrawInfo(this); + ProcessScene(di, toscreen); + if (mainview && toscreen) EndDrawScene(di, lviewsector); // do not call this for camera textures. if (mainview && FGLRenderBuffers::IsEnabled()) { - GLRenderer->PostProcessScene(FixedColormap, [&]() { if (gl_bloom && FixedColormap == CM_DEFAULT) DrawEndScene2D(gl_drawinfo, lviewsector); }); + GLRenderer->PostProcessScene(FixedColormap, [&]() { if (gl_bloom && FixedColormap == CM_DEFAULT) DrawEndScene2D(di, lviewsector); }); // This should be done after postprocessing, not before. GLRenderer->mBuffers->BindCurrentFB(); diff --git a/src/gl/scene/gl_scenedrawer.h b/src/gl/scene/gl_scenedrawer.h index 9f7f27708b..dfca8f4fae 100644 --- a/src/gl/scene/gl_scenedrawer.h +++ b/src/gl/scene/gl_scenedrawer.h @@ -34,9 +34,9 @@ class GLSceneDrawer void RenderBSPNode(void *node); void RenderScene(FDrawInfo *di, int recursion); - void RenderTranslucent(); + void RenderTranslucent(FDrawInfo *di); - void CreateScene(); + void CreateScene(FDrawInfo *di); public: GLSceneDrawer() @@ -58,8 +58,8 @@ public: void Set3DViewport(bool mainview); void Reset3DViewport(); void SetFixedColormap(player_t *player); - void DrawScene(int drawmode); - void ProcessScene(bool toscreen = false); + void DrawScene(FDrawInfo *di, int drawmode); + void ProcessScene(FDrawInfo *di, bool toscreen = false); void EndDrawScene(FDrawInfo *di, sector_t * viewsector); void DrawEndScene2D(FDrawInfo *di, sector_t * viewsector); diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index a476d2ab31..38a70ea33d 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -271,7 +271,7 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool // // //----------------------------------------------------------------------------- -void GLSkyPortal::DrawContents() +void GLSkyPortal::DrawContents(FDrawInfo *di) { bool drawBoth = false;