1 // Copyright (c) 2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Graphic3d_ZLayerSettings_HeaderFile
15 #define _Graphic3d_ZLayerSettings_HeaderFile
18 #include <Geom_Transformation.hxx>
19 #include <Graphic3d_LightSet.hxx>
20 #include <Graphic3d_PolygonOffset.hxx>
21 #include <TCollection_AsciiString.hxx>
23 enum Graphic3d_ZLayerSetting
25 Graphic3d_ZLayerDepthTest = 1,
26 Graphic3d_ZLayerDepthWrite = 2,
27 Graphic3d_ZLayerDepthClear = 4,
28 Graphic3d_ZLayerDepthOffset = 8
31 //! Structure defines list of ZLayer properties.
32 struct Graphic3d_ZLayerSettings
36 Graphic3d_ZLayerSettings()
37 : myCullingDistance (Precision::Infinite()),
38 myCullingSize (Precision::Infinite()),
39 myIsImmediate (Standard_False),
40 myUseEnvironmentTexture (Standard_True),
41 myToEnableDepthTest (Standard_True),
42 myToEnableDepthWrite(Standard_True),
43 myToClearDepth (Standard_True),
44 myToRenderInDepthPrepass (Standard_True) {}
46 //! Return user-provided name.
47 const TCollection_AsciiString& Name() const { return myName; }
50 void SetName (const TCollection_AsciiString& theName) { myName = theName; }
52 //! Return lights list to be used for rendering presentations within this Z-Layer; NULL by default.
53 //! NULL list (but not empty list!) means that default lights assigned to the View should be used instead of per-layer lights.
54 const Handle(Graphic3d_LightSet)& Lights() const { return myLights; }
56 //! Assign lights list to be used.
57 void SetLights (const Handle(Graphic3d_LightSet)& theLights) { myLights = theLights; }
59 //! Return the origin of all objects within the layer.
60 const gp_XYZ& Origin() const { return myOrigin; }
62 //! Return the transformation to the origin.
63 const Handle(Geom_Transformation)& OriginTransformation() const { return myOriginTrsf; }
65 //! Set the origin of all objects within the layer.
66 void SetOrigin (const gp_XYZ& theOrigin)
69 myOriginTrsf.Nullify();
70 if (!theOrigin.IsEqual (gp_XYZ(0.0, 0.0, 0.0), gp::Resolution()))
72 myOriginTrsf = new Geom_Transformation();
76 //! Return TRUE, if culling of distant objects (distance culling) should be performed; FALSE by default.
77 //! @sa CullingDistance()
78 Standard_Boolean HasCullingDistance() const { return !Precision::IsInfinite (myCullingDistance) && myCullingDistance > 0.0; }
80 //! Return the distance to discard drawing of distant objects (distance from camera Eye point); by default it is Infinite (distance culling is disabled).
81 //! Since camera eye definition has no strong meaning within orthographic projection, option is considered only within perspective projection.
82 //! Note also that this option has effect only when frustum culling is enabled.
83 Standard_Real CullingDistance() const { return myCullingDistance; }
85 //! Set the distance to discard drawing objects.
86 void SetCullingDistance (Standard_Real theDistance) { myCullingDistance = theDistance; }
88 //! Return TRUE, if culling of small objects (size culling) should be performed; FALSE by default.
90 Standard_Boolean HasCullingSize() const { return !Precision::IsInfinite (myCullingSize) && myCullingSize > 0.0; }
92 //! Return the size to discard drawing of small objects; by default it is Infinite (size culling is disabled).
93 //! Current implementation checks the length of projected diagonal of bounding box in pixels for discarding.
94 //! Note that this option has effect only when frustum culling is enabled.
95 Standard_Real CullingSize() const { return myCullingSize; }
97 //! Set the distance to discard drawing objects.
98 void SetCullingSize (Standard_Real theSize) { myCullingSize = theSize; }
100 //! Return true if this layer should be drawn after all normal (non-immediate) layers.
101 Standard_Boolean IsImmediate() const { return myIsImmediate; }
103 //! Set the flag indicating the immediate layer, which should be drawn after all normal (non-immediate) layers.
104 void SetImmediate (const Standard_Boolean theValue) { myIsImmediate = theValue; }
106 //! Return flag to allow/prevent environment texture mapping usage for specific layer.
107 Standard_Boolean UseEnvironmentTexture() const { return myUseEnvironmentTexture; }
109 //! Set the flag to allow/prevent environment texture mapping usage for specific layer.
110 void SetEnvironmentTexture (const Standard_Boolean theValue) { myUseEnvironmentTexture = theValue; }
112 //! Return true if depth test should be enabled.
113 Standard_Boolean ToEnableDepthTest() const { return myToEnableDepthTest; }
115 //! Set if depth test should be enabled.
116 void SetEnableDepthTest(const Standard_Boolean theValue) { myToEnableDepthTest = theValue; }
118 //! Return true depth values should be written during rendering.
119 Standard_Boolean ToEnableDepthWrite() const { return myToEnableDepthWrite; }
121 //! Set if depth values should be written during rendering.
122 void SetEnableDepthWrite (const Standard_Boolean theValue) { myToEnableDepthWrite = theValue; }
124 //! Return true if depth values should be cleared before drawing the layer.
125 Standard_Boolean ToClearDepth() const { return myToClearDepth; }
127 //! Set if depth values should be cleared before drawing the layer.
128 void SetClearDepth (const Standard_Boolean theValue) { myToClearDepth = theValue; }
130 //! Return TRUE if layer should be rendered within depth pre-pass; TRUE by default.
131 Standard_Boolean ToRenderInDepthPrepass() const { return myToRenderInDepthPrepass; }
133 //! Set if layer should be rendered within depth pre-pass.
134 void SetRenderInDepthPrepass (Standard_Boolean theToRender) { myToRenderInDepthPrepass = theToRender; }
136 //! Return glPolygonOffset() arguments.
137 const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
139 //! Setup glPolygonOffset() arguments.
140 void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams) { myPolygonOffset = theParams; }
142 //! Modify glPolygonOffset() arguments.
143 Graphic3d_PolygonOffset& ChangePolygonOffset() { return myPolygonOffset; }
145 //! Returns true if theSetting is enabled.
146 Standard_DEPRECATED("Deprecated method IsSettingEnabled() should be replaced by individual property getters")
147 Standard_Boolean IsSettingEnabled (const Graphic3d_ZLayerSetting theSetting) const
151 case Graphic3d_ZLayerDepthTest: return myToEnableDepthTest;
152 case Graphic3d_ZLayerDepthWrite: return myToEnableDepthWrite;
153 case Graphic3d_ZLayerDepthClear: return myToClearDepth;
154 case Graphic3d_ZLayerDepthOffset: return myPolygonOffset.Mode != Aspect_POM_Off;
156 return Standard_False;
159 //! Enables theSetting
160 Standard_DEPRECATED("Deprecated method EnableSetting() should be replaced by individual property getters")
161 void EnableSetting (const Graphic3d_ZLayerSetting theSetting)
165 case Graphic3d_ZLayerDepthTest: myToEnableDepthTest = Standard_True; return;
166 case Graphic3d_ZLayerDepthWrite: myToEnableDepthWrite = Standard_True; return;
167 case Graphic3d_ZLayerDepthClear: myToClearDepth = Standard_True; return;
168 case Graphic3d_ZLayerDepthOffset: myPolygonOffset.Mode = Aspect_POM_Fill; return;
172 //! Disables theSetting
173 Standard_DEPRECATED("Deprecated method DisableSetting() should be replaced by individual property getters")
174 void DisableSetting (const Graphic3d_ZLayerSetting theSetting)
178 case Graphic3d_ZLayerDepthTest: myToEnableDepthTest = Standard_False; return;
179 case Graphic3d_ZLayerDepthWrite: myToEnableDepthWrite = Standard_False; return;
180 case Graphic3d_ZLayerDepthClear: myToClearDepth = Standard_False; return;
181 case Graphic3d_ZLayerDepthOffset: myPolygonOffset.Mode = Aspect_POM_Off; return;
185 //! Sets minimal possible positive depth offset.
186 void SetDepthOffsetPositive()
188 myPolygonOffset.Mode = Aspect_POM_Fill;
189 myPolygonOffset.Factor = 1.0f;
190 myPolygonOffset.Units = 1.0f;
193 //! Sets minimal possible negative depth offset.
194 void SetDepthOffsetNegative()
196 myPolygonOffset.Mode = Aspect_POM_Fill;
197 myPolygonOffset.Factor = 1.0f;
198 myPolygonOffset.Units =-1.0f;
203 TCollection_AsciiString myName; //!< user-provided name
204 Handle(Graphic3d_LightSet) myLights; //!< lights list
205 Handle(Geom_Transformation) myOriginTrsf; //!< transformation to the origin
206 gp_XYZ myOrigin; //!< the origin of all objects within the layer
207 Standard_Real myCullingDistance; //!< distance to discard objects
208 Standard_Real myCullingSize; //!< size to discard objects
209 Graphic3d_PolygonOffset myPolygonOffset; //!< glPolygonOffset() arguments
210 Standard_Boolean myIsImmediate; //!< immediate layer will be drawn after all normal layers
211 Standard_Boolean myUseEnvironmentTexture; //!< flag to allow/prevent environment texture mapping usage for specific layer
212 Standard_Boolean myToEnableDepthTest; //!< option to enable depth test
213 Standard_Boolean myToEnableDepthWrite; //!< option to enable write depth values
214 Standard_Boolean myToClearDepth; //!< option to clear depth values before drawing the layer
215 Standard_Boolean myToRenderInDepthPrepass;//!< option to render layer within depth pre-pass
219 #endif // _Graphic3d_ZLayerSettings_HeaderFile