From b3eab8efc324da6165d4219760edb0b890b62e78 Mon Sep 17 00:00:00 2001 From: kgv Date: Fri, 18 Nov 2016 16:00:59 +0300 Subject: [PATCH] 0028127: Visualization - transparent object breaks Z-Layer depth buffer clear 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 | 7 +------ src/OpenGl/OpenGl_LayerList.cxx | 35 ++++++++++++++++++++------------- tests/bugs/vis/bug28127 | 29 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 tests/bugs/vis/bug28127 diff --git a/src/OpenGl/OpenGl_Layer.cxx b/src/OpenGl/OpenGl_Layer.cxx index 6b6c05e3a2..c9bb46beeb 100644 --- a/src/OpenGl/OpenGl_Layer.cxx +++ b/src/OpenGl/OpenGl_Layer.cxx @@ -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()) diff --git a/src/OpenGl/OpenGl_LayerList.cxx b/src/OpenGl/OpenGl_LayerList.cxx index 588396f66c..5f6c61973c 100644 --- a/src/OpenGl/OpenGl_LayerList.cxx +++ b/src/OpenGl/OpenGl_LayerList.cxx @@ -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; - } - } - else - { - if (aLayer.IsImmediate()) - { - continue; - } + // make sure to clear depth of previous layers even if layer has no structures + toClearDepth = toClearDepth || aLayer.LayerSettings().ToClearDepth(); + continue; + } + + // depth buffers + if (toClearDepth + || aLayer.LayerSettings().ToClearDepth()) + { + 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 index 0000000000..7578a1406c --- /dev/null +++ b/tests/bugs/vis/bug28127 @@ -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