]> OCCT Git - occt.git/commitdiff
Fix grid flickering
authormzernova <mzernova@opencascade.com>
Fri, 22 Nov 2024 12:47:20 +0000 (12:47 +0000)
committermzernova <mzernova@opencascade.com>
Fri, 22 Nov 2024 12:49:00 +0000 (12:49 +0000)
src/Graphic3d/Graphic3d_ShaderManager.cxx
src/OpenGl/OpenGl_View.cxx

index 9cd5380c643bf818b74bbe79c612e9c8706eb792..694ed3f2a1ad9c5d91517f1a57297c6ac606dcaa 100644 (file)
@@ -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"}";
 
index 65b5a1ecaf869f5ed239ecefd83000c0491ec50e..06dea367c8e173845ffbd442b8a7c57f39449a7b 100644 (file)
@@ -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();