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 //! Structure defines list of ZLayer properties.
26 struct Graphic3d_ZLayerSettings
30 Graphic3d_ZLayerSettings()
31 : myCullingDistance (Precision::Infinite()),
32 myCullingSize (Precision::Infinite()),
33 myIsImmediate (Standard_False),
34 myToRaytrace (Standard_True),
35 myUseEnvironmentTexture (Standard_True),
36 myToEnableDepthTest (Standard_True),
37 myToEnableDepthWrite(Standard_True),
38 myToClearDepth (Standard_True),
39 myToRenderInDepthPrepass (Standard_True) {}
41 //! Return user-provided name.
42 const TCollection_AsciiString& Name() const { return myName; }
45 void SetName (const TCollection_AsciiString& theName) { myName = theName; }
47 //! Return lights list to be used for rendering presentations within this Z-Layer; NULL by default.
48 //! NULL list (but not empty list!) means that default lights assigned to the View should be used instead of per-layer lights.
49 const Handle(Graphic3d_LightSet)& Lights() const { return myLights; }
51 //! Assign lights list to be used.
52 void SetLights (const Handle(Graphic3d_LightSet)& theLights) { myLights = theLights; }
54 //! Return the origin of all objects within the layer.
55 const gp_XYZ& Origin() const { return myOrigin; }
57 //! Return the transformation to the origin.
58 const Handle(TopLoc_Datum3D)& OriginTransformation() const { return myOriginTrsf; }
60 //! Set the origin of all objects within the layer.
61 void SetOrigin (const gp_XYZ& theOrigin)
64 myOriginTrsf.Nullify();
65 if (!theOrigin.IsEqual (gp_XYZ(0.0, 0.0, 0.0), gp::Resolution()))
68 aTrsf.SetTranslation (theOrigin);
69 myOriginTrsf = new TopLoc_Datum3D (aTrsf);
73 //! Return TRUE, if culling of distant objects (distance culling) should be performed; FALSE by default.
74 //! @sa CullingDistance()
75 Standard_Boolean HasCullingDistance() const { return !Precision::IsInfinite (myCullingDistance) && myCullingDistance > 0.0; }
77 //! Return the distance to discard drawing of distant objects (distance from camera Eye point); by default it is Infinite (distance culling is disabled).
78 //! Since camera eye definition has no strong meaning within orthographic projection, option is considered only within perspective projection.
79 //! Note also that this option has effect only when frustum culling is enabled.
80 Standard_Real CullingDistance() const { return myCullingDistance; }
82 //! Set the distance to discard drawing objects.
83 void SetCullingDistance (Standard_Real theDistance) { myCullingDistance = theDistance; }
85 //! Return TRUE, if culling of small objects (size culling) should be performed; FALSE by default.
87 Standard_Boolean HasCullingSize() const { return !Precision::IsInfinite (myCullingSize) && myCullingSize > 0.0; }
89 //! Return the size to discard drawing of small objects; by default it is Infinite (size culling is disabled).
90 //! Current implementation checks the length of projected diagonal of bounding box in pixels for discarding.
91 //! Note that this option has effect only when frustum culling is enabled.
92 Standard_Real CullingSize() const { return myCullingSize; }
94 //! Set the distance to discard drawing objects.
95 void SetCullingSize (Standard_Real theSize) { myCullingSize = theSize; }
97 //! Return true if this layer should be drawn after all normal (non-immediate) layers.
98 Standard_Boolean IsImmediate() const { return myIsImmediate; }
100 //! Set the flag indicating the immediate layer, which should be drawn after all normal (non-immediate) layers.
101 void SetImmediate (const Standard_Boolean theValue) { myIsImmediate = theValue; }
103 //! Returns TRUE if layer should be processed by ray-tracing renderer; TRUE by default.
104 //! Note that this flag is IGNORED for layers with IsImmediate() flag.
105 Standard_Boolean IsRaytracable() const { return myToRaytrace; }
107 //! Sets if layer should be processed by ray-tracing renderer.
108 void SetRaytracable (Standard_Boolean theToRaytrace) { myToRaytrace = theToRaytrace; }
110 //! Return flag to allow/prevent environment texture mapping usage for specific layer.
111 Standard_Boolean UseEnvironmentTexture() const { return myUseEnvironmentTexture; }
113 //! Set the flag to allow/prevent environment texture mapping usage for specific layer.
114 void SetEnvironmentTexture (const Standard_Boolean theValue) { myUseEnvironmentTexture = theValue; }
116 //! Return true if depth test should be enabled.
117 Standard_Boolean ToEnableDepthTest() const { return myToEnableDepthTest; }
119 //! Set if depth test should be enabled.
120 void SetEnableDepthTest(const Standard_Boolean theValue) { myToEnableDepthTest = theValue; }
122 //! Return true depth values should be written during rendering.
123 Standard_Boolean ToEnableDepthWrite() const { return myToEnableDepthWrite; }
125 //! Set if depth values should be written during rendering.
126 void SetEnableDepthWrite (const Standard_Boolean theValue) { myToEnableDepthWrite = theValue; }
128 //! Return true if depth values should be cleared before drawing the layer.
129 Standard_Boolean ToClearDepth() const { return myToClearDepth; }
131 //! Set if depth values should be cleared before drawing the layer.
132 void SetClearDepth (const Standard_Boolean theValue) { myToClearDepth = theValue; }
134 //! Return TRUE if layer should be rendered within depth pre-pass; TRUE by default.
135 Standard_Boolean ToRenderInDepthPrepass() const { return myToRenderInDepthPrepass; }
137 //! Set if layer should be rendered within depth pre-pass.
138 void SetRenderInDepthPrepass (Standard_Boolean theToRender) { myToRenderInDepthPrepass = theToRender; }
140 //! Return glPolygonOffset() arguments.
141 const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
143 //! Setup glPolygonOffset() arguments.
144 void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams) { myPolygonOffset = theParams; }
146 //! Modify glPolygonOffset() arguments.
147 Graphic3d_PolygonOffset& ChangePolygonOffset() { return myPolygonOffset; }
149 //! Sets minimal possible positive depth offset.
150 void SetDepthOffsetPositive()
152 myPolygonOffset.Mode = Aspect_POM_Fill;
153 myPolygonOffset.Factor = 1.0f;
154 myPolygonOffset.Units = 1.0f;
157 //! Sets minimal possible negative depth offset.
158 void SetDepthOffsetNegative()
160 myPolygonOffset.Mode = Aspect_POM_Fill;
161 myPolygonOffset.Factor = 1.0f;
162 myPolygonOffset.Units =-1.0f;
165 //! Dumps the content of me into the stream
166 void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const
168 OCCT_DUMP_CLASS_BEGIN (theOStream, Graphic3d_ZLayerSettings)
170 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myName)
171 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myOriginTrsf.get())
172 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myOrigin)
174 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCullingDistance)
175 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCullingSize)
177 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPolygonOffset)
179 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsImmediate)
180 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToRaytrace)
181 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUseEnvironmentTexture)
182 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToEnableDepthTest)
183 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToEnableDepthWrite)
184 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToClearDepth)
185 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToRenderInDepthPrepass)
190 TCollection_AsciiString myName; //!< user-provided name
191 Handle(Graphic3d_LightSet) myLights; //!< lights list
192 Handle(TopLoc_Datum3D) myOriginTrsf; //!< transformation to the origin
193 gp_XYZ myOrigin; //!< the origin of all objects within the layer
194 Standard_Real myCullingDistance; //!< distance to discard objects
195 Standard_Real myCullingSize; //!< size to discard objects
196 Graphic3d_PolygonOffset myPolygonOffset; //!< glPolygonOffset() arguments
197 Standard_Boolean myIsImmediate; //!< immediate layer will be drawn after all normal layers
198 Standard_Boolean myToRaytrace; //!< option to render layer within ray-tracing engine
199 Standard_Boolean myUseEnvironmentTexture; //!< flag to allow/prevent environment texture mapping usage for specific layer
200 Standard_Boolean myToEnableDepthTest; //!< option to enable depth test
201 Standard_Boolean myToEnableDepthWrite; //!< option to enable write depth values
202 Standard_Boolean myToClearDepth; //!< option to clear depth values before drawing the layer
203 Standard_Boolean myToRenderInDepthPrepass;//!< option to render layer within depth pre-pass
207 #endif // _Graphic3d_ZLayerSettings_HeaderFile