0030668: Visualization - revise adding ZLayer API
authorkgv <kgv@opencascade.com>
Mon, 15 Jul 2019 18:06:05 +0000 (21:06 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 19 Jul 2019 07:23:22 +0000 (10:23 +0300)
V3d_Viewer::AddZLayer() has been replaced by
V3d_Viewer::InsertLayerBefore() and V3d_Viewer::InsertLayerAfter() methods
allowing to specify Layer settings and index of existing layer to insert new one before/after.
The behavior of V3d_Viewer::AddZLayer() has been adjusted to append
new Layer before Graphic3d_ZLayerId_Top
(between Graphic3d_ZLayerId_Default and Graphic3d_ZLayerId_Top).

Graphic3d_Layer now provides LayerId() property.
Graphic3d_ZLayerSettings has been extended with IsRaytracable() property;
Ray-Tracing now processes multiple layers instead of Graphic3d_ZLayerId_Default.

Moved some methods from OpenGl_View to the base class Graphic3d_CView.

24 files changed:
src/Aspect/Aspect_GenId.cxx
src/Aspect/Aspect_GenId.hxx
src/D3DHost/D3DHost_GraphicDriver.cxx
src/Graphic3d/Graphic3d_CView.cxx
src/Graphic3d/Graphic3d_CView.hxx
src/Graphic3d/Graphic3d_GraphicDriver.cxx
src/Graphic3d/Graphic3d_GraphicDriver.hxx
src/Graphic3d/Graphic3d_Layer.cxx
src/Graphic3d/Graphic3d_Layer.hxx
src/Graphic3d/Graphic3d_ZLayerSettings.hxx
src/OpenGl/OpenGl_FrameStats.cxx
src/OpenGl/OpenGl_GraphicDriver.cxx
src/OpenGl/OpenGl_GraphicDriver.hxx
src/OpenGl/OpenGl_LayerFilter.hxx
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
src/OpenGl/OpenGl_View_Redraw.cxx
src/V3d/V3d_Viewer.cxx
src/V3d/V3d_Viewer.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/v3d/glsl/tiles

index cca7eca..6788bb5 100644 (file)
@@ -48,25 +48,6 @@ Aspect_GenId::Aspect_GenId (const Standard_Integer theLow,
   }
 }
 
-// =======================================================================
-// function : HasFree
-// purpose  :
-// =======================================================================
-Standard_Boolean Aspect_GenId::HasFree() const
-{
-  return myFreeCount > 0
-      || myFreeIds.Extent() > 0;
-}
-
-// =======================================================================
-// function : Available
-// purpose  :
-// =======================================================================
-Standard_Integer Aspect_GenId::Available() const
-{
-  return myFreeCount + myFreeIds.Extent();
-}
-
 // =======================================================================
 // function : Free
 // purpose  :
@@ -99,41 +80,37 @@ void Aspect_GenId::Free (const Standard_Integer theId)
 }
 
 // =======================================================================
-// function : Lower
+// function : Next
 // purpose  :
 // =======================================================================
-Standard_Integer Aspect_GenId::Lower() const
+Standard_Integer Aspect_GenId::Next()
 {
-  return myLowerBound;
+  Standard_Integer aNewId = 0;
+  if (!Next (aNewId))
+  {
+    throw Aspect_IdentDefinitionError("Aspect_GenId::Next(), Error: Available == 0");
+  }
+  return aNewId;
 }
 
 // =======================================================================
 // function : Next
 // purpose  :
 // =======================================================================
-Standard_Integer Aspect_GenId::Next()
+Standard_Boolean Aspect_GenId::Next (Standard_Integer& theId)
 {
   if (!myFreeIds.IsEmpty())
   {
-    const Standard_Integer anId = myFreeIds.First();
+    theId = myFreeIds.First();
     myFreeIds.RemoveFirst();
-    return anId;
+    return Standard_True;
   }
   else if (myFreeCount < 1)
   {
-    throw Aspect_IdentDefinitionError("GenId Next Error: Available == 0");
+    return Standard_False;
   }
 
   --myFreeCount;
-  const Standard_Integer anId = myLowerBound + myLength - myFreeCount - 1;
-  return anId;
-}
-
-// =======================================================================
-// function : Upper
-// purpose  :
-// =======================================================================
-Standard_Integer Aspect_GenId::Upper() const
-{
-  return myUpperBound;
+  theId = myLowerBound + myLength - myFreeCount - 1;
+  return Standard_True;
 }
index 6518c6c..c565d3d 100644 (file)
@@ -49,47 +49,38 @@ public:
   Standard_EXPORT void Free (const Standard_Integer theId);
   
   //! Returns true if there are available identifiers in range.
-  Standard_EXPORT Standard_Boolean HasFree() const;
+  Standard_Boolean HasFree() const
+  {
+    return myFreeCount > 0
+        || myFreeIds.Extent() > 0;
+  }
   
   //! Returns the number of available identifiers.
-  Standard_EXPORT Standard_Integer Available() const;
+  Standard_Integer Available() const { return myFreeCount + myFreeIds.Extent(); }
   
   //! Returns the lower identifier in range.
-  Standard_EXPORT Standard_Integer Lower() const;
+  Standard_Integer Lower() const { return myLowerBound; }
   
   //! Returns the next available identifier.
   //! Warning: Raises IdentDefinitionError if all identifiers are busy.
   Standard_EXPORT Standard_Integer Next();
+
+  //! Generates the next available identifier.
+  //! @param theId [out] generated identifier
+  //! @return FALSE if all identifiers are busy.
+  Standard_EXPORT Standard_Boolean Next (Standard_Integer& theId);
   
   //! Returns the upper identifier in range.
-  Standard_EXPORT Standard_Integer Upper() const;
-
-
-
-
-protected:
-
-
-
-
+  Standard_Integer Upper() const { return myUpperBound; }
 
 private:
 
-
-
   Standard_Integer myFreeCount;
   Standard_Integer myLength;
   Standard_Integer myLowerBound;
   Standard_Integer myUpperBound;
   TColStd_ListOfInteger myFreeIds;
 
-
 };
 
-
-
-
-
-
-
 #endif // _Aspect_GenId_HeaderFile
index 6483e70..6b805a4 100644 (file)
@@ -44,22 +44,17 @@ D3DHost_GraphicDriver::~D3DHost_GraphicDriver()
 }
 
 // =======================================================================
-// function : View
+// function : CreateView
 // purpose  :
 // =======================================================================
 Handle(Graphic3d_CView) D3DHost_GraphicDriver::CreateView (const Handle(Graphic3d_StructureManager)& theMgr)
 {
   Handle(D3DHost_View) aView = new D3DHost_View (theMgr, this, myCaps, &myStateCounter);
-
   myMapOfView.Add (aView);
-
-  for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    const Graphic3d_ZLayerId        aLayerID  = aLayerIt.Value();
-    const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID);
-    aView->AddZLayer         (aLayerID);
-    aView->SetZLayerSettings (aLayerID, aSettings);
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
+    aView->InsertLayerAfter (aLayer->LayerId(), aLayer->LayerSettings(), Graphic3d_ZLayerId_UNKNOWN);
   }
-
   return aView;
 }
index 7b7f9e3..829151d 100644 (file)
 // commercial license or contractual agreement.
 
 #include <Graphic3d_CView.hxx>
+
+#include <Graphic3d_Layer.hxx>
 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
 #include <Graphic3d_StructureManager.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CView,Graphic3d_DataStructureManager)
 
-namespace
-{
-  static const int THE_DEFAULT_LAYERS[] = { Graphic3d_ZLayerId_Top,
-                                            Graphic3d_ZLayerId_Topmost,
-                                            Graphic3d_ZLayerId_BotOSD,
-                                            Graphic3d_ZLayerId_TopOSD };
-
-  static const int THE_NB_DEFAULT_LAYERS = sizeof(THE_DEFAULT_LAYERS) / sizeof(*THE_DEFAULT_LAYERS);
-
-}
-
 //=======================================================================
 //function : Constructor
 //purpose  :
@@ -357,6 +348,28 @@ void Graphic3d_CView::Update (const Graphic3d_ZLayerId theLayerId)
   InvalidateZLayerBoundingBox (theLayerId);
 }
 
+// =======================================================================
+// function : InvalidateZLayerBoundingBox
+// purpose  :
+// =======================================================================
+void Graphic3d_CView::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId)
+{
+  if (Handle(Graphic3d_Layer) aLayer = Layer (theLayerId))
+  {
+    aLayer->InvalidateBoundingBox();
+    return;
+  }
+
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (Layers()); aLayerIter.More(); aLayerIter.Next())
+  {
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
+    if (aLayer->NbOfTransformPersistenceObjects() > 0)
+    {
+      aLayer->InvalidateBoundingBox();
+    }
+  }
+}
+
 // =======================================================================
 // function : ContainsFacet
 // purpose  :
@@ -407,40 +420,25 @@ void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructur
 // =======================================================================
 Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
 {
-  Bnd_Box aResult;
-
   if (!IsDefined())
   {
-    return aResult;
+    return Bnd_Box();
   }
 
-  Handle(Graphic3d_Camera) aCamera = Camera();
-  Standard_Integer aWinWidth  = 0;
-  Standard_Integer aWinHeight = 0;
-
-  Window()->Size (aWinWidth, aWinHeight);
+  const Handle(Graphic3d_Camera)& aCamera = Camera();
+  Graphic3d_Vec2i aWinSize;
+  Window()->Size (aWinSize.x(), aWinSize.y());
 
-  for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
+  Bnd_Box aResult;
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (Layers()); aLayerIter.More(); aLayerIter.Next())
   {
-    Bnd_Box aBox = ZLayerBoundingBox (THE_DEFAULT_LAYERS[aLayer],
-                                      aCamera,
-                                      aWinWidth,
-                                      aWinHeight,
-                                      theToIncludeAuxiliary);
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
+    Bnd_Box aBox = aLayer->BoundingBox (Identification(),
+                                        aCamera,
+                                        aWinSize.x(), aWinSize.y(),
+                                        theToIncludeAuxiliary);
     aResult.Add (aBox);
   }
-
-  Standard_Integer aMaxZLayer = ZLayerMax();
-  for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId <= aMaxZLayer; ++aLayerId)
-  {
-    Bnd_Box aBox = ZLayerBoundingBox (aLayerId,
-                                      aCamera,
-                                      aWinWidth,
-                                      aWinHeight,
-                                      theToIncludeAuxiliary);
-    aResult.Add(aBox);
-  }
-
   return aResult;
 }
 
@@ -455,21 +453,15 @@ Standard_Real Graphic3d_CView::ConsiderZoomPersistenceObjects()
     return 1.0;
   }
 
-  Handle(Graphic3d_Camera) aCamera = Camera();
-  Standard_Integer aWinWidth  = 0;
-  Standard_Integer aWinHeight = 0;
-
-  Window()->Size (aWinWidth, aWinHeight);
+  const Handle(Graphic3d_Camera)& aCamera = Camera();
+  Graphic3d_Vec2i aWinSize;
+  Window()->Size (aWinSize.x(), aWinSize.y());
 
   Standard_Real aMaxCoef = 1.0;
-  for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
-  {
-    aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (THE_DEFAULT_LAYERS[aLayer], aCamera, aWinWidth, aWinHeight));
-  }
-
-  for (Standard_Integer aLayer = Graphic3d_ZLayerId_Default; aLayer <= ZLayerMax(); ++aLayer)
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (Layers()); aLayerIter.More(); aLayerIter.Next())
   {
-    aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (aLayer, aCamera, aWinWidth, aWinHeight));
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
+    aMaxCoef = Max (aMaxCoef, aLayer->considerZoomPersistenceObjects (Identification(), aCamera, aWinSize.x(), aWinSize.y()));
   }
 
   return aMaxCoef;
