From a6df1715edb46edd645a99b15326ca200c462f72 Mon Sep 17 00:00:00 2001 From: kgv Date: Thu, 19 Jul 2018 20:32:51 +0300 Subject: [PATCH] 0029974: Visualization - OpenGl_Layer::Render() produces inconsistent state of Polygon Offset settings OpenGl_Layer::Render() now calls OpenGl_Workspace::SetDefaultPolygonOffset() for managing default polygon offset settings considering OpenGl_Workspace applied aspect logic. --- src/Graphic3d/Graphic3d_AspectFillArea3d.hxx | 3 +++ src/OpenGl/OpenGl_Layer.cxx | 5 ++--- src/OpenGl/OpenGl_Workspace.cxx | 22 +++++++++++++++----- src/OpenGl/OpenGl_Workspace.hxx | 9 ++++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Graphic3d/Graphic3d_AspectFillArea3d.hxx b/src/Graphic3d/Graphic3d_AspectFillArea3d.hxx index f7e46e18d5..57b4c565fd 100644 --- a/src/Graphic3d/Graphic3d_AspectFillArea3d.hxx +++ b/src/Graphic3d/Graphic3d_AspectFillArea3d.hxx @@ -214,6 +214,9 @@ public: //! Returns current polygon offsets settings. const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; } + //! Sets polygon offsets settings. + void SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset) { myPolygonOffset = theOffset; } + //! Returns current polygon offsets settings. void PolygonOffsets (Standard_Integer& theMode, Standard_ShortReal& theFactor, diff --git a/src/OpenGl/OpenGl_Layer.cxx b/src/OpenGl/OpenGl_Layer.cxx index a564d9b8e1..120bbef951 100644 --- a/src/OpenGl/OpenGl_Layer.cxx +++ b/src/OpenGl/OpenGl_Layer.cxx @@ -656,7 +656,6 @@ void OpenGl_Layer::Render (const Handle(OpenGl_Workspace)& theWorkspace, const OpenGl_GlobalLayerSettings& theDefaultSettings) const { const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); - const Graphic3d_PolygonOffset anAppliedOffsetParams = aCtx->PolygonOffset(); // myLayerSettings.ToClearDepth() is handled outside // handle depth test @@ -678,7 +677,7 @@ void OpenGl_Layer::Render (const Handle(OpenGl_Workspace)& theWorkspace, } // handle depth offset - aCtx->SetPolygonOffset (myLayerSettings.PolygonOffset()); + const Graphic3d_PolygonOffset anAppliedOffsetParams = theWorkspace->SetDefaultPolygonOffset (myLayerSettings.PolygonOffset()); // handle depth write theWorkspace->UseDepthWrite() = myLayerSettings.ToEnableDepthWrite() && theDefaultSettings.DepthMask == GL_TRUE; @@ -759,7 +758,7 @@ void OpenGl_Layer::Render (const Handle(OpenGl_Workspace)& theWorkspace, } // always restore polygon offset between layers rendering - aCtx->SetPolygonOffset (anAppliedOffsetParams); + theWorkspace->SetDefaultPolygonOffset (anAppliedOffsetParams); // restore environment texture if (!myLayerSettings.UseEnvironmentTexture()) diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index 7f5f59ceff..8e355a264d 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -43,11 +43,6 @@ namespace static const OpenGl_Vec4 THE_WHITE_COLOR (1.0f, 1.0f, 1.0f, 1.0f); static const OpenGl_Vec4 THE_BLACK_COLOR (0.0f, 0.0f, 0.0f, 1.0f); - static const OpenGl_AspectLine myDefaultAspectLine; - static const OpenGl_AspectFace myDefaultAspectFace; - static const OpenGl_AspectMarker myDefaultAspectMarker; - static const OpenGl_AspectText myDefaultAspectText; - static const OpenGl_Matrix myDefaultMatrix = { {{ 1.0F, 0.0F, 0.0F, 0.0F }, @@ -228,6 +223,23 @@ void OpenGl_Workspace::ResetAppliedAspect() myGlContext->SetLineWidth (myDefaultAspectLine.Aspect()->Width()); } +// ======================================================================= +// function : SetDefaultPolygonOffset +// purpose : +// ======================================================================= +Graphic3d_PolygonOffset OpenGl_Workspace::SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset) +{ + Graphic3d_PolygonOffset aPrev = myDefaultAspectFace.Aspect()->PolygonOffset(); + myDefaultAspectFace.Aspect()->SetPolygonOffset (theOffset); + if (myAspectFaceApplied == myDefaultAspectFace.Aspect() + || myAspectFaceApplied.IsNull() + || (myAspectFaceApplied->PolygonOffset().Mode & Aspect_POM_None) == Aspect_POM_None) + { + myGlContext->SetPolygonOffset (theOffset); + } + return aPrev; +} + // ======================================================================= // function : SetAspectLine // purpose : diff --git a/src/OpenGl/OpenGl_Workspace.hxx b/src/OpenGl/OpenGl_Workspace.hxx index 33b97cee12..fad9e8adf6 100644 --- a/src/OpenGl/OpenGl_Workspace.hxx +++ b/src/OpenGl/OpenGl_Workspace.hxx @@ -86,6 +86,10 @@ public: //! @return true if frustum culling algorithm is enabled Standard_EXPORT Standard_Boolean IsCullingEnabled() const; + //! Configure default polygon offset parameters. + //! Return previous settings. + Standard_EXPORT Graphic3d_PolygonOffset SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset); + //// RELATED TO STATUS //// //! Return true if active group might activate face culling (e.g. primitives are closed). @@ -259,6 +263,11 @@ protected: //! @name fields related to status Standard_Integer myNbSkippedTranspElems; //!< counter of skipped transparent elements for OpenGl_LayerList two rendering passes method Standard_Integer myRenderFilter; //!< active filter for skipping rendering of elements by some criteria (multiple render passes) + OpenGl_AspectLine myDefaultAspectLine; + OpenGl_AspectFace myDefaultAspectFace; + OpenGl_AspectMarker myDefaultAspectMarker; + OpenGl_AspectText myDefaultAspectText; + const OpenGl_AspectLine* myAspectLineSet; const OpenGl_AspectFace* myAspectFaceSet; Handle(Graphic3d_AspectFillArea3d) myAspectFaceApplied;