0027952: Visualization - do not reset RayTracing state on changing structures not...
authorkgv <kgv@opencascade.com>
Tue, 11 Oct 2016 19:55:25 +0000 (22:55 +0300)
committerapn <apn@opencascade.com>
Thu, 13 Oct 2016 10:55:35 +0000 (13:55 +0300)
src/OpenGl/OpenGl_LayerList.cxx
src/OpenGl/OpenGl_LayerList.hxx
src/OpenGl/OpenGl_View.cxx
src/OpenGl/OpenGl_View.hxx
src/OpenGl/OpenGl_View_Raytrace.cxx

index 3735e32..d3b2fc0 100644 (file)
 //=======================================================================
 
 OpenGl_LayerList::OpenGl_LayerList (const Standard_Integer theNbPriorities)
-: myNbPriorities (theNbPriorities),
+: myDefaultLayerIndex (0),
+  myNbPriorities (theNbPriorities),
   myNbStructures (0),
-  myImmediateNbStructures (0)
+  myImmediateNbStructures (0),
+  myModifStateOfRaytraceable (0)
 {
   // insert default priority layers
   myLayers.Append (OpenGl_Layer (myNbPriorities));
@@ -46,6 +48,8 @@ OpenGl_LayerList::OpenGl_LayerList (const Standard_Integer theNbPriorities)
 
   myLayers.Append (OpenGl_Layer (myNbPriorities));
   myLayerIds.Bind (Graphic3d_ZLayerId_TopOSD,  myLayers.Upper());
+
+  myDefaultLayerIndex = myLayerIds.Find (Graphic3d_ZLayerId_Default);
 }
 
 //=======================================================================
@@ -116,13 +120,14 @@ void OpenGl_LayerList::RemoveLayer (const Graphic3d_ZLayerId theLayerId)
   myLayerIds.UnBind (theLayerId);
 
   // updated sequence indexes in map
-  OpenGl_LayerSeqIds::Iterator aMapIt (myLayerIds);
-  for ( ; aMapIt.More (); aMapIt.Next ())
+  for (OpenGl_LayerSeqIds::Iterator aMapIt (myLayerIds); aMapIt.More(); aMapIt.Next())
   {
-    Standard_Integer& aSeqIdx = aMapIt.ChangeValue ();
+    Standard_Integer& aSeqIdx = aMapIt.ChangeValue();
     if (aSeqIdx > aRemovePos)
       aSeqIdx--;
   }
+
+  myDefaultLayerIndex = myLayerIds.Find (Graphic3d_ZLayerId_Default);
 }
 
 //=======================================================================
@@ -179,9 +184,10 @@ void OpenGl_LayerList::RemoveStructure (const OpenGl_Structure* theStructure)
       --myImmediateNbStructures;
     }
 
-    if (theStructure->IsRaytracable())
+    if (aLayerId == Graphic3d_ZLayerId_Default
+     && theStructure->IsRaytracable())
     {
-      ++myModificationState;
+      ++myModifStateOfRaytraceable;
     }
 
     return;
@@ -205,9 +211,10 @@ void OpenGl_LayerList::RemoveStructure (const OpenGl_Structure* theStructure)
         --myImmediateNbStructures;
       }
 
-      if (theStructure->IsRaytracable())
+      if (aSeqId == myDefaultLayerIndex
+       && theStructure->IsRaytracable())
       {
-        ++myModificationState;
+        ++myModifStateOfRaytraceable;
       }
       return;
     }