index 5691912..e79d24f 100644 (file)
@@ -46,6 +46,7 @@
 
 class Graphic3d_CView;
 class Graphic3d_GraphicDriver;
+class Graphic3d_Layer;
 class Graphic3d_StructureManager;
 
 DEFINE_STANDARD_HANDLE (Graphic3d_CView, Graphic3d_DataStructureManager)
@@ -267,32 +268,34 @@ public:
   //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
   virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) = 0;
 
-  //! Add a new top-level z layer with ID <theLayerId> for
-  //! the view. Z layers allow drawing structures in higher layers
-  //! in foreground of structures in lower layers. To add a structure
-  //! to desired layer on display it is necessary to set the layer
-  //! ID for the structure.
-  virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
+  //! Add a layer to the view.
+  //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
+  //! @param theSettings   [in] new layer settings
+  //! @param theLayerAfter [in] id of layer to append new layer before
+  virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
+                                  const Graphic3d_ZLayerSettings& theSettings,
+                                  const Graphic3d_ZLayerId theLayerAfter) = 0;
+
+  //! Add a layer to the view.
+  //! @param theNewLayerId  [in] id of new layer, should be > 0 (negative values are reserved for default layers).
+  //! @param theSettings    [in] new layer settings
+  //! @param theLayerBefore [in] id of layer to append new layer after
+  virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
+                                 const Graphic3d_ZLayerSettings& theSettings,
+                                 const Graphic3d_ZLayerId theLayerBefore) = 0;
 
   //! Returns the maximum Z layer ID.
   //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
   virtual Standard_Integer ZLayerMax() const = 0;
 
-  //! Returns the bounding box of all structures displayed in the Z layer.
-  virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const = 0;
+  //! Returns the list of layers.
+  virtual const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const = 0;
+
+  //! Returns layer with given ID or NULL if undefined.
+  virtual Handle(Graphic3d_Layer) Layer (const Graphic3d_ZLayerId theLayerId) const = 0;
 
   //! Returns the bounding box of all structures displayed in the Z layer.
-  //! @param theLayerId            layer identifier
-  //! @param theCamera             camera definition
-  //! @param theWindowWidth        viewport width  (for applying transformation-persistence)
-  //! @param theWindowHeight       viewport height (for applying transformation-persistence)
-  //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
-  //! @return computed bounding box
-  virtual Bnd_Box ZLayerBoundingBox (const Graphic3d_ZLayerId        theLayerId,
-                                     const Handle(Graphic3d_Camera)& theCamera,
-                                     const Standard_Integer          theWindowWidth,
-                                     const Standard_Integer          theWindowHeight,
-                                     const Standard_Boolean          theToIncludeAuxiliary) const = 0;
+  Standard_EXPORT virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId);
 
   //! Remove Z layer from the specified view. All structures
   //! displayed at the moment in layer will be displayed in default layer
@@ -447,12 +450,6 @@ private:
   virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
                                const Standard_Integer theNewPriority) = 0;
 
-  //! Returns zoom-scale factor.
-  virtual Standard_Real considerZoomPersistenceObjects (const Graphic3d_ZLayerId        theLayerId,
-                                                        const Handle(Graphic3d_Camera)& theCamera,
-                                                        const Standard_Integer          theWindowWidth,
-                                                        const Standard_Integer          theWindowHeight) const = 0;
-
 protected:
 
   Standard_Integer myId;
index 8421319..8253b40 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <Graphic3d_GraphicDriver.hxx>
 
+#include <Graphic3d_Layer.hxx>
+
 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient)
 
 // =======================================================================
@@ -25,70 +27,85 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient)
 Graphic3d_GraphicDriver::Graphic3d_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp)
 : myDisplayConnection (theDisp)
 {
-  // default layers are always presented in display layer sequence it can not be removed
+  // default layers are always presented in display layer sequence and cannot be removed
   {
     Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetName ("UNDERLAY");
     aSettings.SetImmediate          (Standard_False);
+    aSettings.SetRaytracable        (Standard_False);
     aSettings.SetEnvironmentTexture (Standard_False);
     aSettings.SetEnableDepthTest    (Standard_False);
     aSettings.SetEnableDepthWrite   (Standard_False);
     aSettings.SetClearDepth         (Standard_False);
     aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
-    myLayerIds.Add             (Graphic3d_ZLayerId_BotOSD);
-    myLayerSeq.Append          (Graphic3d_ZLayerId_BotOSD);
-    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, aSettings);
+    Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_BotOSD, 1, Handle(Select3D_BVHBuilder3d)());
+    aLayer->SetLayerSettings (aSettings);
+    myLayers.Append (aLayer);
+    myLayerIds.Bind (aLayer->LayerId(), aLayer);
   }
 
   {
     Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetName ("DEFAULT");
     aSettings.SetImmediate          (Standard_False);
+    aSettings.SetRaytracable        (Standard_True);
     aSettings.SetEnvironmentTexture (Standard_True);
     aSettings.SetEnableDepthTest    (Standard_True);
     aSettings.SetEnableDepthWrite   (Standard_True);
     aSettings.SetClearDepth         (Standard_False);
     aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
-    myLayerIds.Add             (Graphic3d_ZLayerId_Default);
-    myLayerSeq.Append          (Graphic3d_ZLayerId_Default);
-    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aSettings);
+    Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_Default, 1, Handle(Select3D_BVHBuilder3d)());
+    aLayer->SetLayerSettings (aSettings);
+    myLayers.Append (aLayer);
+    myLayerIds.Bind (aLayer->LayerId(), aLayer);
   }
 
   {
     Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetName ("TOP");
     aSettings.SetImmediate          (Standard_True);
+    aSettings.SetRaytracable        (Standard_False);
     aSettings.SetEnvironmentTexture (Standard_True);
     aSettings.SetEnableDepthTest    (Standard_True);
     aSettings.SetEnableDepthWrite   (Standard_True);
     aSettings.SetClearDepth         (Standard_False);
     aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
-    myLayerIds.Add             (Graphic3d_ZLayerId_Top);
-    myLayerSeq.Append          (Graphic3d_ZLayerId_Top);
-    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aSettings);
+    Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_Top, 1, Handle(Select3D_BVHBuilder3d)());
+    aLayer->SetLayerSettings (aSettings);
+    myLayers.Append (aLayer);
+    myLayerIds.Bind (aLayer->LayerId(), aLayer);
   }
 
   {
     Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetName ("TOPMOST");
     aSettings.SetImmediate          (Standard_True);
+    aSettings.SetRaytracable        (Standard_False);
     aSettings.SetEnvironmentTexture (Standard_True);
     aSettings.SetEnableDepthTest    (Standard_True);
     aSettings.SetEnableDepthWrite   (Standard_True);
     aSettings.SetClearDepth         (Standard_True);
     aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
-    myLayerIds.Add             (Graphic3d_ZLayerId_Topmost);
-    myLayerSeq.Append          (Graphic3d_ZLayerId_Topmost);
-    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aSettings);
+    Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_Topmost, 1, Handle(Select3D_BVHBuilder3d)());
+    aLayer->SetLayerSettings (aSettings);
+    myLayers.Append (aLayer);
+    myLayerIds.Bind (aLayer->LayerId(), aLayer);
   }
 
   {
     Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetName ("OVERLAY");
     aSettings.SetImmediate          (Standard_True);
+    aSettings.SetRaytracable        (Standard_False);
     aSettings.SetEnvironmentTexture (Standard_False);
     aSettings.SetEnableDepthTest    (Standard_False);
     aSettings.SetEnableDepthWrite   (Standard_False);
     aSettings.SetClearDepth         (Standard_False);
     aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
-    myLayerIds.Add             (Graphic3d_ZLayerId_TopOSD);
-    myLayerSeq.Append          (Graphic3d_ZLayerId_TopOSD);
-    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, aSettings);
+    Handle(Graphic3d_Layer) aLayer = new Graphic3d_Layer (Graphic3d_ZLayerId_TopOSD, 1, Handle(Select3D_BVHBuilder3d)());
+    aLayer->SetLayerSettings (aSettings);
+    myLayers.Append (aLayer);
+    myLayerIds.Bind (aLayer->LayerId(), aLayer);
   }
 }
 
@@ -125,75 +142,142 @@ void Graphic3d_GraphicDriver::RemoveIdentification(const Standard_Integer theId)
 //=======================================================================
 const Graphic3d_ZLayerSettings& Graphic3d_GraphicDriver::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
 {
-  Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId), "Graphic3d_GraphicDriver::ZLayerSettings, Layer with theLayerId does not exist");
-  return myMapOfZLayerSettings.Find (theLayerId);
+  const Handle(Graphic3d_Layer)* aLayer = myLayerIds.Seek (theLayerId);
+  if (aLayer == NULL)
+  {
+    throw Standard_OutOfRange ("Graphic3d_GraphicDriver::ZLayerSettings, Layer with theLayerId does not exist");
+  }
+  return (*aLayer)->LayerSettings();
 }
 
 //=======================================================================
-//function : addZLayerIndex
+//function : ZLayers
 //purpose  :
 //=======================================================================
-void Graphic3d_GraphicDriver::addZLayerIndex (const Graphic3d_ZLayerId theLayerId)
+void Graphic3d_GraphicDriver::ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
 {
-  // remove index
-  for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
+  theLayerSeq.Clear();
+
+  // append normal layers
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    if (aLayerIt.Value() == theLayerId)
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
+    if (!aLayer->IsImmediate())
     {
-      myLayerSeq.Remove (aLayerIt);
-      break;
+      theLayerSeq.Append (aLayer->LayerId());
     }
   }
 
-  if (myMapOfZLayerSettings.Find (theLayerId).IsImmediate())
+  // append immediate layers
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    myLayerSeq.Append (theLayerId);
-    return;
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
+    if (aLayer->IsImmediate())
+    {
+      theLayerSeq.Append (aLayer->LayerId());
+    }
   }
+}
 
-  for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
+//=======================================================================
+//function : InsertLayerBefore
+//purpose  :
+//=======================================================================
+void Graphic3d_GraphicDriver::InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
+                                                 const Graphic3d_ZLayerSettings& theSettings,
+                                                 const Graphic3d_ZLayerId theLayerAfter)
+{
+  Standard_ASSERT_RAISE (theNewLayerId > 0,
+                         "Graphic3d_GraphicDriver::InsertLayerBefore, negative and zero IDs are reserved");
+  Standard_ASSERT_RAISE (!myLayerIds.IsBound (theNewLayerId),
+                         "Graphic3d_GraphicDriver::InsertLayerBefore, Layer with theLayerId already exists");
+
+  Handle(Graphic3d_Layer) aNewLayer = new Graphic3d_Layer (theNewLayerId, 1, Handle(Select3D_BVHBuilder3d)());
+  aNewLayer->SetLayerSettings (theSettings);
+
+  Handle(Graphic3d_Layer) anOtherLayer;
+  if (theLayerAfter != Graphic3d_ZLayerId_UNKNOWN
+   && myLayerIds.Find (theLayerAfter, anOtherLayer))
   {
-    const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerIt.Value());
-    if (aSettings.IsImmediate())
+    for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
     {
-      aLayerIt.Previous();
-      if (aLayerIt.More())
+      if (aLayerIter.Value() == anOtherLayer)
       {
-        myLayerSeq.InsertAfter (aLayerIt, theLayerId);
-        return;
+        myLayers.InsertBefore (aNewLayer, aLayerIter);
+        break;
       }
-
-      // first non-immediate layer
-      myLayerSeq.Prepend (theLayerId);
-      return;
     }
   }
