From ed83270cf0d192d5f19fec79fc7981932e8e3c83 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 8 Jun 2020 10:09:58 +0300 Subject: [PATCH] 0023854: Possibility to apply individual transformation to Graphic3d_Group instance (cherry picked from commit e50bf38102e562ae74c9c1fdfd13145e072b4615) (cherry picked from commit 90c3cbae8186a83cecf2115692e744172413b4b2) (cherry picked from commit 180c8e569284de1f3c93131a2c64e414ed9535ad) (cherry picked from commit 1594b4de4b2e6565454f847a08180058ec9cbc56) (cherry picked from commit 2e30d74ef8b4339ba341e79a068f703947e9d664) (cherry picked from commit 12a15d5727610c79cdaf652822e17ad12586b349) (cherry picked from commit 7809f1f7e75130e8fb9adf8eb5b084077878e945) (cherry picked from commit 0d78b798e07ab057204770acd0311ea4e29b990a) --- src/Graphic3d/Graphic3d_Group.hxx | 8 ++++ src/OpenGl/OpenGl_Structure.cxx | 66 ++++++++++++++++++++++--------- src/OpenGl/OpenGl_Structure.hxx | 9 +++++ 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/Graphic3d/Graphic3d_Group.hxx b/src/Graphic3d/Graphic3d_Group.hxx index 022656245d..ebdd6e3a7f 100644 --- a/src/Graphic3d/Graphic3d_Group.hxx +++ b/src/Graphic3d/Graphic3d_Group.hxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -140,6 +141,12 @@ public: //! sets the flipping to theIsEnabled state. Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled, const gp_Ax2& theRefPlane) = 0; + //! Return transformation persistence. + const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTrsfPers; } + + //! Set transformation persistence. + virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { myTrsfPers = theTrsfPers; } + //! Returns true if the group contains Polygons, Triangles or Quadrangles. bool ContainsFacet() const { return myContainsFacet; } @@ -294,6 +301,7 @@ protected: protected: + Handle(Graphic3d_TransformPers) myTrsfPers; //!< current transform persistence Graphic3d_Structure* myStructure; //!< pointer to the parent structure Graphic3d_BndBox4f myBounds; //!< bounding box bool myIsClosed; //!< flag indicating closed volume diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index b7533c16ff..2fc4f91b41 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -389,10 +389,22 @@ void OpenGl_Structure::renderGeometry (const Handle(OpenGl_Workspace)& theWorksp myInstancedStructure->renderGeometry (theWorkspace, theHasClosed); } + const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next()) { + Handle(Graphic3d_TransformPers) aTrsfPersistence = aGroupIter.Value()->TransformPersistence(); + if (!aTrsfPersistence.IsNull()) + { + applyPersistence (aCtx, aTrsfPersistence, Standard_True); + } + theHasClosed = theHasClosed || aGroupIter.Value()->IsClosed(); aGroupIter.Value()->Render (theWorkspace); + + if (!aTrsfPersistence.IsNull()) + { + applyPersistence (aCtx, aTrsfPersistence, Standard_False); + } } } @@ -437,23 +449,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con if (!myTrsfPers.IsNull()) { - aCtx->WorldViewState.Push(); - OpenGl_Mat4& aWorldView = aCtx->WorldViewState.ChangeCurrent(); - myTrsfPers->Apply (aCtx->Camera(), - aCtx->ProjectionState.Current(), aWorldView, - aCtx->VirtualViewport()[2], aCtx->VirtualViewport()[3]); - - #if !defined(GL_ES_VERSION_2_0) - if (!aCtx->IsGlNormalizeEnabled() - && aCtx->core11 != NULL) - { - const Standard_Real aScale = Graphic3d_TransformUtils::ScaleFactor (aWorldView); - if (Abs (aScale - 1.0) > Precision::Confusion()) - { - aCtx->SetGlNormalizeEnabled (Standard_True); - } - } - #endif + applyPersistence (aCtx, myTrsfPers, Standard_True); } // Take into account transform persistence @@ -602,7 +598,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con if (!myTrsfPers.IsNull()) { - aCtx->WorldViewState.Pop(); + applyPersistence (aCtx, myTrsfPers, Standard_False); } // Restore named status @@ -641,6 +637,40 @@ Handle(Graphic3d_CStructure) OpenGl_Structure::ShadowLink (const Handle(Graphic3 return new OpenGl_StructureShadow (theManager, this); } +// ======================================================================= +// function : applyPersistence +// purpose : +// ======================================================================= +void OpenGl_Structure::applyPersistence (const Handle(OpenGl_Context)& theContext, + const Handle(Graphic3d_TransformPers)& theTrsfPersistence, + const Standard_Boolean toEnable) const +{ + if (toEnable) + { + theContext->WorldViewState.Push(); + OpenGl_Mat4& aWorldView = theContext->WorldViewState.ChangeCurrent(); + theTrsfPersistence->Apply (theContext->Camera(), + theContext->ProjectionState.Current(), aWorldView, + theContext->VirtualViewport()[2], theContext->VirtualViewport()[3]); + + #if !defined(GL_ES_VERSION_2_0) + if (!theContext->IsGlNormalizeEnabled() + && theContext->core11 != NULL) + { + const Standard_Real aScale = Graphic3d_TransformUtils::ScaleFactor (aWorldView); + if (Abs (aScale - 1.0) > Precision::Confusion()) + { + theContext->SetGlNormalizeEnabled (Standard_True); + } + } + #endif + } + else + { + theContext->WorldViewState.Pop(); + } +} + //======================================================================= //function : DumpJson //purpose : diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index b031d31036..b9ba4130b0 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -147,6 +147,15 @@ protected: //! Render the bounding box. Standard_EXPORT void renderBoundingBox(const Handle(OpenGl_Workspace)& theWorkspace) const; + + //! Apply transform persistence into context. + //! @param theWorkspace current workspace + //! @param theTrsfPersistence transform persistence + //! @param toEnable flag to switch ON/OFF persistence + Standard_EXPORT void applyPersistence (const Handle(OpenGl_Context)& theContext, + const Handle(Graphic3d_TransformPers)& theTrsfPersistence, + const Standard_Boolean toEnable) const; + protected: OpenGl_Structure* myInstancedStructure; -- 2.39.5