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 : ProjectionMatrixInverse
50 // purpose : Returns inverse of current projection matrix
51 // =======================================================================
52 const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
54 if (myInverseNeedUpdate)
56 myInverseNeedUpdate = false;
57 myProjectionMatrix.Inverted (myProjectionMatrixInverse);
59 return myProjectionMatrixInverse;
62 // =======================================================================
63 // function : OpenGl_ModelWorldState
64 // purpose : Creates uninitialized model-world state
65 // =======================================================================
66 OpenGl_ModelWorldState::OpenGl_ModelWorldState()
67 : myInverseNeedUpdate (false)
72 // =======================================================================
74 // purpose : Sets new model-world matrix
75 // =======================================================================
76 void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
78 myModelWorldMatrix = theModelWorldMatrix;
79 myInverseNeedUpdate = true;
82 // =======================================================================
83 // function : ModelWorldMatrixInverse
84 // purpose : Returns inverse of current model-world matrix
85 // =======================================================================
86 const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
88 if (myInverseNeedUpdate)
90 myInverseNeedUpdate = false;
91 myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
93 return myModelWorldMatrixInverse;
96 // =======================================================================
97 // function : OpenGl_WorldViewState
98 // purpose : Creates uninitialized world-view state
99 // =======================================================================
100 OpenGl_WorldViewState::OpenGl_WorldViewState()
101 : myInverseNeedUpdate (false)
106 // =======================================================================
108 // purpose : Sets new world-view matrix
109 // =======================================================================
110 void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
112 myWorldViewMatrix = theWorldViewMatrix;
113 myInverseNeedUpdate = true;
116 // =======================================================================
117 // function : WorldViewMatrixInverse
118 // purpose : Returns inverse of current world-view matrix
119 // =======================================================================
120 const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
122 if (myInverseNeedUpdate)
124 myInverseNeedUpdate = false;
125 myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
127 return myWorldViewMatrixInverse;
130 // =======================================================================
131 // function : OpenGl_ClippingState
132 // purpose : Creates new clipping state
133 // =======================================================================
134 OpenGl_ClippingState::OpenGl_ClippingState()
141 // =======================================================================
143 // purpose : Updates current state
144 // =======================================================================
145 void OpenGl_ClippingState::Update()
147 myStateStack.Prepend (myIndex);
148 myIndex = myNextIndex; // use myNextIndex here to handle properly Update() after Revert()
152 // =======================================================================
154 // purpose : Reverts current state
155 // =======================================================================
156 void OpenGl_ClippingState::Revert()
158 if (!myStateStack.IsEmpty())
160 myIndex = myStateStack.First();
161 myStateStack.RemoveFirst();