1 // Created on: 2013-10-02
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <NCollection_Mat4.hxx>
18 #include <OpenGl_ShaderStates.hxx>
20 // =======================================================================
21 // function : OpenGl_StateInterface
22 // purpose : Creates new OCCT state
23 // =======================================================================
24 OpenGl_StateInterface::OpenGl_StateInterface()
30 // =======================================================================
32 // purpose : Returns current state index
33 // =======================================================================
34 Standard_Size OpenGl_StateInterface::Index() const
39 // =======================================================================
41 // purpose : Updates current state
42 // =======================================================================
43 void OpenGl_StateInterface::Update()
48 // =======================================================================
50 // purpose : Reverts current state
51 // =======================================================================
52 void OpenGl_StateInterface::Revert()
60 // =======================================================================
61 // function : OpenGl_ProjectionState
62 // purpose : Creates uninitialized projection state
63 // =======================================================================
64 OpenGl_ProjectionState::OpenGl_ProjectionState()
65 : myInverseNeedUpdate (false)
70 // =======================================================================
72 // purpose : Sets new OCCT projection state
73 // =======================================================================
74 void OpenGl_ProjectionState::Set (const Tmatrix3* theProjectionMatrix)
76 memcpy (myProjectionMatrix, theProjectionMatrix, sizeof (Tmatrix3));
77 myInverseNeedUpdate = true;
80 // =======================================================================
81 // function : ProjectionMatrix
82 // purpose : Returns current projection matrix
83 // =======================================================================
84 const Tmatrix3& OpenGl_ProjectionState::ProjectionMatrix() const
86 return myProjectionMatrix;
89 // =======================================================================
90 // function : ProjectionMatrixInverse
91 // purpose : Returns inverse of current projection matrix
92 // =======================================================================
93 const Tmatrix3& OpenGl_ProjectionState::ProjectionMatrixInverse() const
95 if (!myInverseNeedUpdate)
97 return myProjectionMatrixInverse;
100 reinterpret_cast<const NCollection_Mat4<float>*> (*myProjectionMatrix)->Inverted (
101 *(reinterpret_cast<NCollection_Mat4<float>*> (*myProjectionMatrixInverse)));
102 return myProjectionMatrixInverse;
105 // =======================================================================
106 // function : OpenGl_ModelWorldState
107 // purpose : Creates uninitialized model-world state
108 // =======================================================================
109 OpenGl_ModelWorldState::OpenGl_ModelWorldState()
110 : myInverseNeedUpdate (false)
115 // =======================================================================
117 // purpose : Sets new model-world matrix
118 // =======================================================================
119 void OpenGl_ModelWorldState::Set (const Tmatrix3* theModelWorldMatrix)
121 memcpy (myModelWorldMatrix, theModelWorldMatrix, sizeof (Tmatrix3));
122 myInverseNeedUpdate = true;
125 // =======================================================================
126 // function : ModelWorldMatrix
127 // purpose : Returns current model-world matrix
128 // =======================================================================
129 const Tmatrix3& OpenGl_ModelWorldState::ModelWorldMatrix() const
131 return myModelWorldMatrix;
134 // =======================================================================
135 // function : ModelWorldMatrixInverse
136 // purpose : Returns inverse of current model-world matrix
137 // =======================================================================
138 const Tmatrix3& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
140 if (!myInverseNeedUpdate)
142 return myModelWorldMatrix;
145 reinterpret_cast<const NCollection_Mat4<float>*> (*myModelWorldMatrix)->Inverted (
146 *(reinterpret_cast<NCollection_Mat4<float>*> (*myModelWorldMatrixInverse)));
147 return myModelWorldMatrixInverse;
150 // =======================================================================
151 // function : OpenGl_WorldViewState
152 // purpose : Creates uninitialized world-view state
153 // =======================================================================
154 OpenGl_WorldViewState::OpenGl_WorldViewState()
155 : myInverseNeedUpdate (false)
160 // =======================================================================
162 // purpose : Sets new world-view matrix
163 // =======================================================================
164 void OpenGl_WorldViewState::Set (const Tmatrix3* theWorldViewMatrix)
166 memcpy (myWorldViewMatrix, theWorldViewMatrix, sizeof (Tmatrix3));
167 myInverseNeedUpdate = true;
170 // =======================================================================
171 // function : WorldViewMatrix
172 // purpose : Returns current world-view matrix
173 // =======================================================================
174 const Tmatrix3& OpenGl_WorldViewState::WorldViewMatrix() const
176 return myWorldViewMatrix;
179 // =======================================================================
180 // function : WorldViewMatrixInverse
181 // purpose : Returns inverse of current world-view matrix
182 // =======================================================================
183 const Tmatrix3& OpenGl_WorldViewState::WorldViewMatrixInverse() const
185 if (!myInverseNeedUpdate)
187 return myWorldViewMatrix;
190 reinterpret_cast<const NCollection_Mat4<float>*> (*myWorldViewMatrix)->Inverted (
191 *(reinterpret_cast<NCollection_Mat4<float>*> (*myWorldViewMatrixInverse)));
192 return myWorldViewMatrixInverse;
195 // =======================================================================
196 // function : OpenGl_LightSourceState
197 // purpose : Creates uninitialized state of light sources
198 // =======================================================================
199 OpenGl_LightSourceState::OpenGl_LightSourceState()
200 : myLightSources (NULL)
205 // =======================================================================
207 // purpose : Sets new light sources
208 // =======================================================================
209 void OpenGl_LightSourceState::Set (const OpenGl_ListOfLight* theLightSources)
211 myLightSources = theLightSources;
214 // =======================================================================
215 // function : LightSources
216 // purpose : Returns current list of light sources
217 // =======================================================================
218 const OpenGl_ListOfLight* OpenGl_LightSourceState::LightSources() const
220 return myLightSources;
223 // =======================================================================
224 // function : OpenGl_MaterialState
225 // purpose : Creates uninitialized material state
226 // =======================================================================
227 OpenGl_MaterialState::OpenGl_MaterialState (const OpenGl_Element* theAspect)
228 : myAspect (theAspect)
233 // =======================================================================
235 // purpose : Sets new material aspect
236 // =======================================================================
237 void OpenGl_MaterialState::Set (const OpenGl_Element* theAspect)
239 myAspect = theAspect;
242 // =======================================================================
244 // purpose : Returns material aspect
245 // =======================================================================
246 const OpenGl_Element* OpenGl_MaterialState::Aspect() const
251 // =======================================================================
252 // function : OpenGl_ClippingState
253 // purpose : Creates new clipping state
254 // =======================================================================
255 OpenGl_ClippingState::OpenGl_ClippingState()