0025456: BOPAlgo_CheckerSI reports an error on the given shape
[occt.git] / src / OpenGl / OpenGl_ShaderStates.cxx
CommitLineData
30f0ad28 1// Created on: 2013-10-02
2// Created by: Denis BOGOLEPOV
d5f74e42 3// Copyright (c) 2013-2014 OPEN CASCADE SAS
30f0ad28 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
30f0ad28 6//
d5f74e42 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
973c2be1 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.
30f0ad28 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
30f0ad28 15
16#include <NCollection_Mat4.hxx>
17
18#include <OpenGl_ShaderStates.hxx>
19
20// =======================================================================
21// function : OpenGl_StateInterface
22// purpose : Creates new OCCT state
23// =======================================================================
24OpenGl_StateInterface::OpenGl_StateInterface()
ca102800 25: myIndex (0),
26 myNextIndex (1)
30f0ad28 27{
28 //
29}
30
31// =======================================================================
32// function : Index
33// purpose : Returns current state index
34// =======================================================================
35Standard_Size OpenGl_StateInterface::Index() const
36{
37 return myIndex;
38}
39
40// =======================================================================
41// function : Update
42// purpose : Updates current state
43// =======================================================================
44void OpenGl_StateInterface::Update()
45{
6af4fe1c 46 myStateStack.Prepend (myIndex);
ca102800 47 myIndex = myNextIndex;
48 ++myNextIndex;
30f0ad28 49}
50
51// =======================================================================
52// function : Revert
53// purpose : Reverts current state
54// =======================================================================
55void OpenGl_StateInterface::Revert()
56{
ca102800 57 if (!myStateStack.IsEmpty())
30f0ad28 58 {
6af4fe1c 59 myIndex = myStateStack.First();
60 myStateStack.RemoveFirst();
ca102800 61 }
62 else
63 {
64 myIndex = 0;
30f0ad28 65 }
66}
67
68// =======================================================================
69// function : OpenGl_ProjectionState
70// purpose : Creates uninitialized projection state
71// =======================================================================
72OpenGl_ProjectionState::OpenGl_ProjectionState()
73: myInverseNeedUpdate (false)
74{
75 //
76}
77
78// =======================================================================
79// function : Set
80// purpose : Sets new OCCT projection state
81// =======================================================================
c827ea3a 82void OpenGl_ProjectionState::Set (const OpenGl_Mat4& theProjectionMatrix)
30f0ad28 83{
c827ea3a 84 myProjectionMatrix = theProjectionMatrix;
30f0ad28 85 myInverseNeedUpdate = true;
86}
87
88// =======================================================================
89// function : ProjectionMatrix
90// purpose : Returns current projection matrix
91// =======================================================================
c827ea3a 92const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrix() const
30f0ad28 93{
94 return myProjectionMatrix;
95}
96
97// =======================================================================
98// function : ProjectionMatrixInverse
99// purpose : Returns inverse of current projection matrix
100// =======================================================================
c827ea3a 101const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
30f0ad28 102{
103 if (!myInverseNeedUpdate)
104 {
105 return myProjectionMatrixInverse;
106 }
107
c827ea3a 108 myProjectionMatrix.Inverted (myProjectionMatrixInverse);
109
30f0ad28 110 return myProjectionMatrixInverse;
111}
112
113// =======================================================================
114// function : OpenGl_ModelWorldState
115// purpose : Creates uninitialized model-world state
116// =======================================================================
117OpenGl_ModelWorldState::OpenGl_ModelWorldState()
118: myInverseNeedUpdate (false)
119{
120 //
121}
122
123// =======================================================================
124// function : Set
125// purpose : Sets new model-world matrix
126// =======================================================================
c827ea3a 127void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
30f0ad28 128{
c827ea3a 129 myModelWorldMatrix = theModelWorldMatrix;
30f0ad28 130 myInverseNeedUpdate = true;
131}
132
133// =======================================================================
134// function : ModelWorldMatrix
135// purpose : Returns current model-world matrix
136// =======================================================================
c827ea3a 137const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrix() const
30f0ad28 138{
139 return myModelWorldMatrix;
140}
141
142// =======================================================================
143// function : ModelWorldMatrixInverse
144// purpose : Returns inverse of current model-world matrix
145// =======================================================================
c827ea3a 146const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
30f0ad28 147{
148 if (!myInverseNeedUpdate)
149 {
150 return myModelWorldMatrix;
151 }
152
c827ea3a 153 myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
154
30f0ad28 155 return myModelWorldMatrixInverse;
156}
157
158// =======================================================================
159// function : OpenGl_WorldViewState
160// purpose : Creates uninitialized world-view state
161// =======================================================================
162OpenGl_WorldViewState::OpenGl_WorldViewState()
163: myInverseNeedUpdate (false)
164{
165 //
166}
167
168// =======================================================================
169// function : Set
170// purpose : Sets new world-view matrix
171// =======================================================================
c827ea3a 172void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
30f0ad28 173{
c827ea3a 174 myWorldViewMatrix = theWorldViewMatrix;
30f0ad28 175 myInverseNeedUpdate = true;
176}
177
178// =======================================================================
179// function : WorldViewMatrix
180// purpose : Returns current world-view matrix
181// =======================================================================
c827ea3a 182const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrix() const
30f0ad28 183{
184 return myWorldViewMatrix;
185}
186
187// =======================================================================
188// function : WorldViewMatrixInverse
189// purpose : Returns inverse of current world-view matrix
190// =======================================================================
c827ea3a 191const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
30f0ad28 192{
193 if (!myInverseNeedUpdate)
194 {
195 return myWorldViewMatrix;
196 }
197
c827ea3a 198 myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
199
30f0ad28 200 return myWorldViewMatrixInverse;
201}
202
203// =======================================================================
204// function : OpenGl_LightSourceState
205// purpose : Creates uninitialized state of light sources
206// =======================================================================
207OpenGl_LightSourceState::OpenGl_LightSourceState()
208: myLightSources (NULL)
209{
210 //
211}
212
213// =======================================================================
214// function : Set
215// purpose : Sets new light sources
216// =======================================================================
217void OpenGl_LightSourceState::Set (const OpenGl_ListOfLight* theLightSources)
218{
219 myLightSources = theLightSources;
220}
221
222// =======================================================================
223// function : LightSources
224// purpose : Returns current list of light sources
225// =======================================================================
226const OpenGl_ListOfLight* OpenGl_LightSourceState::LightSources() const
227{
228 return myLightSources;
229}
230
231// =======================================================================
232// function : OpenGl_MaterialState
233// purpose : Creates uninitialized material state
234// =======================================================================
235OpenGl_MaterialState::OpenGl_MaterialState (const OpenGl_Element* theAspect)
236: myAspect (theAspect)
237{
238 //
239}
240
241// =======================================================================
242// function : Set
243// purpose : Sets new material aspect
244// =======================================================================
245void OpenGl_MaterialState::Set (const OpenGl_Element* theAspect)
246{
247 myAspect = theAspect;
248}
249
250// =======================================================================
251// function : Aspect
252// purpose : Returns material aspect
253// =======================================================================
254const OpenGl_Element* OpenGl_MaterialState::Aspect() const
255{
256 return myAspect;
257}
258
259// =======================================================================
260// function : OpenGl_ClippingState
261// purpose : Creates new clipping state
262// =======================================================================
263OpenGl_ClippingState::OpenGl_ClippingState()
264{
265 //
266}