-
-  // no immediate layers
-  myLayerSeq.Append (theLayerId);
+  else
+  {
+    myLayers.Prepend (aNewLayer);
+  }
+  myLayerIds.Bind (theNewLayerId, aNewLayer);
 }
 
 //=======================================================================
-//function : SetZLayerSettings
+//function : InsertLayerAfter
 //purpose  :
 //=======================================================================
-void Graphic3d_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
-                                                 const Graphic3d_ZLayerSettings& theSettings)
+void Graphic3d_GraphicDriver::InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
+                                                const Graphic3d_ZLayerSettings& theSettings,
+                                                const Graphic3d_ZLayerId theLayerBefore)
 {
-  Graphic3d_ZLayerSettings* aSettings = myMapOfZLayerSettings.ChangeSeek (theLayerId);
-  if (aSettings != NULL)
+  Standard_ASSERT_RAISE (theNewLayerId > 0,
+                         "Graphic3d_GraphicDriver::InsertLayerAfter, negative and zero IDs are reserved");
+  Standard_ASSERT_RAISE (!myLayerIds.IsBound (theNewLayerId),
+                         "Graphic3d_GraphicDriver::InsertLayerAfter, Layer with theLayerId already exists");
+
+  Handle(Graphic3d_Layer) aNewLayer = new Graphic3d_Layer (theNewLayerId, 1, Handle(Select3D_BVHBuilder3d)());
+  aNewLayer->SetLayerSettings (theSettings);
+
+  Handle(Graphic3d_Layer) anOtherLayer;
+  if (theLayerBefore != Graphic3d_ZLayerId_UNKNOWN
+   && myLayerIds.Find (theLayerBefore, anOtherLayer))
   {
-    const bool isChanged = (aSettings->IsImmediate() != theSettings.IsImmediate());
-    *aSettings = theSettings;
-    if (isChanged)
+    for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
     {
-      addZLayerIndex (theLayerId);
+      if (aLayerIter.Value() == anOtherLayer)
+      {
+        myLayers.InsertAfter (aNewLayer, aLayerIter);
+        break;
+      }
     }
   }
   else
   {
-    // abnormal case
-    myMapOfZLayerSettings.Bind (theLayerId, theSettings);
-    addZLayerIndex (theLayerId);
+    myLayers.Append (aNewLayer);
   }
+  myLayerIds.Bind (theNewLayerId, aNewLayer);
+}
+
+//=======================================================================
+//function : RemoveZLayer
+//purpose  :
+//=======================================================================
+void Graphic3d_GraphicDriver::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
+{
+  Standard_ASSERT_RAISE (theLayerId > 0,
+                         "Graphic3d_GraphicDriver::RemoveZLayer, negative and zero IDs are reserved and cannot be removed");
+
+  Handle(Graphic3d_Layer) aLayerDef;
+  myLayerIds.Find (theLayerId, aLayerDef);
+  Standard_ASSERT_RAISE (!aLayerDef.IsNull(),
+                         "Graphic3d_GraphicDriver::RemoveZLayer, Layer with theLayerId does not exist");
+  myLayers.Remove (aLayerDef);
+  myLayerIds.UnBind (theLayerId);
+}
+
+//=======================================================================
+//function : SetZLayerSettings
+//purpose  :
+//=======================================================================
+void Graphic3d_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
+                                                 const Graphic3d_ZLayerSettings& theSettings)
+{
+  Handle(Graphic3d_Layer) aLayerDef;
+  myLayerIds.Find (theLayerId, aLayerDef);
+  Standard_ASSERT_RAISE (!aLayerDef.IsNull(),
+                         "Graphic3d_GraphicDriver::SetZLayerSettings, Layer with theLayerId does not exist");
+  aLayerDef->SetLayerSettings (theSettings);
 }
index dd4fd3e..6fe63e4 100644 (file)
@@ -52,6 +52,7 @@
 class Aspect_DisplayConnection;
 class Graphic3d_CView;
 class Graphic3d_GraphicDriver;
+class Graphic3d_Layer;
 class Graphic3d_TransformError;
 class Graphic3d_Structure;
 class Graphic3d_StructureManager;
@@ -65,7 +66,7 @@ DEFINE_STANDARD_HANDLE(Graphic3d_GraphicDriver, Standard_Transient)
 //! for 3d interface (currently only OpenGl driver is used).
 class Graphic3d_GraphicDriver : public Standard_Transient
 {
-
+  DEFINE_STANDARD_RTTIEXT(Graphic3d_GraphicDriver, Standard_Transient)
 public:
 
   //! Request limit of graphic resource of specific type.
@@ -110,24 +111,31 @@ public:
                          Standard_ShortReal&            theAscent,
                          Standard_ShortReal&            theDescent) const = 0;
 
-  //! Add a new top-level z layer with ID <theLayerId> for
-  //! the view. Z layers allow drawing structures in higher layers
-  //! in foreground of structures in lower layers. To add a structure
-  //! to desired layer on display it is necessary to set the layer
-  //! ID for the structure.
-  virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
+  //! Adds a layer to all views.
+  //! To add a structure to desired layer on display it is necessary to set the layer ID for the structure.
+  //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
+  //! @param theSettings   [in] new layer settings
+  //! @param theLayerAfter [in] id of layer to append new layer before
+  Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
+                                                  const Graphic3d_ZLayerSettings& theSettings,
+                                                  const Graphic3d_ZLayerId theLayerAfter) = 0;
+
+  //! Adds a layer to all views.
+  //! @param theNewLayerId  [in] id of new layer, should be > 0 (negative values are reserved for default layers).
+  //! @param theSettings    [in] new layer settings
+  //! @param theLayerBefore [in] id of layer to append new layer after
+  Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
+                                                 const Graphic3d_ZLayerSettings& theSettings,
+                                                 const Graphic3d_ZLayerId theLayerBefore) = 0;
 
   //! Removes Z layer. All structures displayed at the moment in layer will be displayed in
   //! default layer (the bottom-level z layer). By default, there are always default
   //! bottom-level layer that can't be removed.  The passed theLayerId should be not less than 0
   //! (reserved for default layers that can not be removed).
-  virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
+  Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
 
   //! Returns list of Z layers defined for the graphical driver.
-  virtual void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
-  {
-    theLayerSeq.Assign (myLayerSeq);
-  }
+  Standard_EXPORT virtual void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const;
 
   //! Sets the settings for a single Z layer.
   Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) = 0;
@@ -148,23 +156,17 @@ public:
   //! Frees the identifier of a structure.
   Standard_EXPORT void RemoveIdentification(const Standard_Integer theId);
 
-  DEFINE_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient)
-
 protected:
   
   //! Initializes the Driver
   Standard_EXPORT Graphic3d_GraphicDriver(const Handle(Aspect_DisplayConnection)& theDisp);
 
-  //! Insert index layer at proper position.
-  Standard_EXPORT void addZLayerIndex (const Graphic3d_ZLayerId theLayerId);
-
 protected:
 
   Handle(Aspect_DisplayConnection) myDisplayConnection;
   Aspect_GenId myStructGenId;
-  TColStd_MapOfInteger          myLayerIds;
-  TColStd_SequenceOfInteger     myLayerSeq;
-  Graphic3d_MapOfZLayerSettings myMapOfZLayerSettings;
+  NCollection_List<Handle(Graphic3d_Layer)> myLayers;
+  NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)> myLayerIds;
 
 };
 
index fad60a3..70a4eaf 100644 (file)
@@ -22,11 +22,13 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Layer, Standard_Transient)
 // function : Graphic3d_Layer
 // purpose  :
 // =======================================================================
-Graphic3d_Layer::Graphic3d_Layer (Standard_Integer theNbPriorities,
+Graphic3d_Layer::Graphic3d_Layer (Graphic3d_ZLayerId theId,
+                                  Standard_Integer theNbPriorities,
                                   const Handle(Select3D_BVHBuilder3d)& theBuilder)
 : myArray                     (0, theNbPriorities - 1),
   myNbStructures              (0),
   myNbStructuresNotCulled     (0),
+  myLayerId                   (theId),
   myBVHPrimitivesTrsfPers     (theBuilder),
   myBVHIsLeftChildQueuedFirst (Standard_True),
   myIsBVHPrimitivesNeedsReset (Standard_False)
index dc947bc..820113e 100644 (file)
@@ -17,6 +17,7 @@
 #include <Graphic3d_BvhCStructureSet.hxx>
 #include <Graphic3d_BvhCStructureSetTrsfPers.hxx>
 #include <Graphic3d_Camera.hxx>
+#include <Graphic3d_ZLayerId.hxx>
 #include <Graphic3d_ZLayerSettings.hxx>
 #include <Graphic3d_RenderingParams.hxx>
 #include <NCollection_Array1.hxx>
@@ -38,12 +39,16 @@ class Graphic3d_Layer : public Standard_Transient
 public:
 
   //! Initializes associated priority list and layer properties
-  Standard_EXPORT Graphic3d_Layer (Standard_Integer theNbPriorities,
+  Standard_EXPORT Graphic3d_Layer (Graphic3d_ZLayerId theId,
+                                   Standard_Integer theNbPriorities,
                                    const Handle(Select3D_BVHBuilder3d)& theBuilder);
 
   //! Destructor.
   Standard_EXPORT virtual ~Graphic3d_Layer();
 
+  //! Return layer id.
+  Graphic3d_ZLayerId LayerId() const { return myLayerId; }
+
   //! Returns BVH tree builder for frustom culling.
   const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHPrimitivesTrsfPers.Builder(); }
 
@@ -158,6 +163,9 @@ private:
   //! Layer setting flags.
   Graphic3d_ZLayerSettings myLayerSettings;
 
+  //! Layer id.
+  Graphic3d_ZLayerId myLayerId;
+
   //! Set of Graphic3d_CStructures structures for building BVH tree.
   mutable Graphic3d_BvhCStructureSet myBVHPrimitives;
 
index fa2233c..b61c0a3 100644 (file)
@@ -38,6 +38,7 @@ struct Graphic3d_ZLayerSettings
   : myCullingDistance (Precision::Infinite()),
     myCullingSize     (Precision::Infinite()),
     myIsImmediate       (Standard_False),
+    myToRaytrace        (Standard_True),
     myUseEnvironmentTexture (Standard_True),
     myToEnableDepthTest (Standard_True),
     myToEnableDepthWrite(Standard_True),
@@ -105,6 +106,13 @@ struct Graphic3d_ZLayerSettings
   //! Set the flag indicating the immediate layer, which should be drawn after all normal (non-immediate) layers.
   void SetImmediate (const Standard_Boolean theValue) { myIsImmediate = theValue; }
 
+  //! Returns TRUE if layer should be processed by ray-tracing renderer; TRUE by default.
+  //! Note that this flag is IGNORED for layers with IsImmediate() flag.
+  Standard_Boolean IsRaytracable() const { return myToRaytrace; }
+
+  //! Sets if layer should be processed by ray-tracing renderer.
+  void SetRaytracable (Standard_Boolean theToRaytrace) { myToRaytrace = theToRaytrace; }
+
   //! Return flag to allow/prevent environment texture mapping usage for specific layer.
   Standard_Boolean UseEnvironmentTexture() const { return myUseEnvironmentTexture; }
 
@@ -210,6 +218,7 @@ protected:
   Standard_Real               myCullingSize;           //!< size to discard objects
   Graphic3d_PolygonOffset     myPolygonOffset;         //!< glPolygonOffset() arguments
   Standard_Boolean            myIsImmediate;           //!< immediate layer will be drawn after all normal layers
+  Standard_Boolean            myToRaytrace;            //!< option to render layer within ray-tracing engine
   Standard_Boolean            myUseEnvironmentTexture; //!< flag to allow/prevent environment texture mapping usage for specific layer
   Standard_Boolean            myToEnableDepthTest;     //!< option to enable depth test
   Standard_Boolean            myToEnableDepthWrite;    //!< option to enable write depth values
index ff55ab0..27b7916 100644 (file)
@@ -103,7 +103,7 @@ void OpenGl_FrameStats::updateStatistics (const Handle(Graphic3d_CView)& theView
    || (aBits & Graphic3d_RenderingParams::PerfCounters_Layers)    != 0)
   {
     const Standard_Integer aViewId = aView->Identification();
-    for (OpenGl_SequenceOfLayers::Iterator aLayerIter (aView->LayerList().Layers()); aLayerIter.More(); aLayerIter.Next())
+    for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (aView->LayerList().Layers()); aLayerIter.More(); aLayerIter.Next())
     {
       const Handle(OpenGl_Layer)& aLayer = aLayerIter.Value();
       myCountersTmp[Graphic3d_FrameStatsCounter_NbStructs] += aLayer->NbStructures();
index b60b7cd..ea2d2fb 100644 (file)
@@ -526,29 +526,36 @@ void OpenGl_GraphicDriver::TextSize (const Handle(Graphic3d_CView)& theView,
 }
 
 //=======================================================================
-//function : AddZLayer
+//function : InsertLayerBefore
 //purpose  :
 //=======================================================================
-void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_ZLayerId theLayerId)
+void OpenGl_GraphicDriver::InsertLayerBefore (const Graphic3d_ZLayerId theLayerId,
+                                              const Graphic3d_ZLayerSettings& theSettings,
+                                              const Graphic3d_ZLayerId theLayerAfter)
 {
-  if (theLayerId < 1)
+  base_type::InsertLayerBefore (theLayerId, theSettings, theLayerAfter);
+
+  // Add layer to all views
+  for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView); aViewIt.More(); aViewIt.Next())
   {
-    Standard_ASSERT_RAISE (theLayerId > 0,
-                           "OpenGl_GraphicDriver::AddZLayer, "
-                           "negative and zero IDs are reserved");
+    aViewIt.Value()->InsertLayerBefore (theLayerId, theSettings, theLayerAfter);
   }
