0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / OpenGl / OpenGl_ShaderStates.cxx
... / ...
CommitLineData
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#include <NCollection_Mat4.hxx>
19
20// =======================================================================
21// function : OpenGl_StateInterface
22// purpose :
23// =======================================================================
24OpenGl_StateInterface::OpenGl_StateInterface()
25: myIndex (0)
26{
27 //
28}
29
30// =======================================================================
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// =======================================================================
44void OpenGl_ProjectionState::Set (const OpenGl_Mat4& theProjectionMatrix)
45{
46 myProjectionMatrix = theProjectionMatrix;
47 myInverseNeedUpdate = true;
48}
49
50// =======================================================================
51// function : ProjectionMatrix
52// purpose : Returns current projection matrix
53// =======================================================================
54const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrix() const
55{
56 return myProjectionMatrix;
57}
58
59// =======================================================================
60// function : ProjectionMatrixInverse
61// purpose : Returns inverse of current projection matrix
62// =======================================================================
63const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
64{
65 if (!myInverseNeedUpdate)
66 {
67 return myProjectionMatrixInverse;
68 }
69
70 myProjectionMatrix.Inverted (myProjectionMatrixInverse);
71
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// =======================================================================
89void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
90{
91 myModelWorldMatrix = theModelWorldMatrix;
92 myInverseNeedUpdate = true;
93}
94
95// =======================================================================
96// function : ModelWorldMatrix
97// purpose : Returns current model-world matrix
98// =======================================================================
99const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrix() const
100{
101 return myModelWorldMatrix;
102}
103
104// =======================================================================
105// function : ModelWorldMatrixInverse
106// purpose : Returns inverse of current model-world matrix
107// =======================================================================
108const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
109{
110 if (!myInverseNeedUpdate)
111 {
112 return myModelWorldMatrix;
113 }
114
115 myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
116
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// =======================================================================
134void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
135{
136 myWorldViewMatrix = theWorldViewMatrix;
137 myInverseNeedUpdate = true;
138}
139
140// =======================================================================
141// function : WorldViewMatrix
142// purpose : Returns current world-view matrix
143// =======================================================================
144const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrix() const
145{
146 return myWorldViewMatrix;
147}
148
149// =======================================================================
150// function : WorldViewMatrixInverse
151// purpose : Returns inverse of current world-view matrix
152// =======================================================================
153const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
154{
155 if (!myInverseNeedUpdate)
156 {
157 return myWorldViewMatrix;
158 }
159
160 myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
161
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()
226: myIndex (0),
227 myNextIndex (1)
228{
229 //
230}
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}