0030635: Visualization - move OpenGl_Layer to Graphic3d_Layer
[occt.git] / src / Graphic3d / Graphic3d_ZLayerSettings.hxx
CommitLineData
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
24enum 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 33struct 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),
7c3ef2f7 41 myUseEnvironmentTexture (Standard_True),
42 myToEnableDepthTest (Standard_True),
43 myToEnableDepthWrite(Standard_True),
f88457e6 44 myToClearDepth (Standard_True),
45 myToRenderInDepthPrepass (Standard_True) {}
7c3ef2f7 46
47 //! Return user-provided name.
48 const TCollection_AsciiString& Name() const { return myName; }
49
50 //! Set custom name.
51 void SetName (const TCollection_AsciiString& theName) { myName = theName; }
52
992ed6b3 53 //! Return lights list to be used for rendering presentations within this Z-Layer; NULL by default.
54 //! NULL list (but not empty list!) means that default lights assigned to the View should be used instead of per-layer lights.
55 const Handle(Graphic3d_LightSet)& Lights() const { return myLights; }
56
57 //! Assign lights list to be used.
58 void SetLights (const Handle(Graphic3d_LightSet)& theLights) { myLights = theLights; }
59
7c3ef2f7 60 //! Return the origin of all objects within the layer.
61 const gp_XYZ& Origin() const { return myOrigin; }
62
63 //! Return the transformation to the origin.
64 const Handle(Geom_Transformation)& OriginTransformation() const { return myOriginTrsf; }
65
66 //! Set the origin of all objects within the layer.
67 void SetOrigin (const gp_XYZ& theOrigin)
68 {
69 myOrigin = theOrigin;
70 myOriginTrsf.Nullify();
71 if (!theOrigin.IsEqual (gp_XYZ(0.0, 0.0, 0.0), gp::Resolution()))
72 {
73 myOriginTrsf = new Geom_Transformation();
74 }
75 }
76
4ecf34cc 77 //! Return TRUE, if culling of distant objects (distance culling) should be performed; FALSE by default.
78 //! @sa CullingDistance()
79 Standard_Boolean HasCullingDistance() const { return !Precision::IsInfinite (myCullingDistance) && myCullingDistance > 0.0; }
80
81 //! Return the distance to discard drawing of distant objects (distance from camera Eye point); by default it is Infinite (distance culling is disabled).
82 //! Since camera eye definition has no strong meaning within orthographic projection, option is considered only within perspective projection.
83 //! Note also that this option has effect only when frustum culling is enabled.
84 Standard_Real CullingDistance() const { return myCullingDistance; }
85
86 //! Set the distance to discard drawing objects.
87 void SetCullingDistance (Standard_Real theDistance) { myCullingDistance = theDistance; }
88
89 //! Return TRUE, if culling of small objects (size culling) should be performed; FALSE by default.
90 //! @sa CullingSize()
91 Standard_Boolean HasCullingSize() const { return !Precision::IsInfinite (myCullingSize) && myCullingSize > 0.0; }
92
93 //! Return the size to discard drawing of small objects; by default it is Infinite (size culling is disabled).
94 //! Current implementation checks the length of projected diagonal of bounding box in pixels for discarding.
95 //! Note that this option has effect only when frustum culling is enabled.
96 Standard_Real CullingSize() const { return myCullingSize; }
97
98 //! Set the distance to discard drawing objects.
99 void SetCullingSize (Standard_Real theSize) { myCullingSize = theSize; }
100
7c3ef2f7 101 //! Return true if this layer should be drawn after all normal (non-immediate) layers.
102 Standard_Boolean IsImmediate() const { return myIsImmediate; }
103
104 //! Set the flag indicating the immediate layer, which should be drawn after all normal (non-immediate) layers.
105 void SetImmediate (const Standard_Boolean theValue) { myIsImmediate = theValue; }
106
107 //! Return flag to allow/prevent environment texture mapping usage for specific layer.
108 Standard_Boolean UseEnvironmentTexture() const { return myUseEnvironmentTexture; }
109
110 //! Set the flag to allow/prevent environment texture mapping usage for specific layer.
111 void SetEnvironmentTexture (const Standard_Boolean theValue) { myUseEnvironmentTexture = theValue; }
112
113 //! Return true if depth test should be enabled.
114 Standard_Boolean ToEnableDepthTest() const { return myToEnableDepthTest; }
115
116 //! Set if depth test should be enabled.
117 void SetEnableDepthTest(const Standard_Boolean theValue) { myToEnableDepthTest = theValue; }
118
119 //! Return true depth values should be written during rendering.
120 Standard_Boolean ToEnableDepthWrite() const { return myToEnableDepthWrite; }
121
122 //! Set if depth values should be written during rendering.
123 void SetEnableDepthWrite (const Standard_Boolean theValue) { myToEnableDepthWrite = theValue; }
124
125 //! Return true if depth values should be cleared before drawing the layer.
126 Standard_Boolean ToClearDepth() const { return myToClearDepth; }
127
128 //! Set if depth values should be cleared before drawing the layer.
129 void SetClearDepth (const Standard_Boolean theValue) { myToClearDepth = theValue; }
130
f88457e6 131 //! Return TRUE if layer should be rendered within depth pre-pass; TRUE by default.
132 Standard_Boolean ToRenderInDepthPrepass() const { return myToRenderInDepthPrepass; }
133
134 //! Set if layer should be rendered within depth pre-pass.
135 void SetRenderInDepthPrepass (Standard_Boolean theToRender) { myToRenderInDepthPrepass = theToRender; }
136
7c3ef2f7 137 //! Return glPolygonOffset() arguments.
138 const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
139
140 //! Setup glPolygonOffset() arguments.
141 void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams) { myPolygonOffset = theParams; }
142
143 //! Modify glPolygonOffset() arguments.
144 Graphic3d_PolygonOffset& ChangePolygonOffset() { return myPolygonOffset; }
c5751993 145
146 //! Returns true if theSetting is enabled.
7c3ef2f7 147 Standard_DEPRECATED("Deprecated method IsSettingEnabled() should be replaced by individual property getters")
487bf1ce 148 Standard_Boolean IsSettingEnabled (const Graphic3d_ZLayerSetting theSetting) const
c5751993 149 {
7c3ef2f7 150 switch (theSetting)
151 {
152 case Graphic3d_ZLayerDepthTest: return myToEnableDepthTest;
153 case Graphic3d_ZLayerDepthWrite: return myToEnableDepthWrite;
154 case Graphic3d_ZLayerDepthClear: return myToClearDepth;
155 case Graphic3d_ZLayerDepthOffset: return myPolygonOffset.Mode != Aspect_POM_Off;
156 }
157 return Standard_False;
c5751993 158 }
159
160 //! Enables theSetting
7c3ef2f7 161 Standard_DEPRECATED("Deprecated method EnableSetting() should be replaced by individual property getters")
c5751993 162 void EnableSetting (const Graphic3d_ZLayerSetting theSetting)
163 {
7c3ef2f7 164 switch (theSetting)
165 {
166 case Graphic3d_ZLayerDepthTest: myToEnableDepthTest = Standard_True; return;
167 case Graphic3d_ZLayerDepthWrite: myToEnableDepthWrite = Standard_True; return;
168 case Graphic3d_ZLayerDepthClear: myToClearDepth = Standard_True; return;
169 case Graphic3d_ZLayerDepthOffset: myPolygonOffset.Mode = Aspect_POM_Fill; return;
170 }
c5751993 171 }
172
173 //! Disables theSetting
7c3ef2f7 174 Standard_DEPRECATED("Deprecated method DisableSetting() should be replaced by individual property getters")
c5751993 175 void DisableSetting (const Graphic3d_ZLayerSetting theSetting)
176 {
7c3ef2f7 177 switch (theSetting)
178 {
179 case Graphic3d_ZLayerDepthTest: myToEnableDepthTest = Standard_False; return;
180 case Graphic3d_ZLayerDepthWrite: myToEnableDepthWrite = Standard_False; return;
181 case Graphic3d_ZLayerDepthClear: myToClearDepth = Standard_False; return;
182 case Graphic3d_ZLayerDepthOffset: myPolygonOffset.Mode = Aspect_POM_Off; return;
183 }
c5751993 184 }
185
186 //! Sets minimal possible positive depth offset.
c5751993 187 void SetDepthOffsetPositive()
188 {
7c3ef2f7 189 myPolygonOffset.Mode = Aspect_POM_Fill;
190 myPolygonOffset.Factor = 1.0f;
191 myPolygonOffset.Units = 1.0f;
c5751993 192 }
193
194 //! Sets minimal possible negative depth offset.
c5751993 195 void SetDepthOffsetNegative()
196 {
7c3ef2f7 197 myPolygonOffset.Mode = Aspect_POM_Fill;
198 myPolygonOffset.Factor = 1.0f;
199 myPolygonOffset.Units =-1.0f;
c5751993 200 }
201
7c3ef2f7 202protected:
a1954302 203
7c3ef2f7 204 TCollection_AsciiString myName; //!< user-provided name
992ed6b3 205 Handle(Graphic3d_LightSet) myLights; //!< lights list
7c3ef2f7 206 Handle(Geom_Transformation) myOriginTrsf; //!< transformation to the origin
207 gp_XYZ myOrigin; //!< the origin of all objects within the layer
4ecf34cc 208 Standard_Real myCullingDistance; //!< distance to discard objects
209 Standard_Real myCullingSize; //!< size to discard objects
7c3ef2f7 210 Graphic3d_PolygonOffset myPolygonOffset; //!< glPolygonOffset() arguments
211 Standard_Boolean myIsImmediate; //!< immediate layer will be drawn after all normal layers
212 Standard_Boolean myUseEnvironmentTexture; //!< flag to allow/prevent environment texture mapping usage for specific layer
213 Standard_Boolean myToEnableDepthTest; //!< option to enable depth test
214 Standard_Boolean myToEnableDepthWrite; //!< option to enable write depth values
215 Standard_Boolean myToClearDepth; //!< option to clear depth values before drawing the layer
f88457e6 216 Standard_Boolean myToRenderInDepthPrepass;//!< option to render layer within depth pre-pass
c5751993 217
c5751993 218};
219
220#endif // _Graphic3d_ZLayerSettings_HeaderFile