0031172: Unexpected result of BRepTools::OuterWire()
[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
16#ifndef _OpenGl_LayerList_Header
17#define _OpenGl_LayerList_Header
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_Sequence.hxx>
26#include <NCollection_DataMap.hxx>
27
bc73b006 28class OpenGl_FrameBuffer;
59f45b7c 29class OpenGl_Structure;
d325cb7f 30class OpenGl_Workspace;
31struct OpenGl_GlobalLayerSettings;
59f45b7c 32
bd6a8454 33//! Class defining the list of layers.
59f45b7c 34class OpenGl_LayerList
35{
a1954302 36public:
37
59f45b7c 38 //! Constructor
b31fbc83 39 Standard_EXPORT OpenGl_LayerList (const Standard_Integer theNbPriorities);
a1954302 40
59f45b7c 41 //! Destructor
b31fbc83 42 Standard_EXPORT virtual ~OpenGl_LayerList();
a1954302 43
59f45b7c 44 //! Method returns the number of available priorities
a1954302 45 Standard_Integer NbPriorities() const { return myNbPriorities; }
59f45b7c 46
47 //! Number of displayed structures
a1954302 48 Standard_Integer NbStructures() const { return myNbStructures; }
49
50 //! Return number of structures within immediate layers
51 Standard_Integer NbImmediateStructures() const { return myImmediateNbStructures; }
59f45b7c 52
53 //! Insert a new layer with id.
b31fbc83 54 Standard_EXPORT void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
55 const Graphic3d_ZLayerSettings& theSettings,
56 const Graphic3d_ZLayerId theLayerAfter);
1c728f2d 57
58 //! Insert a new layer with id.
b31fbc83 59 Standard_EXPORT void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
60 const Graphic3d_ZLayerSettings& theSettings,
61 const Graphic3d_ZLayerId theLayerBefore);
a1954302 62
59f45b7c 63 //! Remove layer by its id.
b31fbc83 64 Standard_EXPORT void RemoveLayer (const Graphic3d_ZLayerId theLayerId);
a1954302 65
59f45b7c 66 //! Add structure to list with given priority. The structure will be inserted
67 //! to specified layer. If the layer isn't found, the structure will be put
68 //! to default bottom-level layer.
b31fbc83 69 Standard_EXPORT void AddStructure (const OpenGl_Structure* theStruct,
70 const Graphic3d_ZLayerId theLayerId,
71 const Standard_Integer thePriority,
72 Standard_Boolean isForChangePriority = Standard_False);
a1954302 73
59f45b7c 74 //! Remove structure from structure list and return its previous priority
b31fbc83 75 Standard_EXPORT void RemoveStructure (const OpenGl_Structure* theStructure);
a1954302 76
59f45b7c 77 //! Change structure z layer
78 //! If the new layer is not presented, the structure will be displayed
79 //! in default z layer
b31fbc83 80 Standard_EXPORT void ChangeLayer (const OpenGl_Structure* theStructure,
81 const Graphic3d_ZLayerId theOldLayerId,
82 const Graphic3d_ZLayerId theNewLayerId);
c5751993 83
b7cd4ba7 84 //! Changes structure priority within its ZLayer
b31fbc83 85 Standard_EXPORT void ChangePriority (const OpenGl_Structure* theStructure,
86 const Graphic3d_ZLayerId theLayerId,
87 const Standard_Integer theNewPriority);
b7cd4ba7 88
c5751993 89 //! Returns reference to the layer with given ID.
1c728f2d 90 OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) { return *myLayerIds.Find (theLayerId); }
c5751993 91
92 //! Returns reference to the layer with given ID.
1c728f2d 93 const OpenGl_Layer& Layer (const Graphic3d_ZLayerId theLayerId) const { return *myLayerIds.Find (theLayerId); }
a1954302 94
95 //! Assign new settings to the layer.
b31fbc83 96 Standard_EXPORT void SetLayerSettings (const Graphic3d_ZLayerId theLayerId,
97 const Graphic3d_ZLayerSettings& theSettings);
a1954302 98
2b8832bb 99 //! Update culling state - should be called before rendering.
b31fbc83 100 Standard_EXPORT void UpdateCulling (const Handle(OpenGl_Workspace)& theWorkspace,
101 const Standard_Boolean theToDrawImmediate);
2b8832bb 102
59f45b7c 103 //! Render this element
b31fbc83 104 Standard_EXPORT void Render (const Handle(OpenGl_Workspace)& theWorkspace,
105 const Standard_Boolean theToDrawImmediate,
106 const OpenGl_LayerFilter theLayersToProcess,
107 OpenGl_FrameBuffer* theReadDrawFbo,
108 OpenGl_FrameBuffer* theOitAccumFbo) const;
e276548b 109
110 //! Returns the set of OpenGL Z-layers.
1c728f2d 111 const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const { return myLayers; }
e276548b 112
50d06d8f 113 //! Returns the map of Z-layer IDs to indexes.
1c728f2d 114 const NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)>& LayerIDs() const { return myLayerIds; }
50d06d8f 115
b7cd4ba7 116 //! Marks BVH tree for given priority list as dirty and
117 //! marks primitive set for rebuild.
b31fbc83 118 Standard_EXPORT void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId);
b7cd4ba7 119
e276548b 120 //! Returns structure modification state (for ray-tracing).
bd6a8454 121 Standard_Size ModificationStateOfRaytracable() const { return myModifStateOfRaytraceable; }
e276548b 122
f5b72419 123 //! Returns BVH tree builder for frustom culling.
124 const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHBuilder; }
125
126 //! Assigns BVH tree builder for frustom culling.
b31fbc83 127 Standard_EXPORT void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder);
f5b72419 128
bc73b006 129 //! Dumps the content of me into the stream
130 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
131
a1954302 132protected:
59f45b7c 133
a1073ae2 134 //! Stack of references to existing layers of predefined maximum size.
135 class OpenGl_LayerStack
136 {
137 public:
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;
152 myStackSpace.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.
1c728f2d 168 iterator Origin() const { return myStackSpace.IsEmpty() ? 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
173 //! Returns true if nothing has been pushed into the stack.
174 Standard_Boolean IsEmpty() const { return Back() == Origin(); }
175
176 private:
177
1c728f2d 178 NCollection_Array1<const OpenGl_Layer*> myStackSpace;
179 iterator myBackPtr;
a1073ae2 180 };
181
182 //! Render transparent objects using blending operator.
183 //! Additional accumulation framebuffer is used for blended order-independent
184 //! transparency algorithm. It should support floating-point color components
185 //! and share depth with main reading/drawing framebuffer.
186 //! @param theWorkspace [in] the currently used workspace for rendering.
187 //! @param theLayerIter [in/out] the current iterator of transparent layers to process.
188 //! @param theGlobalSettings [in] the set of global settings used for rendering.
189 //! @param theReadDrawFbo [in] the framebuffer for reading depth and writing final color.
190 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
b31fbc83 191 Standard_EXPORT void renderTransparent (const Handle(OpenGl_Workspace)& theWorkspace,
192 OpenGl_LayerStack::iterator& theLayerIter,
193 const OpenGl_GlobalLayerSettings& theGlobalSettings,
194 OpenGl_FrameBuffer* theReadDrawFbo,
195 OpenGl_FrameBuffer* theOitAccumFbo) const;
a1073ae2 196
d325cb7f 197 // Render structures within specified layer.
b31fbc83 198 Standard_EXPORT void renderLayer (const Handle(OpenGl_Workspace)& theWorkspace,
199 const OpenGl_GlobalLayerSettings& theDefaultSettings,
200 const Graphic3d_Layer& theLayer) const;
d325cb7f 201
a1073ae2 202protected:
203
1c728f2d 204 NCollection_List<Handle(Graphic3d_Layer)> myLayers;
205 NCollection_DataMap<Graphic3d_ZLayerId, Handle(Graphic3d_Layer)> myLayerIds;
f5b72419 206 Handle(Select3D_BVHBuilder3d) myBVHBuilder; //!< BVH tree builder for frustom culling
a1954302 207
59f45b7c 208 Standard_Integer myNbPriorities;
209 Standard_Integer myNbStructures;
a1954302 210 Standard_Integer myImmediateNbStructures; //!< number of structures within immediate layers
59f45b7c 211
bd6a8454 212 mutable Standard_Size myModifStateOfRaytraceable;
e276548b 213
a1073ae2 214 //! Collection of references to layers with transparency gathered during rendering pass.
215 mutable OpenGl_LayerStack myTransparentToProcess;
216
a1954302 217public:
218
65c62757 219 DEFINE_STANDARD_ALLOC
a1954302 220
59f45b7c 221};
222
223#endif //_OpenGl_LayerList_Header