+}
 
-  myLayerIds.Add (theLayerId);
-
-  // Default z-layer settings
-  myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings());
-  addZLayerIndex (theLayerId);
+//=======================================================================
+//function : InsertLayerAfter
+//purpose  :
+//=======================================================================
+void OpenGl_GraphicDriver::InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
+                                             const Graphic3d_ZLayerSettings& theSettings,
+                                             const Graphic3d_ZLayerId theLayerBefore)
+{
+  base_type::InsertLayerAfter (theNewLayerId, theSettings, theLayerBefore);
 
   // Add layer to all views
-  NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView);
-  for (; aViewIt.More(); aViewIt.Next())
+  for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView); aViewIt.More(); aViewIt.Next())
   {
-    aViewIt.Value()->AddZLayer (theLayerId);
+    aViewIt.Value()->InsertLayerAfter (theNewLayerId, theSettings, theLayerBefore);
   }
 }
 
@@ -558,43 +565,21 @@ void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_ZLayerId theLayerId)
 //=======================================================================
 void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
 {
-  Standard_ASSERT_RAISE (theLayerId > 0,
-                         "OpenGl_GraphicDriver::AddZLayer, "
-                         "negative and zero IDs are reserved"
-                         "and can not be removed");
-
-  Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId),
-                         "OpenGl_GraphicDriver::RemoveZLayer, "
-                         "Layer with theLayerId does not exist");
+  base_type::RemoveZLayer (theLayerId);
 
   // Remove layer from all of the views
-  NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView);
-  for (; aViewIt.More(); aViewIt.Next())
+  for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView); aViewIt.More(); aViewIt.Next())
   {
     aViewIt.Value()->RemoveZLayer (theLayerId);
   }
 
   // Unset Z layer for all of the structures.
-  NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
-  for( ; aStructIt.More (); aStructIt.Next ())
+  for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure); aStructIt.More(); aStructIt.Next())
   {
     OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
     if (aStruct->ZLayer() == theLayerId)
       aStruct->SetZLayer (Graphic3d_ZLayerId_Default);
   }
-
-  // Remove index
-  for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
-  {
-    if (aLayerIt.Value() == theLayerId)
-    {
-      myLayerSeq.Remove (aLayerIt);
-      break;
-    }
-  }
-
-  myMapOfZLayerSettings.UnBind (theLayerId);
-  myLayerIds.Remove  (theLayerId);
 }
 
 //=======================================================================
@@ -642,23 +627,18 @@ void OpenGl_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCSt
 }
 
 // =======================================================================
-// function : View
+// function : CreateView
 // purpose  :
 // =======================================================================
 Handle(Graphic3d_CView) OpenGl_GraphicDriver::CreateView (const Handle(Graphic3d_StructureManager)& theMgr)
 {
   Handle(OpenGl_View) aView = new OpenGl_View (theMgr, this, myCaps, &myStateCounter);
-
   myMapOfView.Add (aView);
-
-  for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    const Graphic3d_ZLayerId        aLayerID  = aLayerIt.Value();
-    const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID);
-    aView->AddZLayer         (aLayerID);
-    aView->SetZLayerSettings (aLayerID, aSettings);
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.Value();
+    aView->InsertLayerAfter (aLayer->LayerId(), aLayer->LayerSettings(), Graphic3d_ZLayerId_UNKNOWN);
   }
-
   return aView;
 }
 
index a07ec64..4c63bb0 100644 (file)
@@ -108,10 +108,21 @@ public:
 
 public:
 
-  //! Adds a new top-level z layer with ID theLayerId for all views. Z layers allow drawing structures in higher layers
-  //! in foreground of structures in lower layers. To add a structure to desired layer on display it is necessary to
-  //! set the layer index for the structure. The passed theLayerId should be not less than 0 (reserved for default layers).
-  Standard_EXPORT void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
+  //! Adds a layer to all views.
+  //! @param theLayerId    [in] id of new layer, should be > 0 (negative values are reserved for default layers).
+  //! @param theSettings   [in] new layer settings
+  //! @param theLayerAfter [in] id of layer to append new layer before
+  Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
+                                                  const Graphic3d_ZLayerSettings& theSettings,
+                                                  const Graphic3d_ZLayerId theLayerAfter) Standard_OVERRIDE;
+
+  //! Adds a layer to all views.
+  //! @param theLayerId     [in] id of created layer
+  //! @param theSettings    [in] new layer settings
+  //! @param theLayerBefore [in] id of layer to append new layer after
+  Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
+                                                 const Graphic3d_ZLayerSettings& theSettings,
+                                                 const Graphic3d_ZLayerId theLayerBefore) Standard_OVERRIDE;
 
   //! Removes Z layer. All structures displayed at the moment in layer will be displayed in
   //! default layer (the bottom-level z layer). By default, there are always default
index 1860431..0531bf1 100644 (file)
 #ifndef _OpenGl_LayerFilter_H__
 #define _OpenGl_LayerFilter_H__
 
-//! Tool object to specify processed OpenGL layers.
+//! Tool object to specify processed OpenGL layers
+//! for intermixed rendering of raytracable and non-raytracable layers.
 enum OpenGl_LayerFilter
 {
-  OpenGl_LF_All,    //!< process all layers
-  OpenGl_LF_Upper,  //!< process only top layers
-  OpenGl_LF_Bottom, //!< process only bottom layer
-  OpenGl_LF_Default //!< process only default layer
+  OpenGl_LF_All,        //!< process all layers
+  OpenGl_LF_Upper,      //!< process only top non-raytracable layers
+  OpenGl_LF_Bottom,     //!< process only Graphic3d_ZLayerId_BotOSD
+  OpenGl_LF_RayTracable //!< process only normal raytracable layers (save the bottom layer)
 };
 
 #endif //_OpenGl_LayerFilter_H__
index 4aee97b..0e46b23 100644 (file)
 namespace
 {
   //! Auxiliary class extending sequence iterator with index.
-  class OpenGl_IndexedLayerIterator : public OpenGl_SequenceOfLayers::Iterator
+  class OpenGl_IndexedLayerIterator : public NCollection_List<Handle(Graphic3d_Layer)>::Iterator
   {
   public:
     //! Main constructor.
-    OpenGl_IndexedLayerIterator (const OpenGl_SequenceOfLayers& theSeq)
-    : OpenGl_SequenceOfLayers::Iterator (theSeq),
-      myIndex (theSeq.Lower()) {}
+    OpenGl_IndexedLayerIterator (const NCollection_List<Handle(Graphic3d_Layer)>& theSeq)
+    : NCollection_List<Handle(Graphic3d_Layer)>::Iterator (theSeq),
+      myIndex (1) {}
 
     //! Return index of current position.
     Standard_Integer Index() const { return myIndex; }
@@ -43,7 +43,7 @@ namespace
     //! Move to the next position.
     void Next()
     {
-      OpenGl_SequenceOfLayers::Iterator::Next();
+      NCollection_List<Handle(Graphic3d_Layer)>::Iterator::Next();
       ++myIndex;
     }
 
@@ -56,12 +56,10 @@ namespace
   {
   public:
     //! Main constructor.
-    OpenGl_FilteredIndexedLayerIterator (const OpenGl_SequenceOfLayers& theSeq,
-                                         Standard_Integer theDefaultLayerIndex,
+    OpenGl_FilteredIndexedLayerIterator (const NCollection_List<Handle(Graphic3d_Layer)>& theSeq,
                                          Standard_Boolean theToDrawImmediate,
                                          OpenGl_LayerFilter theLayersToProcess)
     : myIter (theSeq),
-      myDefaultLayerIndex (theDefaultLayerIndex),
       myLayersToProcess (theLayersToProcess),
       myToDrawImmediate (theToDrawImmediate)
     {
@@ -90,7 +88,8 @@ namespace
     {
       for (; myIter.More(); myIter.Next())
       {
-        if (myIter.Value()->IsImmediate() != myToDrawImmediate)
+        const Handle(Graphic3d_Layer)& aLayer = myIter.Value();
+        if (aLayer->IsImmediate() != myToDrawImmediate)
         {
           continue;
         }
@@ -99,39 +98,41 @@ namespace
         {
           case OpenGl_LF_All:
           {
-            break;
+            return;
           }
           case OpenGl_LF_Upper:
           {
-            if (myIter.Index() <= myDefaultLayerIndex)
+            if (aLayer->LayerId() != Graphic3d_ZLayerId_BotOSD
+             && (!aLayer->LayerSettings().IsRaytracable()
+               || aLayer->IsImmediate()))
             {
-              continue;
+              return;
             }
             break;
           }
           case OpenGl_LF_Bottom:
           {
-            if (myIter.Index() >= myDefaultLayerIndex)
+            if (aLayer->LayerId() == Graphic3d_ZLayerId_BotOSD
+            && !aLayer->LayerSettings().IsRaytracable())
             {
-              continue;
+              return;
             }
             break;
           }
-          case OpenGl_LF_Default:
+          case OpenGl_LF_RayTracable:
           {
-            if (myIter.Index() != myDefaultLayerIndex)
+            if (aLayer->LayerSettings().IsRaytracable()
+            && !aLayer->IsImmediate())
             {
-              continue;
+              return;
             }
             break;
           }
         }
-        return;
       }
     }
   private:
     OpenGl_IndexedLayerIterator myIter;
-    Standard_Integer            myDefaultLayerIndex;
     OpenGl_LayerFilter          myLayersToProcess;
     Standard_Boolean            myToDrawImmediate;
   };
@@ -150,31 +151,12 @@ struct OpenGl_GlobalLayerSettings
 
 OpenGl_LayerList::OpenGl_LayerList (const Standard_Integer theNbPriorities)
 : myBVHBuilder (new BVH_LinearBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth)),
-  myDefaultLayerIndex (0),
   myNbPriorities (theNbPriorities),
   myNbStructures (0),
   myImmediateNbStructures (0),
   myModifStateOfRaytraceable (0)
 {
-  // insert default priority layers
-  myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
-  myLayerIds.Bind (Graphic3d_ZLayerId_BotOSD,  myLayers.Upper());
-
-  myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
-  myLayerIds.Bind (Graphic3d_ZLayerId_Default, myLayers.Upper());
-
-  myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
-  myLayerIds.Bind (Graphic3d_ZLayerId_Top,     myLayers.Upper());
-
-  myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
-  myLayerIds.Bind (Graphic3d_ZLayerId_Topmost, myLayers.Upper());
-
-  myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
-  myLayerIds.Bind (Graphic3d_ZLayerId_TopOSD,  myLayers.Upper());
-
-  myDefaultLayerIndex = myLayerIds.Find (Graphic3d_ZLayerId_Default);
-
-  myTransparentToProcess.Allocate (myLayers.Length());
+  //
 }
 
 //=======================================================================
@@ -193,85 +175,109 @@ OpenGl_LayerList::~OpenGl_LayerList()
 void OpenGl_LayerList::SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder)
 {
   myBVHBuilder = theBuilder;
-  for (OpenGl_SequenceOfLayers::Iterator anIts (myLayers); anIts.More(); anIts.Next())
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    anIts.ChangeValue()->SetFrustumCullingBVHBuilder (theBuilder);
+    aLayerIter.ChangeValue()->SetFrustumCullingBVHBuilder (theBuilder);
   }
 }
 
 //=======================================================================
-//function : AddLayer
-//purpose  : 
+//function : InsertLayerBefore
+//purpose  :
 //=======================================================================
-
-void OpenGl_LayerList::AddLayer (const Graphic3d_ZLayerId theLayerId)
+void OpenGl_LayerList::InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
+                                          const Graphic3d_ZLayerSettings& theSettings,
+                                          const Graphic3d_ZLayerId theLayerAfter)
 {
-  if (myLayerIds.IsBound (theLayerId))
+  if (myLayerIds.IsBound (theNewLayerId))
   {
     return;
   }
 
-  // add the new layer
-  myLayers.Append (new OpenGl_Layer (myNbPriorities, myBVHBuilder));
-  myLayerIds.Bind (theLayerId, myLayers.Length());
+  Handle(Graphic3d_Layer) aNewLayer = new Graphic3d_Layer (theNewLayerId, myNbPriorities, myBVHBuilder);
+  aNewLayer->SetLayerSettings (theSettings);
 
-  myTransparentToProcess.Allocate (myLayers.Length());
-}
+  Handle(Graphic3d_Layer) anOtherLayer;
+  if (theLayerAfter != Graphic3d_ZLayerId_UNKNOWN
+   && myLayerIds.Find (theLayerAfter, anOtherLayer))
+  {
+    for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
+    {
+      if (aLayerIter.Value() == anOtherLayer)
+      {
+        myLayers.InsertBefore (aNewLayer, aLayerIter);
+        break;
+      }
+    }
+  }
+  else
+  {
+    myLayers.Prepend (aNewLayer);
+  }
 
