]> OCCT Git - occt-copy.git/commitdiff
Added proper cleaning of LOD groups:
authorvpa <vpa@opencascade.com>
Fri, 1 Apr 2016 16:26:57 +0000 (19:26 +0300)
committervpa <vpa@opencascade.com>
Fri, 8 Apr 2016 17:20:03 +0000 (20:20 +0300)
- Graphic3d_Structure's Remove and GraphicClear now take into account LOD structures;
- LOD graphic resources are cleaned up properly in OpenGl_Structure;
Correction of warnings.

TODO:
There are a lot of places in OpenGl_Structure where the structure tries to iterate through its own graphic groups.
In case of objects represented as LODs, such loops are useless and likely will affect the performance.

src/Graphic3d/Graphic3d_LOD.cxx
src/Graphic3d/Graphic3d_LOD.hxx
src/Graphic3d/Graphic3d_LODManager.cxx
src/Graphic3d/Graphic3d_LODManager.hxx
src/Graphic3d/Graphic3d_Structure.cxx
src/MeshVS/MeshVS_Mesh.cxx
src/OpenGl/OpenGl_LOD.cxx
src/OpenGl/OpenGl_LOD.hxx
src/OpenGl/OpenGl_Structure.cxx

index badb32bcdd159e44abfe173fb49622ac7019fdc8..a78f9975b962e746d8ed40608c5ac4416dcb8e69 100644 (file)
@@ -23,6 +23,7 @@ IMPLEMENT_STANDARD_RTTIEXT (Graphic3d_LOD, Standard_Transient)
 //=======================================================================
 Graphic3d_LOD::~Graphic3d_LOD()
 {
+  Clear (Standard_True);
   myGroups.Clear();
 }
 
@@ -37,3 +38,26 @@ void Graphic3d_LOD::SetRange (const Standard_Real theFrom, const Standard_Real t
 
   myRange = Graphic3d_RangeOfLOD (theFrom, theTo);
 }
+
+//=======================================================================
+// function : Clear
+// purpose  :
+//=======================================================================
+void Graphic3d_LOD::Clear (const Standard_Boolean theWithDestruction)
+{
+  for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
+  {
+    aGroupIter.ChangeValue()->Clear();
+  }
+
+  if (!theWithDestruction)
+  {
+    return;
+  }
+
+  while (!myGroups.IsEmpty())
+  {
+    Handle(Graphic3d_Group) aGroup = myGroups.First();
+    aGroup->Remove();
+  }
+}
index d86bf8d5b0ff87ade8c7f16dec936f7b9d57653f..1e01889868bf318ff7606e3688936bcb65479291 100644 (file)
@@ -81,6 +81,8 @@ public:
     return myGroups;
   }
 
+  Standard_EXPORT virtual void Clear (const Standard_Boolean theWithDestruction);
+
   DEFINE_STANDARD_RTTIEXT (Graphic3d_LOD, Standard_Transient)
 
 protected:
index f7d8d5e0aa0dcb0d06340c25baa77ac2024d80c6..979bb8cd3b809384f0c394c8d8ba1e06300092f1 100644 (file)
@@ -115,3 +115,27 @@ Standard_Boolean Graphic3d_LODManager::IsEmpty() const
 
   return Standard_True;
 }
+
+//=======================================================================
+// function : Clear
+// purpose  :
+//=======================================================================
+void Graphic3d_LODManager::Clear (const Standard_Boolean theWithDestruction)
+{
+  for (Standard_Integer aLodIdx = 0; aLodIdx < myLODs.Size(); ++aLodIdx)
+  {
+    myLODs.Value (aLodIdx)->Clear (theWithDestruction);
+  }
+}
+
+//=======================================================================
+// function : GetLodById
+// purpose  :
+//=======================================================================
+const Handle(Graphic3d_LOD)& Graphic3d_LODManager::GetLodById (const Standard_Integer theLodIdx)
+{
+  Standard_ASSERT_RAISE (theLodIdx >= 0 || theLodIdx < myLODs.Size(),
+    "Index of LOD is out of range");
+
+  return myLODs.Value (theLodIdx);
+}
index ab5299ce1d0a8cb33a47f651f5ddd98288647222..fa9a8ce56714d210145789be28297647dffdbda1 100644 (file)
@@ -58,6 +58,10 @@ public:
   //! Returns false if at least one of LODs has non-empty sequence of Graphic3d_Groups
   Standard_EXPORT Standard_Boolean IsEmpty() const;
 
+  Standard_EXPORT void Clear (const Standard_Boolean theWithDestruction);
+
+  Standard_EXPORT const Handle(Graphic3d_LOD)& GetLodById (const Standard_Integer theLodIdx);
+
   DEFINE_STANDARD_RTTIEXT (Graphic3d_LODManager, Standard_Transient)
 
 protected:
index cba7c821fb3c981d72ac5305c6daa54334bbdbe1..1198ec1c664a2f26a8080232bb3983e5ee3ad2c4 100644 (file)
@@ -187,6 +187,12 @@ void Graphic3d_Structure::Remove()
     ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT);
   }
 
