0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / OpenGl / OpenGl_LayerList.hxx
CommitLineData
6aca4d39 1// Created on: 2012-02-02
b311480e 2// Created by: Anton POLETAEV
6aca4d39 3// Copyright (c) 2012-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
59f45b7c 15
5bd54bef 16#ifndef OpenGl_LayerList_HeaderFile
17#define OpenGl_LayerList_HeaderFile
59f45b7c 18
c5751993 19#include <OpenGl_Layer.hxx>
91c60b57 20#include <OpenGl_LayerFilter.hxx>
59f45b7c 21
d325cb7f 22#include <Graphic3d_ZLayerId.hxx>
a1073ae2 23#include <NCollection_Array1.hxx>
24#include <NCollection_Handle.hxx>
59f45b7c 25#include <NCollection_DataMap.hxx>
26
bc73b006 27class OpenGl_FrameBuffer;
59f45b7c 28class OpenGl_Structure;
d325cb7f 29class OpenGl_Workspace;
30struct OpenGl_GlobalLayerSettings;
59f45b7c 31
bd6a8454 32//! Class defining the list of layers.
59f45b7c 33class OpenGl_LayerList
34{
a1954302 35public:
36
59f45b7c 37 //! Constructor
e463b2f6 38 Standard_EXPORT OpenGl_LayerList();
a1954302 39
59f45b7c 40 //! Destructor
b31fbc83 41 Standard_EXPORT virtual ~OpenGl_LayerList();
a1954302 42
59f45b7c 43 //! Method returns the number of available priorities
e463b2f6 44 Standard_Integer NbPriorities() const { return Graphic3d_DisplayPriority_NB; }
59f45b7c 45
46 //! Number of displayed structures
a1954302 47 Standard_Integer NbStructures() const { return myNbStructures; }
48
49 //! Return number of structures within immediate layers
50 Standard_Integer NbImmediateStructures() const { return myImmediateNbStructures; }
59f45b7c 51
52 //! Insert a new layer with id.
b31fbc83 53 Standard_EXPORT void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
54 const Graphic3d_ZLayerSettings& theSettings,
55 const Graphic3d_ZLayerId theLayerAfter);
1c728f2d 56
57 //! Insert a new layer with id.
b31fbc83 58 Standard_EXPORT void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
59 const Graphic3d_ZLayerSettings& theSettings,
60 const Graphic3d_ZLayerId theLayerBefore);
a1954302 61
59f45b7c 62 //! Remove layer by its id.
b31fbc83 63 Standard_EXPORT void RemoveLayer (const Graphic3d_ZLayerId theLayerId);
a1954302 64
59f45b7c 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.
b31fbc83 68 Standard_EXPORT void AddStructure (const OpenGl_Structure* theStruct,
69 const Graphic3d_ZLayerId theLayerId,
e463b2f6 70 const Graphic3d_DisplayPriority thePriority,
b31fbc83 71 Standard_Boolean isForChangePriority = Standard_False);
a1954302 72
59f45b7c 73 //! Remove structure from structure list and return its previous priority
b31fbc83 74 Standard_EXPORT void RemoveStructure (const OpenGl_Structure* theStructure);
a1954302 75
59f45b7c 76 //! Change structure z layer
77 //! If the new layer is not presented, the structure will be displayed
78 //! in default z layer
b31fbc83 79 Standard_EXPORT void ChangeLayer (const OpenGl_Structure* theStructure,
80 const Graphic3d_ZLayerId theOldLayerId,
81 const Graphic3d_ZLayerId theNewLayerId);
c5751993 82
b7cd4ba7 83 //! Changes structure priority within its ZLayer
b31fbc83 84 Standard_EXPORT void ChangePriority (const OpenGl_Structure* theStructure,
85 const Graphic3d_ZLayerId theLayerId,
e463b2f6 86 const Graphic3d_DisplayPriority theNewPriority);
b7cd4ba7 87
c5751993 88 //! Returns reference to the layer with given ID.
1c728f2d 89 OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) { return *myLayerIds.Find (theLayerId); }
c5751993 90
91 //! Returns reference to the layer with given ID.
1c728f2d 92 const OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) const { return *myLayerIds.Find (theLayerId); }
a1954302 93
94 //! Assign new settings to the layer.
b31fbc83 95 Standard_EXPORT void SetLayerSettings (const Graphic3d_ZLayerId theLayerId,
96 const Graphic3d_ZLayerSettings& theSettings);
a1954302 97
2b8832bb 98 //! Update culling state - should be called before rendering.
b31fbc83 99 Standard_EXPORT void UpdateCulling (const Handle(OpenGl_Workspace)& theWorkspace,
100 const Standard_Boolean theToDrawImmediate);
2b8832bb 101
59f45b7c 102 //! Render this element
b31fbc83 103 Standard_EXPORT 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;
e276548b 108
109 //! Returns the set of OpenGL Z-layers.
1c728f2d 110 const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const { return myLayers; }
e276548b 111
50d06d8f 112 //! Returns the map of Z-layer IDs to indexes.
1c728f2d 113 const NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)>& LayerIDs() const { return myLayerIds; }
50d06d8f 114
b7cd4ba7 115 //! Marks BVH tree for given priority list as dirty and
116 //! marks primitive set for rebuild.
b31fbc83 117 Standard_EXPORT void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId);
b7cd4ba7 118
e276548b 119 //! Returns structure modification state (for ray-tracing).
bd6a8454 120 Standard_Size ModificationStateOfRaytracable() const { return myModifStateOfRaytraceable; }
e276548b 121
e463b2f6 122 //! Returns BVH tree builder for frustum culling.
f5b72419 123 const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHBuilder; }
124
e463b2f6 125 //! Assigns BVH tree builder for frustum culling.
b31fbc83 126 Standard_EXPORT void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder);
f5b72419 127
bc73b006 128 //! Dumps the content of me into the stream
129 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
130
a1073ae2 131protected:
132
a1073ae2 133 //! Stack of references to existing layers of predefined maximum size.
134 class OpenGl_LayerStack
135 {
136 public:
1103eb60 137 typedef NCollection_Array1<const Graphic3d_Layer*>::const_iterator const_iterator;
d325cb7f 138 typedef NCollection_Array1<const Graphic3d_Layer*>::iterator iterator;
a1073ae2 139
140 //! Reallocate internal buffer of the stack.
141 void Allocate (Standard_Integer theSize)
142 {
143 if (theSize > 0)
144 {
1c728f2d 145 myStackSpace.Resize (1, theSize, false);
146 myStackSpace.Init (NULL);
147 myBackPtr = myStackSpace.begin();
a1073ae2 148 }
149 else
150 {
1c728f2d 151 NCollection_Array1<const Graphic3d_Layer*> aDummy;
1103eb60 152 myStackSpace.Move (std::move(aDummy));
a1073ae2 153 myBackPtr = iterator();
154 }
155 }
156
157 //! Clear stack.
158 void Clear()
159 {
1c728f2d 160 myStackSpace.Init (NULL);
161 myBackPtr = myStackSpace.begin();
a1073ae2 162 }
163
164 //! Push a new layer reference to the stack.
165 void Push (const OpenGl_Layer* theLayer) { (*myBackPtr++) = theLayer; }
166
167 //! Returns iterator to the origin of the stack.
1103eb60 168 const_iterator Origin() const { return myStackSpace.IsEmpty() ? const_iterator() : myStackSpace.begin(); }
a1073ae2 169
170 //! Returns iterator to the back of the stack (after last item added).
171 iterator Back() const { return myBackPtr; }
172
1103eb60 173 //! Returns iterator to the origin of the stack.
174 iterator Origin() { return myStackSpace.IsEmpty() ? iterator() : myStackSpace.begin(); }
175
a1073ae2 176 //! Returns true if nothing has been pushed into the stack.
177 Standard_Boolean IsEmpty() const { return Back() == Origin(); }
178
179 private:
180
1c728f2d 181 NCollection_Array1<const OpenGl_Layer*> myStackSpace;
182 iterator myBackPtr;
a1073ae2 183 };
184
185 //! Render transparent objects using blending operator.
186 //! Additional accumulation framebuffer is used for blended order-independent
187 //! transparency algorithm. It should support floating-point color components
188 //! and share depth with main reading/drawing framebuffer.
189 //! @param theWorkspace [in] the currently used workspace for rendering.
190 //! @param theLayerIter [in/out] the current iterator of transparent layers to process.
191 //! @param theGlobalSettings [in] the set of global settings used for rendering.
192 //! @param theReadDrawFbo [in] the framebuffer for reading depth and writing final color.
193 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
b31fbc83 194 Standard_EXPORT void renderTransparent (const Handle(OpenGl_Workspace)& theWorkspace,
195 OpenGl_LayerStack::iterator& theLayerIter,
196 const OpenGl_GlobalLayerSettings& theGlobalSettings,
197 OpenGl_FrameBuffer* theReadDrawFbo,
198 OpenGl_FrameBuffer* theOitAccumFbo) const;
a1073ae2 199
d325cb7f 200 // Render structures within specified layer.
b31fbc83 201 Standard_EXPORT void renderLayer (const Handle(OpenGl_Workspace)& theWorkspace,
202 const OpenGl_GlobalLayerSettings& theDefaultSettings,
203 const Graphic3d_Layer& theLayer) const;
d325cb7f 204
a1954302 205protected:
59f45b7c 206
1c728f2d 207 NCollection_List<Handle(Graphic3d_Layer)> myLayers;
208 NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)> myLayerIds;
e463b2f6 209 Handle(Select3D_BVHBuilder3d) myBVHBuilder; //!< BVH tree builder for frustum culling
a1954302 210
59f45b7c 211 Standard_Integer myNbStructures;
a1954302 212 Standard_Integer myImmediateNbStructures; //!< number of structures within immediate layers
59f45b7c 213
bd6a8454 214 mutable Standard_Size myModifStateOfRaytraceable;
e276548b 215
a1073ae2 216 //! Collection of references to layers with transparency gathered during rendering pass.
217 mutable OpenGl_LayerStack myTransparentToProcess;
218
a1954302 219public:
220
65c62757 221 DEFINE_STANDARD_ALLOC
a1954302 222
59f45b7c 223};
224
225#endif //_OpenGl_LayerList_Header