0024192: Adding support for shaders to OCCT visualization toolkit
[occt.git] / src / OpenGl / OpenGl_ShaderStates.cxx
CommitLineData
30f0ad28 1// Created on: 2013-10-02
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2013 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20#include <NCollection_Mat4.hxx>
21
22#include <OpenGl_ShaderStates.hxx>
23
24// =======================================================================
25// function : OpenGl_StateInterface
26// purpose : Creates new OCCT state
27// =======================================================================
28OpenGl_StateInterface::OpenGl_StateInterface()
29: myIndex (0)
30{
31 //
32}
33
34// =======================================================================
35// function : Index
36// purpose : Returns current state index
37// =======================================================================
38Standard_Size OpenGl_StateInterface::Index() const
39{
40 return myIndex;
41}
42
43// =======================================================================
44// function : Update
45// purpose : Updates current state
46// =======================================================================
47void OpenGl_StateInterface::Update()
48{
49 ++myIndex;
50}
51
52// =======================================================================
53// function : Revert
54// purpose : Reverts current state
55// =======================================================================
56void OpenGl_StateInterface::Revert()
57{
58 if (myIndex > 0)
59 {
60 --myIndex;
61 }
62}
63
64// =======================================================================
65// function : OpenGl_ProjectionState
66// purpose : Creates uninitialized projection state
67// =======================================================================
68OpenGl_ProjectionState::OpenGl_ProjectionState()
69: myInverseNeedUpdate (false)
70{
71 //
72}
73
74// =======================================================================
75// function : Set
76// purpose : Sets new OCCT projection state
77// =======================================================================
78void OpenGl_ProjectionState::Set (const Tmatrix3& theProjectionMatrix)
79{
80 memcpy (myProjectionMatrix, theProjectionMatrix, sizeof (Tmatrix3));
81 myInverseNeedUpdate = true;
82}
83
84// =======================================================================
85// function : ProjectionMatrix
86// purpose : Returns current projection matrix
87// =======================================================================
88const Tmatrix3& OpenGl_ProjectionState::ProjectionMatrix() const
89{
90 return myProjectionMatrix;
91}
92
93// =======================================================================
94// function : ProjectionMatrixInverse
95// purpose : Returns inverse of current projection matrix
96// =======================================================================
97const Tmatrix3& OpenGl_ProjectionState::ProjectionMatrixInverse() const
98{
99 if (!myInverseNeedUpdate)
100 {
101 return myProjectionMatrixInverse;
102 }
103
104 reinterpret_cast<const NCollection_Mat4<float>*> (*myProjectionMatrix)->Inverted (
105 *(reinterpret_cast<NCollection_Mat4<float>*> (*myProjectionMatrixInverse)));
106 return myProjectionMatrixInverse;
107}
108
109// =======================================================================
110// function : OpenGl_ModelWorldState
111// purpose : Creates uninitialized model-world state
112// =======================================================================
113OpenGl_ModelWorldState::OpenGl_ModelWorldState()
114: myInverseNeedUpdate (false)
115{
116 //
117}
118
119// =======================================================================
120// function : Set
121// purpose : Sets new model-world matrix
122// =======================================================================
123void OpenGl_ModelWorldState::Set (const Tmatrix3& theModelWorldMatrix)
124{
125 memcpy (myModelWorldMatrix, theModelWorldMatrix, sizeof (Tmatrix3));
126 myInverseNeedUpdate = true;
127}
128
129// =======================================================================
130// function : ModelWorldMatrix
131// purpose : Returns current model-world matrix
132// =======================================================================
133const Tmatrix3& OpenGl_ModelWorldState::ModelWorldMatrix() const
134{
135 return myModelWorldMatrix;
136}
137
138// =======================================================================
139// function : ModelWorldMatrixInverse
140// purpose : Returns inverse of current model-world matrix
141// =======================================================================
142const Tmatrix3& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
143{
144 if (!myInverseNeedUpdate)
145 {
146 return myModelWorldMatrix;
147 }
148
149 reinterpret_cast<const NCollection_Mat4<float>*> (*myModelWorldMatrix)->Inverted (
150 *(reinterpret_cast<NCollection_Mat4<float>*> (*myModelWorldMatrixInverse)));
151 return myModelWorldMatrixInverse;
152}
153
154// =======================================================================
155// function : OpenGl_WorldViewState
156// purpose : Creates uninitialized world-view state
157// =======================================================================
158OpenGl_WorldViewState::OpenGl_WorldViewState()
159: myInverseNeedUpdate (false)
160{
161 //
162}
163
164// =======================================================================
165// function : Set
166// purpose : Sets new world-view matrix
167// =======================================================================
168void OpenGl_WorldViewState::Set (const Tmatrix3& theWorldViewMatrix)
169{
170 memcpy (myWorldViewMatrix, theWorldViewMatrix, sizeof (Tmatrix3));
171 myInverseNeedUpdate = true;
172}
173
174// =======================================================================
175// function : WorldViewMatrix
176// purpose : Returns current world-view matrix
177// =======================================================================
178const Tmatrix3& OpenGl_WorldViewState::WorldViewMatrix() const
179{
180 return myWorldViewMatrix;
181}
182
183// =======================================================================
184// function : WorldViewMatrixInverse
185// purpose : Returns inverse of current world-view matrix
186// =======================================================================
187const Tmatrix3& OpenGl_WorldViewState::WorldViewMatrixInverse() const
188{
189 if (!myInverseNeedUpdate)
190 {
191 return myWorldViewMatrix;
192 }
193
194 reinterpret_cast<const NCollection_Mat4<float>*> (*myWorldViewMatrix)->Inverted (
195 *(reinterpret_cast<NCollection_Mat4<float>*> (*myWorldViewMatrixInverse)));
196 return myWorldViewMatrixInverse;
197}
198
199// =======================================================================
200// function : OpenGl_LightSourceState
201// purpose : Creates uninitialized state of light sources
202// =======================================================================
203OpenGl_LightSourceState::OpenGl_LightSourceState()
204: myLightSources (NULL)
205{
206 //
207}
208
209// =======================================================================
210// function : Set
211// purpose : Sets new light sources
212// =======================================================================
213void OpenGl_LightSourceState::Set (const OpenGl_ListOfLight* theLightSources)
214{
215 myLightSources = theLightSources;
216}
217
218// =======================================================================
219// function : LightSources
220// purpose : Returns current list of light sources
221// =======================================================================
222const OpenGl_ListOfLight* OpenGl_LightSourceState::LightSources() const
223{
224 return myLightSources;
225}
226
227// =======================================================================
228// function : OpenGl_MaterialState
229// purpose : Creates uninitialized material state
230// =======================================================================
231OpenGl_MaterialState::OpenGl_MaterialState (const OpenGl_Element* theAspect)
232: myAspect (theAspect)
233{
234 //
235}
236
237// =======================================================================
238// function : Set
239// purpose : Sets new material aspect
240// =======================================================================
241void OpenGl_MaterialState::Set (const OpenGl_Element* theAspect)
242{
243 myAspect = theAspect;
244}
245
246// =======================================================================
247// function : Aspect
248// purpose : Returns material aspect
249// =======================================================================
250const OpenGl_Element* OpenGl_MaterialState::Aspect() const
251{
252 return myAspect;
253}
254
255// =======================================================================
256// function : OpenGl_ClippingState
257// purpose : Creates new clipping state
258// =======================================================================
259OpenGl_ClippingState::OpenGl_ClippingState()
260{
261 //
262}