]> OCCT Git - occt-copy.git/commitdiff
0023854: Possibility to apply individual transformation to Graphic3d_Group instance
authornds <natalia.ermolaeva@opencascade.com>
Mon, 8 Jun 2020 07:09:58 +0000 (10:09 +0300)
committerNatalia Ermolaeva <natalia.ermolaeva@opencascade.com>
Tue, 22 Jun 2021 15:20:53 +0000 (18:20 +0300)
(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
src/OpenGl/OpenGl_Structure.cxx
src/OpenGl/OpenGl_Structure.hxx

index e26516f351e66b55325e617aee7d192d038ca463..69a1e3a67bb7e31f9d422c39c0f622abb89fa083 100644 (file)
@@ -32,6 +32,7 @@
 #include <Graphic3d_IndexBuffer.hxx>
 #include <Graphic3d_Buffer.hxx>
 #include <Graphic3d_BoundBuffer.hxx>
+#include <Graphic3d_TransformPers.hxx>
 #include <gp_Ax2.hxx>
 #include <TCollection_ExtendedString.hxx>
 
@@ -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
index ded5c09c4a267ccff20cb1f6a052b8f317969fc6..7f62d3107d587b5c5a7465b641551d01bbbc37df 100644 (file)
@@ -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<Standard_ShortReal> (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<Standard_ShortReal> (aWorldView);
+      if (Abs (aScale - 1.0) > Precision::Confusion())
+      {
+        theContext->SetGlNormalizeEnabled (Standard_True);
+      }
+    }
+  #endif
+  }
+  else
+  {
+    theContext->WorldViewState.Pop();
+    theContext->ShaderManager()->SetCastShadows (theOldCastShadows);
+  }
+}
+
 //=======================================================================
 //function : DumpJson
 //purpose  : 
index e603e309731553ee02663ef537228bfe49fbef6f..96d139664bb2585374886030ccca714bade9d15d 100644 (file)
@@ -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;