diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index a692145d30..1e7addf624 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -80,8 +80,6 @@ void FRenderState::Reset() mLightParms[0] = mLightParms[1] = mLightParms[2] = 0.0f; mLightParms[3] = -1.f; mSpecialEffect = EFF_NONE; - mClipHeight = 0.f; - mClipHeightDirection = 0.f; mGlossiness = 0.0f; mSpecularLevel = 0.0f; mShaderTimer = 0.0f; @@ -165,8 +163,6 @@ bool FRenderState::ApplyShader() activeShader->muObjectColor2.Set(mObjectColor2); activeShader->muDynLightColor.Set(mDynColor.vec); activeShader->muInterpolationFactor.Set(mInterpolationFactor); - activeShader->muClipHeight.Set(mClipHeight); - activeShader->muClipHeightDirection.Set(mClipHeightDirection); activeShader->muTimer.Set((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.); activeShader->muAlphaThreshold.Set(mAlphaThreshold); activeShader->muLightIndex.Set(-1); @@ -304,20 +300,3 @@ void FRenderState::ApplyLightIndex(int index) } activeShader->muLightIndex.Set(index); } - -void FRenderState::SetClipHeight(float height, float direction) -{ - mClipHeight = height; - mClipHeightDirection = direction; - - if (gl.flags & RFL_NO_CLIP_PLANES) return; - - if (direction != 0.f) - { - glEnable(GL_CLIP_DISTANCE0); - } - else - { - glDisable(GL_CLIP_DISTANCE0); // GL_CLIP_PLANE0 is the same value so no need to make a distinction - } -} diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 257ef56a8c..00338dbe18 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -196,8 +196,6 @@ public: return mClipLineShouldBeActive; } - void SetClipHeight(float height, float direction); - void SetNormal(FVector3 norm) { mNormal.Set(norm.X, norm.Y, norm.Z, 0.f); diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 22687eaa7d..192f179454 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -745,29 +745,13 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di) di->UpdateCurrentMapSection(); - gl_RenderState.SetClipHeight(planez, PlaneMirrorMode < 0 ? -1.f : 1.f); + di->SetClipHeight(planez, PlaneMirrorMode < 0 ? -1.f : 1.f); di->DrawScene(DM_PORTAL); - gl_RenderState.SetClipHeight(0.f, 0.f); PlaneMirrorFlag--; PlaneMirrorMode = old_pm; std::swap(screen->instack[sector_t::floor], screen->instack[sector_t::ceiling]); } -void GLPlaneMirrorPortal::PushState() -{ - planestack.Push(gl_RenderState.GetClipHeight()); - planestack.Push(gl_RenderState.GetClipHeightDirection()); - gl_RenderState.SetClipHeight(0.f, 0.f); -} - -void GLPlaneMirrorPortal::PopState() -{ - float d, f; - planestack.Pop(d); - planestack.Pop(f); - gl_RenderState.SetClipHeight(f, d); -} - //----------------------------------------------------------------------------- // // Common code for line to line and mirror portals diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index a6d153aa7a..fd0e0fbf0d 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -302,8 +302,6 @@ protected: virtual void DrawContents(FDrawInfo *di); virtual void * GetSource() const { return origin; } virtual const char *GetName(); - virtual void PushState(); - virtual void PopState(); secplane_t * origin; public: diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 72f3d89158..f39c428dfa 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -76,6 +76,18 @@ void FDrawInfo::ApplyVPUniforms() { VPUniforms.CalcDependencies(); GLRenderer->mShaderManager->ApplyMatrices(&VPUniforms, NORMAL_PASS); + + if (!(gl.flags & RFL_NO_CLIP_PLANES)) + { + if (VPUniforms.mClipHeightDirection != 0.f) + { + glEnable(GL_CLIP_DISTANCE0); + } + else + { + glDisable(GL_CLIP_DISTANCE0); + } + } } //----------------------------------------------------------------------------- diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 953b31e909..d14d1ee342 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -324,8 +324,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muSplitTopPlane.Init(hShader, "uSplitTopPlane"); muClipLine.Init(hShader, "uClipLine"); muInterpolationFactor.Init(hShader, "uInterpolationFactor"); - muClipHeight.Init(hShader, "uClipHeight"); - muClipHeightDirection.Init(hShader, "uClipHeightDirection"); muAlphaThreshold.Init(hShader, "uAlphaThreshold"); muSpecularMaterial.Init(hShader, "uSpecularMaterial"); muTimer.Init(hShader, "timer"); @@ -345,6 +343,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * camerapos_index = glGetUniformLocation(hShader, "uCameraPos"); pallightlevels_index = glGetUniformLocation(hShader, "uPalLightLevels"); globvis_index = glGetUniformLocation(hShader, "uGlobVis"); + clipheight_index = glGetUniformLocation(hShader, "uClipHeight"); + clipheightdirection_index = glGetUniformLocation(hShader, "uClipHeightDirection"); if (!(gl.flags & RFL_SHADER_STORAGE_BUFFER)) { @@ -446,6 +446,8 @@ void FShader::ApplyMatrices(HWViewpointUniforms *u) glUniform1i(viewheight_index, u->mViewHeight); glUniform1i(pallightlevels_index, u->mPalLightLevels); glUniform1f(globvis_index, u->mGlobVis); + glUniform1f(clipheight_index, u->mClipHeight); + glUniform1f(clipheightdirection_index, u->mClipHeightDirection); } //========================================================================== diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 9a0b52eb18..4a84cf0ed8 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -259,8 +259,6 @@ class FShader FUniform4f muSplitTopPlane; FUniform4f muClipLine; FBufferedUniform1f muInterpolationFactor; - FBufferedUniform1f muClipHeight; - FBufferedUniform1f muClipHeightDirection; FBufferedUniform1f muAlphaThreshold; FBufferedUniform2f muSpecularMaterial; FBufferedUniform1f muTimer; @@ -277,6 +275,8 @@ class FShader int camerapos_index; int pallightlevels_index; int globvis_index; + int clipheight_index; + int clipheightdirection_index; public: int vertexmatrix_index; diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index f62c12a62e..a2464931db 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -158,6 +158,12 @@ public: VPUniforms.mCameraPos = { (float)pos.X, (float)pos.Z, (float)pos.Y, 0.f }; } + void SetClipHeight(float h, float d) + { + VPUniforms.mClipHeight = h; + VPUniforms.mClipHeightDirection = d; + } + void RenderBSPNode(void *node); void ClearBuffers(); diff --git a/src/hwrenderer/scene/hw_viewpointuniforms.h b/src/hwrenderer/scene/hw_viewpointuniforms.h index 2727fbd255..39fa1dbb72 100644 --- a/src/hwrenderer/scene/hw_viewpointuniforms.h +++ b/src/hwrenderer/scene/hw_viewpointuniforms.h @@ -11,9 +11,11 @@ struct HWViewpointUniforms FVector4 mCameraPos; FVector4 mClipLine; - float mGlobVis; - int mPalLightLevels; - int mViewHeight; + float mGlobVis = 1.f; + int mPalLightLevels = 0; + int mViewHeight = 0; + float mClipHeight = 0.f; + float mClipHeightDirection = 0.f; void CalcDependencies() {