+  // Clear LODs graphic groups if there are any
+  if (!myCStructure->GetLodManager().IsNull())
+  {
+    myCStructure->GetLodManager()->Clear (Standard_False);
+  }
+
   // Destruction of me in the graphic library
   const Standard_Integer aStructId = myCStructure->Id;
   myCStructure->GraphicDriver()->RemoveStructure (myCStructure);
@@ -643,6 +649,13 @@ void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestructio
     return;
   }
 
+  if (!myCStructure->GetLodManager().IsNull())
+  {
+    myCStructure->GetLodManager()->Clear (theWithDestruction);
+    if (theWithDestruction)
+      myCStructure->Clear();
+  }
+
   // clean and empty each group
   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
   {
@@ -1777,8 +1790,7 @@ Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
 Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
 {
   Graphic3d_BndBox4f aBnd;
-  const Handle(Graphic3d_LODManager)& aLodMgr = myCStructure->GetLodManager();
-  if (aLodMgr.IsNull())
+  if (myCStructure->GetLodManager().IsNull())
   {
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
     {
@@ -1787,7 +1799,7 @@ Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
   }
   else
   {
-    aLodMgr->GetCombinedBndBox (aBnd);
+    myCStructure->GetLodManager()->GetCombinedBndBox (aBnd);
   }
   return aBnd;
 }
index 4727e48f2d8d1e27bbad8ef303059f8ebbe8af8f..e1ebb90c326af330b5f8b845e5e77958115c2be9 100644 (file)
@@ -155,15 +155,17 @@ void MeshVS_Mesh::ComputeLods (const Handle(PrsMgr_PresentationManager3d)& thePr
                                const Handle(Prs3d_Presentation)& thePrs,
                                const Standard_Integer theMode)
 {
+  TColStd_PackedMapOfInteger aDummy;
   for (Standard_Integer aLodBldrIdx = 1; aLodBldrIdx <= myBuilders.Length(); ++aLodBldrIdx)
   {
     const Handle(MeshVS_LODBuilder) aLodBldr = Handle(MeshVS_LODBuilder)::DownCast (myBuilders.Value (aLodBldrIdx));
     if (aLodBldr.IsNull())
       continue;
 
+    aLodBldr->SetPresentationManager (thePrsMgr);
     const TColStd_PackedMapOfInteger aTrgIdxs = aLodBldr->GetDataSource()->GetAllElements();
     if (!aTrgIdxs.IsEmpty())
-      aLodBldr->Build (thePrs, aTrgIdxs, TColStd_PackedMapOfInteger(), Standard_True,  theMode);
+      aLodBldr->Build (thePrs, aTrgIdxs, aDummy, Standard_True,  theMode);
   }
 }
 
index 1e7aea9164a6fdb18f0b8388d8dbf64ad0d6d1e2..53ceaf4c0492f8435262727ca11f2b477ec055ac 100644 (file)
@@ -27,3 +27,15 @@ Handle(Graphic3d_Group) OpenGl_LOD::NewGroup (const Handle(Graphic3d_Structure)&
   myGroups.Append (aGroup);
   return aGroup;
 }
+
+//=======================================================================
+// function : ReleaseGraphicResources
+// purpose  :
+//=======================================================================
+void OpenGl_LOD::ReleaseGraphicResources (const Handle(OpenGl_Context)& theGlCtx)
+{
+  for (OpenGl_Structure::GroupIterator aGroupIter (myGroups); aGroupIter.More(); aGroupIter.Next())
+  {
+    aGroupIter.ChangeValue()->Release (theGlCtx);
+  }
+}
index fccafd4a70efff8351d7bd92c39e3c0bc0a60f4e..f81da210f94f3e05a1c77df20f981028915ae5e8 100644 (file)
@@ -30,6 +30,8 @@ public:
 
   Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theParentStruct) Standard_OVERRIDE;
 
+  void ReleaseGraphicResources (const Handle(OpenGl_Context)& theGlCtx);
+
   DEFINE_STANDARD_RTTIEXT (OpenGl_LOD, Graphic3d_LOD)
 };
 
index 70504e8da19a669f44bd852775f66c7af3052acf..2729997927989e234734114afae5de82e7d07276 100644 (file)
@@ -753,6 +753,14 @@ void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCt
   {
     aGroupIter.ChangeValue()->Release (theGlCtx);
   }
+  if (!myLODManager.IsNull())
+  {
+    for (Standard_Integer aLodIdx = 0; aLodIdx < myLODManager->NbOfDetailLevels(); ++aLodIdx)
+    {
+      Handle(OpenGl_LOD) aLod = Handle(OpenGl_LOD)::DownCast (myLODManager->GetLodById (aLodIdx));
+      aLod->ReleaseGraphicResources (theGlCtx);
+    }
+  }
   if (myAspectLine != NULL)
   {
     myAspectLine->Release (theGlCtx.operator->());