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 <TopLoc_Datum3D.hxx>
19 #include <Graphic3d_LightSet.hxx>
20 #include <Graphic3d_PolygonOffset.hxx>
21 #include <Precision.hxx>
22 #include <Standard_Dump.hxx>
23 #include <TCollection_AsciiString.hxx>
25 enum Graphic3d_ZLayerSetting
27 Graphic3d_ZLayerDepthTest = 1,
28 Graphic3d_ZLayerDepthWrite = 2,
29 Graphic3d_ZLayerDepthClear = 4,
30 Graphic3d_ZLayerDepthOffset = 8
33 //! Structure defines list of ZLayer properties.
34 struct Graphic3d_ZLayerSettings
38 Graphic3d_ZLayerSettings()
39 : myCullingDistance (Precision::Infinite()),
40 myCullingSize (Precision::Infinite()),
41 myIsImmediate (Standard_False),
42 myToRaytrace (Standard_True),
43 myUseEnvironmentTexture (Standard_True),
44 myToEnableDepthTest (Standard_True),
45 myToEnableDepthWrite(Standard_True),
46 myToClearDepth (Standard_True),
47 myToRenderInDepthPrepass (Standard_True) {}
49 //! Return user-provided name.
50 const TCollection_AsciiString& Name() const { return myName; }
53 void SetName (const TCollection_AsciiString& theName) { myName = theName; }
55 //! Return lights list to be used for rendering presentations within this Z-Layer; NULL by default.
56 //! NULL list (but not empty list!) means that default lights assigned to the View should be used instead of per-layer lights.
57 const Handle(Graphic3d_LightSet)& Lights() const { return myLights; }
59 //! Assign lights list to be used.
60 void SetLights (const Handle(Graphic3d_LightSet)& theLights) { myLights = theLights; }
62 //! Return the origin of all objects within the layer.
63 const gp_XYZ& Origin() const { return myOrigin; }
65 //! Return the transformation to the origin.
66 const Handle(TopLoc_Datum3D)& OriginTransformation() const { return myOriginTrsf; }
68 //! Set the origin of all objects within the layer.
69 void SetOrigin (const gp_XYZ& theOrigin)
72 myOriginTrsf.Nullify();
73 if (!theOrigin.IsEqual (gp_XYZ(0.0, 0.0, 0.0), gp::Resolution()))
76 aTrsf.SetTranslation (theOrigin);
77 myOriginTrsf = new TopLoc_Datum3D (aTrsf);
81 //! Return TRUE, if culling of distant objects (distance culling) should be performed; FALSE by default.
82 //! @sa CullingDistance()
83 Standard_Boolean HasCullingDistance() const { return !Precision::IsInfinite (myCullingDistance) && myCullingDistance > 0.0; }
85 //! Return the distance to discard drawing of distant objects (distance from camera Eye point); by default it is Infinite (distance culling is disabled).
86 //! Since camera eye definition has no strong meaning within orthographic projection, option is considered only within perspective projection.
87 //! Note also that this option has effect only when frustum culling is enabled.
88 Standard_Real CullingDistance() const { return myCullingDistance; }
90 //! Set the distance to discard drawing objects.
91 void SetCullingDistance (Standard_Real theDistance) { myCullingDistance = theDistance; }
93 //! Return TRUE, if culling of small objects (size culling) should be performed; FALSE by default.
95 Standard_Boolean HasCullingSize() const { return !Precision::IsInfinite (myCullingSize) && myCullingSize > 0.0; }
97 //! Return the size to discard drawing of small objects; by default it is Infinite (size culling is disabled).
98 //! Current implementation checks the length of projected diagonal of bounding box in pixels for discarding.
99 //! Note that this option has effect only when frustum culling is enabled.
100 Standard_Real CullingSize() const { return myCullingSize; }
102 //! Set the distance to discard drawing objects.
103 void SetCullingSize (Standard_Real theSize) { myCullingSize = theSize; }
105 //! Return true if this layer should be drawn after all normal (non-immediate) layers.
106 Standard_Boolean IsImmediate() const { return myIsImmediate; }
108 //! Set the flag indicating the immediate layer, which should be drawn after all normal (non-immediate) layers.
109 void SetImmediate (const Standard_Boolean theValue) { myIsImmediate = theValue; }
111 //! Returns TRUE if layer should be processed by ray-tracing renderer; TRUE by default.
112 //! Note that this flag is IGNORED for layers with IsImmediate() flag.
113 Standard_Boolean IsRaytracable() const { return myToRaytrace; }
115 //! Sets if layer should be processed by ray-tracing renderer.
116 void SetRaytracable (Standard_Boolean theToRaytrace) { myToRaytrace = theToRaytrace; }
118 //! Return flag to allow/prevent environment texture mapping usage for specific layer.
119 Standard_Boolean UseEnvironmentTexture() const { return myUseEnvironmentTexture; }
121 //! Set the flag to allow/prevent environment texture mapping usage for specific layer.
122 void SetEnvironmentTexture (const Standard_Boolean theValue) { myUseEnvironmentTexture = theValue; }
124 //! Return true if depth test should be enabled.
125 Standard_Boolean ToEnableDepthTest() const { return myToEnableDepthTest; }
127 //! Set if depth test should be enabled.
128 void SetEnableDepthTest(const Standard_Boolean theValue) { myToEnableDepthTest = theValue; }
130 //! Return true depth values should be written during rendering.
131 Standard_Boolean ToEnableDepthWrite() const { return myToEnableDepthWrite; }
133 //! Set if depth values should be written during rendering.
134 void SetEnableDepthWrite (const Standard_Boolean theValue) { myToEnableDepthWrite = theValue; }
136 //! Return true if depth values should be cleared before drawing the layer.
137 Standard_Boolean ToClearDepth() const { return myToClearDepth; }
139 //! Set if depth values should be cleared before drawing the layer.
140 void SetClearDepth (const Standard_Boolean theValue) { myToClearDepth = theValue; }
142 //! Return TRUE if layer should be rendered within depth pre-pass; TRUE by default.
143 Standard_Boolean ToRenderInDepthPrepass() const { return myToRenderInDepthPrepass; }
145 //! Set if layer should be rendered within depth pre-pass.
146 void SetRenderInDepthPrepass (Standard_Boolean theToRender) { myToRenderInDepthPrepass = theToRender; }
148 //! Return glPolygonOffset() arguments.
149 const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
151 //! Setup glPolygonOffset() arguments.
152 void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams) { myPolygonOffset = theParams; }
154 //! Modify glPolygonOffset() arguments.
155 Graphic3d_PolygonOffset& ChangePolygonOffset() { return myPolygonOffset; }
157 //! Returns true if theSetting is enabled.
158 Standard_DEPRECATED("Deprecated method IsSettingEnabled() should be replaced by individual property getters")
159 Standard_Boolean IsSettingEnabled (const Graphic3d_ZLayerSetting theSetting) const
163 case Graphic3d_ZLayerDepthTest: return myToEnableDepthTest;
164 case Graphic3d_ZLayerDepthWrite: return myToEnableDepthWrite;
165 case Graphic3d_ZLayerDepthClear: return myToClearDepth;
166 case Graphic3d_ZLayerDepthOffset: return myPolygonOffset.Mode != Aspect_POM_Off;
168 return Standard_False;
171 //! Enables theSetting
172 Standard_DEPRECATED("Deprecated method EnableSetting() should be replaced by individual property getters")
173 void EnableSetting (const Graphic3d_ZLayerSetting theSetting)
177 case Graphic3d_ZLayerDepthTest: myToEnableDepthTest = Standard_True; return;
178 case Graphic3d_ZLayerDepthWrite: myToEnableDepthWrite = Standard_True; return;
179 case Graphic3d_ZLayerDepthClear: myToClearDepth = Standard_True; return;
180 case Graphic3d_ZLayerDepthOffset: myPolygonOffset.Mode = Aspect_POM_Fill; return;
184 //! Disables theSetting
185 Standard_DEPRECATED("Deprecated method DisableSetting() should be replaced by individual property getters")
186 void DisableSetting (const Graphic3d_ZLayerSetting theSetting)
190 case Graphic3d_ZLayerDepthTest: myToEnableDepthTest = Standard_False; return;
191 case Graphic3d_ZLayerDepthWrite: myToEnableDepthWrite = Standard_False; return;
192 case Graphic3d_ZLayerDepthClear: myToClearDepth = Standard_False; return;
193 case Graphic3d_ZLayerDepthOffset: myPolygonOffset.Mode = Aspect_POM_Off; return;
197 //! Sets minimal possible positive depth offset.
198 void SetDepthOffsetPositive()
200 myPolygonOffset.Mode = Aspect_POM_Fill;
201 myPolygonOffset.Factor = 1.0f;
202 myPolygonOffset.Units = 1.0f;
205 //! Sets minimal possible negative depth offset.
206 void SetDepthOffsetNegative()
208 myPolygonOffset.Mode = Aspect_POM_Fill;
209 myPolygonOffset.Factor = 1.0f;
210 myPolygonOffset.Units =-1.0f;
213 //! Dumps the content of me into the stream
214 void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const
216 OCCT_DUMP_CLASS_BEGIN (theOStream, Graphic3d_ZLayerSettings)
218 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myName)
219 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myOriginTrsf.get())
220 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myOrigin)
222 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCullingDistance)
223 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCullingSize)
225 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPolygonOffset)
227 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsImmediate)
228 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToRaytrace)
229 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUseEnvironmentTexture)
230 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToEnableDepthTest)
231 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToEnableDepthWrite)
232 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToClearDepth)
233 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToRenderInDepthPrepass)
238 TCollection_AsciiString myName; //!< user-provided name
239 Handle(Graphic3d_LightSet) myLights; //!< lights list
240 Handle(TopLoc_Datum3D) myOriginTrsf; //!< transformation to the origin
241 gp_XYZ myOrigin; //!< the origin of all objects within the layer
242 Standard_Real myCullingDistance; //!< distance to discard objects
243 Standard_Real myCullingSize; //!< size to discard objects
244 Graphic3d_PolygonOffset myPolygonOffset; //!< glPolygonOffset() arguments
245 Standard_Boolean myIsImmediate; //!< immediate layer will be drawn after all normal layers
246 Standard_Boolean myToRaytrace; //!< option to render layer within ray-tracing engine
247 Standard_Boolean myUseEnvironmentTexture; //!< flag to allow/prevent environment texture mapping usage for specific layer
248 Standard_Boolean myToEnableDepthTest; //!< option to enable depth test
249 Standard_Boolean myToEnableDepthWrite; //!< option to enable write depth values
250 Standard_Boolean myToClearDepth; //!< option to clear depth values before drawing the layer
251 Standard_Boolean myToRenderInDepthPrepass;//!< option to render layer within depth pre-pass
255 #endif // _Graphic3d_ZLayerSettings_HeaderFile