0031405: Advanced wrappers, C# wrapper - dark colors in WPF sample
[occt.git] / src / OpenGl / OpenGl_ShaderStates.cxx
1 // Created on: 2013-10-02
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <OpenGl_ShaderStates.hxx>
17
18 // =======================================================================
19 // function : OpenGl_StateInterface
20 // purpose  :
21 // =======================================================================
22 OpenGl_StateInterface::OpenGl_StateInterface()
23 : myIndex (0)
24 {
25   //
26 }
27
28 // =======================================================================
29 // function : OpenGl_ProjectionState
30 // purpose  : Creates uninitialized projection state
31 // =======================================================================
32 OpenGl_ProjectionState::OpenGl_ProjectionState()
33 : myInverseNeedUpdate (false)
34 {
35   //
36 }
37
38 // =======================================================================
39 // function : Set
40 // purpose  : Sets new OCCT projection state
41 // =======================================================================
42 void OpenGl_ProjectionState::Set (const OpenGl_Mat4& theProjectionMatrix)
43 {
44   myProjectionMatrix = theProjectionMatrix;
45   myInverseNeedUpdate = true;
46 }
47
48 // =======================================================================
49 // function : ProjectionMatrixInverse
50 // purpose  : Returns inverse of current projection matrix
51 // =======================================================================
52 const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
53 {
54   if (myInverseNeedUpdate)
55   {
56     myInverseNeedUpdate = false;
57     myProjectionMatrix.Inverted (myProjectionMatrixInverse);
58   }
59   return myProjectionMatrixInverse;
60 }
61
62 // =======================================================================
63 // function : OpenGl_ModelWorldState
64 // purpose  : Creates uninitialized model-world state
65 // =======================================================================
66 OpenGl_ModelWorldState::OpenGl_ModelWorldState()
67 : myInverseNeedUpdate (false)
68 {
69   //
70 }
71
72 // =======================================================================
73 // function : Set
74 // purpose  : Sets new model-world matrix
75 // =======================================================================
76 void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
77 {
78   myModelWorldMatrix = theModelWorldMatrix;
79   myInverseNeedUpdate = true;
80 }
81
82 // =======================================================================
83 // function : ModelWorldMatrixInverse
84 // purpose  : Returns inverse of current model-world matrix
85 // =======================================================================
86 const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
87 {
88   if (myInverseNeedUpdate)
89   {
90     myInverseNeedUpdate = false;
91     myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
92   }
93   return myModelWorldMatrixInverse;
94 }
95
96 // =======================================================================
97 // function : OpenGl_WorldViewState
98 // purpose  : Creates uninitialized world-view state
99 // =======================================================================
100 OpenGl_WorldViewState::OpenGl_WorldViewState()
101 : myInverseNeedUpdate (false)
102 {
103   //
104 }
105
106 // =======================================================================
107 // function : Set
108 // purpose  : Sets new world-view matrix
109 // =======================================================================
110 void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
111 {
112   myWorldViewMatrix = theWorldViewMatrix;
113   myInverseNeedUpdate = true;
114 }
115
116 // =======================================================================
117 // function : WorldViewMatrixInverse
118 // purpose  : Returns inverse of current world-view matrix
119 // =======================================================================
120 const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
121 {
122   if (myInverseNeedUpdate)
123   {
124     myInverseNeedUpdate = false;
125     myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
126   }
127   return myWorldViewMatrixInverse;
128 }
129
130 // =======================================================================
131 // function : OpenGl_ClippingState
132 // purpose  : Creates new clipping state
133 // =======================================================================
134 OpenGl_ClippingState::OpenGl_ClippingState()
135 : myIndex (0),
136   myNextIndex (1)
137 {
138   //
139 }
140
141 // =======================================================================
142 // function : Update
143 // purpose  : Updates current state
144 // =======================================================================
145 void OpenGl_ClippingState::Update()
146 {
147   myStateStack.Prepend (myIndex);
148   myIndex = myNextIndex; // use myNextIndex here to handle properly Update() after Revert()
149   ++myNextIndex;
150 }
151
152 // =======================================================================
153 // function : Revert
154 // purpose  : Reverts current state
155 // =======================================================================
156 void OpenGl_ClippingState::Revert()
157 {
158   if (!myStateStack.IsEmpty())
159   {
160     myIndex = myStateStack.First();
161     myStateStack.RemoveFirst();
162   }
163   else
164   {
165     myIndex = 0;
166   }
167 }