From acad8315d0a54887096fda26114f786661c6c7ef Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 21 Oct 2018 10:58:11 +0200 Subject: [PATCH] - move stencil recursion counter to render state. --- src/gl/renderer/gl_renderstate.cpp | 3 +-- src/gl/renderer/gl_renderstate.h | 6 ++++++ src/gl/scene/gl_portal.cpp | 18 ++++++++---------- src/hwrenderer/scene/hw_portal.h | 7 ------- src/hwrenderer/scene/hw_renderstate.h | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 5143b76c5b..02a7125e8f 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -240,8 +240,7 @@ void FGLRenderState::Apply() if (mStencil.mChanged) { - int recursion = GLRenderer->mPortalState.GetRecursion(); - glStencilFunc(GL_EQUAL, recursion + mStencil.mOffsVal, ~0); // draw sky into stencil + glStencilFunc(GL_EQUAL, mStencil.mBaseVal + mStencil.mOffsVal, ~0); // draw sky into stencil glStencilOp(GL_KEEP, GL_KEEP, op2gl[mStencil.mOperation]); // this stage doesn't modify the stencil bool cmon = !(mStencil.mFlags & SF_ColorMaskOff); diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 00353e6607..83b90b9057 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -201,6 +201,12 @@ public: return mPassType == GBUFFER_PASS ? 3 : 1; } + // Temporary helper. + int GetStencilCounter() + { + return mStencil.mBaseVal; + } + }; extern FGLRenderState gl_RenderState; diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 477b1fa390..9631339983 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -133,7 +133,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw } // Create stencil - glStencilFunc(GL_EQUAL, mState->recursion, ~0); // create stencil + glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter(), ~0); // create stencil glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); // increment stencil of valid pixels { glColorMask(0,0,0,0); // don't write to the graphics buffer @@ -157,7 +157,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw if (doquery) glEndQuery(GL_SAMPLES_PASSED); // Clear Z-buffer - glStencilFunc(GL_EQUAL, mState->recursion + 1, ~0); // draw sky into stencil + glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter() + 1, ~0); // draw sky into stencil glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // this stage doesn't modify the stencil glDepthMask(true); // enable z-buffer again glDepthRange(1, 1); @@ -179,7 +179,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw { // restore default stencil op. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glStencilFunc(GL_EQUAL, mState->recursion, ~0); // draw sky into stencil + glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter(), ~0); // draw sky into stencil return false; } } @@ -192,7 +192,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw glDepthMask(true); DrawPortalStencil(STP_AllInOne); - glStencilFunc(GL_EQUAL, mState->recursion + 1, ~0); // draw sky into stencil + glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter() + 1, ~0); // draw sky into stencil glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // this stage doesn't modify the stencil gl_RenderState.EnableTexture(true); glColorMask(1,1,1,1); @@ -201,9 +201,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw glDepthMask(false); // don't write to Z-buffer! } } - mState->recursion++; - - + gl_RenderState.IncStencilValue(); } else { @@ -265,7 +263,7 @@ void GLPortal::End(HWDrawInfo *di, bool usestencil) glDepthFunc(GL_LEQUAL); glDepthRange(0, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_DECR); - glStencilFunc(GL_EQUAL, mState->recursion, ~0); // draw sky into stencil + glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter(), ~0); // draw sky into stencil DrawPortalStencil(STP_DepthRestore); glDepthFunc(GL_LESS); @@ -273,11 +271,11 @@ void GLPortal::End(HWDrawInfo *di, bool usestencil) gl_RenderState.EnableTexture(true); gl_RenderState.SetEffect(EFF_NONE); glColorMask(1, 1, 1, 1); - mState->recursion--; + gl_RenderState.DecStencilValue(); // restore old stencil op. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glStencilFunc(GL_EQUAL, mState->recursion, ~0); // draw sky into stencil + glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter(), ~0); // draw sky into stencil } else { diff --git a/src/hwrenderer/scene/hw_portal.h b/src/hwrenderer/scene/hw_portal.h index d3228ab1dc..36047a3f53 100644 --- a/src/hwrenderer/scene/hw_portal.h +++ b/src/hwrenderer/scene/hw_portal.h @@ -79,8 +79,6 @@ public: struct FPortalSceneState { - int recursion = 0; - int MirrorFlag = 0; int PlaneMirrorFlag = 0; int renderdepth = 0; @@ -101,11 +99,6 @@ struct FPortalSceneState UniquePlaneMirrors.Clear(); } - int GetRecursion() const - { - return recursion; - } - bool isMirrored() const { return !!((MirrorFlag ^ PlaneMirrorFlag) & 1); diff --git a/src/hwrenderer/scene/hw_renderstate.h b/src/hwrenderer/scene/hw_renderstate.h index 473f60ae06..46c099bfb4 100644 --- a/src/hwrenderer/scene/hw_renderstate.h +++ b/src/hwrenderer/scene/hw_renderstate.h @@ -74,6 +74,7 @@ struct FMaterialState struct FStencilState { + int mBaseVal; int mOffsVal; int mOperation; int mFlags; @@ -81,6 +82,7 @@ struct FStencilState void Reset() { + mBaseVal = 0; mOffsVal = 0; mOperation = SOP_Keep; mFlags = SF_AllOn; @@ -402,6 +404,19 @@ public: mStencil.mChanged = true; } + void IncStencilValue() + { + mStencil.mBaseVal++; + mStencil.mChanged = true; + } + + void DecStencilValue() + { + mStencil.mBaseVal--; + mStencil.mChanged = true; + } + + void SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon = false); void SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive);