}
}
-// =======================================================================
-// 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 :
}
// =======================================================================
-// 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;
}
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
}
// =======================================================================
-// 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;
}
// 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 :
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 :
// =======================================================================
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;
}
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;
class Graphic3d_CView;
class Graphic3d_GraphicDriver;
+class Graphic3d_Layer;
class Graphic3d_StructureManager;
DEFINE_STANDARD_HANDLE (Graphic3d_CView, Graphic3d_DataStructureManager)
//! 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
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;
#include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_Layer.hxx>
+
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);
}
}
//=======================================================================
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);
}
class Aspect_DisplayConnection;
class Graphic3d_CView;
class Graphic3d_GraphicDriver;
+class Graphic3d_Layer;
class Graphic3d_TransformError;
class Graphic3d_Structure;
class Graphic3d_StructureManager;
//! 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.
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;
//! 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;
};
// 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)
#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>
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(); }
//! Layer setting flags.
Graphic3d_ZLayerSettings myLayerSettings;
+ //! Layer id.
+ Graphic3d_ZLayerId myLayerId;
+
//! Set of Graphic3d_CStructures structures for building BVH tree.
mutable Graphic3d_BvhCStructureSet myBVHPrimitives;
: myCullingDistance (Precision::Infinite()),
myCullingSize (Precision::Infinite()),
myIsImmediate (Standard_False),
+ myToRaytrace (Standard_True),
myUseEnvironmentTexture (Standard_True),
myToEnableDepthTest (Standard_True),
myToEnableDepthWrite(Standard_True),
//! 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; }
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
|| (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();
}
//=======================================================================
-//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);
}
}
//=======================================================================
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);
}
//=======================================================================
}
// =======================================================================
-// 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;
}
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
#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__
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; }
//! Move to the next position.
void Next()
{
- OpenGl_SequenceOfLayers::Iterator::Next();
+ NCollection_List<Handle(Graphic3d_Layer)>::Iterator::Next();
++myIndex;
}
{
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)
{
{
for (; myIter.More(); myIter.Next())
{
- if (myIter.Value()->IsImmediate() != myToDrawImmediate)
+ const Handle(Graphic3d_Layer)& aLayer = myIter.Value();
+ if (aLayer->IsImmediate() != myToDrawImmediate)
{
continue;
}
{
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;
};
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());
+ //
}
//=======================================================================
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());
}
//=======================================================================
{
// 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;
}
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;
}
// 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;
//=======================================================================
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();
}
//=======================================================================
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;
}
}
// 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;
}
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;
}
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;
}
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())
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();
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)
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
{
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);
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,
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.
{
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();
}
}
//! 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; }
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.
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;
}
//=======================================================================
-//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);
}
//=======================================================================
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()));
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 :
//! 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;
//! 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;
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.
// 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())
}
// 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);
}
}
//=======================================================================
-//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;
}
//=======================================================================
//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);
}
//! 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.
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);
}
}
+ Graphic3d_ZLayerId anOtherLayerId = Graphic3d_ZLayerId_UNKNOWN;
for (; anArgIter < theArgNb; ++anArgIter)
{
// perform operation
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")
{
aSettings.SetEnvironmentTexture (toEnable);
}
+ else if (aSubOp == "raytracing")
+ {
+ aSettings.SetRaytracable (toEnable);
+ }
aViewer->SetZLayerSettings (aLayerId, aSettings);
}
__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"
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