From cf87399b2606401e2657507c10c2dbddbe2de015 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) (cherry picked from commit ed83270cf0d192d5f19fec79fc7981932e8e3c83) (cherry picked from commit 6e29a7f17846d2fea5e51a1f68b1e9f7bce33747) # Conflicts: # src/OpenGl/OpenGl_Structure.cxx (cherry picked from commit 71741cae77616c39855c0e8b9c92d1fbaffa753b) --- src/Graphic3d/Graphic3d_Group.hxx | 8 ++++ src/OpenGl/OpenGl_Structure.cxx | 75 ++++++++++++++++++++++--------- src/OpenGl/OpenGl_Structure.hxx | 10 +++++ 3 files changed, 72 insertions(+), 21 deletions(-) diff --git a/src/Graphic3d/Graphic3d_Group.hxx b/src/Graphic3d/Graphic3d_Group.hxx index e26516f351..69a1e3a67b 100644 --- a/src/Graphic3d/Graphic3d_Group.hxx +++ b/src/Graphic3d/Graphic3d_Group.hxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -137,6 +138,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 ded5c09c4a..7f62d3107d 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -394,10 +394,23 @@ 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(); + Standard_Boolean anOldCastShadows; + if (!aTrsfPersistence.IsNull()) + { + applyPersistence (aCtx, aTrsfPersistence, anOldCastShadows, Standard_True); + } + theHasClosed = theHasClosed || aGroupIter.Value()->IsClosed(); aGroupIter.Value()->Render (theWorkspace); + + if (!aTrsfPersistence.IsNull()) + { + applyPersistence (aCtx, aTrsfPersistence, anOldCastShadows, Standard_False); + } } } @@ -446,26 +459,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con #endif if (!myTrsfPers.IsNull()) { - // temporarily disable shadows on non-3d objects - anOldCastShadows = aCtx->ShaderManager()->SetCastShadows (false); - - 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->core11ffp != NULL) - { - const Standard_Real aScale = Graphic3d_TransformUtils::ScaleFactor (aWorldView); - if (Abs (aScale - 1.0) > Precision::Confusion()) - { - aCtx->SetGlNormalizeEnabled (Standard_True); - } - } - #endif + applyPersistence (aCtx, myTrsfPers, anOldCastShadows, Standard_True); #ifdef GL_DEPTH_CLAMP if (myTrsfPers->Mode() == Graphic3d_TMF_CameraPers @@ -623,7 +617,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con if (!myTrsfPers.IsNull()) { - aCtx->WorldViewState.Pop(); + applyPersistence (aCtx, myTrsfPers, anOldCastShadows, Standard_False); aCtx->ShaderManager()->SetCastShadows (anOldCastShadows); #ifdef GL_DEPTH_CLAMP if (toRestoreDepthClamp) { aCtx->core11fwd->glDisable (GL_DEPTH_CLAMP); } @@ -666,6 +660,45 @@ 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, + Standard_Boolean& theOldCastShadows, + const Standard_Boolean toEnable) const +{ + if (toEnable) + { + // temporarily disable shadows on non-3d objects + theOldCastShadows = theContext->ShaderManager()->SetCastShadows (false); + + 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->core11ffp != 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(); + theContext->ShaderManager()->SetCastShadows (theOldCastShadows); + } +} + //======================================================================= //function : DumpJson //purpose : diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index e603e30973..96d139664b 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -146,6 +146,16 @@ 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, + Standard_Boolean& theOldCastShadows, + const Standard_Boolean toEnable) const; + protected: OpenGl_Structure* myInstancedStructure; -- 2.39.5