a1954302 |
1 | // Created on: 2011-11-02 |
2 | // Created by: Sergey ZERCHANINOV |
3 | // Copyright (c) 2011-2015 OPEN CASCADE SAS |
c5751993 |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
0a36ca0a |
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 |
c5751993 |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _OpenGl_Layer_Header |
17 | #define _OpenGl_Layer_Header |
18 | |
a1954302 |
19 | #include <NCollection_Sequence.hxx> |
20 | #include <NCollection_Array1.hxx> |
21 | |
a1954302 |
22 | #include <OpenGl_BVHClipPrimitiveSet.hxx> |
825aa485 |
23 | #include <OpenGl_BVHClipPrimitiveTrsfPersSet.hxx> |
a1954302 |
24 | #include <OpenGl_BVHTreeSelector.hxx> |
25 | |
c5751993 |
26 | #include <Graphic3d_ZLayerSettings.hxx> |
825aa485 |
27 | #include <Graphic3d_Camera.hxx> |
550f3b8b |
28 | #include <OpenGl_GlCore11.hxx> |
c5751993 |
29 | |
c5751993 |
30 | |
550f3b8b |
31 | struct OpenGl_GlobalLayerSettings |
32 | { |
33 | GLint DepthFunc; |
34 | GLboolean DepthMask; |
35 | }; |
36 | |
825aa485 |
37 | //! Defines index map of OpenGL structures. |
38 | typedef NCollection_IndexedMap<const OpenGl_Structure*> OpenGl_IndexedMapOfStructure; |
39 | |
40 | //! Defines array of indexed maps of OpenGL structures. |
41 | typedef NCollection_Array1<OpenGl_IndexedMapOfStructure> OpenGl_ArrayOfIndexedMapOfStructure; |
42 | |
a1954302 |
43 | //! Presentations list sorted within priorities. |
c5751993 |
44 | class OpenGl_Layer |
45 | { |
46 | public: |
47 | |
48 | //! Initializes associated priority list and layer properties |
49 | OpenGl_Layer (const Standard_Integer theNbPriorities = 11); |
50 | |
a1954302 |
51 | //! Destructor. |
52 | virtual ~OpenGl_Layer(); |
53 | |
c5751993 |
54 | //! Returns settings of the layer object. |
a1954302 |
55 | const Graphic3d_ZLayerSettings& LayerSettings() const { return myLayerSettings; }; |
c5751993 |
56 | |
57 | //! Sets settings of the layer object. |
a1954302 |
58 | void SetLayerSettings (const Graphic3d_ZLayerSettings& theSettings) |
c5751993 |
59 | { |
60 | myLayerSettings = theSettings; |
61 | } |
62 | |
63 | //! Returns true if theSetting is enabled for the layer. |
487bf1ce |
64 | Standard_Boolean IsSettingEnabled (const Graphic3d_ZLayerSetting theSetting) const |
c5751993 |
65 | { |
66 | return myLayerSettings.IsSettingEnabled (theSetting); |
67 | } |
68 | |
a1954302 |
69 | void Add (const OpenGl_Structure* theStruct, |
70 | const Standard_Integer thePriority, |
71 | Standard_Boolean isForChangePriority = Standard_False); |
72 | |
73 | //! Remove structure and returns its priority, if the structure is not found, method returns negative value |
74 | bool Remove (const OpenGl_Structure* theStruct, |
75 | Standard_Integer& thePriority, |
76 | Standard_Boolean isForChangePriority = Standard_False); |
77 | |
78 | //! @return the number of structures |
79 | Standard_Integer NbStructures() const { return myNbStructures; } |
80 | |
81 | //! Returns the number of available priority levels |
82 | Standard_Integer NbPriorities() const { return myArray.Length(); } |
83 | |
84 | //! Append layer of acceptable type (with similar number of priorities or less). |
85 | //! Returns Standard_False if the list can not be accepted. |
86 | Standard_Boolean Append (const OpenGl_Layer& theOther); |
87 | |
88 | //! Returns array of OpenGL structures. |
9f112210 |
89 | const OpenGl_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; } |
c5751993 |
90 | |
a1954302 |
91 | //! Marks BVH tree for given priority list as dirty and |
92 | //! marks primitive set for rebuild. |
50d06d8f |
93 | void InvalidateBVHData() const; |
94 | |
95 | //! Marks cached bounding box as obsolete. |
96 | void InvalidateBoundingBox() const |
97 | { |
98 | myIsBoundingBoxNeedsReset[0] = myIsBoundingBoxNeedsReset[1] = true; |
99 | } |
100 | |
101 | //! Returns layer bounding box. |
102 | const Graphic3d_BndBox4f& BoundingBox (const Standard_Integer theViewId, |
103 | const Handle(Graphic3d_Camera)& theCamera, |
104 | const Standard_Integer theWindowWidth, |
105 | const Standard_Integer theWindowHeight, |
106 | const Standard_Boolean theToIgnoreInfiniteFlag) const; |
107 | |
108 | //! Returns zoom-scale factor. |
109 | Standard_Real considerZoomPersistenceObjects (const Standard_Integer theViewId, |
110 | const Handle(Graphic3d_Camera)& theCamera, |
111 | const Standard_Integer theWindowWidth, |
112 | const Standard_Integer theWindowHeight, |
113 | const Standard_Boolean theToIgnoreInfiniteFlag) const; |
c5751993 |
114 | |
a1954302 |
115 | // Render all structures. |
116 | void Render (const Handle(OpenGl_Workspace)& theWorkspace, |
117 | const OpenGl_GlobalLayerSettings& theDefaultSettings) const; |
118 | |
50d06d8f |
119 | //! Returns number of transform persistence objects. |
120 | Standard_Integer NbOfTransformPersistenceObjects() const |
121 | { |
122 | return myBVHPrimitivesTrsfPers.Size(); |
123 | } |
124 | |
a1954302 |
125 | protected: |
126 | |
127 | //! Traverses through BVH tree to determine which structures are in view volume. |
128 | void traverse (OpenGl_BVHTreeSelector& theSelector) const; |
129 | |
130 | //! Iterates through the hierarchical list of existing structures and renders them all. |
131 | void renderAll (const Handle(OpenGl_Workspace)& theWorkspace) const; |
132 | |
133 | //! Iterates through the hierarchical list of existing structures and renders only overlapping ones. |
134 | void renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace) const; |
c5751993 |
135 | |
136 | private: |
137 | |
825aa485 |
138 | //! Array of OpenGl_Structures by priority rendered in layer. |
9f112210 |
139 | OpenGl_ArrayOfIndexedMapOfStructure myArray; |
825aa485 |
140 | |
141 | //! Overall number of structures rendered in the layer. |
142 | Standard_Integer myNbStructures; |
143 | |
144 | //! Layer setting flags. |
145 | Graphic3d_ZLayerSettings myLayerSettings; |
146 | |
147 | //! Set of OpenGl_Structures structures for building BVH tree. |
148 | mutable OpenGl_BVHClipPrimitiveSet myBVHPrimitives; |
149 | |
150 | //! Set of transform persistent OpenGl_Structures for building BVH tree. |
151 | mutable OpenGl_BVHClipPrimitiveTrsfPersSet myBVHPrimitivesTrsfPers; |
152 | |
153 | //! Is needed for implementation of stochastic order of BVH traverse. |
154 | mutable Standard_Boolean myBVHIsLeftChildQueuedFirst; |
155 | |
156 | //! Defines if the primitive set for BVH is outdated. |
157 | mutable Standard_Boolean myIsBVHPrimitivesNeedsReset; |
a1954302 |
158 | |
50d06d8f |
159 | //! Defines if the cached bounding box is outdated. |
160 | mutable bool myIsBoundingBoxNeedsReset[2]; |
161 | |
162 | //! Cached layer bounding box. |
163 | mutable Graphic3d_BndBox4f myBoundingBox[2]; |
164 | |
a1954302 |
165 | public: |
166 | |
167 | DEFINE_STANDARD_ALLOC |
c5751993 |
168 | |
c5751993 |
169 | }; |
a1954302 |
170 | |
c5751993 |
171 | #endif //_OpenGl_Layer_Header |