@@ -244,6 +251,12 @@ void OpenGl_LayerList::ChangeLayer (const OpenGl_Structure*  theStructure,
   // if the structure is not found there, scan through all other layers
   if (aLayer.Remove (theStructure, aPriority, Standard_False))
   {
+    if (theOldLayerId == Graphic3d_ZLayerId_Default
+     && theStructure->IsRaytracable())
+    {
+      ++myModifStateOfRaytraceable;
+    }
+
     --myNbStructures;
     if (aLayer.LayerSettings().IsImmediate)
     {
@@ -269,6 +282,12 @@ void OpenGl_LayerList::ChangeLayer (const OpenGl_Structure*  theStructure,
     OpenGl_Layer& aLayerEx = anIts.ChangeValue();
     if (aLayerEx.Remove (theStructure, aPriority, Standard_True))
     {
+      if (aSeqId == myDefaultLayerIndex
+       && theStructure->IsRaytracable())
+      {
+        ++myModifStateOfRaytraceable;
+      }
+
       --myNbStructures;
       if (aLayerEx.LayerSettings().IsImmediate)
       {
@@ -367,20 +386,20 @@ void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace)& theWorkspace,
   aCtx->core11fwd->glGetIntegerv (GL_DEPTH_FUNC,      &aDefaultSettings.DepthFunc);
   aCtx->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &aDefaultSettings.DepthMask);
 
-  Standard_Integer aSeqId = myLayers.Lower(), aMainId = myLayerIds.Find (Graphic3d_ZLayerId_Default);
+  Standard_Integer aSeqId = myLayers.Lower();
   for (OpenGl_SequenceOfLayers::Iterator anIts (myLayers); anIts.More(); anIts.Next(), ++aSeqId)
   {
     if (theLayersToProcess == OpenGl_LF_Bottom)
     {
-      if (aSeqId >= aMainId) continue;
+      if (aSeqId >= myDefaultLayerIndex) continue;
     }
     else if (theLayersToProcess == OpenGl_LF_Upper)
     {
-      if (aSeqId <= aMainId) continue;
+      if (aSeqId <= myDefaultLayerIndex) continue;
     }
     else if (theLayersToProcess == OpenGl_LF_Default)
     {
-      if (aSeqId != aMainId) continue;
+      if (aSeqId != myDefaultLayerIndex) continue;
     }
 
     const OpenGl_Layer& aLayer = anIts.Value();
index a8fa966..cd45cc3 100644 (file)
@@ -27,6 +27,7 @@ class OpenGl_Structure;
 typedef NCollection_Sequence<OpenGl_Layer> OpenGl_SequenceOfLayers;
 typedef NCollection_DataMap<int, int> OpenGl_LayerSeqIds;
 
+//! Class defining the list of layers.
 class OpenGl_LayerList
 {
 public:
@@ -101,19 +102,20 @@ public:
   void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId);
 
   //! Returns structure modification state (for ray-tracing).
-  Standard_Size ModificationState() const { return myModificationState; }
+  Standard_Size ModificationStateOfRaytracable() const { return myModifStateOfRaytraceable; }
 
 protected:
 
   // number of structures temporary put to default layer
   OpenGl_SequenceOfLayers myLayers;
   OpenGl_LayerSeqIds      myLayerIds;
+  Standard_Integer        myDefaultLayerIndex;     //!< index of Graphic3d_ZLayerId_Default layer in myLayers sequence
 
   Standard_Integer        myNbPriorities;
   Standard_Integer        myNbStructures;
   Standard_Integer        myImmediateNbStructures; //!< number of structures within immediate layers
 
-  mutable Standard_Size   myModificationState;
+  mutable Standard_Size   myModifStateOfRaytraceable;
 
 public:
 
index 5a4bbc3..7c1af76 100644 (file)
@@ -81,7 +81,7 @@ OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
   myIsRaytraceDataValid    (Standard_False),
   myIsRaytraceWarnTextures (Standard_False),
   myToUpdateEnvironmentMap (Standard_False),
-  myLayerListState (0)
+  myRaytraceLayerListState (0)
 {
   myWorkspace = new OpenGl_Workspace (this, NULL);
 
index f23dd47..9b468cc 100644 (file)
@@ -1029,7 +1029,7 @@ protected: //! @name fields related to ray-tracing
   Standard_Boolean myToUpdateEnvironmentMap;
 
   //! State of OpenGL layer list.
-  Standard_Size myLayerListState;
+  Standard_Size myRaytraceLayerListState;
 
   //! Number of accumulated frames (for progressive rendering).
   Standard_Integer myAccumFrames;
index ded7610..a6b17e6 100644 (file)
@@ -49,7 +49,7 @@ Standard_Boolean OpenGl_View::updateRaytraceGeometry (const RaytraceUpdateMode
   // modifications. This is light-weight procedure performed on each frame
   if (theMode == OpenGl_GUM_CHECK)
   {
-    if (myLayerListState != myZLayers.ModificationState())
+    if (myRaytraceLayerListState != myZLayers.ModificationStateOfRaytracable())
     {
       return updateRaytraceGeometry (OpenGl_GUM_PREPARE, theViewId, theGlContext);
     }
@@ -185,7 +185,7 @@ Standard_Boolean OpenGl_View::updateRaytraceGeometry (const RaytraceUpdateMode
     }
 
     // Actualize OpenGL layer list state
-    myLayerListState = myZLayers.ModificationState();
+    myRaytraceLayerListState = myZLayers.ModificationStateOfRaytracable();
 
     // Rebuild two-level acceleration structure
     myRaytraceGeometry.ProcessAcceleration();