diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 1e7addf624..258fc9a058 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -61,7 +61,7 @@ static void matrixToGL(const VSMatrix &mat, int loc) void FRenderState::Reset() { mTextureEnabled = true; - mClipLineShouldBeActive = mClipLineEnabled = mSplitEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false; + mSplitEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false; mColorMask[0] = mColorMask[1] = mColorMask[2] = mColorMask[3] = true; currentColorMask[0] = currentColorMask[1] = currentColorMask[2] = currentColorMask[3] = true; mFogColor.d = -1; @@ -99,7 +99,6 @@ void FRenderState::Reset() mGlowBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); mSplitTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); mSplitBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); - mClipLine.Set(0.0f, 0.0f, 0.0f, 0.0f); mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f); mEffectState = 0; activeShader = nullptr; @@ -201,17 +200,6 @@ bool FRenderState::ApplyShader() activeShader->currentsplitstate = 0; } - if (mClipLineEnabled) - { - activeShader->muClipLine.Set(mClipLine.vec); - activeShader->currentcliplinestate = 1; - } - else if (activeShader->currentcliplinestate) - { - activeShader->muClipLine.Set(-10000000.0, 0, 0, 0); - activeShader->currentcliplinestate = 0; - } - if (mTextureMatrixEnabled) { matrixToGL(mTextureMatrix, activeShader->texturematrix_index); diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 00338dbe18..e1dc4bec00 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -79,8 +79,6 @@ class FRenderState uint8_t mFogEnabled; bool mGlowEnabled; bool mSplitEnabled; - bool mClipLineEnabled; - bool mClipLineShouldBeActive; bool mBrightmapEnabled; bool mColorMask[4]; bool currentColorMask[4]; @@ -96,7 +94,6 @@ class FRenderState bool mTextureMatrixEnabled; bool mLastDepthClamp; float mInterpolationFactor; - float mClipHeight, mClipHeightDirection; float mGlossiness, mSpecularLevel; float mShaderTimer; @@ -106,7 +103,6 @@ class FRenderState FStateVec4 mGlowTop, mGlowBottom; FStateVec4 mGlowTopPlane, mGlowBottomPlane; FStateVec4 mSplitTopPlane, mSplitBottomPlane; - FStateVec4 mClipLine; PalEntry mFogColor; PalEntry mObjectColor; PalEntry mObjectColor2; @@ -171,31 +167,6 @@ public: mCurrentVertexBuffer = NULL; } - float GetClipHeight() - { - return mClipHeight; - } - - float GetClipHeightDirection() - { - return mClipHeightDirection; - } - - FStateVec4 &GetClipLine() - { - return mClipLine; - } - - bool GetClipLineState() - { - return mClipLineEnabled; - } - - bool GetClipLineShouldBeActive() - { - return mClipLineShouldBeActive; - } - void SetNormal(FVector3 norm) { mNormal.Set(norm.X, norm.Y, norm.Z, 0.f); @@ -300,32 +271,6 @@ public: } } - void SetClipLine(line_t *line) - { - mClipLine.Set(line->v1->fX(), line->v1->fY(), line->Delta().X, line->Delta().Y); - } - - void EnableClipLine(bool on) - { - if (!(gl.flags & RFL_NO_CLIP_PLANES)) - { - mClipLineEnabled = on; - if (on) - { - glEnable(GL_CLIP_DISTANCE0); - } - else - { - glDisable(GL_CLIP_DISTANCE0); - } - } - else - { - // this needs to be flagged because in this case per-sector plane rendering needs to be disabled if a clip plane is active. - mClipLineShouldBeActive = on; - } - } - void EnableBrightmap(bool on) { mBrightmapEnabled = on; diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index c123007ed0..b8a3d7c706 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -207,7 +207,13 @@ FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUnifo di->mVBO = GLRenderer->mVBO; di->mClipper = &staticClipper; di->Viewpoint = parentvp; - if (uniforms) di->VPUniforms = *uniforms; + if (uniforms) + { + di->VPUniforms = *uniforms; + // The clip planes will never be inherited from the parent drawinfo. + di->VPUniforms.mClipLine.X = -1000001.f; + di->VPUniforms.mClipHeight = 0; + } else di->VPUniforms.SetDefaults(); di->mClipper->SetViewpoint(di->Viewpoint); staticClipper.Clear(); diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index f7b0729f10..d50a00f9cb 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -166,7 +166,7 @@ void FDrawInfo::ProcessLights(GLFlat *flat, bool istrans) { flat->dynlightindex = GLRenderer->mLights->GetIndexPtr(); - if (flat->sector->ibocount > 0 && !gl_RenderState.GetClipLineShouldBeActive()) + if (flat->sector->ibocount > 0 && !ClipLineShouldBeActive()) { SetupSectorLights(flat, GLPASS_LIGHTSONLY, nullptr); } @@ -215,7 +215,7 @@ void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool if (iboindex >= 0) { - if (vcount > 0 && !gl_RenderState.GetClipLineShouldBeActive()) + if (vcount > 0 && !ClipLineShouldBeActive()) { if (processlights) SetupSectorLights(flat, GLPASS_ALL, &dli); drawcalls.Clock(); diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index c337d113c5..2b49309760 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -758,29 +758,6 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di) // //----------------------------------------------------------------------------- -void GLLinePortal::PushState() -{ - FStateVec4 &v = gl_RenderState.GetClipLine(); - planestack.Push(v.vec[0]); - planestack.Push(v.vec[1]); - planestack.Push(v.vec[2]); - planestack.Push(v.vec[3]); - planestack.Push(gl_RenderState.GetClipLineState()); - gl_RenderState.EnableClipLine(false); -} - -void GLLinePortal::PopState() -{ - FStateVec4 &v = gl_RenderState.GetClipLine(); - float e = 0; - planestack.Pop(e); - planestack.Pop(v.vec[3]); - planestack.Pop(v.vec[2]); - planestack.Pop(v.vec[1]); - planestack.Pop(v.vec[0]); - gl_RenderState.EnableClipLine(e != 0); -} - int GLLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos) { line_t *linedef = seg->linedef; @@ -793,7 +770,7 @@ int GLLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos) int GLLinePortal::ClipSubsector(subsector_t *sub) { - // this seg is completely behind the mirror! + // this seg is completely behind the mirror for(unsigned int i=0;inumlines;i++) { if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), line()) == 0) return PClip_Inside; @@ -895,6 +872,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di) vp.ViewActor = nullptr; MirrorFlag++; + di->SetClipLine(linedef); di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); di->mClipper->Clear(); @@ -904,10 +882,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di) di->mClipper->SafeAddClipRange(linedef->v1, linedef->v2); - gl_RenderState.SetClipLine(linedef); - gl_RenderState.EnableClipLine(true); di->DrawScene(DM_PORTAL); - gl_RenderState.EnableClipLine(false); MirrorFlag--; } @@ -972,13 +947,11 @@ void GLLineToLinePortal::DrawContents(FDrawInfo *di) } vp.ViewActor = nullptr; + di->SetClipLine(glport->lines[0]->mDestination); di->SetupView(vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); ClearClipper(di); - gl_RenderState.SetClipLine(glport->lines[0]->mDestination); - gl_RenderState.EnableClipLine(true); di->DrawScene(DM_PORTAL); - gl_RenderState.EnableClipLine(false); } void GLLineToLinePortal::RenderAttached(FDrawInfo *di) diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index fd0e0fbf0d..b7d04b971f 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -180,8 +180,6 @@ struct GLLinePortal : public GLPortal virtual int ClipSubsector(subsector_t *sub); virtual int ClipPoint(const DVector2 &pos); virtual bool NeedCap() { return false; } - virtual void PushState(); - virtual void PopState(); }; diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index f39c428dfa..057683caf3 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -79,7 +79,7 @@ void FDrawInfo::ApplyVPUniforms() if (!(gl.flags & RFL_NO_CLIP_PLANES)) { - if (VPUniforms.mClipHeightDirection != 0.f) + if (VPUniforms.mClipHeightDirection != 0.f || VPUniforms.mClipLine.X > -10000000.0f) { glEnable(GL_CLIP_DISTANCE0); } @@ -90,6 +90,7 @@ void FDrawInfo::ApplyVPUniforms() } } + //----------------------------------------------------------------------------- // // Setup the modelview matrix diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index d14d1ee342..a5a7a7249d 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -322,7 +322,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muGlowTopPlane.Init(hShader, "uGlowTopPlane"); muSplitBottomPlane.Init(hShader, "uSplitBottomPlane"); muSplitTopPlane.Init(hShader, "uSplitTopPlane"); - muClipLine.Init(hShader, "uClipLine"); muInterpolationFactor.Init(hShader, "uInterpolationFactor"); muAlphaThreshold.Init(hShader, "uAlphaThreshold"); muSpecularMaterial.Init(hShader, "uSpecularMaterial"); @@ -345,6 +344,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * globvis_index = glGetUniformLocation(hShader, "uGlobVis"); clipheight_index = glGetUniformLocation(hShader, "uClipHeight"); clipheightdirection_index = glGetUniformLocation(hShader, "uClipHeightDirection"); + clipline_index = glGetUniformLocation(hShader, "uClipLine"); if (!(gl.flags & RFL_SHADER_STORAGE_BUFFER)) { diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 4a84cf0ed8..cb63b502d2 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -257,7 +257,6 @@ class FShader FUniform4f muGlowTopPlane; FUniform4f muSplitBottomPlane; FUniform4f muSplitTopPlane; - FUniform4f muClipLine; FBufferedUniform1f muInterpolationFactor; FBufferedUniform1f muAlphaThreshold; FBufferedUniform2f muSpecularMaterial; @@ -277,6 +276,7 @@ class FShader int globvis_index; int clipheight_index; int clipheightdirection_index; + int clipline_index; public: int vertexmatrix_index; diff --git a/src/hwrenderer/scene/hw_drawinfo.cpp b/src/hwrenderer/scene/hw_drawinfo.cpp index 2f3936d87d..3b73d72c6c 100644 --- a/src/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/hwrenderer/scene/hw_drawinfo.cpp @@ -226,7 +226,8 @@ void HWViewpointUniforms::SetDefaults() mViewMatrix.loadIdentity(); mNormalViewMatrix.loadIdentity(); mViewHeight = viewheight; - mGlobVis = R_GetGlobVis(r_viewwindow, r_visibility) / 32.f; + mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f; mPalLightLevels = static_cast(gl_bandedswlight) | (static_cast(gl_fogmode) << 8); + mClipLine.X = -10000000.0f; } diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index a2464931db..2c55145c9d 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -5,6 +5,7 @@ #include "r_defs.h" #include "r_utility.h" #include "hw_viewpointuniforms.h" +#include "v_video.h" struct FSectorPortalGroup; @@ -162,6 +163,18 @@ public: { VPUniforms.mClipHeight = h; VPUniforms.mClipHeightDirection = d; + VPUniforms.mClipLine.X = -1000001.f; + } + + void SetClipLine(line_t *line) + { + VPUniforms.mClipLine = { (float)line->v1->fX(), (float)line->v1->fY(), (float)line->Delta().X, (float)line->Delta().Y }; + VPUniforms.mClipHeight = 0; + } + + bool ClipLineShouldBeActive() + { + return (screen->hwcaps & RFL_NO_CLIP_PLANES) && VPUniforms.mClipLine.X > -1000000.f; } void RenderBSPNode(void *node); diff --git a/src/hwrenderer/scene/hw_viewpointuniforms.h b/src/hwrenderer/scene/hw_viewpointuniforms.h index 39fa1dbb72..27a78aef47 100644 --- a/src/hwrenderer/scene/hw_viewpointuniforms.h +++ b/src/hwrenderer/scene/hw_viewpointuniforms.h @@ -25,3 +25,6 @@ struct HWViewpointUniforms void SetDefaults(); }; + + +