0028127: Visualization - transparent object breaks Z-Layer depth buffer clear
authorkgv <kgv@opencascade.com>
Fri, 18 Nov 2016 13:00:59 +0000 (16:00 +0300)
committerapn <apn@opencascade.com>
Wed, 23 Nov 2016 10:05:18 +0000 (13:05 +0300)
OpenGl_LayerList::Render() now calls glDepthMask(GL_TRUE) before clearing depth buffer.
Depth buffer is now cleared even if ZLayer with this command has no structures.

src/OpenGl/OpenGl_Layer.cxx
src/OpenGl/OpenGl_LayerList.cxx
tests/bugs/vis/bug28127 [new file with mode: 0644]

index 6b6c05e..c9bb46b 100644 (file)
@@ -663,12 +663,7 @@ void OpenGl_Layer::Render (const Handle(OpenGl_Workspace)&   theWorkspace,
                            const OpenGl_GlobalLayerSettings& theDefaultSettings) const
 {
   const Graphic3d_PolygonOffset anAppliedOffsetParams = theWorkspace->AppliedPolygonOffset();
-
-  // separate depth buffers
-  if (myLayerSettings.ToClearDepth())
-  {
-    glClear (GL_DEPTH_BUFFER_BIT);
-  }
+  // myLayerSettings.ToClearDepth() is handled outside
 
   // handle depth test
   if (myLayerSettings.ToEnableDepthTest())
index 588396f..5f6c619 100644 (file)
@@ -387,6 +387,7 @@ void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace)& theWorkspace,
   aCtx->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &aDefaultSettings.DepthMask);
 
   Standard_Integer aSeqId = myLayers.Lower();
+  bool toClearDepth = false;
   for (OpenGl_SequenceOfLayers::Iterator anIts (myLayers); anIts.More(); anIts.Next(), ++aSeqId)
   {
     if (theLayersToProcess == OpenGl_LF_Bottom)
@@ -403,29 +404,35 @@ void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace)& theWorkspace,
     }
 
     const OpenGl_Layer& aLayer = anIts.Value();
-    if (aLayer.NbStructures() < 1)
+    if (aLayer.IsImmediate() != theToDrawImmediate)
     {
       continue;
     }
-    else if (theToDrawImmediate)
+    else if (aLayer.NbStructures() < 1)
     {
-      if (!aLayer.IsImmediate())
-      {
-        continue;
-      }
+      // make sure to clear depth of previous layers even if layer has no structures
+      toClearDepth = toClearDepth || aLayer.LayerSettings().ToClearDepth();
+      continue;
     }
-    else
+
+    // depth buffers
+    if (toClearDepth
+     || aLayer.LayerSettings().ToClearDepth())
     {
-      if (aLayer.IsImmediate())
-      {
-        continue;
-      }
+      toClearDepth = false;
+      glDepthMask (GL_TRUE);
+      glClear (GL_DEPTH_BUFFER_BIT);
     }
 
-    // render layer
     aLayer.Render (theWorkspace, aDefaultSettings);
   }
 
+  if (toClearDepth)
+  {
+    glDepthMask (GL_TRUE);
+    glClear (GL_DEPTH_BUFFER_BIT);
+  }
+
   aCtx->core11fwd->glDepthMask (aDefaultSettings.DepthMask);
   aCtx->core11fwd->glDepthFunc (aDefaultSettings.DepthFunc);
 }
diff --git a/tests/bugs/vis/bug28127 b/tests/bugs/vis/bug28127
new file mode 100644 (file)
index 0000000..7578a14
--- /dev/null
@@ -0,0 +1,29 @@
+puts "==========="
+puts "OCC28127"
+puts "Visualization - transparent object breaks Z-Layer depth buffer clear"
+puts "==========="
+puts ""
+
+pload MODELING VISUALIZATION
+box r 0 0   0 1 0.1 1
+box g 0 0.2 0 1 0.1 1
+box b 0 0.4 0 1 0.1 1
+
+vclear
+vinit View1
+vaxo
+vdisplay -noupdate -dispMode 1 -top r g b
+vsetcolor -noupdate r RED
+vsetcolor -noupdate g GREEN
+vsetcolor -noupdate b BLUE1
+vfit
+
+vdisplay -topmost g
+vzbufftrihedron -on -position left_upper
+
+vsettransparency b 0.5
+
+if { [vreadpixel 150 150 rgb name] != "GREEN3" } { puts "Error: wrong color - GREEN box should overlap RED one" }
+if { [vreadpixel  84  64 rgb name] == "RED3"   } { puts "Error: wrong color - Trihedron should overlap RED box" }
+
+vdump $imagedir/${casename}.png