From e6efee61b1190470c5afd2b712b73e9b0dbbca4c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Oct 2018 17:09:22 +0100 Subject: [PATCH] - moved the last remaining function from gl_shadowmap.cpp elsewhere so that the file can be deleted. --- src/CMakeLists.txt | 2 - src/gl/dynlights/gl_shadowmap.cpp | 69 ----------------------- src/gl/dynlights/gl_shadowmap.h | 13 ----- src/gl/renderer/gl_renderer.cpp | 35 +++++++++++- src/gl/renderer/gl_renderer.h | 5 +- src/hwrenderer/dynlights/hw_shadowmap.cpp | 23 ++++++-- src/hwrenderer/dynlights/hw_shadowmap.h | 12 ++-- 7 files changed, 61 insertions(+), 98 deletions(-) delete mode 100644 src/gl/dynlights/gl_shadowmap.cpp delete mode 100644 src/gl/dynlights/gl_shadowmap.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e583676be..93ee0b4b2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -700,7 +700,6 @@ file( GLOB HEADER_FILES hwrenderer/textures/*.h hwrenderer/utility/*.h gl/*.h - gl/dynlights/*.h gl/models/*.h gl/renderer/*.h gl/scene/*.h @@ -1037,7 +1036,6 @@ set (PCH_SOURCES g_statusbar/sbarinfo.cpp g_statusbar/sbar_mugshot.cpp g_statusbar/shared_sbar.cpp - gl/dynlights/gl_shadowmap.cpp gl/renderer/gl_renderer.cpp gl/renderer/gl_renderstate.cpp gl/renderer/gl_renderbuffers.cpp diff --git a/src/gl/dynlights/gl_shadowmap.cpp b/src/gl/dynlights/gl_shadowmap.cpp deleted file mode 100644 index bc0ec9da7..000000000 --- a/src/gl/dynlights/gl_shadowmap.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// -//--------------------------------------------------------------------------- -// 1D dynamic shadow maps (OpenGL dependent part) -// Copyright(C) 2017 Magnus Norddahl -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// - -#include "gl_load/gl_system.h" -#include "gl/shaders/gl_shader.h" -#include "gl/dynlights/gl_shadowmap.h" -#include "gl/system/gl_debug.h" -#include "hwrenderer/utility/hw_cvars.h" -#include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_postprocessstate.h" -#include "gl/renderer/gl_renderbuffers.h" -#include "hwrenderer/postprocessing/hw_shadowmapshader.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" -#include "stats.h" - -void FShadowMap::Update() -{ - UpdateCycles.Reset(); - LightsProcessed = 0; - LightsShadowmapped = 0; - - if (!IsEnabled()) - return; - - UpdateCycles.Clock(); - - PerformUpdate(); - - FGLDebug::PushGroup("ShadowMap"); - FGLPostProcessState savedState; - - GLRenderer->mBuffers->BindShadowMapFB(); - - GLRenderer->mShadowMapShader->Bind(NOQUEUE); - GLRenderer->mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality; - GLRenderer->mShadowMapShader->Uniforms.Set(); - - glViewport(0, 0, gl_shadowmap_quality, 1024); - GLRenderer->RenderScreenQuad(); - - const auto &viewport = screen->mScreenViewport; - glViewport(viewport.left, viewport.top, viewport.width, viewport.height); - - GLRenderer->mBuffers->BindShadowMapTexture(16); - - FGLDebug::PopGroup(); - - UpdateCycles.Unclock(); -} - diff --git a/src/gl/dynlights/gl_shadowmap.h b/src/gl/dynlights/gl_shadowmap.h deleted file mode 100644 index 958c006e1..000000000 --- a/src/gl/dynlights/gl_shadowmap.h +++ /dev/null @@ -1,13 +0,0 @@ - -#pragma once - -#include "hwrenderer/dynlights/hw_shadowmap.h" - -class IDataBuffer; - -class FShadowMap : public IShadowMap -{ -public: - // Update shadow map texture - void Update() override; -}; diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 9d35db9ac..ee5ca09b2 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -60,6 +60,7 @@ #include "hwrenderer/data/hw_viewpointbuffer.h" #include "r_videoscale.h" #include "r_data/models/models.h" +#include "gl/renderer/gl_postprocessstate.h" EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Bool, cl_capfps) @@ -177,6 +178,38 @@ void FGLRenderer::EndOffscreen() glBindFramebuffer(GL_FRAMEBUFFER, mOldFBID); } +//=========================================================================== +// +// +// +//=========================================================================== + +void FGLRenderer::UpdateShadowMap() +{ + if (mShadowMap.PerformUpdate()) + { + FGLDebug::PushGroup("ShadowMap"); + + FGLPostProcessState savedState; + + mBuffers->BindShadowMapFB(); + + mShadowMapShader->Bind(NOQUEUE); + mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality; + mShadowMapShader->Uniforms.Set(); + + glViewport(0, 0, gl_shadowmap_quality, 1024); + RenderScreenQuad(); + + const auto &viewport = screen->mScreenViewport; + glViewport(viewport.left, viewport.top, viewport.width, viewport.height); + + mBuffers->BindShadowMapTexture(16); + FGLDebug::PopGroup(); + mShadowMap.FinishUpdate(); + } +} + //----------------------------------------------------------------------------- // // renders the view @@ -230,7 +263,7 @@ sector_t *FGLRenderer::RenderView(player_t* player) fovratio = ratio; } - mShadowMap.Update(); + UpdateShadowMap(); retsec = RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); } All.Unclock(); diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index dd332ddf2..1644fa37a 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -7,7 +7,7 @@ #include "r_renderer.h" #include "r_data/matrix.h" #include "hwrenderer/scene/hw_portal.h" -#include "gl/dynlights/gl_shadowmap.h" +#include "hwrenderer/dynlights/hw_shadowmap.h" #include #ifdef _MSC_VER @@ -65,7 +65,7 @@ public: FShadowMapShader *mShadowMapShader = nullptr; FCustomPostProcessShaders *mCustomPostProcessShaders = nullptr; - FShadowMap mShadowMap; + IShadowMap mShadowMap; //FRotator mAngles; @@ -103,6 +103,7 @@ public: bool StartOffscreen(); void EndOffscreen(); + void UpdateShadowMap(); void BindToFrameBuffer(FMaterial *mat); }; diff --git a/src/hwrenderer/dynlights/hw_shadowmap.cpp b/src/hwrenderer/dynlights/hw_shadowmap.cpp index c5110ce87..024a5cc97 100644 --- a/src/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/hwrenderer/dynlights/hw_shadowmap.cpp @@ -162,13 +162,24 @@ bool IShadowMap::ValidateAABBTree() return false; } -void IShadowMap::PerformUpdate() +bool IShadowMap::PerformUpdate() { - UploadAABBTree(); - UploadLights(); - mLightList->BindBase(); - mNodesBuffer->BindBase(); - mLinesBuffer->BindBase(); + UpdateCycles.Reset(); + + LightsProcessed = 0; + LightsShadowmapped = 0; + + if (IsEnabled()) + { + UpdateCycles.Clock(); + UploadAABBTree(); + UploadLights(); + mLightList->BindBase(); + mNodesBuffer->BindBase(); + mLinesBuffer->BindBase(); + return true; + } + return false; } void IShadowMap::UploadLights() diff --git a/src/hwrenderer/dynlights/hw_shadowmap.h b/src/hwrenderer/dynlights/hw_shadowmap.h index 02ad3ab59..8c004b559 100644 --- a/src/hwrenderer/dynlights/hw_shadowmap.h +++ b/src/hwrenderer/dynlights/hw_shadowmap.h @@ -15,9 +15,6 @@ public: IShadowMap() { } virtual ~IShadowMap(); - // Update shadow map texture - virtual void Update() = 0; - // Test if a world position is in shadow relative to the specified light and returns false if it is bool ShadowTest(ADynamicLight *light, const DVector3 &pos); @@ -27,11 +24,16 @@ public: static cycle_t UpdateCycles; static int LightsProcessed; static int LightsShadowmapped; - + + bool PerformUpdate(); + void FinishUpdate() + { + UpdateCycles.Clock(); + } + protected: void CollectLights(); bool ValidateAABBTree(); - void PerformUpdate(); // Upload the AABB-tree to the GPU void UploadAABBTree();