c5751993 |
1 | // Copyright (c) 2014 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
0a36ca0a |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
c5751993 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _Graphic3d_ZLayerSettings_HeaderFile |
15 | #define _Graphic3d_ZLayerSettings_HeaderFile |
16 | |
7c3ef2f7 |
17 | #include <gp_XYZ.hxx> |
18 | #include <Geom_Transformation.hxx> |
992ed6b3 |
19 | #include <Graphic3d_LightSet.hxx> |
7c3ef2f7 |
20 | #include <Graphic3d_PolygonOffset.hxx> |
d325cb7f |
21 | #include <Precision.hxx> |
7c3ef2f7 |
22 | #include <TCollection_AsciiString.hxx> |
c5751993 |
23 | |
24 | enum Graphic3d_ZLayerSetting |
25 | { |
26 | Graphic3d_ZLayerDepthTest = 1, |
27 | Graphic3d_ZLayerDepthWrite = 2, |
28 | Graphic3d_ZLayerDepthClear = 4, |
29 | Graphic3d_ZLayerDepthOffset = 8 |
30 | }; |
31 | |
a1954302 |
32 | //! Structure defines list of ZLayer properties. |
c5751993 |
33 | struct Graphic3d_ZLayerSettings |
34 | { |
a1954302 |
35 | |
36 | //! Default settings. |
c5751993 |
37 | Graphic3d_ZLayerSettings() |
4ecf34cc |
38 | : myCullingDistance (Precision::Infinite()), |
39 | myCullingSize (Precision::Infinite()), |
40 | myIsImmediate (Standard_False), |
1c728f2d |
41 | myToRaytrace (Standard_True), |
7c3ef2f7 |
42 | myUseEnvironmentTexture (Standard_True), |
43 | myToEnableDepthTest (Standard_True), |
44 | myToEnableDepthWrite(Standard_True), |
f88457e6 |
45 | myToClearDepth (Standard_True), |
46 | myToRenderInDepthPrepass (Standard_True) {} |
7c3ef2f7 |
47 | |
48 | //! Return user-provided name. |
49 | const TCollection_AsciiString& Name() const { return myName; } |
50 | |
51 | //! Set custom name. |
52 | void SetName (const TCollection_AsciiString& theName) { myName = theName; } |
53 | |
992ed6b3 |
54 | //! Return lights list to be used for rendering presentations within this Z-Layer; NULL by default. |
55 | //! NULL list (but not empty list!) means that default lights assigned to the View should be used instead of per-layer lights. |
56 | const Handle(Graphic3d_LightSet)& Lights() const { return myLights; } |
57 | |
58 | //! Assign lights list to be used. |
59 | void SetLights (const Handle(Graphic3d_LightSet)& theLights) { myLights = theLights; } |
60 | |
7c3ef2f7 |
61 | //! Return the origin of all objects within the layer. |
62 | const gp_XYZ& Origin() const { return myOrigin; } |
63 | |
64 | //! Return the transformation to the origin. |
65 | const Handle(Geom_Transformation)& OriginTransformation() const { return myOriginTrsf; } |
66 | |
67 | //! Set the origin of all objects within the layer. |
68 | void SetOrigin (const gp_XYZ& theOrigin) |
69 | { |
70 | myOrigin = theOrigin; |
71 | myOriginTrsf.Nullify(); |
72 | if (!theOrigin.IsEqual (gp_XYZ(0.0, 0.0, 0.0), gp::Resolution())) |
73 | { |
74 | myOriginTrsf = new Geom_Transformation(); |
130bc3c0 |
75 | myOriginTrsf->SetTranslation (theOrigin); |
7c3ef2f7 |
76 | } |
77 | } |
78 | |
4ecf34cc |
79 | //! Return TRUE, if culling of distant objects (distance culling) should be performed; FALSE by default. |
80 | //! @sa CullingDistance() |
81 | Standard_Boolean HasCullingDistance() const { return !Precision::IsInfinite (myCullingDistance) && myCullingDistance > 0.0; } |
82 | |
83 | //! Return the distance to discard drawing of distant objects (distance from camera Eye point); by default it is Infinite (distance culling is disabled). |
84 | //! Since camera eye definition has no strong meaning within orthographic projection, option is considered only within perspective projection. |
85 | //! Note also that this option has effect only when frustum culling is enabled. |
86 | Standard_Real CullingDistance() const { return myCullingDistance; } |
87 | |
88 | //! Set the distance to discard drawing objects. |
89 | void SetCullingDistance (Standard_Real theDistance) { myCullingDistance = theDistance; } |
90 | |
91 | //! Return TRUE, if culling of small objects (size culling) should be performed; FALSE by default. |
92 | //! @sa CullingSize() |
93 | Standard_Boolean HasCullingSize() const { return !Precision::IsInfinite (myCullingSize) && myCullingSize > 0.0; } |
94 | |
95 | //! Return the size to discard drawing of small objects; by default it is Infinite (size culling is disabled). |
96 | //! Current implementation checks the length of projected diagonal of bounding box in pixels for discarding. |
97 | //! Note that this option has effect only when frustum culling is enabled. |
98 | Standard_Real CullingSize() const { return myCullingSize; } |
99 | |
100 | //! Set the distance to discard drawing objects. |
101 | void SetCullingSize (Standard_Real theSize) { myCullingSize = theSize; } |
102 | |
7c3ef2f7 |
103 | //! Return true if this layer should be drawn after all normal (non-immediate) layers. |
104 | Standard_Boolean IsImmediate() const { return myIsImmediate; } |
105 | |
106 | //! Set the flag indicating the immediate layer, which should be drawn after all normal (non-immediate) layers. |
107 | void SetImmediate (const Standard_Boolean theValue) { myIsImmediate = theValue; } |
108 | |
1c728f2d |
109 | //! Returns TRUE if layer should be processed by ray-tracing renderer; TRUE by default. |
110 | //! Note that this flag is IGNORED for layers with IsImmediate() flag. |
111 | Standard_Boolean IsRaytracable() const { return myToRaytrace; } |
112 | |
113 | //! Sets if layer should be processed by ray-tracing renderer. |
114 | void SetRaytracable (Standard_Boolean theToRaytrace) { myToRaytrace = theToRaytrace; } |
115 | |
7c3ef2f7 |
116 | //! Return flag to allow/prevent environment texture mapping usage for specific layer. |
117 | Standard_Boolean UseEnvironmentTexture() const { return myUseEnvironmentTexture; } |
118 | |
119 | //! Set the flag to allow/prevent environment texture mapping usage for specific layer. |
120 | void SetEnvironmentTexture (const Standard_Boolean theValue) { myUseEnvironmentTexture = theValue; } |
121 | |
122 | //! Return true if depth test should be enabled. |
123 | Standard_Boolean ToEnableDepthTest() const { return myToEnableDepthTest; } |
124 | |
125 | //! Set if depth test should be enabled. |
126 | void SetEnableDepthTest(const Standard_Boolean theValue) { myToEnableDepthTest = theValue; } |
127 | |
128 | //! Return true depth values should be written during rendering. |
129 | Standard_Boolean ToEnableDepthWrite() const { return myToEnableDepthWrite; } |
130 | |
131 | //! Set if depth values should be written during rendering. |
132 | void SetEnableDepthWrite (const Standard_Boolean theValue) { myToEnableDepthWrite = theValue; } |
133 | |
134 | //! Return true if depth values should be cleared before drawing the layer. |
135 | Standard_Boolean ToClearDepth() const { return myToClearDepth; } |
136 | |
137 | //! Set if depth values should be cleared before drawing the layer. |
138 | void SetClearDepth (const Standard_Boolean theValue) { myToClearDepth = theValue; } |
139 | |
f88457e6 |
140 | //! Return TRUE if layer should be rendered within depth pre-pass; TRUE by default. |
141 | Standard_Boolean ToRenderInDepthPrepass() const { return myToRenderInDepthPrepass; } |
142 | |
143 | //! Set if layer should be rendered within depth pre-pass. |
144 | void SetRenderInDepthPrepass (Standard_Boolean theToRender) { myToRenderInDepthPrepass = theToRender; } |
145 | |
7c3ef2f7 |
146 | //! Return glPolygonOffset() arguments. |
147 | const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; } |
148 | |
149 | //! Setup glPolygonOffset() arguments. |
150 | void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams) { myPolygonOffset = theParams; } |
151 | |
152 | //! Modify glPolygonOffset() arguments. |
153 | Graphic3d_PolygonOffset& ChangePolygonOffset() { return myPolygonOffset; } |
c5751993 |
154 | |
155 | //! Returns true if theSetting is enabled. |
7c3ef2f7 |
156 | Standard_DEPRECATED("Deprecated method IsSettingEnabled() should be replaced by individual property getters") |
487bf1ce |
157 | Standard_Boolean IsSettingEnabled (const Graphic3d_ZLayerSetting theSetting) const |
c5751993 |
158 | { |
7c3ef2f7 |
159 | switch (theSetting) |
160 | { |
161 | case Graphic3d_ZLayerDepthTest: return myToEnableDepthTest; |
162 | case Graphic3d_ZLayerDepthWrite: return myToEnableDepthWrite; |
163 | case Graphic3d_ZLayerDepthClear: return myToClearDepth; |
164 | case Graphic3d_ZLayerDepthOffset: return myPolygonOffset.Mode != Aspect_POM_Off; |
165 | } |
166 | return Standard_False; |
c5751993 |
167 | } |
168 | |
169 | //! Enables theSetting |
7c3ef2f7 |
170 | Standard_DEPRECATED("Deprecated method EnableSetting() should be replaced by individual property getters") |
c5751993 |
171 | void EnableSetting (const Graphic3d_ZLayerSetting theSetting) |
172 | { |
7c3ef2f7 |
173 | switch (theSetting) |
174 | { |
175 | case Graphic3d_ZLayerDepthTest: myToEnableDepthTest = Standard_True; return; |
176 | case Graphic3d_ZLayerDepthWrite: myToEnableDepthWrite = Standard_True; return; |
177 | case Graphic3d_ZLayerDepthClear: myToClearDepth = Standard_True; return; |
178 | case Graphic3d_ZLayerDepthOffset: myPolygonOffset.Mode = Aspect_POM_Fill; return; |
179 | } |
c5751993 |
180 | } |
181 | |
182 | //! Disables theSetting |
7c3ef2f7 |
183 | Standard_DEPRECATED("Deprecated method DisableSetting() should be replaced by individual property getters") |
c5751993 |
184 | void DisableSetting (const Graphic3d_ZLayerSetting theSetting) |
185 | { |
7c3ef2f7 |
186 | switch (theSetting) |
187 | { |
188 | case Graphic3d_ZLayerDepthTest: myToEnableDepthTest = Standard_False; return; |
189 | case Graphic3d_ZLayerDepthWrite: myToEnableDepthWrite = Standard_False; return; |
190 | case Graphic3d_ZLayerDepthClear: myToClearDepth = Standard_False; return; |
191 | case Graphic3d_ZLayerDepthOffset: myPolygonOffset.Mode = Aspect_POM_Off; return; |
192 | } |
c5751993 |
193 | } |
194 | |
195 | //! Sets minimal possible positive depth offset. |
c5751993 |
196 | void SetDepthOffsetPositive() |
197 | { |
7c3ef2f7 |
198 | myPolygonOffset.Mode = Aspect_POM_Fill; |
199 | myPolygonOffset.Factor = 1.0f; |
200 | myPolygonOffset.Units = 1.0f; |
c5751993 |
201 | } |
202 | |
203 | //! Sets minimal possible negative depth offset. |
c5751993 |
204 | void SetDepthOffsetNegative() |
205 | { |
7c3ef2f7 |
206 | myPolygonOffset.Mode = Aspect_POM_Fill; |
207 | myPolygonOffset.Factor = 1.0f; |
208 | myPolygonOffset.Units =-1.0f; |
c5751993 |
209 | } |
210 | |
7c3ef2f7 |
211 | protected: |
a1954302 |
212 | |
7c3ef2f7 |
213 | TCollection_AsciiString myName; //!< user-provided name |
992ed6b3 |
214 | Handle(Graphic3d_LightSet) myLights; //!< lights list |
7c3ef2f7 |
215 | Handle(Geom_Transformation) myOriginTrsf; //!< transformation to the origin |
216 | gp_XYZ myOrigin; //!< the origin of all objects within the layer |
4ecf34cc |
217 | Standard_Real myCullingDistance; //!< distance to discard objects |
218 | Standard_Real myCullingSize; //!< size to discard objects |
7c3ef2f7 |
219 | Graphic3d_PolygonOffset myPolygonOffset; //!< glPolygonOffset() arguments |
220 | Standard_Boolean myIsImmediate; //!< immediate layer will be drawn after all normal layers |
1c728f2d |
221 | Standard_Boolean myToRaytrace; //!< option to render layer within ray-tracing engine |
7c3ef2f7 |
222 | Standard_Boolean myUseEnvironmentTexture; //!< flag to allow/prevent environment texture mapping usage for specific layer |
223 | Standard_Boolean myToEnableDepthTest; //!< option to enable depth test |
224 | Standard_Boolean myToEnableDepthWrite; //!< option to enable write depth values |
225 | Standard_Boolean myToClearDepth; //!< option to clear depth values before drawing the layer |
f88457e6 |
226 | Standard_Boolean myToRenderInDepthPrepass;//!< option to render layer within depth pre-pass |
c5751993 |
227 | |
c5751993 |
228 | }; |
229 | |
230 | #endif // _Graphic3d_ZLayerSettings_HeaderFile |