-//=======================================================================
-//function : Layer
-//purpose  : 
-//=======================================================================
-OpenGl_Layer& OpenGl_LayerList::Layer (const Graphic3d_ZLayerId theLayerId)
-{
-  return *myLayers.ChangeValue (myLayerIds.Find (theLayerId));
+  myLayerIds.Bind (theNewLayerId, aNewLayer);
+  myTransparentToProcess.Allocate (myLayers.Size());
 }
 
 //=======================================================================
-//function : Layer
-//purpose  : 
+//function : InsertLayerAfter
+//purpose  :
 //=======================================================================
-const OpenGl_Layer& OpenGl_LayerList::Layer (const Graphic3d_ZLayerId theLayerId) const
+void OpenGl_LayerList::InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
+                                         const Graphic3d_ZLayerSettings& theSettings,
+                                         const Graphic3d_ZLayerId theLayerBefore)
 {
-  return *myLayers.Value (myLayerIds.Find (theLayerId));
+  if (myLayerIds.IsBound (theNewLayerId))
+  {
+    return;
+  }
+
+  Handle(Graphic3d_Layer) aNewLayer = new Graphic3d_Layer (theNewLayerId, myNbPriorities, myBVHBuilder);
+  aNewLayer->SetLayerSettings (theSettings);
+
+  Handle(Graphic3d_Layer) anOtherLayer;
+  if (theLayerBefore != Graphic3d_ZLayerId_UNKNOWN
+   && myLayerIds.Find (theLayerBefore, anOtherLayer))
+  {
+    for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
+    {
+      if (aLayerIter.Value() == anOtherLayer)
+      {
+        myLayers.InsertAfter (aNewLayer, aLayerIter);
+        break;
+      }
+    }
+  }
+  else
+  {
+    myLayers.Append (aNewLayer);
+  }
+
+  myLayerIds.Bind (theNewLayerId, aNewLayer);
+  myTransparentToProcess.Allocate (myLayers.Size());
 }
 
 //=======================================================================
 //function : RemoveLayer
 //purpose  :
 //=======================================================================
-
 void OpenGl_LayerList::RemoveLayer (const Graphic3d_ZLayerId theLayerId)
 {
-  if (!myLayerIds.IsBound (theLayerId)
-    || theLayerId <= 0)
+  Handle(Graphic3d_Layer) aLayerToRemove;
+  if (theLayerId <= 0
+  || !myLayerIds.Find (theLayerId, aLayerToRemove))
   {
     return;
   }
 
-  const Standard_Integer aRemovePos = myLayerIds.Find (theLayerId);
-  
   // move all displayed structures to first layer
-  {
-    const OpenGl_Layer& aLayerToMove = *myLayers.Value (aRemovePos);
-    myLayers.ChangeFirst()->Append (aLayerToMove);
-  }
+  myLayerIds.Find (Graphic3d_ZLayerId_Default)->Append (*aLayerToRemove);
 
   // remove layer
-  myLayers.Remove (aRemovePos);
+  myLayers.Remove (aLayerToRemove);
   myLayerIds.UnBind (theLayerId);
 
-  // updated sequence indexes in map
-  for (OpenGl_LayerSeqIds::Iterator aMapIt (myLayerIds); aMapIt.More(); aMapIt.Next())
-  {
-    Standard_Integer& aSeqIdx = aMapIt.ChangeValue();
-    if (aSeqIdx > aRemovePos)
-      aSeqIdx--;
-  }
-
-  myDefaultLayerIndex = myLayerIds.Find (Graphic3d_ZLayerId_Default);
-
-  myTransparentToProcess.Allocate (myLayers.Length());
+  myTransparentToProcess.Allocate (myLayers.Size());
 }
 
 //=======================================================================
