0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[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
30f0ad28 16#include <OpenGl_ShaderStates.hxx>
17
8cf06aa2 18#include <NCollection_Mat4.hxx>
19
30f0ad28 20// =======================================================================
21// function : OpenGl_StateInterface
8cf06aa2 22// purpose :
30f0ad28 23// =======================================================================
24OpenGl_StateInterface::OpenGl_StateInterface()
8cf06aa2 25: myIndex (0)
30f0ad28 26{
27 //
28}
29
30// =======================================================================
30f0ad28 31// function : OpenGl_ProjectionState
32// purpose : Creates uninitialized projection state
33// =======================================================================
34OpenGl_ProjectionState::OpenGl_ProjectionState()
35: myInverseNeedUpdate (false)
36{
37 //
38}
39
40// =======================================================================
41// function : Set
42// purpose : Sets new OCCT projection state
43// =======================================================================
c827ea3a 44void OpenGl_ProjectionState::Set (const OpenGl_Mat4& theProjectionMatrix)
30f0ad28 45{
c827ea3a 46 myProjectionMatrix = theProjectionMatrix;
30f0ad28 47 myInverseNeedUpdate = true;
48}
49
50// =======================================================================
51// function : ProjectionMatrix
52// purpose : Returns current projection matrix
53// =======================================================================
c827ea3a 54const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrix() const
30f0ad28 55{
56 return myProjectionMatrix;
57}
58
59// =======================================================================
60// function : ProjectionMatrixInverse
61// purpose : Returns inverse of current projection matrix
62// =======================================================================
c827ea3a 63const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
30f0ad28 64{
65 if (!myInverseNeedUpdate)
66 {
67 return myProjectionMatrixInverse;
68 }
69
c827ea3a 70 myProjectionMatrix.Inverted (myProjectionMatrixInverse);
71
30f0ad28 72 return myProjectionMatrixInverse;
73}
74
75// =======================================================================
76// function : OpenGl_ModelWorldState
77// purpose : Creates uninitialized model-world state
78// =======================================================================
79OpenGl_ModelWorldState::OpenGl_ModelWorldState()
80: myInverseNeedUpdate (false)
81{
82 //
83}
84
85// =======================================================================
86// function : Set
87// purpose : Sets new model-world matrix
88// =======================================================================
c827ea3a 89void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
30f0ad28 90{
c827ea3a 91 myModelWorldMatrix = theModelWorldMatrix;
30f0ad28 92 myInverseNeedUpdate = true;
93}
94
95// =======================================================================
96// function : ModelWorldMatrix
97// purpose : Returns current model-world matrix
98// =======================================================================
c827ea3a 99const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrix() const
30f0ad28 100{
101 return myModelWorldMatrix;
102}
103
104// =======================================================================
105// function : ModelWorldMatrixInverse
106// purpose : Returns inverse of current model-world matrix
107// =======================================================================
c827ea3a 108const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
30f0ad28 109{
110 if (!myInverseNeedUpdate)
111 {
112 return myModelWorldMatrix;
113 }
114
c827ea3a 115 myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
116
30f0ad28 117 return myModelWorldMatrixInverse;
118}
119
120// =======================================================================
121// function : OpenGl_WorldViewState
122// purpose : Creates uninitialized world-view state
123// =======================================================================
124OpenGl_WorldViewState::OpenGl_WorldViewState()
125: myInverseNeedUpdate (false)
126{
127 //
128}
129
130// =======================================================================
131// function : Set
132// purpose : Sets new world-view matrix
133// =======================================================================
c827ea3a 134void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
30f0ad28 135{
c827ea3a 136 myWorldViewMatrix = theWorldViewMatrix;
30f0ad28 137 myInverseNeedUpdate = true;
138}
139
140// =======================================================================
141// function : WorldViewMatrix
142// purpose : Returns current world-view matrix
143// =======================================================================
c827ea3a 144const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrix() const
30f0ad28 145{
146 return myWorldViewMatrix;
147}
148
149// =======================================================================
150// function : WorldViewMatrixInverse
151// purpose : Returns inverse of current world-view matrix
152// =======================================================================
c827ea3a 153const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
30f0ad28 154{
155 if (!myInverseNeedUpdate)
156 {
157 return myWorldViewMatrix;
158 }
159
c827ea3a 160 myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
161
30f0ad28 162 return myWorldViewMatrixInverse;
163}
164
165// =======================================================================
166// function : OpenGl_LightSourceState
167// purpose : Creates uninitialized state of light sources
168// =======================================================================
169OpenGl_LightSourceState::OpenGl_LightSourceState()
170: myLightSources (NULL)
171{
172 //
173}
174
175// =======================================================================
176// function : Set
177// purpose : Sets new light sources
178// =======================================================================
179void OpenGl_LightSourceState::Set (const OpenGl_ListOfLight* theLightSources)
180{
181 myLightSources = theLightSources;
182}
183
184// =======================================================================
185// function : LightSources
186// purpose : Returns current list of light sources
187// =======================================================================
188const OpenGl_ListOfLight* OpenGl_LightSourceState::LightSources() const
189{
190 return myLightSources;
191}
192
193// =======================================================================
194// function : OpenGl_MaterialState
195// purpose : Creates uninitialized material state
196// =======================================================================
197OpenGl_MaterialState::OpenGl_MaterialState (const OpenGl_Element* theAspect)
198: myAspect (theAspect)
199{
200 //
201}
202
203// =======================================================================
204// function : Set
205// purpose : Sets new material aspect
206// =======================================================================
207void OpenGl_MaterialState::Set (const OpenGl_Element* theAspect)
208{
209 myAspect = theAspect;
210}
211
212// =======================================================================
213// function : Aspect
214// purpose : Returns material aspect
215// =======================================================================
216const OpenGl_Element* OpenGl_MaterialState::Aspect() const
217{
218 return myAspect;
219}
220
221// =======================================================================
222// function : OpenGl_ClippingState
223// purpose : Creates new clipping state
224// =======================================================================
225OpenGl_ClippingState::OpenGl_ClippingState()
8cf06aa2 226: myIndex (0),
227 myNextIndex (1)
30f0ad28 228{
229 //
230}
8cf06aa2 231
232// =======================================================================
233// function : Update
234// purpose : Updates current state
235// =======================================================================
236void OpenGl_ClippingState::Update()
237{
238 myStateStack.Prepend (myIndex);
239 myIndex = myNextIndex; // use myNextIndex here to handle properly Update() after Revert()
240 ++myNextIndex;
241}
242
243// =======================================================================
244// function : Revert
245// purpose : Reverts current state
246// =======================================================================
247void OpenGl_ClippingState::Revert()
248{
249 if (!myStateStack.IsEmpty())
250 {
251 myIndex = myStateStack.First();
252 myStateStack.RemoveFirst();
253 }
254 else
255 {
256 myIndex = 0;
257 }
258}