0027341: Incorrect exact HLR results
[occt.git] / src / OpenGl / OpenGl_ShaderStates.hxx
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 #ifndef _OpenGl_State_HeaderFile
17 #define _OpenGl_State_HeaderFile
18
19 #include <InterfaceGraphic_tgl_all.hxx>
20 #include <NCollection_List.hxx>
21 #include <OpenGl_Element.hxx>
22 #include <OpenGl_Light.hxx>
23 #include <OpenGl_Vec.hxx>
24
25 //! Defines interface for OpenGL state.
26 class OpenGl_StateInterface
27 {
28 public:
29
30   //! Creates new state.
31   OpenGl_StateInterface();
32
33   //! Returns current state index.
34   Standard_Size Index() const { return myIndex; }
35
36   //! Increment current state.
37   void Update() { ++myIndex; }
38
39 protected:
40
41   Standard_Size myIndex; //!< current state index
42
43 };
44
45 //! Defines state of OCCT projection transformation.
46 class OpenGl_ProjectionState : public OpenGl_StateInterface
47 {
48 public:
49
50   //! Creates uninitialized projection state.
51   OpenGl_ProjectionState();
52
53   //! Sets new projection matrix.
54   void Set (const OpenGl_Mat4& theProjectionMatrix);
55
56   //! Returns current projection matrix.
57   const OpenGl_Mat4& ProjectionMatrix() const;
58
59   //! Returns inverse of current projection matrix.
60   const OpenGl_Mat4& ProjectionMatrixInverse() const;
61
62 private:
63
64   OpenGl_Mat4         myProjectionMatrix;        //!< OCCT projection matrix
65   mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix
66   bool                myInverseNeedUpdate;       //!< Is inversed matrix outdated?
67
68 };
69
70 //! Defines state of OCCT model-world transformation.
71 class OpenGl_ModelWorldState : public OpenGl_StateInterface
72 {
73 public:
74
75   //! Creates uninitialized model-world state.
76   OpenGl_ModelWorldState();
77
78   //! Sets new model-world matrix.
79   void Set (const OpenGl_Mat4& theModelWorldMatrix);
80
81   //! Returns current model-world matrix.
82   const OpenGl_Mat4& ModelWorldMatrix() const;
83
84   //! Returns inverse of current model-world matrix.
85   const OpenGl_Mat4& ModelWorldMatrixInverse() const;
86
87 private:
88
89   OpenGl_Mat4         myModelWorldMatrix;        //!< OCCT model-world matrix
90   mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix
91   bool                myInverseNeedUpdate;       //!< Is inversed matrix outdated?
92   
93 };
94
95 //! Defines state of OCCT world-view transformation.
96 class OpenGl_WorldViewState : public OpenGl_StateInterface
97 {
98 public:
99
100   //! Creates uninitialized world-view state.
101   OpenGl_WorldViewState();
102
103   //! Sets new world-view matrix.
104   void Set (const OpenGl_Mat4& theWorldViewMatrix);
105
106   //! Returns current world-view matrix.
107   const OpenGl_Mat4& WorldViewMatrix() const;
108
109   //! Returns inverse of current world-view matrix.
110   const OpenGl_Mat4& WorldViewMatrixInverse() const;
111
112 private:
113
114   OpenGl_Mat4         myWorldViewMatrix;        //!< OCCT world-view matrix
115   mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix
116   bool                myInverseNeedUpdate;      //!< Is inversed matrix outdated?
117
118 };
119
120 //! Defines state of OCCT light sources.
121 class OpenGl_LightSourceState : public OpenGl_StateInterface
122 {
123 public:
124
125   //! Creates uninitialized state of light sources.
126   OpenGl_LightSourceState();
127
128   //! Sets new light sources.
129   void Set (const OpenGl_ListOfLight* theLightSources);
130
131   //! Returns current list of light sources.
132   const OpenGl_ListOfLight* LightSources() const;
133
134 private:
135
136   const OpenGl_ListOfLight* myLightSources; //!< List of OCCT light sources
137
138 };
139
140 //! Defines generic state of OCCT material properties.
141 class OpenGl_MaterialState : public OpenGl_StateInterface
142 {
143 public:
144
145   //! Creates new material state.
146   OpenGl_MaterialState (const OpenGl_Element* theAspect = NULL);
147
148   //! Sets new material aspect.
149   void Set (const OpenGl_Element* theAspect);
150
151   //! Returns material aspect.
152   const OpenGl_Element* Aspect() const;
153
154 private:
155
156   const OpenGl_Element* myAspect; //!< OCCT material aspect
157
158 };
159
160 //! Defines generic state of OCCT clipping state.
161 class OpenGl_ClippingState
162 {
163 public:
164
165   //! Creates new clipping state.
166   OpenGl_ClippingState();
167
168   //! Returns current state index.
169   Standard_Size Index() const { return myIndex; }
170
171   //! Updates current state.
172   void Update();
173
174   //! Reverts current state.
175   void Revert();
176
177 protected:
178
179   Standard_Size                   myIndex;      //!< Current state index
180   Standard_Size                   myNextIndex;  //!< Next    state index
181   NCollection_List<Standard_Size> myStateStack; //!< Stack of previous states
182
183 };
184
185 #endif // _OpenGl_State_HeaderFile