0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[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
18// =======================================================================
19// function : OpenGl_StateInterface
8cf06aa2 20// purpose :
30f0ad28 21// =======================================================================
22OpenGl_StateInterface::OpenGl_StateInterface()
8cf06aa2 23: myIndex (0)
30f0ad28 24{
25 //
26}
27
28// =======================================================================
30f0ad28 29// function : OpenGl_ProjectionState
30// purpose : Creates uninitialized projection state
31// =======================================================================
32OpenGl_ProjectionState::OpenGl_ProjectionState()
33: myInverseNeedUpdate (false)
34{
35 //
36}
37
38// =======================================================================
39// function : Set
40// purpose : Sets new OCCT projection state
41// =======================================================================
c827ea3a 42void OpenGl_ProjectionState::Set (const OpenGl_Mat4& theProjectionMatrix)
30f0ad28 43{
c827ea3a 44 myProjectionMatrix = theProjectionMatrix;
30f0ad28 45 myInverseNeedUpdate = true;
46}
47
48// =======================================================================
49// function : ProjectionMatrix
50// purpose : Returns current projection matrix
51// =======================================================================
c827ea3a 52const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrix() const
30f0ad28 53{
54 return myProjectionMatrix;
55}
56
57// =======================================================================
58// function : ProjectionMatrixInverse
59// purpose : Returns inverse of current projection matrix
60// =======================================================================
c827ea3a 61const OpenGl_Mat4& OpenGl_ProjectionState::ProjectionMatrixInverse() const
30f0ad28 62{
63 if (!myInverseNeedUpdate)
64 {
65 return myProjectionMatrixInverse;
66 }
67
c827ea3a 68 myProjectionMatrix.Inverted (myProjectionMatrixInverse);
69
30f0ad28 70 return myProjectionMatrixInverse;
71}
72
73// =======================================================================
74// function : OpenGl_ModelWorldState
75// purpose : Creates uninitialized model-world state
76// =======================================================================
77OpenGl_ModelWorldState::OpenGl_ModelWorldState()
78: myInverseNeedUpdate (false)
79{
80 //
81}
82
83// =======================================================================
84// function : Set
85// purpose : Sets new model-world matrix
86// =======================================================================
c827ea3a 87void OpenGl_ModelWorldState::Set (const OpenGl_Mat4& theModelWorldMatrix)
30f0ad28 88{
c827ea3a 89 myModelWorldMatrix = theModelWorldMatrix;
30f0ad28 90 myInverseNeedUpdate = true;
91}
92
93// =======================================================================
94// function : ModelWorldMatrix
95// purpose : Returns current model-world matrix
96// =======================================================================
c827ea3a 97const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrix() const
30f0ad28 98{
99 return myModelWorldMatrix;
100}
101
102// =======================================================================
103// function : ModelWorldMatrixInverse
104// purpose : Returns inverse of current model-world matrix
105// =======================================================================
c827ea3a 106const OpenGl_Mat4& OpenGl_ModelWorldState::ModelWorldMatrixInverse() const
30f0ad28 107{
108 if (!myInverseNeedUpdate)
109 {
110 return myModelWorldMatrix;
111 }
112
c827ea3a 113 myModelWorldMatrix.Inverted (myModelWorldMatrixInverse);
114
30f0ad28 115 return myModelWorldMatrixInverse;
116}
117
118// =======================================================================
119// function : OpenGl_WorldViewState
120// purpose : Creates uninitialized world-view state
121// =======================================================================
122OpenGl_WorldViewState::OpenGl_WorldViewState()
123: myInverseNeedUpdate (false)
124{
125 //
126}
127
128// =======================================================================
129// function : Set
130// purpose : Sets new world-view matrix
131// =======================================================================
c827ea3a 132void OpenGl_WorldViewState::Set (const OpenGl_Mat4& theWorldViewMatrix)
30f0ad28 133{
c827ea3a 134 myWorldViewMatrix = theWorldViewMatrix;
30f0ad28 135 myInverseNeedUpdate = true;
136}
137
138// =======================================================================
139// function : WorldViewMatrix
140// purpose : Returns current world-view matrix
141// =======================================================================
c827ea3a 142const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrix() const
30f0ad28 143{
144 return myWorldViewMatrix;
145}
146
147// =======================================================================
148// function : WorldViewMatrixInverse
149// purpose : Returns inverse of current world-view matrix
150// =======================================================================
c827ea3a 151const OpenGl_Mat4& OpenGl_WorldViewState::WorldViewMatrixInverse() const
30f0ad28 152{
153 if (!myInverseNeedUpdate)
154 {
155 return myWorldViewMatrix;
156 }
157
c827ea3a 158 myWorldViewMatrix.Inverted (myWorldViewMatrixInverse);
159
30f0ad28 160 return myWorldViewMatrixInverse;
161}
162
163// =======================================================================
30f0ad28 164// function : OpenGl_ClippingState
165// purpose : Creates new clipping state
166// =======================================================================
167OpenGl_ClippingState::OpenGl_ClippingState()
8cf06aa2 168: myIndex (0),
169 myNextIndex (1)
30f0ad28 170{
171 //
172}
8cf06aa2 173
174// =======================================================================
175// function : Update
176// purpose : Updates current state
177// =======================================================================
178void OpenGl_ClippingState::Update()
179{
180 myStateStack.Prepend (myIndex);
181 myIndex = myNextIndex; // use myNextIndex here to handle properly Update() after Revert()
182 ++myNextIndex;
183}
184
185// =======================================================================
186// function : Revert
187// purpose : Reverts current state
188// =======================================================================
189void OpenGl_ClippingState::Revert()
190{
191 if (!myStateStack.IsEmpty())
192 {
193 myIndex = myStateStack.First();
194 myStateStack.RemoveFirst();
195 }
196 else
197 {
198 myIndex = 0;
199 }
200}