1 // Created on: 2012-02-02
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_LayerList_Header
17 #define _OpenGl_LayerList_Header
19 #include <OpenGl_Layer.hxx>
20 #include <OpenGl_LayerFilter.hxx>
22 #include <Graphic3d_ZLayerId.hxx>
23 #include <NCollection_Array1.hxx>
24 #include <NCollection_Handle.hxx>
25 #include <NCollection_Sequence.hxx>
26 #include <NCollection_DataMap.hxx>
28 class OpenGl_Structure;
29 class OpenGl_Workspace;
30 struct OpenGl_GlobalLayerSettings;
32 //! Class defining the list of layers.
33 class OpenGl_LayerList
38 OpenGl_LayerList (const Standard_Integer theNbPriorities);
41 virtual ~OpenGl_LayerList();
43 //! Method returns the number of available priorities
44 Standard_Integer NbPriorities() const { return myNbPriorities; }
46 //! Number of displayed structures
47 Standard_Integer NbStructures() const { return myNbStructures; }
49 //! Return number of structures within immediate layers
50 Standard_Integer NbImmediateStructures() const { return myImmediateNbStructures; }
52 //! Insert a new layer with id.
53 void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
54 const Graphic3d_ZLayerSettings& theSettings,
55 const Graphic3d_ZLayerId theLayerAfter);
57 //! Insert a new layer with id.
58 void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
59 const Graphic3d_ZLayerSettings& theSettings,
60 const Graphic3d_ZLayerId theLayerBefore);
62 //! Remove layer by its id.
63 void RemoveLayer (const Graphic3d_ZLayerId theLayerId);
65 //! Add structure to list with given priority. The structure will be inserted
66 //! to specified layer. If the layer isn't found, the structure will be put
67 //! to default bottom-level layer.
68 void AddStructure (const OpenGl_Structure* theStruct,
69 const Graphic3d_ZLayerId theLayerId,
70 const Standard_Integer thePriority,
71 Standard_Boolean isForChangePriority = Standard_False);
73 //! Remove structure from structure list and return its previous priority
74 void RemoveStructure (const OpenGl_Structure* theStructure);
76 //! Change structure z layer
77 //! If the new layer is not presented, the structure will be displayed
78 //! in default z layer
79 void ChangeLayer (const OpenGl_Structure* theStructure,
80 const Graphic3d_ZLayerId theOldLayerId,
81 const Graphic3d_ZLayerId theNewLayerId);
83 //! Changes structure priority within its ZLayer
84 void ChangePriority (const OpenGl_Structure* theStructure,
85 const Graphic3d_ZLayerId theLayerId,
86 const Standard_Integer theNewPriority);
88 //! Returns reference to the layer with given ID.
89 OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) { return *myLayerIds.Find (theLayerId); }
91 //! Returns reference to the layer with given ID.
92 const OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) const { return *myLayerIds.Find (theLayerId); }
94 //! Assign new settings to the layer.
95 void SetLayerSettings (const Graphic3d_ZLayerId theLayerId,
96 const Graphic3d_ZLayerSettings& theSettings);
98 //! Update culling state - should be called before rendering.
99 void UpdateCulling (const Handle(OpenGl_Workspace)& theWorkspace,
100 const Standard_Boolean theToDrawImmediate);
102 //! Render this element
103 void Render (const Handle(OpenGl_Workspace)& theWorkspace,
104 const Standard_Boolean theToDrawImmediate,
105 const OpenGl_LayerFilter theLayersToProcess,
106 OpenGl_FrameBuffer* theReadDrawFbo,
107 OpenGl_FrameBuffer* theOitAccumFbo) const;
109 //! Returns the set of OpenGL Z-layers.
110 const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const { return myLayers; }
112 //! Returns the map of Z-layer IDs to indexes.
113 const NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)>& LayerIDs() const { return myLayerIds; }
115 //! Marks BVH tree for given priority list as dirty and
116 //! marks primitive set for rebuild.
117 void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId);
119 //! Returns structure modification state (for ray-tracing).
120 Standard_Size ModificationStateOfRaytracable() const { return myModifStateOfRaytraceable; }
122 //! Returns BVH tree builder for frustom culling.
123 const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHBuilder; }
125 //! Assigns BVH tree builder for frustom culling.
126 void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder);
130 //! Stack of references to existing layers of predefined maximum size.
131 class OpenGl_LayerStack
134 typedef NCollection_Array1<const Graphic3d_Layer*>::iterator iterator;
136 //! Reallocate internal buffer of the stack.
137 void Allocate (Standard_Integer theSize)
141 myStackSpace.Resize (1, theSize, false);
142 myStackSpace.Init (NULL);
143 myBackPtr = myStackSpace.begin();
147 NCollection_Array1<const Graphic3d_Layer*> aDummy;
148 myStackSpace.Move (aDummy);
149 myBackPtr = iterator();
156 myStackSpace.Init (NULL);
157 myBackPtr = myStackSpace.begin();
160 //! Push a new layer reference to the stack.
161 void Push (const OpenGl_Layer* theLayer) { (*myBackPtr++) = theLayer; }
163 //! Returns iterator to the origin of the stack.
164 iterator Origin() const { return myStackSpace.IsEmpty() ? iterator() : myStackSpace.begin(); }
166 //! Returns iterator to the back of the stack (after last item added).
167 iterator Back() const { return myBackPtr; }
169 //! Returns true if nothing has been pushed into the stack.
170 Standard_Boolean IsEmpty() const { return Back() == Origin(); }
174 NCollection_Array1<const OpenGl_Layer*> myStackSpace;
178 //! Render transparent objects using blending operator.
179 //! Additional accumulation framebuffer is used for blended order-independent
180 //! transparency algorithm. It should support floating-point color components
181 //! and share depth with main reading/drawing framebuffer.
182 //! @param theWorkspace [in] the currently used workspace for rendering.
183 //! @param theLayerIter [in/out] the current iterator of transparent layers to process.
184 //! @param theGlobalSettings [in] the set of global settings used for rendering.
185 //! @param theReadDrawFbo [in] the framebuffer for reading depth and writing final color.
186 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
187 void renderTransparent (const Handle(OpenGl_Workspace)& theWorkspace,
188 OpenGl_LayerStack::iterator& theLayerIter,
189 const OpenGl_GlobalLayerSettings& theGlobalSettings,
190 OpenGl_FrameBuffer* theReadDrawFbo,
191 OpenGl_FrameBuffer* theOitAccumFbo) const;
193 // Render structures within specified layer.
194 void renderLayer (const Handle(OpenGl_Workspace)& theWorkspace,
195 const OpenGl_GlobalLayerSettings& theDefaultSettings,
196 const Graphic3d_Layer& theLayer) const;
200 NCollection_List<Handle(Graphic3d_Layer)> myLayers;
201 NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)> myLayerIds;
202 Handle(Select3D_BVHBuilder3d) myBVHBuilder; //!< BVH tree builder for frustom culling
204 Standard_Integer myNbPriorities;
205 Standard_Integer myNbStructures;
206 Standard_Integer myImmediateNbStructures; //!< number of structures within immediate layers
208 mutable Standard_Size myModifStateOfRaytraceable;
210 //! Collection of references to layers with transparency gathered during rendering pass.
211 mutable OpenGl_LayerStack myTransparentToProcess;
215 DEFINE_STANDARD_ALLOC
219 #endif //_OpenGl_LayerList_Header