From 59360f2d77f4f6c6d7dd97eb67208a3eb331d834 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 21:08:07 +0200 Subject: [PATCH] - started cleanup of dependencies of the framebuffer class. * made the portal state global, outside the framebuffer, because it is pure logic state without dependencies on the backend. * took the setup functions out of FDynLightData - there is no need to have them as members and they age game dependent. --- .../hwrenderer/dynlights/hw_dynlightdata.cpp | 11 ++++---- .../hwrenderer/dynlights/hw_dynlightdata.h | 5 ---- .../hwrenderer/dynlights/hw_lightbuffer.h | 1 - .../hwrenderer/dynlights/hw_shadowmap.cpp | 1 + src/rendering/hwrenderer/hw_entrypoint.cpp | 1 + src/rendering/hwrenderer/models/hw_models.cpp | 4 +-- .../hwrenderer/scene/hw_drawinfo.cpp | 10 +++---- .../hwrenderer/scene/hw_drawlistadd.cpp | 1 + .../hwrenderer/scene/hw_drawstructs.h | 5 ++++ src/rendering/hwrenderer/scene/hw_flats.cpp | 3 +- src/rendering/hwrenderer/scene/hw_portal.cpp | 1 + src/rendering/hwrenderer/scene/hw_portal.h | 2 ++ .../hwrenderer/scene/hw_renderhacks.cpp | 3 +- .../hwrenderer/scene/hw_renderstate.cpp | 2 +- .../hwrenderer/scene/hw_spritelight.cpp | 4 ++- src/rendering/hwrenderer/scene/hw_walls.cpp | 28 +++++++++---------- 16 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp index 5139b545d..c7107f847 100644 --- a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp @@ -26,8 +26,9 @@ **/ #include "actorinlines.h" - +#include "a_dynlight.h" #include "hw_dynlightdata.h" +#include "hwrenderer/scene/hw_drawstructs.h" // If we want to share the array to avoid constant allocations it needs to be thread local unless it'd be littered with expensive synchronization. thread_local FDynLightData lightdata; @@ -48,7 +49,7 @@ CVAR (Bool, gl_light_particles, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); // Sets up the parameters to render one dynamic light onto one plane // //========================================================================== -bool FDynLightData::GetLight(int group, Plane & p, FDynamicLight * light, bool checkside) +bool GetLight(FDynLightData& dld, int group, Plane & p, FDynamicLight * light, bool checkside) { DVector3 pos = light->PosRelative(group); float radius = (light->GetRadius()); @@ -62,7 +63,7 @@ bool FDynLightData::GetLight(int group, Plane & p, FDynamicLight * light, bool c return false; } - AddLightToList(group, light, false); + AddLightToList(dld, group, light, false); return true; } @@ -71,7 +72,7 @@ bool FDynLightData::GetLight(int group, Plane & p, FDynamicLight * light, bool c // Add one dynamic light to the light data list // //========================================================================== -void FDynLightData::AddLightToList(int group, FDynamicLight * light, bool forceAttenuate) +void AddLightToList(FDynLightData &dld, int group, FDynamicLight * light, bool forceAttenuate) { int i = 0; @@ -129,7 +130,7 @@ void FDynLightData::AddLightToList(int group, FDynamicLight * light, bool forceA spotDirZ = float(-Angle.Sin() * xzLen); } - float *data = &arrays[i][arrays[i].Reserve(16)]; + float *data = &dld.arrays[i][dld.arrays[i].Reserve(16)]; data[0] = float(pos.X); data[1] = float(pos.Z); data[2] = float(pos.Y); diff --git a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h index ec5f6d89e..e24e49bed 100644 --- a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h +++ b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h @@ -23,9 +23,6 @@ #ifndef __GLC_DYNLIGHT_H #define __GLC_DYNLIGHT_H -#include "a_dynlight.h" - - struct FDynLightData { TArray arrays[3]; @@ -53,8 +50,6 @@ struct FDynLightData if (siz[2] > max) siz[2] = max; } - bool GetLight(int group, Plane & p, FDynamicLight * light, bool checkside); - void AddLightToList(int group, FDynamicLight * light, bool forceAttenuate); }; diff --git a/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h b/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h index df9d679a7..aae08dbed 100644 --- a/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h +++ b/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h @@ -43,7 +43,6 @@ public: }; -int gl_SetDynModelLight(AActor *self, int dynlightindex); #endif diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp index aba51140a..e9fb4686f 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp @@ -28,6 +28,7 @@ #include "stats.h" #include "g_levellocals.h" #include "v_video.h" +#include "a_dynlight.h" /* The 1D shadow maps are stored in a 1024x1024 texture as float depth values (R32F). diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index dd8a22c9c..d4e9fdab9 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -27,6 +27,7 @@ #include "gl_system.h" #include "gi.h" +#include "a_dynlight.h" #include "m_png.h" #include "doomstat.h" #include "r_data/r_interpolate.h" diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 9eff4f205..6b1aa5a33 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -62,7 +62,7 @@ void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, con // TO-DO: Implement proper depth sorting. if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES)) { - state.SetCulling((mirrored ^ screen->mPortalState->isMirrored()) ? Cull_CCW : Cull_CW); + state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CCW : Cull_CW); } state.mModelMatrix = objectToWorldMatrix; @@ -86,7 +86,7 @@ void FHWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectTo // TO-DO: Implement proper depth sorting. if (!(actor->RenderStyle == DefaultRenderStyle())) { - state.SetCulling((mirrored ^ screen->mPortalState->isMirrored()) ? Cull_CW : Cull_CCW); + state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CW : Cull_CCW); } state.mModelMatrix = objectToWorldMatrix; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index b1cad03a1..e1697adec 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -432,7 +432,7 @@ void HWDrawInfo::CreateScene(bool drawpsprites) mClipper->SafeAddClipRangeRealAngles(vp.Angles.Yaw.BAMs() + a1, vp.Angles.Yaw.BAMs() - a1); // reset the portal manager - screen->mPortalState->StartFrame(); + portalState.StartFrame(); ProcessAll.Clock(); @@ -689,7 +689,7 @@ void HWDrawInfo::DrawScene(int drawmode) auto& RenderState = *screen->RenderState(); RenderState.SetDepthMask(true); - if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this, RenderState); + if (!gl_no_skyclear) portalState.RenderFirstSkyPortal(recursion, this, RenderState); RenderScene(RenderState); @@ -702,7 +702,7 @@ void HWDrawInfo::DrawScene(int drawmode) // Handle all portals after rendering the opaque objects but before // doing all translucent stuff recursion++; - screen->mPortalState->EndFrame(this, RenderState); + portalState.EndFrame(this, RenderState); recursion--; RenderTranslucent(RenderState); } @@ -716,7 +716,7 @@ void HWDrawInfo::DrawScene(int drawmode) void HWDrawInfo::ProcessScene(bool toscreen) { - screen->mPortalState->BeginScene(); + portalState.BeginScene(); int mapsection = Level->PointInRenderSubsector(Viewpoint.Pos)->mapsection; CurrentMapSections.Set(mapsection); @@ -735,7 +735,7 @@ void HWDrawInfo::AddSubsectorToPortal(FSectorPortalGroup *ptg, subsector_t *sub) auto portal = FindPortal(ptg); if (!portal) { - portal = new HWSectorStackPortal(screen->mPortalState, ptg); + portal = new HWSectorStackPortal(&portalState, ptg); Portals.Push(portal); } auto ptl = static_cast(portal); diff --git a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp index 7224824d3..3c4a85f38 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -26,6 +26,7 @@ #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hw_material.h" +#include "actor.h" EXTERN_CVAR(Bool, gl_seamless) diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index e8a244562..271f24a09 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -430,3 +430,8 @@ bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FGameTexture * g void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata); extern const float LARGE_VALUE; + +struct FDynLightData; +struct FDynamicLight; +bool GetLight(FDynLightData& dld, int group, Plane& p, FDynamicLight* light, bool checkside); +void AddLightToList(FDynLightData &dld, int group, FDynamicLight* light, bool forceAttenuate); diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 82ce3ac4e..eb64cea2a 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -26,6 +26,7 @@ */ #include "a_sharedglobal.h" +#include "a_dynlight.h" #include "r_defs.h" #include "r_sky.h" #include "r_utility.h" @@ -168,7 +169,7 @@ void HWFlat::SetupLights(HWDrawInfo *di, FLightNode * node, FDynLightData &light } p.Set(plane.plane.Normal(), plane.plane.fD()); - draw_dlightf += lightdata.GetLight(portalgroup, p, light, false); + draw_dlightf += GetLight(lightdata, portalgroup, p, light, false); node = node->nextLight; } diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index 69c963148..11d0e95f1 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -71,6 +71,7 @@ CCMD(gl_portalinfo) } static FString indent; +FPortalSceneState portalState; //----------------------------------------------------------------------------- // diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index a6bf05f42..28767e15d 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -128,6 +128,8 @@ struct FPortalSceneState void RenderPortal(HWPortal *p, FRenderState &state, bool usestencil, HWDrawInfo *outer_di); }; +extern FPortalSceneState portalState; + class HWScenePortalBase : public HWPortal { diff --git a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp index 6ebdab3f8..cc8a2af3e 100644 --- a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp @@ -26,6 +26,7 @@ */ #include "a_sharedglobal.h" +#include "a_dynlight.h" #include "r_utility.h" #include "r_sky.h" #include "g_levellocals.h" @@ -128,7 +129,7 @@ int HWDrawInfo::SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &light iter_dlightf++; p.Set(plane->Normal(), plane->fD()); - draw_dlightf += lightdata.GetLight(sub->sector->PortalGroup, p, light, true); + draw_dlightf += GetLight(lightdata, sub->sector->PortalGroup, p, light, true); node = node->nextLight; } diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.cpp b/src/rendering/hwrenderer/scene/hw_renderstate.cpp index 60fad5dbb..3f08c7f33 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderstate.cpp @@ -118,7 +118,7 @@ void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool } // Make fog a little denser when inside a skybox - if (screen->mPortalState->inskybox) fogdensity += fogdensity / 2; + if (portalState.inskybox) fogdensity += fogdensity / 2; // no fog in enhanced vision modes! diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index a8bc1f849..b5019975f 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -26,6 +26,7 @@ */ #include "c_dispatch.h" +#include "a_dynlight.h" #include "p_local.h" #include "p_effect.h" #include "g_level.h" @@ -34,6 +35,7 @@ #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/dynlights/hw_shadowmap.h" #include "hwrenderer/scene/hw_drawinfo.h" +#include "hwrenderer/scene/hw_drawstructs.h" #include "r_data/models/models.h" template @@ -182,7 +184,7 @@ void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata) { if (std::find(addedLights.begin(), addedLights.end(), light) == addedLights.end()) // Check if we already added this light from a different subsector { - modellightdata.AddLightToList(group, light, true); + AddLightToList(modellightdata, group, light, true); addedLights.Push(light); } } diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index eb907770f..dcde26054 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -22,6 +22,7 @@ #include "p_local.h" #include "p_lnspec.h" +#include "a_dynlight.h" #include "a_sharedglobal.h" #include "r_defs.h" #include "r_sky.h" @@ -412,7 +413,7 @@ void HWWall::SetupLights(HWDrawInfo *di, FDynLightData &lightdata) } if (outcnt[0]!=4 && outcnt[1]!=4 && outcnt[2]!=4 && outcnt[3]!=4) { - draw_dlight += lightdata.GetLight(seg->frontsector->PortalGroup, p, node->lightsource, true); + draw_dlight += GetLight(lightdata, seg->frontsector->PortalGroup, p, node->lightsource, true); } } } @@ -497,7 +498,6 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent) void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) { - auto pstate = screen->mPortalState; HWPortal * portal = nullptr; MakeVertices(di, false); @@ -506,11 +506,11 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) // portals don't go into the draw list. // Instead they are added to the portal manager case PORTALTYPE_HORIZON: - horizon = pstate->UniqueHorizons.Get(horizon); + horizon = portalState.UniqueHorizons.Get(horizon); portal = di->FindPortal(horizon); if (!portal) { - portal = new HWHorizonPortal(pstate, horizon, di->Viewpoint); + portal = new HWHorizonPortal(&portalState, horizon, di->Viewpoint); di->Portals.Push(portal); } portal->AddLine(this); @@ -521,10 +521,10 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) if (!portal) { // either a regular skybox or an Eternity-style horizon - if (secportal->mType != PORTS_SKYVIEWPOINT) portal = new HWEEHorizonPortal(pstate, secportal); + if (secportal->mType != PORTS_SKYVIEWPOINT) portal = new HWEEHorizonPortal(&portalState, secportal); else { - portal = new HWSkyboxPortal(pstate, secportal); + portal = new HWSkyboxPortal(&portalState, secportal); di->Portals.Push(portal); } } @@ -535,20 +535,20 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) portal = di->FindPortal(this->portal); if (!portal) { - portal = new HWSectorStackPortal(pstate, this->portal); + portal = new HWSectorStackPortal(&portalState, this->portal); di->Portals.Push(portal); } portal->AddLine(this); break; case PORTALTYPE_PLANEMIRROR: - if (pstate->PlaneMirrorMode * planemirror->fC() <= 0) + if (portalState.PlaneMirrorMode * planemirror->fC() <= 0) { - planemirror = pstate->UniquePlaneMirrors.Get(planemirror); + planemirror = portalState.UniquePlaneMirrors.Get(planemirror); portal = di->FindPortal(planemirror); if (!portal) { - portal = new HWPlaneMirrorPortal(pstate, planemirror); + portal = new HWPlaneMirrorPortal(&portalState, planemirror); di->Portals.Push(portal); } portal->AddLine(this); @@ -559,7 +559,7 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) portal = di->FindPortal(seg->linedef); if (!portal) { - portal = new HWMirrorPortal(pstate, seg->linedef); + portal = new HWMirrorPortal(&portalState, seg->linedef); di->Portals.Push(portal); } portal->AddLine(this); @@ -581,18 +581,18 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) { di->ProcessActorsInPortal(otherside->getPortal()->mGroup, di->in_area); } - portal = new HWLineToLinePortal(pstate, lineportal); + portal = new HWLineToLinePortal(&portalState, lineportal); di->Portals.Push(portal); } portal->AddLine(this); break; case PORTALTYPE_SKY: - sky = pstate->UniqueSkies.Get(sky); + sky = portalState.UniqueSkies.Get(sky); portal = di->FindPortal(sky); if (!portal) { - portal = new HWSkyPortal(screen->mSkyData, pstate, sky); + portal = new HWSkyPortal(screen->mSkyData, &portalState, sky); di->Portals.Push(portal); } portal->AddLine(this);