1 // Created on: 2013-10-02
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 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 under
8 // the terms of the GNU Lesser General Public License 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 <OpenGl_ShaderStates.hxx>
18 // =======================================================================
19 // function : OpenGl_StateInterface
21 // =======================================================================
22 OpenGl_StateInterface::OpenGl_StateInterface()
28 // =======================================================================
29 // function : OpenGl_ProjectionState
30 // purpose : Creates uninitialized projection state
31 // =======================================================================
32 OpenGl_ProjectionState::OpenGl_ProjectionState()
33 : myInverseNeedUpdate (false)
38 // =======================================================================
40 // purpose : Sets new OCCT projection state
41 // =======================================================================
42 void OpenGl_ProjectionState::Set (const OpenGl_Mat4& theProjectionMatrix)
44 myProjectionMatrix = theProjectionMatrix;
45 myInverseNeedUpdate = true;
48 // =======================================================================
49 // function : ProjectionMatrix
50 // purpose : Returns current projection matrix
51 // =======================================================================
52 const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrix() const
54 return myProjectionMatrix;
57 // =======================================================================
58 // function : ProjectionMatrixInverse
59 // purpose : Returns inverse of current projection matrix
60 // =======================================================================
61 const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
63 if (!myInverseNeedUpdate)
65 return myProjectionMatrixInverse;
68 myProjectionMatrix.Inverted (myProjectionMatrixInverse);
70 return myProjectionMatrixInverse;
73 // =======================================================================
74 // function : OpenGl_ModelWorldState
75 // purpose : Creates uninitialized model-world state
76 // =======================================================================
77 OpenGl_ModelWorldState::OpenGl_ModelWorldState()
78 : myInverseNeedUpdate (false)
83 // =======================================================================
85 // purpose : Sets new model-world matrix
86 // =======================================================================
87 void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
89 myModelWorldMatrix = theModelWorldMatrix;
90 myInverseNeedUpdate = true;
93 // =======================================================================
94 // function : ModelWorldMatrix
95 // purpose : Returns current model-world matrix
96 // =======================================================================
97 const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrix() const
99 return myModelWorldMatrix;
102 // =======================================================================
103 // function : ModelWorldMatrixInverse
104 // purpose : Returns inverse of current model-world matrix
105 // =======================================================================
106 const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
108 if (!myInverseNeedUpdate)
110 return myModelWorldMatrix;
113 myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
115 return myModelWorldMatrixInverse;
118 // =======================================================================
119 // function : OpenGl_WorldViewState
120 // purpose : Creates uninitialized world-view state
121 // =======================================================================
122 OpenGl_WorldViewState::OpenGl_WorldViewState()
123 : myInverseNeedUpdate (false)
128 // =======================================================================
130 // purpose : Sets new world-view matrix
131 // =======================================================================
132 void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
134 myWorldViewMatrix = theWorldViewMatrix;
135 myInverseNeedUpdate = true;
138 // =======================================================================
139 // function : WorldViewMatrix
140 // purpose : Returns current world-view matrix
141 // =======================================================================
142 const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrix() const
144 return myWorldViewMatrix;
147 // =======================================================================
148 // function : WorldViewMatrixInverse
149 // purpose : Returns inverse of current world-view matrix
150 // =======================================================================
151 const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
153 if (!myInverseNeedUpdate)
155 return myWorldViewMatrix;
158 myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
160 return myWorldViewMatrixInverse;
163 // =======================================================================
164 // function : OpenGl_LightSourceState
165 // purpose : Creates uninitialized state of light sources
166 // =======================================================================
167 OpenGl_LightSourceState::OpenGl_LightSourceState()
168 : myLightSources (NULL)
173 // =======================================================================
175 // purpose : Sets new light sources
176 // =======================================================================
177 void OpenGl_LightSourceState::Set (const OpenGl_ListOfLight* theLightSources)
179 myLightSources = theLightSources;
182 // =======================================================================
183 // function : LightSources
184 // purpose : Returns current list of light sources
185 // =======================================================================
186 const OpenGl_ListOfLight* OpenGl_LightSourceState::LightSources() const
188 return myLightSources;
191 // =======================================================================
192 // function : OpenGl_ClippingState
193 // purpose : Creates new clipping state
194 // =======================================================================
195 OpenGl_ClippingState::OpenGl_ClippingState()
202 // =======================================================================
204 // purpose : Updates current state
205 // =======================================================================
206 void OpenGl_ClippingState::Update()
208 myStateStack.Prepend (myIndex);
209 myIndex = myNextIndex; // use myNextIndex here to handle properly Update() after Revert()
213 // =======================================================================
215 // purpose : Reverts current state
216 // =======================================================================
217 void OpenGl_ClippingState::Revert()
219 if (!myStateStack.IsEmpty())
221 myIndex = myStateStack.First();
222 myStateStack.RemoveFirst();