From 926a918e0cac83f68891d6fd809eb6661c275c00 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Oct 2018 15:22:48 +0100 Subject: [PATCH] - moved the light buffer pointer to globally visible state. --- src/gl/renderer/gl_renderer.cpp | 6 ++---- src/gl/renderer/gl_renderer.h | 1 - src/gl/renderer/gl_renderstate.cpp | 2 +- src/gl/scene/gl_drawinfo.cpp | 5 ----- src/gl/scene/gl_drawinfo.h | 2 -- src/gl/scene/gl_scene.cpp | 6 +++--- src/gl/shaders/gl_shader.cpp | 6 +++--- src/gl/system/gl_framebuffer.cpp | 8 ++++++-- src/hwrenderer/scene/hw_drawinfo.h | 1 - src/hwrenderer/scene/hw_flats.cpp | 3 ++- src/hwrenderer/scene/hw_renderhacks.cpp | 3 ++- src/hwrenderer/scene/hw_sprites.cpp | 3 ++- src/hwrenderer/scene/hw_walls.cpp | 3 ++- src/hwrenderer/scene/hw_weapon.cpp | 3 ++- src/v_video.h | 2 ++ 15 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index a3f8134ef..9d35db9ac 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -102,7 +102,6 @@ void FGLRenderer::Initialize(int width, int height) glBindVertexArray(mVAOID); FGLDebug::LabelObject(GL_VERTEX_ARRAY, mVAOID, "FGLRenderer.mVAOID"); - mLights = new FLightBuffer(); mFBID = 0; mOldFBID = 0; @@ -117,7 +116,6 @@ FGLRenderer::~FGLRenderer() FMaterial::FlushAll(); if (mShaderManager != nullptr) delete mShaderManager; if (mSamplerManager != nullptr) delete mSamplerManager; - if (mLights != nullptr) delete mLights; if (mFBID != 0) glDeleteFramebuffers(1, &mFBID); if (mVAOID != 0) { @@ -209,7 +207,7 @@ sector_t *FGLRenderer::RenderView(player_t* player) P_FindParticleSubsectors(); - mLights->Clear(); + screen->mLights->Clear(); screen->mViewpoints->Clear(); // NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below. @@ -311,7 +309,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i P_FindParticleSubsectors(); // make sure that all recently spawned particles have a valid subsector. screen->mVertexData->Bind(gl_RenderState); screen->mVertexData->Reset(); - mLights->Clear(); + screen->mLights->Clear(); screen->mViewpoints->Clear(); // This shouldn't overwrite the global viewpoint even for a short time. diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 760b9fb1e..dd332ddf2 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -69,7 +69,6 @@ public: //FRotator mAngles; - FLightBuffer *mLights = nullptr; SWSceneDrawer *swdrawer = nullptr; float mSceneClearColor[3]; diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 922c281cc..4cf498c29 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -200,7 +200,7 @@ bool FGLRenderState::ApplyShader() matrixToGL(identityMatrix, activeShader->normalmodelmatrix_index); } - auto index = GLRenderer->mLights->BindUBO(mLightIndex); + auto index = screen->mLights->BindUBO(mLightIndex); activeShader->muLightIndex.Set(index); return true; diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index ae2d116e3..6d07483a2 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -158,11 +158,6 @@ void FDrawInfo::AddSubsectorToPortal(FSectorPortalGroup *ptg, subsector_t *sub) ptl->AddSubsector(sub); } -int FDrawInfo::UploadLights(FDynLightData &data) -{ - return GLRenderer->mLights->UploadLights(data); -} - bool FDrawInfo::SetDepthClamp(bool on) { return gl_RenderState.SetDepthClamp(on); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 399512d47..4129f92c5 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -39,8 +39,6 @@ struct FDrawInfo : public HWDrawInfo void AddFlat(GLFlat *flat, bool fog) override; void AddSprite(GLSprite *sprite, bool translucent) override; - int UploadLights(FDynLightData &data) override; - void Draw(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) override; void DrawIndexed(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) override; void RenderPortal(HWPortal *p, bool stencil) override; diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 63151c9a4..3e9072afb 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -105,7 +105,7 @@ void FDrawInfo::CreateScene() // clip the scene and fill the drawlists Bsp.Clock(); screen->mVertexData->Map(); - GLRenderer->mLights->Map(); + screen->mLights->Map(); // Give the DrawInfo the viewpoint in fixed point because that's what the nodes are. viewx = FLOAT2FIXED(vp.Pos.X); @@ -130,7 +130,7 @@ void FDrawInfo::CreateScene() HandleHackedSubsectors(); // open sector hacks for deep water ProcessSectorStacks(in_area); // merge visplanes of sector stacks PrepareUnhandledMissingTextures(); - GLRenderer->mLights->Unmap(); + screen->mLights->Unmap(); screen->mVertexData->Unmap(); ProcessAll.Unclock(); @@ -153,7 +153,7 @@ void FDrawInfo::RenderScene(int recursion) glDepthMask(true); if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this); - GLRenderer->mLights->BindBase(gl_RenderState); // not needed for OpenGL but necessary for Vulkan command buffers to do it here! + screen->mLights->BindBase(gl_RenderState); // not needed for OpenGL but necessary for Vulkan command buffers to do it here! gl_RenderState.EnableFog(true); gl_RenderState.SetRenderStyle(STYLE_Source); diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 1a94c3ae6..a2e627989 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -166,10 +166,10 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * // FString vp_comb; - assert(GLRenderer->mLights != NULL); + assert(screen->mLights != NULL); - bool lightbuffertype = GLRenderer->mLights->GetBufferType(); - unsigned int lightbuffersize = GLRenderer->mLights->GetBlockSize(); + bool lightbuffertype = screen->mLights->GetBufferType(); + unsigned int lightbuffersize = screen->mLights->GetBlockSize(); if (!lightbuffertype) { vp_comb.Format("#version 330 core\n#define NUM_UBO_LIGHTS %d\n", lightbuffersize); diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 163c921aa..b211df6d4 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -41,6 +41,7 @@ #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/data/hw_viewpointbuffer.h" +#include "hwrenderer/dynlights/hw_lightbuffer.h" #include "gl/shaders/gl_shaderprogram.h" #include "gl_debug.h" #include "r_videoscale.h" @@ -87,6 +88,7 @@ OpenGLFrameBuffer::~OpenGLFrameBuffer() if (mVertexData != nullptr) delete mVertexData; if (mSkyData != nullptr) delete mSkyData; if (mViewpoints != nullptr) delete mViewpoints; + if (mLights != nullptr) delete mLights; if (GLRenderer) { @@ -144,13 +146,15 @@ void OpenGLFrameBuffer::InitializeState() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - GLRenderer = new FGLRenderer(this); - GLRenderer->Initialize(GetWidth(), GetHeight()); SetViewportRects(nullptr); mVertexData = new FFlatVertexBuffer(GetWidth(), GetHeight()); mSkyData = new FSkyVertexBuffer; mViewpoints = new GLViewpointBuffer; + mLights = new FLightBuffer(); + + GLRenderer = new FGLRenderer(this); + GLRenderer->Initialize(GetWidth(), GetHeight()); mDebug = std::make_shared(); mDebug->Update(); diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index e70761c99..ae8c09e78 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -337,7 +337,6 @@ public: virtual void AddFlat(GLFlat *flat, bool fog) = 0; virtual void AddSprite(GLSprite *sprite, bool translucent) = 0; - virtual int UploadLights(FDynLightData &data) = 0; virtual void ApplyVPUniforms() = 0; virtual bool SetDepthClamp(bool on) = 0; diff --git a/src/hwrenderer/scene/hw_flats.cpp b/src/hwrenderer/scene/hw_flats.cpp index 1d0a817bf..948534fbb 100644 --- a/src/hwrenderer/scene/hw_flats.cpp +++ b/src/hwrenderer/scene/hw_flats.cpp @@ -42,6 +42,7 @@ #include "hwrenderer/textures/hw_material.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/data/flatvertices.h" +#include "hwrenderer/dynlights/hw_lightbuffer.h" #include "hw_drawstructs.h" #include "hw_renderstate.h" @@ -170,7 +171,7 @@ void GLFlat::SetupLights(HWDrawInfo *di, FLightNode * node, FDynLightData &light node = node->nextLight; } - dynlightindex = di->UploadLights(lightdata); + dynlightindex = screen->mLights->UploadLights(lightdata); } //========================================================================== diff --git a/src/hwrenderer/scene/hw_renderhacks.cpp b/src/hwrenderer/scene/hw_renderhacks.cpp index 7ab286352..b52cb023d 100644 --- a/src/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/hwrenderer/scene/hw_renderhacks.cpp @@ -36,6 +36,7 @@ #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/data/flatvertices.h" +#include "hwrenderer/dynlights/hw_lightbuffer.h" sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool back); @@ -71,7 +72,7 @@ int HWDrawInfo::SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &light node = node->nextLight; } - return UploadLights(lightdata); + return screen->mLights->UploadLights(lightdata); } else return -1; } diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index 06ef08925..637fe886c 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -53,6 +53,7 @@ #include "hwrenderer/utility/hw_lighting.h" #include "hwrenderer/textures/hw_material.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hwrenderer/dynlights/hw_lightbuffer.h" #include "hw_renderstate.h" extern TArray sprites; @@ -460,7 +461,7 @@ inline void GLSprite::PutSprite(HWDrawInfo *di, bool translucent) if (modelframe && RenderStyle.BlendOp != STYLEOP_Shadow && gl_light_sprites && level.HasDynamicLights && !di->isFullbrightScene() && !fullbright) { hw_GetDynModelLight(actor, lightdata); - dynlightindex = di->UploadLights(lightdata); + dynlightindex = screen->mLights->UploadLights(lightdata); } else dynlightindex = -1; diff --git a/src/hwrenderer/scene/hw_walls.cpp b/src/hwrenderer/scene/hw_walls.cpp index 047c2dba6..232d1ec7d 100644 --- a/src/hwrenderer/scene/hw_walls.cpp +++ b/src/hwrenderer/scene/hw_walls.cpp @@ -38,6 +38,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_portal.h" +#include "hwrenderer/dynlights/hw_lightbuffer.h" #include "hw_renderstate.h" #include "hw_skydome.h" @@ -359,7 +360,7 @@ void GLWall::SetupLights(HWDrawInfo *di, FDynLightData &lightdata) } node = node->nextLight; } - dynlightindex = di->UploadLights(lightdata); + dynlightindex = screen->mLights->UploadLights(lightdata); } diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index 374b6ea9f..e0dfe13e5 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -43,6 +43,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/data/flatvertices.h" +#include "hwrenderer/dynlights/hw_lightbuffer.h" #include "hw_renderstate.h" EXTERN_CVAR(Float, transsouls) @@ -544,7 +545,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) else { hw_GetDynModelLight(playermo, lightdata); - hudsprite.lightindex = UploadLights(lightdata); + hudsprite.lightindex = screen->mLights->UploadLights(lightdata); } } diff --git a/src/v_video.h b/src/v_video.h index 0776b42ca..6a414ad04 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -55,6 +55,7 @@ class IVertexBuffer; class IDataBuffer; class FFlatVertexBuffer; class GLViewpointBuffer; +class FLightBuffer; enum EHWCaps { @@ -380,6 +381,7 @@ public: FSkyVertexBuffer *mSkyData = nullptr; // the sky vertex buffer FFlatVertexBuffer *mVertexData = nullptr; // Global vertex data GLViewpointBuffer *mViewpoints = nullptr; // Viewpoint render data. + FLightBuffer *mLights = nullptr; // Dynamic lights IntRect mScreenViewport; IntRect mSceneViewport;