@@ -286,13 +292,11 @@ void OpenGl_LayerList::AddStructure (const OpenGl_Structure*  theStruct,
 {
   // add structure to associated layer,
   // if layer doesn't exists, display structure in default layer
-  Standard_Integer aSeqPos = myLayers.Lower();
-  myLayerIds.Find (theLayerId, aSeqPos);
-
-  OpenGl_Layer& aLayer = *myLayers.ChangeValue (aSeqPos);
-  aLayer.Add (theStruct, thePriority, isForChangePriority);
+  const Handle(Graphic3d_Layer)* aLayerPtr = myLayerIds.Seek (theLayerId);
+  const Handle(Graphic3d_Layer)& aLayer = aLayerPtr != NULL ? *aLayerPtr : myLayerIds.Find (Graphic3d_ZLayerId_Default);
+  aLayer->Add (theStruct, thePriority, isForChangePriority);
   ++myNbStructures;
-  if (aLayer.IsImmediate())
+  if (aLayer->IsImmediate())
   {
     ++myImmediateNbStructures;
   }
@@ -310,25 +314,23 @@ void OpenGl_LayerList::AddStructure (const OpenGl_Structure*  theStruct,
 void OpenGl_LayerList::RemoveStructure (const OpenGl_Structure* theStructure)
 {
   const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer();
+  const Handle(Graphic3d_Layer)* aLayerPtr = myLayerIds.Seek (aLayerId);
+  const Handle(Graphic3d_Layer)& aLayer = aLayerPtr != NULL ? *aLayerPtr : myLayerIds.Find (Graphic3d_ZLayerId_Default);
 
-  Standard_Integer aSeqPos = myLayers.Lower();
-  myLayerIds.Find (aLayerId, aSeqPos);
-
-  OpenGl_Layer&    aLayer    = *myLayers.ChangeValue (aSeqPos);
   Standard_Integer aPriority = -1;
 
   // remove structure from associated list
   // if the structure is not found there,
   // scan through layers and remove it
-  if (aLayer.Remove (theStructure, aPriority))
+  if (aLayer->Remove (theStructure, aPriority))
   {
     --myNbStructures;
-    if (aLayer.IsImmediate())
+    if (aLayer->IsImmediate())
     {
       --myImmediateNbStructures;
     }
 
-    if (aLayerId == Graphic3d_ZLayerId_Default
+    if (aLayer->LayerSettings().IsRaytracable()
      && theStructure->IsRaytracable())
     {
       ++myModifStateOfRaytraceable;
@@ -338,23 +340,23 @@ void OpenGl_LayerList::RemoveStructure (const OpenGl_Structure* theStructure)
   }
 
   // scan through layers and remove it
-  for (OpenGl_IndexedLayerIterator anIts (myLayers); anIts.More(); anIts.Next())
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    OpenGl_Layer& aLayerEx = *anIts.ChangeValue();
-    if (aSeqPos == anIts.Index())
+    const Handle(Graphic3d_Layer)& aLayerEx = aLayerIter.ChangeValue();
+    if (aLayerEx == aLayer)
     {
       continue;
     }
 
-    if (aLayerEx.Remove (theStructure, aPriority))
+    if (aLayerEx->Remove (theStructure, aPriority))
     {
       --myNbStructures;
-      if (aLayerEx.IsImmediate())
+      if (aLayerEx->IsImmediate())
       {
         --myImmediateNbStructures;
       }
 
-      if (anIts.Index() == myDefaultLayerIndex
+      if (aLayerEx->LayerSettings().IsRaytracable()
        && theStructure->IsRaytracable())
       {
         ++myModifStateOfRaytraceable;
@@ -370,10 +372,9 @@ void OpenGl_LayerList::RemoveStructure (const OpenGl_Structure* theStructure)
 //=======================================================================
 void OpenGl_LayerList::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId)
 {
-  Standard_Integer aSeqPos = myLayers.Lower();
-  myLayerIds.Find (theLayerId, aSeqPos);
-  OpenGl_Layer& aLayer = *myLayers.ChangeValue (aSeqPos);
-  aLayer.InvalidateBVHData();
+  const Handle(Graphic3d_Layer)* aLayerPtr = myLayerIds.Seek (theLayerId);
+  const Handle(Graphic3d_Layer)& aLayer = aLayerPtr != NULL ? *aLayerPtr : myLayerIds.Find (Graphic3d_ZLayerId_Default);
+  aLayer->InvalidateBVHData();
 }
 
 //=======================================================================
@@ -385,23 +386,24 @@ void OpenGl_LayerList::ChangeLayer (const OpenGl_Structure*  theStructure,
                                     const Graphic3d_ZLayerId theOldLayerId,
                                     const Graphic3d_ZLayerId theNewLayerId)
 {
-  Standard_Integer aSeqPos = myLayers.Lower();
-  myLayerIds.Find (theOldLayerId, aSeqPos);
-  OpenGl_Layer&    aLayer    = *myLayers.ChangeValue (aSeqPos);
+  const Handle(Graphic3d_Layer)* aLayerPtr = myLayerIds.Seek (theOldLayerId);
+  const Handle(Graphic3d_Layer)& aLayer = aLayerPtr != NULL ? *aLayerPtr : myLayerIds.Find (Graphic3d_ZLayerId_Default);
+
   Standard_Integer aPriority = -1;
 
   // take priority and remove structure from list found by <theOldLayerId>
   // if the structure is not found there, scan through all other layers
-  if (aLayer.Remove (theStructure, aPriority, Standard_False))
+  if (aLayer->Remove (theStructure, aPriority, Standard_False))
   {
-    if (theOldLayerId == Graphic3d_ZLayerId_Default
-     && theStructure->IsRaytracable())
+    if (aLayer->LayerSettings().IsRaytracable()
+    && !aLayer->LayerSettings().IsImmediate()
+    &&  theStructure->IsRaytracable())
     {
       ++myModifStateOfRaytraceable;
     }
 
     --myNbStructures;
-    if (aLayer.IsImmediate())
+    if (aLayer->IsImmediate())
     {
       --myImmediateNbStructures;
     }
@@ -413,25 +415,26 @@ void OpenGl_LayerList::ChangeLayer (const OpenGl_Structure*  theStructure,
   }
 
   // scan through layers and remove it
-  for (OpenGl_IndexedLayerIterator anIts (myLayers); anIts.More(); anIts.Next())
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    if (aSeqPos == anIts.Index())
+    const Handle(OpenGl_Layer)& aLayerEx = aLayerIter.ChangeValue();
+    if (aLayerEx == aLayer)
     {
       continue;
     }
   
     // try to remove structure and get priority value from this layer
-    OpenGl_Layer& aLayerEx = *anIts.ChangeValue();
-    if (aLayerEx.Remove (theStructure, aPriority, Standard_True))
+    if (aLayerEx->Remove (theStructure, aPriority, Standard_True))
     {
-      if (anIts.Index() == myDefaultLayerIndex
-       && theStructure->IsRaytracable())
+      if (aLayerEx->LayerSettings().IsRaytracable()
+      && !aLayerEx->LayerSettings().IsImmediate()
+      &&  theStructure->IsRaytracable())
       {
         ++myModifStateOfRaytraceable;
       }
 
       --myNbStructures;
-      if (aLayerEx.IsImmediate())
+      if (aLayerEx->IsImmediate())
       {
         --myImmediateNbStructures;
       }
@@ -452,15 +455,15 @@ void OpenGl_LayerList::ChangePriority (const OpenGl_Structure*  theStructure,
                                        const Graphic3d_ZLayerId theLayerId,
                                        const Standard_Integer   theNewPriority)
 {
-  Standard_Integer aSeqPos = myLayers.Lower();
-  myLayerIds.Find (theLayerId, aSeqPos);
-  OpenGl_Layer&    aLayer        = *myLayers.ChangeValue (aSeqPos);
+  const Handle(Graphic3d_Layer)* aLayerPtr = myLayerIds.Seek (theLayerId);
+  const Handle(Graphic3d_Layer)& aLayer = aLayerPtr != NULL ? *aLayerPtr : myLayerIds.Find (Graphic3d_ZLayerId_Default);
+
   Standard_Integer anOldPriority = -1;
 
-  if (aLayer.Remove (theStructure, anOldPriority, Standard_True))
+  if (aLayer->Remove (theStructure, anOldPriority, Standard_True))
   {
     --myNbStructures;
-    if (aLayer.IsImmediate())
+    if (aLayer->IsImmediate())
     {
       --myImmediateNbStructures;
     }
@@ -469,18 +472,18 @@ void OpenGl_LayerList::ChangePriority (const OpenGl_Structure*  theStructure,
     return;
   }
 
-  for (OpenGl_IndexedLayerIterator anIts (myLayers); anIts.More(); anIts.Next())
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    if (aSeqPos == anIts.Index())
+    const Handle(OpenGl_Layer)& aLayerEx = aLayerIter.ChangeValue();
+    if (aLayerEx == aLayer)
     {
       continue;
     }
 
-    OpenGl_Layer& aLayerEx = *anIts.ChangeValue();
-    if (aLayerEx.Remove (theStructure, anOldPriority, Standard_True))
+    if (aLayerEx->Remove (theStructure, anOldPriority, Standard_True))
     {
       --myNbStructures;
-      if (aLayerEx.IsImmediate())
+      if (aLayerEx->IsImmediate())
       {
         --myImmediateNbStructures;
       }
@@ -498,7 +501,12 @@ void OpenGl_LayerList::ChangePriority (const OpenGl_Structure*  theStructure,
 void OpenGl_LayerList::SetLayerSettings (const Graphic3d_ZLayerId        theLayerId,
                                          const Graphic3d_ZLayerSettings& theSettings)
 {
-  OpenGl_Layer& aLayer = Layer (theLayerId);
+  Graphic3d_Layer& aLayer = Layer (theLayerId);
+  if (aLayer.LayerSettings().IsRaytracable() != theSettings.IsRaytracable()
+   && aLayer.NbStructures() != 0)
+  {
+    ++myModifStateOfRaytraceable;
+  }
   if (aLayer.LayerSettings().IsImmediate() != theSettings.IsImmediate())
   {
     if (theSettings.IsImmediate())
@@ -526,15 +534,15 @@ void OpenGl_LayerList::UpdateCulling (const Handle(OpenGl_Workspace)& theWorkspa
 
   const Standard_Integer aViewId = theWorkspace->View()->Identification();
   const Graphic3d_CullingTool& aSelector = theWorkspace->View()->BVHTreeSelector();
-  for (OpenGl_IndexedLayerIterator anIts (myLayers); anIts.More(); anIts.Next())
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myLayers); aLayerIter.More(); aLayerIter.Next())
   {
-    OpenGl_Layer& aLayer = *anIts.ChangeValue();
-    if (aLayer.IsImmediate() != theToDrawImmediate)
+    const Handle(Graphic3d_Layer)& aLayer = aLayerIter.ChangeValue();
+    if (aLayer->IsImmediate() != theToDrawImmediate)
     {
       continue;
     }
 
-    aLayer.UpdateCulling (aViewId, aSelector, theWorkspace->View()->RenderingParams().FrustumCullingState);
+    aLayer->UpdateCulling (aViewId, aSelector, theWorkspace->View()->RenderingParams().FrustumCullingState);
   }
 
   aTimer.Stop();
@@ -716,7 +724,7 @@ void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace)& theWorkspace,
   const bool toPerformDepthPrepass = theWorkspace->View()->RenderingParams().ToEnableDepthPrepass
                                   && aPrevSettings.DepthMask == GL_TRUE;
   const Handle(Graphic3d_LightSet) aLightsBack = aCtx->ShaderManager()->LightSourceState().LightSources();
-  for (OpenGl_FilteredIndexedLayerIterator aLayerIterStart (myLayers, myDefaultLayerIndex, theToDrawImmediate, theLayersToProcess); aLayerIterStart.More();)
+  for (OpenGl_FilteredIndexedLayerIterator aLayerIterStart (myLayers, theToDrawImmediate, theLayersToProcess); aLayerIterStart.More();)
   {
     bool hasSkippedDepthLayers = false;
     for (int aPassIter = toPerformDepthPrepass ? 0 : 2; aPassIter < 3; ++aPassIter)
index 813bc47..d85d871 100644 (file)
@@ -29,9 +29,6 @@ class OpenGl_Structure;
 class OpenGl_Workspace;
 struct OpenGl_GlobalLayerSettings;
 
-typedef NCollection_Sequence<Handle(OpenGl_Layer)> OpenGl_SequenceOfLayers;
-typedef NCollection_DataMap<int, int> OpenGl_LayerSeqIds;
-
 //! Class defining the list of layers.
 class OpenGl_LayerList
 {
@@ -53,7 +50,14 @@ public:
   Standard_Integer NbImmediateStructures() const { return myImmediateNbStructures; }
 
   //! Insert a new layer with id.
-  void AddLayer (const Graphic3d_ZLayerId theLayerId);
+  void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
+                          const Graphic3d_ZLayerSettings& theSettings,
+                          const Graphic3d_ZLayerId theLayerAfter);
+
+  //! Insert a new layer with id.
+  void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
+                         const Graphic3d_ZLayerSettings& theSettings,
+                         const Graphic3d_ZLayerId theLayerBefore);
 
   //! Remove layer by its id.
   void RemoveLayer (const Graphic3d_ZLayerId theLayerId);
@@ -82,10 +86,10 @@ public:
                        const Standard_Integer   theNewPriority);
 
   //! Returns reference to the layer with given ID.
-  OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId);
+  OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) { return *myLayerIds.Find (theLayerId); }
 
   //! Returns reference to the layer with given ID.
-  const OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) const;
+  const OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) const { return *myLayerIds.Find (theLayerId); }
 
   //! Assign new settings to the layer.
   void SetLayerSettings (const Graphic3d_ZLayerId        theLayerId,
@@ -103,10 +107,10 @@ public:
                OpenGl_FrameBuffer*             theOitAccumFbo) const;
 
   //! Returns the set of OpenGL Z-layers.
-  const OpenGl_SequenceOfLayers& Layers() const { return myLayers; }
+  const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const { return myLayers; }
 
   //! Returns the map of Z-layer IDs to indexes.
-  const OpenGl_LayerSeqIds& LayerIDs() const { return myLayerIds; }
+  const NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)>& LayerIDs() const { return myLayerIds; }
 
   //! Marks BVH tree for given priority list as dirty and
   //! marks primitive set for rebuild.
@@ -134,13 +138,14 @@ protected:
     {
       if (theSize > 0)
       {
-        myStackSpace = new NCollection_Array1<const Graphic3d_Layer*> (1, theSize);
-        myStackSpace->Init (NULL);
-        myBackPtr    = myStackSpace->begin();
+        myStackSpace.Resize (1, theSize, false);
+        myStackSpace.Init (NULL);
+        myBackPtr = myStackSpace.begin();
       }
       else
       {
-        myStackSpace.Nullify();
+        NCollection_Array1<const Graphic3d_Layer*> aDummy;
+        myStackSpace.Move (aDummy);
         myBackPtr = iterator();
       }
     }
@@ -148,18 +153,15 @@ protected:
     //! Clear stack.
     void Clear()
     {
-      if (!myStackSpace.IsNull())
-      {
-        myStackSpace->Init (NULL);
-        myBackPtr = myStackSpace->begin();
-      }
+      myStackSpace.Init (NULL);
+      myBackPtr = myStackSpace.begin();
     }
 
     //! Push a new layer reference to the stack.
     void Push (const OpenGl_Layer* theLayer) { (*myBackPtr++) = theLayer; }
 
     //! Returns iterator to the origin of the stack.
-    iterator Origin() const { return myStackSpace.IsNull() ? iterator() : myStackSpace->begin(); }
+    iterator Origin() const { return myStackSpace.IsEmpty() ? iterator() : myStackSpace.begin(); }
 
     //! Returns iterator to the back of the stack (after last item added).
     iterator Back() const { return myBackPtr; }
@@ -169,8 +171,8 @@ protected:
 
   private:
 
-    NCollection_Handle<NCollection_Array1<const OpenGl_Layer*> > myStackSpace;
-    iterator                                                     myBackPtr;
+    NCollection_Array1<const OpenGl_Layer*> myStackSpace;
+    iterator                                myBackPtr;
   };
 
   //! Render transparent objects using blending operator.
@@ -195,11 +197,9 @@ protected:
 
 protected:
 
-  // number of structures temporary put to default layer
-  OpenGl_SequenceOfLayers myLayers;
-  OpenGl_LayerSeqIds      myLayerIds;
+  NCollection_List<Handle(Graphic3d_Layer)> myLayers;
+  NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)> myLayerIds;
   Handle(Select3D_BVHBuilder3d) myBVHBuilder;      //!< BVH tree builder for frustom culling
-  Standard_Integer        myDefaultLayerIndex;     //!< index of Graphic3d_ZLayerId_Default layer in myLayers sequence
 
   Standard_Integer        myNbPriorities;
   Standard_Integer        myNbStructures;
index a3a388b..b4b9966 100644 (file)
@@ -488,12 +488,25 @@ void OpenGl_View::SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle)
 }
 
 //=======================================================================
-//function : AddZLayer
+//function : InsertLayerBefore
 //purpose  :
 //=======================================================================
-void OpenGl_View::AddZLayer (const Graphic3d_ZLayerId theLayerId)
+void OpenGl_View::InsertLayerBefore (const Graphic3d_ZLayerId theLayerId,
+                                     const Graphic3d_ZLayerSettings& theSettings,
+                                     const Graphic3d_ZLayerId theLayerAfter)
 {
-  myZLayers.AddLayer (theLayerId);
+  myZLayers.InsertLayerBefore (theLayerId, theSettings, theLayerAfter);
+}
+
+//=======================================================================
+//function : InsertLayerAfter
+//purpose  :
+//=======================================================================
+void OpenGl_View::InsertLayerAfter (const Graphic3d_ZLayerId theLayerId,
+                                    const Graphic3d_ZLayerSettings& theSettings,
+                                    const Graphic3d_ZLayerId theLayerBefore)
+{
+  myZLayers.InsertLayerAfter (theLayerId, theSettings, theLayerBefore);
 }
 
 //=======================================================================
@@ -522,83 +535,74 @@ void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId        theLayerId,
 Standard_Integer OpenGl_View::ZLayerMax() const
 {
   Standard_Integer aLayerMax = Graphic3d_ZLayerId_Default;
-  for (OpenGl_LayerSeqIds::Iterator aMapIt(myZLayers.LayerIDs()); aMapIt.More(); aMapIt.Next())
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myZLayers.Layers()); aLayerIter.More(); aLayerIter.Next())
   {
-    aLayerMax = Max (aLayerMax, aMapIt.Value());
+    aLayerMax = Max (aLayerMax, aLayerIter.Value()->LayerId());
   }
-
   return aLayerMax;
 }
 
 //=======================================================================
-//function : InvalidateZLayerBoundingBox
+//function : Layers
+//purpose  :
+//=======================================================================
+const NCollection_List<Handle(Graphic3d_Layer)>& OpenGl_View::Layers() const
+{
+  return myZLayers.Layers();
+}
+
+//=======================================================================
+//function : Layer
 //purpose  :
 //=======================================================================
-void OpenGl_View::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const
+Handle(Graphic3d_Layer) OpenGl_View::Layer (const Graphic3d_ZLayerId theLayerId) const
 {
-  if (myZLayers.LayerIDs().IsBound (theLayerId))
+  Handle(Graphic3d_Layer) aLayer;
+  if (theLayerId != Graphic3d_ZLayerId_UNKNOWN)
   {
-    myZLayers.Layer (theLayerId).InvalidateBoundingBox();
-  }
-  else
-  {
-    const Standard_Integer aLayerMax = ZLayerMax();
-    for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId < aLayerMax; ++aLayerId)
-    {
-      if (myZLayers.LayerIDs().IsBound (aLayerId))
-      {
-        const OpenGl_Layer& aLayer = myZLayers.Layer (aLayerId);
-        if (aLayer.NbOfTransformPersistenceObjects() > 0)
-        {
-          aLayer.InvalidateBoundingBox();
-        }
-      }
-    }
+    myZLayers.LayerIDs().Find (theLayerId, aLayer);
   }
+  return aLayer;
 }
 
 //=======================================================================
-//function : ZLayerBoundingBox
+//function : MinMaxValues
 //purpose  :
 //=======================================================================
-Bnd_Box OpenGl_View::ZLayerBoundingBox (const Graphic3d_ZLayerId        theLayerId,
-                                        const Handle(Graphic3d_Camera)& theCamera,
-                                        const Standard_Integer          theWindowWidth,
-                                        const Standard_Integer          theWindowHeight,
-                                        const Standard_Boolean          theToIncludeAuxiliary) const
+Bnd_Box OpenGl_View::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
 {
-  Bnd_Box aBox;
-  if (myZLayers.LayerIDs().IsBound (theLayerId))
+  if (!IsDefined())
   {
-    aBox = myZLayers.Layer (theLayerId).BoundingBox (Identification(),
-                                                     theCamera,
-                                                     theWindowWidth,
-                                                     theWindowHeight,
-                                                     theToIncludeAuxiliary);
+    return Bnd_Box();
   }
 
+  Bnd_Box aBox = base_type::MinMaxValues (theToIncludeAuxiliary);
+
   // add bounding box of gradient/texture background for proper Z-fit
   if (theToIncludeAuxiliary
-   && theLayerId == Graphic3d_ZLayerId_BotOSD
    && (myBgTextureArray->IsDefined()
     || myBgGradientArray->IsDefined()))
   {
+    const Handle(Graphic3d_Camera)& aCamera = Camera();
+    Graphic3d_Vec2i aWinSize;
+    Window()->Size (aWinSize.x(), aWinSize.y());
+
     // Background is drawn using 2D transformation persistence
     // (e.g. it is actually placed in 3D coordinates within active camera position).
     // We add here full-screen plane with 2D transformation persistence
     // for simplicity (myBgTextureArray might define a little bit different options
     // but it is updated within ::Render())
-    const Graphic3d_Mat4d& aProjectionMat = theCamera->ProjectionMatrix();
-    const Graphic3d_Mat4d& aWorldViewMat  = theCamera->OrientationMatrix();
+    const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
+    const Graphic3d_Mat4d& aWorldViewMat  = aCamera->OrientationMatrix();
     Graphic3d_BndBox3d aBox2d (Graphic3d_Vec3d (0.0, 0.0, 0.0),
-                               Graphic3d_Vec3d (double(theWindowWidth), double(theWindowHeight), 0.0));
+                               Graphic3d_Vec3d (double(aWinSize.x()), double(aWinSize.y()), 0.0));
 
     Graphic3d_TransformPers aTrsfPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER);
-    aTrsfPers.Apply (theCamera,
+    aTrsfPers.Apply (aCamera,
                      aProjectionMat,
                      aWorldViewMat,
-                     theWindowWidth,
-                     theWindowHeight,
+                     aWinSize.x(),
+                     aWinSize.y(),
                      aBox2d);
     aBox.Add (gp_Pnt (aBox2d.CornerMin().x(), aBox2d.CornerMin().y(), aBox2d.CornerMin().z()));
     aBox.Add (gp_Pnt (aBox2d.CornerMax().x(), aBox2d.CornerMax().y(), aBox2d.CornerMax().z()));
@@ -607,26 +611,6 @@ Bnd_Box OpenGl_View::ZLayerBoundingBox (const Graphic3d_ZLayerId        theLayer
   return aBox;
 }
 
-//=======================================================================
-//function : considerZoomPersistenceObjects
-//purpose  :
-//=======================================================================
-Standard_Real OpenGl_View::considerZoomPersistenceObjects (const Graphic3d_ZLayerId        theLayerId,
-                                                           const Handle(Graphic3d_Camera)& theCamera,
-                                                           const Standard_Integer          theWindowWidth,
-                                                           const Standard_Integer          theWindowHeight) const
-{
-  if (myZLayers.LayerIDs().IsBound (theLayerId))
-  {
-    return myZLayers.Layer (theLayerId).considerZoomPersistenceObjects (Identification(),
-                                                                        theCamera,
-                                                                        theWindowWidth,
-                                                                        theWindowHeight);
-  }
-
-  return 1.0;
-}
-
 //=======================================================================
 //function : FBO
 //purpose  :
index 44ead7c..225bfe8 100644 (file)
@@ -136,8 +136,21 @@ public:
   //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
   Standard_EXPORT virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
 
-  //! Insert a new top-level z layer with the given ID.
-  Standard_EXPORT virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
+  //! Add a layer to the view.
+  //! @param theNewLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
+  //! @param theSettings   [in] new layer settings
+  //! @param theLayerAfter [in] id of layer to append new layer before
+  Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theLayerId,
+                                                  const Graphic3d_ZLayerSettings& theSettings,
+                                                  const Graphic3d_ZLayerId theLayerAfter) Standard_OVERRIDE;
+
+  //! Add a layer to the view.
+  //! @param theNewLayerId  [in] id of new layer, should be > 0 (negative values are reserved for default layers).
+  //! @param theSettings    [in] new layer settings
+  //! @param theLayerBefore [in] id of layer to append new layer after
+  Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
+                                                 const Graphic3d_ZLayerSettings& theSettings,
+                                                 const Graphic3d_ZLayerId theLayerBefore) Standard_OVERRIDE;
 
   //! Remove a z layer with the given ID.
   Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
@@ -150,23 +163,18 @@ public:
   //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
   Standard_EXPORT virtual Standard_Integer ZLayerMax() const Standard_OVERRIDE;
 
-  //! Returns the bounding box of all structures displayed in the Z layer.
-  //! Never fails. If Z layer does not exist nothing happens.
-  Standard_EXPORT virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
+  //! Returns the list of layers.
+  Standard_EXPORT virtual const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const Standard_OVERRIDE;
 
-  //! Returns the bounding box of all structures displayed in the Z layer.
-  //! If Z layer does not exist the empty box is returned.
-  //! @param theLayerId            layer identifier
-  //! @param theCamera             camera definition
-  //! @param theWindowWidth        viewport width  (for applying transformation-persistence)
-  //! @param theWindowHeight       viewport height (for applying transformation-persistence)
+  //! Returns layer with given ID or NULL if undefined.
+  Standard_EXPORT virtual Handle(Graphic3d_Layer) Layer (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
+
+  //! Returns the bounding box of all structures displayed in the view.
+  //! If theToIncludeAuxiliary is TRUE, then the boundary box also includes minimum and maximum limits
+  //! of graphical elements forming parts of infinite and other auxiliary structures.
   //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
   //! @return computed bounding box
-  Standard_EXPORT virtual Bnd_Box ZLayerBoundingBox (const Graphic3d_ZLayerId        theLayerId,
-                                                     const Handle(Graphic3d_Camera)& theCamera,
-                                                     const Standard_Integer          theWindowWidth,
-                                                     const Standard_Integer          theWindowHeight,
-                                                     const Standard_Boolean          theToIncludeAuxiliary) const Standard_OVERRIDE;
+  Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const Standard_OVERRIDE;
 
   //! Returns pointer to an assigned framebuffer object.
   Standard_EXPORT virtual Handle(Standard_Transient) FBO() const Standard_OVERRIDE;
@@ -409,12 +417,6 @@ private:
   Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
                                                const Standard_Integer theNewPriority) Standard_OVERRIDE;
 
-  //! Returns zoom-scale factor.
-  Standard_EXPORT virtual Standard_Real considerZoomPersistenceObjects (const Graphic3d_ZLayerId        theLayerId,
-                                                                        const Handle(Graphic3d_Camera)& theCamera,
-                                                                        const Standard_Integer          theWindowWidth,
-                                                                        const Standard_Integer          theWindowHeight) const Standard_OVERRIDE;
-
 private:
 
   //! Copy content of Back buffer to the Front buffer.
index 05b495b..9f900fe 100644 (file)
@@ -107,12 +107,17 @@ Standard_Boolean OpenGl_View::updateRaytraceGeometry (const RaytraceUpdateMode
   // of changes in OpenGL scene (only for path tracing)
   std::set<Standard_Integer> aNonRaytraceIDs;
 
-  const OpenGl_Layer& aLayer = myZLayers.Layer (Graphic3d_ZLayerId_Default);
-
-  if (aLayer.NbStructures() != 0)
+  for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myZLayers.Layers()); aLayerIter.More(); aLayerIter.Next())
   {
-    const Graphic3d_ArrayOfIndexedMapOfStructure& aStructArray = aLayer.ArrayOfStructures();
+    const Handle(OpenGl_Layer)& aLayer = aLayerIter.Value();
+    if (aLayer->NbStructures() == 0
+    || !aLayer->LayerSettings().IsRaytracable()
+    ||  aLayer->LayerSettings().IsImmediate())
+    {
+      continue;
+    }
 
+    const Graphic3d_ArrayOfIndexedMapOfStructure& aStructArray = aLayer->ArrayOfStructures();
     for (Standard_Integer anIndex = 0; anIndex < aStructArray.Length(); ++anIndex)
     {
       for (OpenGl_Structure::StructIterator aStructIt (aStructArray.Value (anIndex)); aStructIt.More(); aStructIt.Next())
index cdf41b6..fa2877a 100644 (file)
@@ -1129,7 +1129,7 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
           }
 
           // Render non-polygonal elements in default layer
-          myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Default, theReadDrawFbo, theOitAccumFbo);
+          myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_RayTracable, theReadDrawFbo, theOitAccumFbo);
         }
         myWorkspace->SetRenderFilter (aPrevFilter);
       }
