From 54f46fdfee2ee61f38e6f200bfefe6e3cdddc7a5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Oct 2018 16:11:04 +0100 Subject: [PATCH] - moved most of FShadowMap to IShadowMap, except the main Update function. --- src/gl/dynlights/gl_shadowmap.cpp | 37 +------------------- src/gl/dynlights/gl_shadowmap.h | 19 ----------- src/hwrenderer/dynlights/hw_shadowmap.cpp | 41 +++++++++++++++++++++++ src/hwrenderer/dynlights/hw_shadowmap.h | 21 +++++++++--- 4 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/gl/dynlights/gl_shadowmap.cpp b/src/gl/dynlights/gl_shadowmap.cpp index 67403b308..bc0ec9da7 100644 --- a/src/gl/dynlights/gl_shadowmap.cpp +++ b/src/gl/dynlights/gl_shadowmap.cpp @@ -43,8 +43,7 @@ void FShadowMap::Update() UpdateCycles.Clock(); - UploadAABBTree(); - UploadLights(); + PerformUpdate(); FGLDebug::PushGroup("ShadowMap"); FGLPostProcessState savedState; @@ -54,9 +53,6 @@ void FShadowMap::Update() GLRenderer->mShadowMapShader->Bind(NOQUEUE); GLRenderer->mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality; GLRenderer->mShadowMapShader->Uniforms.Set(); - mLightList->BindBase(); - mNodesBuffer->BindBase(); - mLinesBuffer->BindBase(); glViewport(0, 0, gl_shadowmap_quality, 1024); GLRenderer->RenderScreenQuad(); @@ -71,34 +67,3 @@ void FShadowMap::Update() UpdateCycles.Unclock(); } - -void FShadowMap::UploadLights() -{ - CollectLights(); - - if (mLightList == nullptr) - mLightList = screen->CreateDataBuffer(4, true); - - mLightList->SetData(sizeof(float) * mLights.Size(), &mLights[0]); -} - - -void FShadowMap::UploadAABBTree() -{ - if (!ValidateAABBTree()) - { - mNodesBuffer = screen->CreateDataBuffer(2, true); - mNodesBuffer->SetData(sizeof(hwrenderer::AABBTreeNode) * mAABBTree->nodes.Size(), &mAABBTree->nodes[0]); - - mLinesBuffer = screen->CreateDataBuffer(3, true); - mLinesBuffer->SetData(sizeof(hwrenderer::AABBTreeLine) * mAABBTree->lines.Size(), &mAABBTree->lines[0]); - } -} - -void FShadowMap::Clear() -{ - if (mLightList) delete mLightList; - if (mNodesBuffer) delete mNodesBuffer; - if (mLinesBuffer) delete mLinesBuffer; -} - diff --git a/src/gl/dynlights/gl_shadowmap.h b/src/gl/dynlights/gl_shadowmap.h index e415bf23d..958c006e1 100644 --- a/src/gl/dynlights/gl_shadowmap.h +++ b/src/gl/dynlights/gl_shadowmap.h @@ -8,25 +8,6 @@ class IDataBuffer; class FShadowMap : public IShadowMap { public: - ~FShadowMap() { Clear(); } - - // Release resources - void Clear() override; - // Update shadow map texture void Update() override; - -private: - // Upload the AABB-tree to the GPU - void UploadAABBTree(); - - // Upload light list to the GPU - void UploadLights(); - - // OpenGL storage buffer with the list of lights in the shadow map texture - IDataBuffer *mLightList = nullptr; - - // OpenGL storage buffers for the AABB tree - IDataBuffer *mNodesBuffer = nullptr; - IDataBuffer *mLinesBuffer = nullptr; }; diff --git a/src/hwrenderer/dynlights/hw_shadowmap.cpp b/src/hwrenderer/dynlights/hw_shadowmap.cpp index 027942f46..c5110ce87 100644 --- a/src/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/hwrenderer/dynlights/hw_shadowmap.cpp @@ -23,6 +23,7 @@ #include "hwrenderer/dynlights/hw_shadowmap.h" #include "hwrenderer/utility/hw_cvars.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hwrenderer/data/buffers.h" #include "stats.h" #include "g_levellocals.h" @@ -160,3 +161,43 @@ bool IShadowMap::ValidateAABBTree() mAABBTree.reset(new hwrenderer::LevelAABBTree()); return false; } + +void IShadowMap::PerformUpdate() +{ + UploadAABBTree(); + UploadLights(); + mLightList->BindBase(); + mNodesBuffer->BindBase(); + mLinesBuffer->BindBase(); +} + +void IShadowMap::UploadLights() +{ + CollectLights(); + + if (mLightList == nullptr) + mLightList = screen->CreateDataBuffer(4, true); + + mLightList->SetData(sizeof(float) * mLights.Size(), &mLights[0]); +} + + +void IShadowMap::UploadAABBTree() +{ + if (!ValidateAABBTree()) + { + mNodesBuffer = screen->CreateDataBuffer(2, true); + mNodesBuffer->SetData(sizeof(hwrenderer::AABBTreeNode) * mAABBTree->nodes.Size(), &mAABBTree->nodes[0]); + + mLinesBuffer = screen->CreateDataBuffer(3, true); + mLinesBuffer->SetData(sizeof(hwrenderer::AABBTreeLine) * mAABBTree->lines.Size(), &mAABBTree->lines[0]); + } +} + +IShadowMap::~IShadowMap() +{ + if (mLightList) delete mLightList; + if (mNodesBuffer) delete mNodesBuffer; + if (mLinesBuffer) delete mLinesBuffer; +} + diff --git a/src/hwrenderer/dynlights/hw_shadowmap.h b/src/hwrenderer/dynlights/hw_shadowmap.h index 492993919..02ad3ab59 100644 --- a/src/hwrenderer/dynlights/hw_shadowmap.h +++ b/src/hwrenderer/dynlights/hw_shadowmap.h @@ -7,15 +7,13 @@ class ADynamicLight; struct level_info_t; +class IDataBuffer; class IShadowMap { public: IShadowMap() { } - virtual ~IShadowMap() { } - - // Release resources - virtual void Clear() = 0; + virtual ~IShadowMap(); // Update shadow map texture virtual void Update() = 0; @@ -33,6 +31,13 @@ public: protected: void CollectLights(); bool ValidateAABBTree(); + void PerformUpdate(); + + // Upload the AABB-tree to the GPU + void UploadAABBTree(); + + // Upload light list to the GPU + void UploadLights(); // Working buffer for creating the list of lights. Stored here to avoid allocating memory each frame TArray mLights; @@ -47,4 +52,12 @@ protected: IShadowMap(const IShadowMap &) = delete; IShadowMap &operator=(IShadowMap &) = delete; + + // OpenGL storage buffer with the list of lights in the shadow map texture + IDataBuffer *mLightList = nullptr; + + // OpenGL storage buffers for the AABB tree + IDataBuffer *mNodesBuffer = nullptr; + IDataBuffer *mLinesBuffer = nullptr; + };