From 2a1fa7be507ebc76d634df5b18549b0f79a0f832 Mon Sep 17 00:00:00 2001 From: mzernova Date: Fri, 22 Nov 2024 12:47:20 +0000 Subject: [PATCH] Fix grid flickering --- src/Graphic3d/Graphic3d_ShaderManager.cxx | 3 ++- src/OpenGl/OpenGl_View.cxx | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Graphic3d/Graphic3d_ShaderManager.cxx b/src/Graphic3d/Graphic3d_ShaderManager.cxx index 9cd5380c64..694ed3f2a1 100644 --- a/src/Graphic3d/Graphic3d_ShaderManager.cxx +++ b/src/Graphic3d/Graphic3d_ShaderManager.cxx @@ -2280,7 +2280,8 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const EOL" aColor.a *= aFading;" EOL" }" - EOL" gl_FragDepth = uIsBackground ? 1.0 : min (aDepth, 1.0);" + EOL" float aMaxDepth = 1.0 - 1e-5;" + EOL" gl_FragDepth = uIsBackground ? aMaxDepth : min (aDepth, aMaxDepth);" EOL" occFragColor = aColor;" EOL"}"; diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index 65b5a1ecaf..06dea367c8 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -2597,10 +2597,14 @@ void OpenGl_View::renderGrid() aContext->ApplyWorldViewMatrix(); aContext->core11fwd->glEnable (GL_DEPTH_TEST); - aContext->core11fwd->glDepthFunc (GL_LEQUAL); + aContext->core11fwd->glDepthFunc (GL_LESS); aContext->core11fwd->glDepthMask (GL_TRUE); aContext->core11fwd->glEnable (GL_BLEND); - aContext->core20fwd->glBlendFuncSeparate (GL_SRC_ALPHA, GL_DST_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + const bool wasDepthClamped = aContext->arbDepthClamp && aContext->core11fwd->glIsEnabled (GL_DEPTH_CLAMP); + if (aContext->arbDepthClamp && !wasDepthClamped) + { + aContext->core11fwd->glEnable (GL_DEPTH_CLAMP); + } const Standard_Real aCameraScale = aContext->Camera()->Scale(); Standard_Real aScale = myGridParams.IsInfinity() @@ -2625,6 +2629,10 @@ void OpenGl_View::renderGrid() aContext->Camera()->SetZRange (aZNear, aZFar); aContext->Camera()->SetProjectionType (aProjectionType); aContext->core11fwd->glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (aContext->arbDepthClamp && !wasDepthClamped) + { + aContext->core11fwd->glDisable (GL_DEPTH_CLAMP); + } aContext->WorldViewState.Pop(); aContext->ProjectionState.Pop();