index 2255815..f6c2e90 100644 (file)
@@ -275,26 +275,37 @@ void V3d_Viewer::DelView (const Handle(V3d_View)& theView)
 }
 
 //=======================================================================
-//function : AddZLayer
+//function : InsertLayerBefore
 //purpose  :
 //=======================================================================
-Standard_Boolean V3d_Viewer::AddZLayer (Graphic3d_ZLayerId& theLayerId)
+Standard_Boolean V3d_Viewer::InsertLayerBefore (Graphic3d_ZLayerId& theNewLayerId,
+                                                const Graphic3d_ZLayerSettings& theSettings,
+                                                const Graphic3d_ZLayerId theLayerAfter)
 {
-  try
+  if (myZLayerGenId.Next (theNewLayerId))
   {
-    OCC_CATCH_SIGNALS
-    theLayerId = myZLayerGenId.Next();
+    myLayerIds.Add (theNewLayerId);
+    myDriver->InsertLayerBefore (theNewLayerId, theSettings, theLayerAfter);
+    return Standard_True;
   }
-  catch (Aspect_IdentDefinitionError const&)
+  return Standard_False;
+}
+
+//=======================================================================
+//function : InsertLayerAfter
+//purpose  :
+//=======================================================================
+Standard_Boolean V3d_Viewer::InsertLayerAfter (Graphic3d_ZLayerId& theNewLayerId,
+                                               const Graphic3d_ZLayerSettings& theSettings,
+                                               const Graphic3d_ZLayerId theLayerBefore)
+{
+  if (myZLayerGenId.Next (theNewLayerId))
   {
-    // new index can't be generated
-    return Standard_False;
+    myLayerIds.Add (theNewLayerId);
+    myDriver->InsertLayerAfter (theNewLayerId, theSettings, theLayerBefore);
+    return Standard_True;
   }
-
-  myLayerIds.Add (theLayerId);
-  myDriver->AddZLayer (theLayerId);
-
-  return Standard_True;
+  return Standard_False;
 }
 
 //=======================================================================
