30f0ad28 |
1 | // Created on: 2013-10-02 |
2 | // Created by: Denis BOGOLEPOV |
d5f74e42 |
3 | // Copyright (c) 2013-2014 OPEN CASCADE SAS |
30f0ad28 |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
30f0ad28 |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
30f0ad28 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
30f0ad28 |
15 | |
16 | #ifndef _OpenGl_State_HeaderFile |
17 | #define _OpenGl_State_HeaderFile |
18 | |
e135a155 |
19 | #include <NCollection_List.hxx> |
992ed6b3 |
20 | #include <Graphic3d_LightSet.hxx> |
30f0ad28 |
21 | #include <OpenGl_Element.hxx> |
c827ea3a |
22 | #include <OpenGl_Vec.hxx> |
ca102800 |
23 | |
30f0ad28 |
24 | //! Defines interface for OpenGL state. |
25 | class OpenGl_StateInterface |
26 | { |
27 | public: |
28 | |
8cf06aa2 |
29 | //! Creates new state. |
96fffdc6 |
30 | Standard_EXPORT OpenGl_StateInterface(); |
30f0ad28 |
31 | |
32 | //! Returns current state index. |
8cf06aa2 |
33 | Standard_Size Index() const { return myIndex; } |
30f0ad28 |
34 | |
8cf06aa2 |
35 | //! Increment current state. |
36 | void Update() { ++myIndex; } |
30f0ad28 |
37 | |
38 | protected: |
39 | |
8cf06aa2 |
40 | Standard_Size myIndex; //!< current state index |
30f0ad28 |
41 | |
42 | }; |
43 | |
44 | //! Defines state of OCCT projection transformation. |
45 | class OpenGl_ProjectionState : public OpenGl_StateInterface |
46 | { |
47 | public: |
48 | |
49 | //! Creates uninitialized projection state. |
96fffdc6 |
50 | Standard_EXPORT OpenGl_ProjectionState(); |
30f0ad28 |
51 | |
52 | //! Sets new projection matrix. |
96fffdc6 |
53 | Standard_EXPORT void Set (const OpenGl_Mat4& theProjectionMatrix); |
30f0ad28 |
54 | |
55 | //! Returns current projection matrix. |
96fffdc6 |
56 | Standard_EXPORT const OpenGl_Mat4& ProjectionMatrix() const; |
30f0ad28 |
57 | |
58 | //! Returns inverse of current projection matrix. |
96fffdc6 |
59 | Standard_EXPORT const OpenGl_Mat4& ProjectionMatrixInverse() const; |
30f0ad28 |
60 | |
61 | private: |
62 | |
c827ea3a |
63 | OpenGl_Mat4 myProjectionMatrix; //!< OCCT projection matrix |
64 | mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix |
65 | bool myInverseNeedUpdate; //!< Is inversed matrix outdated? |
30f0ad28 |
66 | |
67 | }; |
68 | |
69 | //! Defines state of OCCT model-world transformation. |
70 | class OpenGl_ModelWorldState : public OpenGl_StateInterface |
71 | { |
72 | public: |
73 | |
74 | //! Creates uninitialized model-world state. |
96fffdc6 |
75 | Standard_EXPORT OpenGl_ModelWorldState(); |
30f0ad28 |
76 | |
77 | //! Sets new model-world matrix. |
96fffdc6 |
78 | Standard_EXPORT void Set (const OpenGl_Mat4& theModelWorldMatrix); |
30f0ad28 |
79 | |
80 | //! Returns current model-world matrix. |
96fffdc6 |
81 | Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrix() const; |
30f0ad28 |
82 | |
83 | //! Returns inverse of current model-world matrix. |
96fffdc6 |
84 | Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrixInverse() const; |
30f0ad28 |
85 | |
86 | private: |
87 | |
c827ea3a |
88 | OpenGl_Mat4 myModelWorldMatrix; //!< OCCT model-world matrix |
89 | mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix |
90 | bool myInverseNeedUpdate; //!< Is inversed matrix outdated? |
30f0ad28 |
91 | |
92 | }; |
93 | |
94 | //! Defines state of OCCT world-view transformation. |
95 | class OpenGl_WorldViewState : public OpenGl_StateInterface |
96 | { |
97 | public: |
98 | |
99 | //! Creates uninitialized world-view state. |
96fffdc6 |
100 | Standard_EXPORT OpenGl_WorldViewState(); |
e135a155 |
101 | |
30f0ad28 |
102 | //! Sets new world-view matrix. |
96fffdc6 |
103 | Standard_EXPORT void Set (const OpenGl_Mat4& theWorldViewMatrix); |
30f0ad28 |
104 | |
105 | //! Returns current world-view matrix. |
96fffdc6 |
106 | Standard_EXPORT const OpenGl_Mat4& WorldViewMatrix() const; |
30f0ad28 |
107 | |
108 | //! Returns inverse of current world-view matrix. |
96fffdc6 |
109 | Standard_EXPORT const OpenGl_Mat4& WorldViewMatrixInverse() const; |
30f0ad28 |
110 | |
111 | private: |
112 | |
c827ea3a |
113 | OpenGl_Mat4 myWorldViewMatrix; //!< OCCT world-view matrix |
114 | mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix |
115 | bool myInverseNeedUpdate; //!< Is inversed matrix outdated? |
30f0ad28 |
116 | |
117 | }; |
118 | |
119 | //! Defines state of OCCT light sources. |
120 | class OpenGl_LightSourceState : public OpenGl_StateInterface |
121 | { |
122 | public: |
123 | |
124 | //! Creates uninitialized state of light sources. |
67312b79 |
125 | OpenGl_LightSourceState() : mySpecIBLMapLevels (0) {} |
30f0ad28 |
126 | |
127 | //! Sets new light sources. |
992ed6b3 |
128 | void Set (const Handle(Graphic3d_LightSet)& theLightSources) { myLightSources = theLightSources; } |
30f0ad28 |
129 | |
130 | //! Returns current list of light sources. |
992ed6b3 |
131 | const Handle(Graphic3d_LightSet)& LightSources() const { return myLightSources; } |
30f0ad28 |
132 | |
67312b79 |
133 | //! Returns number of mipmap levels used in specular IBL map. |
134 | //! 0 by default or in case of using non-PBR shading model. |
135 | Standard_Integer SpecIBLMapLevels() const { return mySpecIBLMapLevels; } |
136 | |
137 | //! Sets number of mipmap levels used in specular IBL map. |
138 | void SetSpecIBLMapLevels(Standard_Integer theSpecIBLMapLevels) { mySpecIBLMapLevels = theSpecIBLMapLevels; } |
139 | |
30f0ad28 |
140 | private: |
141 | |
67312b79 |
142 | Handle(Graphic3d_LightSet) myLightSources; //!< List of OCCT light sources |
143 | Standard_Integer mySpecIBLMapLevels; //!< Number of mipmap levels used in specular IBL map (0 by default or in case of using non-PBR shading model) |
30f0ad28 |
144 | |
145 | }; |
146 | |
30f0ad28 |
147 | //! Defines generic state of OCCT clipping state. |
8cf06aa2 |
148 | class OpenGl_ClippingState |
30f0ad28 |
149 | { |
150 | public: |
151 | |
152 | //! Creates new clipping state. |
96fffdc6 |
153 | Standard_EXPORT OpenGl_ClippingState(); |
30f0ad28 |
154 | |
8cf06aa2 |
155 | //! Returns current state index. |
156 | Standard_Size Index() const { return myIndex; } |
157 | |
158 | //! Updates current state. |
96fffdc6 |
159 | Standard_EXPORT void Update(); |
8cf06aa2 |
160 | |
161 | //! Reverts current state. |
96fffdc6 |
162 | Standard_EXPORT void Revert(); |
8cf06aa2 |
163 | |
164 | protected: |
165 | |
166 | Standard_Size myIndex; //!< Current state index |
167 | Standard_Size myNextIndex; //!< Next state index |
168 | NCollection_List<Standard_Size> myStateStack; //!< Stack of previous states |
169 | |
30f0ad28 |
170 | }; |
171 | |
a1073ae2 |
172 | //! Defines generic state of order-independent transparency rendering properties. |
173 | class OpenGl_OitState : public OpenGl_StateInterface |
174 | { |
175 | public: |
176 | |
177 | //! Creates new uniform state. |
178 | OpenGl_OitState() : myToEnableWrite (false), myDepthFactor (0.5f) {} |
179 | |
180 | //! Sets the uniform values. |
181 | //! @param theToEnableWrite [in] flag indicating whether color and coverage |
182 | //! values for OIT processing should be written by shader program. |
183 | //! @param theDepthFactor [in] scalar factor [0-1] defining influence of depth |
184 | //! component of a fragment to its final coverage coefficient. |
185 | void Set (const bool theToEnableWrite, |
186 | const float theDepthFactor) |
187 | { |
188 | myToEnableWrite = theToEnableWrite; |
189 | myDepthFactor = static_cast<float> (Max (0.f, Min (1.f, theDepthFactor))); |
190 | } |
191 | |
192 | //! Returns flag indicating whether writing of output for OIT processing |
193 | //! should be enabled/disabled. |
194 | bool ToEnableWrite() const { return myToEnableWrite; } |
195 | |
196 | //! Returns factor defining influence of depth component of a fragment |
197 | //! to its final coverage coefficient. |
198 | float DepthFactor() const { return myDepthFactor; } |
199 | |
200 | private: |
201 | |
202 | bool myToEnableWrite; //!< writing color and coverage. |
203 | float myDepthFactor; //!< factor of depth influence to coverage. |
204 | }; |
205 | |
30f0ad28 |
206 | #endif // _OpenGl_State_HeaderFile |