30f0ad28 |
1 | // Created on: 2013-10-02 |
2 | // Created by: Denis BOGOLEPOV |
3 | // Copyright (c) 2013 OPEN CASCADE SAS |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
30f0ad28 |
6 | // |
973c2be1 |
7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public version 2.1 as published |
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 | #include <NCollection_Mat4.hxx> |
17 | |
18 | #include <OpenGl_ShaderStates.hxx> |
19 | |
20 | // ======================================================================= |
21 | // function : OpenGl_StateInterface |
22 | // purpose : Creates new OCCT state |
23 | // ======================================================================= |
24 | OpenGl_StateInterface::OpenGl_StateInterface() |
25 | : myIndex (0) |
26 | { |
27 | // |
28 | } |
29 | |
30 | // ======================================================================= |
31 | // function : Index |
32 | // purpose : Returns current state index |
33 | // ======================================================================= |
34 | Standard_Size OpenGl_StateInterface::Index() const |
35 | { |
36 | return myIndex; |
37 | } |
38 | |
39 | // ======================================================================= |
40 | // function : Update |
41 | // purpose : Updates current state |
42 | // ======================================================================= |
43 | void OpenGl_StateInterface::Update() |
44 | { |
45 | ++myIndex; |
46 | } |
47 | |
48 | // ======================================================================= |
49 | // function : Revert |
50 | // purpose : Reverts current state |
51 | // ======================================================================= |
52 | void OpenGl_StateInterface::Revert() |
53 | { |
54 | if (myIndex > 0) |
55 | { |
56 | --myIndex; |
57 | } |
58 | } |
59 | |
60 | // ======================================================================= |
61 | // function : OpenGl_ProjectionState |
62 | // purpose : Creates uninitialized projection state |
63 | // ======================================================================= |
64 | OpenGl_ProjectionState::OpenGl_ProjectionState() |
65 | : myInverseNeedUpdate (false) |
66 | { |
67 | // |
68 | } |
69 | |
70 | // ======================================================================= |
71 | // function : Set |
72 | // purpose : Sets new OCCT projection state |
73 | // ======================================================================= |
b5ac8292 |
74 | void OpenGl_ProjectionState::Set (const Tmatrix3* theProjectionMatrix) |
30f0ad28 |
75 | { |
76 | memcpy (myProjectionMatrix, theProjectionMatrix, sizeof (Tmatrix3)); |
77 | myInverseNeedUpdate = true; |
78 | } |
79 | |
80 | // ======================================================================= |
81 | // function : ProjectionMatrix |
82 | // purpose : Returns current projection matrix |
83 | // ======================================================================= |
84 | const Tmatrix3& OpenGl_ProjectionState::ProjectionMatrix() const |
85 | { |
86 | return myProjectionMatrix; |
87 | } |
88 | |
89 | // ======================================================================= |
90 | // function : ProjectionMatrixInverse |
91 | // purpose : Returns inverse of current projection matrix |
92 | // ======================================================================= |
93 | const Tmatrix3& OpenGl_ProjectionState::ProjectionMatrixInverse() const |
94 | { |
95 | if (!myInverseNeedUpdate) |
96 | { |
97 | return myProjectionMatrixInverse; |
98 | } |
99 | |
100 | reinterpret_cast<const NCollection_Mat4<float>*> (*myProjectionMatrix)->Inverted ( |
101 | *(reinterpret_cast<NCollection_Mat4<float>*> (*myProjectionMatrixInverse))); |
102 | return myProjectionMatrixInverse; |
103 | } |
104 | |
105 | // ======================================================================= |
106 | // function : OpenGl_ModelWorldState |
107 | // purpose : Creates uninitialized model-world state |
108 | // ======================================================================= |
109 | OpenGl_ModelWorldState::OpenGl_ModelWorldState() |
110 | : myInverseNeedUpdate (false) |
111 | { |
112 | // |
113 | } |
114 | |
115 | // ======================================================================= |
116 | // function : Set |
117 | // purpose : Sets new model-world matrix |
118 | // ======================================================================= |
b5ac8292 |
119 | void OpenGl_ModelWorldState::Set (const Tmatrix3* theModelWorldMatrix) |
30f0ad28 |
120 | { |
121 | memcpy (myModelWorldMatrix, theModelWorldMatrix, sizeof (Tmatrix3)); |
122 | myInverseNeedUpdate = true; |
123 | } |
124 | |
125 | // ======================================================================= |
126 | // function : ModelWorldMatrix |
127 | // purpose : Returns current model-world matrix |
128 | // ======================================================================= |
129 | const Tmatrix3& OpenGl_ModelWorldState::ModelWorldMatrix() const |
130 | { |
131 | return myModelWorldMatrix; |
132 | } |
133 | |
134 | // ======================================================================= |
135 | // function : ModelWorldMatrixInverse |
136 | // purpose : Returns inverse of current model-world matrix |
137 | // ======================================================================= |
138 | const Tmatrix3& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const |
139 | { |
140 | if (!myInverseNeedUpdate) |
141 | { |
142 | return myModelWorldMatrix; |
143 | } |
144 | |
145 | reinterpret_cast<const NCollection_Mat4<float>*> (*myModelWorldMatrix)->Inverted ( |
146 | *(reinterpret_cast<NCollection_Mat4<float>*> (*myModelWorldMatrixInverse))); |
147 | return myModelWorldMatrixInverse; |
148 | } |
149 | |
150 | // ======================================================================= |
151 | // function : OpenGl_WorldViewState |
152 | // purpose : Creates uninitialized world-view state |
153 | // ======================================================================= |
154 | OpenGl_WorldViewState::OpenGl_WorldViewState() |
155 | : myInverseNeedUpdate (false) |
156 | { |
157 | // |
158 | } |
159 | |
160 | // ======================================================================= |
161 | // function : Set |
162 | // purpose : Sets new world-view matrix |
163 | // ======================================================================= |
b5ac8292 |
164 | void OpenGl_WorldViewState::Set (const Tmatrix3* theWorldViewMatrix) |
30f0ad28 |
165 | { |
166 | memcpy (myWorldViewMatrix, theWorldViewMatrix, sizeof (Tmatrix3)); |
167 | myInverseNeedUpdate = true; |
168 | } |
169 | |
170 | // ======================================================================= |
171 | // function : WorldViewMatrix |
172 | // purpose : Returns current world-view matrix |
173 | // ======================================================================= |
174 | const Tmatrix3& OpenGl_WorldViewState::WorldViewMatrix() const |
175 | { |
176 | return myWorldViewMatrix; |
177 | } |
178 | |
179 | // ======================================================================= |
180 | // function : WorldViewMatrixInverse |
181 | // purpose : Returns inverse of current world-view matrix |
182 | // ======================================================================= |
183 | const Tmatrix3& OpenGl_WorldViewState::WorldViewMatrixInverse() const |
184 | { |
185 | if (!myInverseNeedUpdate) |
186 | { |
187 | return myWorldViewMatrix; |
188 | } |
189 | |
190 | reinterpret_cast<const NCollection_Mat4<float>*> (*myWorldViewMatrix)->Inverted ( |
191 | *(reinterpret_cast<NCollection_Mat4<float>*> (*myWorldViewMatrixInverse))); |
192 | return myWorldViewMatrixInverse; |
193 | } |
194 | |
195 | // ======================================================================= |
196 | // function : OpenGl_LightSourceState |
197 | // purpose : Creates uninitialized state of light sources |
198 | // ======================================================================= |
199 | OpenGl_LightSourceState::OpenGl_LightSourceState() |
200 | : myLightSources (NULL) |
201 | { |
202 | // |
203 | } |
204 | |
205 | // ======================================================================= |
206 | // function : Set |
207 | // purpose : Sets new light sources |
208 | // ======================================================================= |
209 | void OpenGl_LightSourceState::Set (const OpenGl_ListOfLight* theLightSources) |
210 | { |
211 | myLightSources = theLightSources; |
212 | } |
213 | |
214 | // ======================================================================= |
215 | // function : LightSources |
216 | // purpose : Returns current list of light sources |
217 | // ======================================================================= |
218 | const OpenGl_ListOfLight* OpenGl_LightSourceState::LightSources() const |
219 | { |
220 | return myLightSources; |
221 | } |
222 | |
223 | // ======================================================================= |
224 | // function : OpenGl_MaterialState |
225 | // purpose : Creates uninitialized material state |
226 | // ======================================================================= |
227 | OpenGl_MaterialState::OpenGl_MaterialState (const OpenGl_Element* theAspect) |
228 | : myAspect (theAspect) |
229 | { |
230 | // |
231 | } |
232 | |
233 | // ======================================================================= |
234 | // function : Set |
235 | // purpose : Sets new material aspect |
236 | // ======================================================================= |
237 | void OpenGl_MaterialState::Set (const OpenGl_Element* theAspect) |
238 | { |
239 | myAspect = theAspect; |
240 | } |
241 | |
242 | // ======================================================================= |
243 | // function : Aspect |
244 | // purpose : Returns material aspect |
245 | // ======================================================================= |
246 | const OpenGl_Element* OpenGl_MaterialState::Aspect() const |
247 | { |
248 | return myAspect; |
249 | } |
250 | |
251 | // ======================================================================= |
252 | // function : OpenGl_ClippingState |
253 | // purpose : Creates new clipping state |
254 | // ======================================================================= |
255 | OpenGl_ClippingState::OpenGl_ClippingState() |
256 | { |
257 | // |
258 | } |