@@ -339,7 +350,7 @@ void V3d_Viewer::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const G
 //function : ZLayerSettings
 //purpose  :
 //=======================================================================
-Graphic3d_ZLayerSettings V3d_Viewer::ZLayerSettings (const Graphic3d_ZLayerId theLayerId)
+const Graphic3d_ZLayerSettings& V3d_Viewer::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
 {
   return myDriver->ZLayerSettings (theLayerId);
 }
index 7413a2a..51e2db1 100644 (file)
@@ -190,9 +190,39 @@ public:
 
   //! Add a new top-level Z layer to all managed views and get its ID as <theLayerId> value.
   //! The Z layers are controlled entirely by viewer, it is not possible to add a layer to a particular view.
-  //! The method returns Standard_False if the layer can not be created.
-  //! The layer mechanism allows to display structures in higher layers in overlay of structures in lower layers.
-  Standard_EXPORT Standard_Boolean AddZLayer (Graphic3d_ZLayerId& theLayerId);
+  //! Custom layers will be inserted before Graphic3d_ZLayerId_Top (e.g. between Graphic3d_ZLayerId_Default and before Graphic3d_ZLayerId_Top).
+  //! @param theLayerId [out] id of created layer
+  //! @param theSettings [in] new layer settings
+  //! @return FALSE if the layer can not be created
+  Standard_Boolean AddZLayer (Graphic3d_ZLayerId& theLayerId,
+                              const Graphic3d_ZLayerSettings& theSettings = Graphic3d_ZLayerSettings())
+  {
+    return InsertLayerBefore (theLayerId, theSettings, Graphic3d_ZLayerId_Top);
+  }
+
+  //! Add a new top-level Z layer to all managed views and get its ID as <theLayerId> value.
+  //! The Z layers are controlled entirely by viewer, it is not possible to add a layer to a particular view.
+  //! Layer rendering order is defined by its position in list (altered by theLayerAfter)
+  //! and IsImmediate() flag (all layers with IsImmediate() flag are drawn afterwards);
+  //! @param theNewLayerId [out] id of created layer; layer id is arbitrary and does not depend on layer position in the list
+  //! @param theSettings    [in] new layer settings
+  //! @param theLayerAfter  [in] id of layer to append new layer before
+  //! @return FALSE if the layer can not be created
+  Standard_EXPORT Standard_Boolean InsertLayerBefore (Graphic3d_ZLayerId& theNewLayerId,
+                                                      const Graphic3d_ZLayerSettings& theSettings,
+                                                      const Graphic3d_ZLayerId theLayerAfter);
+
+  //! Add a new top-level Z layer to all managed views and get its ID as <theLayerId> value.
+  //! The Z layers are controlled entirely by viewer, it is not possible to add a layer to a particular view.
+  //! Layer rendering order is defined by its position in list (altered by theLayerAfter)
+  //! and IsImmediate() flag (all layers with IsImmediate() flag are drawn afterwards);
+  //! @param theNewLayerId [out] id of created layer; layer id is arbitrary and does not depend on layer position in the list
+  //! @param theSettings    [in] new layer settings
+  //! @param theLayerBefore [in] id of layer to append new layer after
+  //! @return FALSE if the layer can not be created
+  Standard_EXPORT Standard_Boolean InsertLayerAfter (Graphic3d_ZLayerId& theNewLayerId,
+                                                     const Graphic3d_ZLayerSettings& theSettings,
+                                                     const Graphic3d_ZLayerId theLayerBefore);
 
   //! Remove Z layer with ID <theLayerId>.
   //! Method returns Standard_False if the layer can not be removed or doesn't exists.
@@ -200,7 +230,7 @@ public:
   Standard_EXPORT Standard_Boolean RemoveZLayer (const Graphic3d_ZLayerId theLayerId);
 
   //! Returns the settings of a single Z layer.
-  Standard_EXPORT Graphic3d_ZLayerSettings ZLayerSettings (const Graphic3d_ZLayerId theLayerId);
+  Standard_EXPORT const Graphic3d_ZLayerSettings& ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const;
 
   //! Sets the settings for a single Z layer.
   Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings);
index 13bdca3..b131a07 100644 (file)
@@ -5322,6 +5322,7 @@ static int VZLayer (Draw_Interpretor& theDI,
     }
   }
 
+  Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN;
   for (; anArgIter < theArgNb; ++anArgIter)
   {
     // perform operation
@@ -5343,6 +5344,34 @@ static int VZLayer (Draw_Interpretor& theDI,
 
       theDI << aLayerId;
     }
+    else if (anArg == "-insertbefore"
+          && anArgIter + 1 < theArgNb
+          && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
+    {
+      ++anArgIter;
+      aLayerId = Graphic3d_ZLayerId_UNKNOWN;
+      if (!aViewer->InsertLayerBefore (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
+      {
+        std::cout << "Error: can not add a new z layer!\n";
+        return 0;
+      }
+
+      theDI << aLayerId;
+    }
+    else if (anArg == "-insertafter"
+          && anArgIter + 1 < theArgNb
+          && ViewerTest::ParseZLayer (theArgVec[anArgIter + 1], anOtherLayerId))
+    {
+      ++anArgIter;
+      aLayerId = Graphic3d_ZLayerId_UNKNOWN;
+      if (!aViewer->InsertLayerAfter (aLayerId, Graphic3d_ZLayerSettings(), anOtherLayerId))
+      {
+        std::cout << "Error: can not add a new z layer!\n";
+        return 0;
+      }
+
+      theDI << aLayerId;
+    }
     else if (anArg == "-del"
           || anArg == "-delete"
           || anArg == "del")
@@ -5584,6 +5613,10 @@ static int VZLayer (Draw_Interpretor& theDI,
       {
         aSettings.SetEnvironmentTexture (toEnable);
       }
+      else if (aSubOp == "raytracing")
+      {
+        aSettings.SetRaytracable (toEnable);
+      }
 
       aViewer->SetZLayerSettings (aLayerId, aSettings);
     }
@@ -13336,12 +13369,14 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     __FILE__, VTile, group);
   theCommands.Add("vzlayer",
               "vzlayer [layerId]"
-      "\n\t\t:         [-add|-delete|-get|-settings]"
+      "\n\t\t:         [-add|-delete|-get|-settings] [-insertBefore AnotherLayer] [-insertAfter AnotherLayer]"
       "\n\t\t:         [-origin X Y Z] [-cullDist Distance] [-cullSize Size]"
       "\n\t\t:         [-enable|-disable {depthTest|depthWrite|depthClear|depthoffset}]"
-      "\n\t\t:         [-enable|-disable {positiveOffset|negativeOffset|textureenv}]"
+      "\n\t\t:         [-enable|-disable {positiveOffset|negativeOffset|textureenv|rayTracing}]"
       "\n\t\t: ZLayer list management:"
       "\n\t\t:   -add      add new z layer to viewer and print its id"
+      "\n\t\t:   -insertBefore add new z layer and insert it before existing one"
+      "\n\t\t:   -insertAfter  add new z layer and insert it after  existing one"
       "\n\t\t:   -delete   delete z layer"
       "\n\t\t:   -get      print sequence of z layers"
       "\n\t\t:   -settings print status of z layer settings"
index 80d16c7..e084ce4 100644 (file)
@@ -28,7 +28,7 @@ vzbufftrihedron
 
 catch { vzlayer del 1 }
 set aLayerId [vzlayer add]
-vzlayer $aLayerId -enable depthClear
+vzlayer $aLayerId -enable depthClear -disable rayTracing
 
 vtrihedron trh
 vdisplay  -noupdate trh -layer $aLayerId -trihedron topRight 100 100