1 // Created on: 2013-10-02
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_State_HeaderFile
17 #define _OpenGl_State_HeaderFile
19 #include <NCollection_List.hxx>
20 #include <Graphic3d_LightSet.hxx>
21 #include <OpenGl_Element.hxx>
22 #include <OpenGl_Vec.hxx>
24 //! Defines interface for OpenGL state.
25 class OpenGl_StateInterface
29 //! Creates new state.
30 Standard_EXPORT OpenGl_StateInterface();
32 //! Returns current state index.
33 Standard_Size Index() const { return myIndex; }
35 //! Increment current state.
36 void Update() { ++myIndex; }
40 Standard_Size myIndex; //!< current state index
44 //! Defines state of OCCT projection transformation.
45 class OpenGl_ProjectionState : public OpenGl_StateInterface
49 //! Creates uninitialized projection state.
50 Standard_EXPORT OpenGl_ProjectionState();
52 //! Sets new projection matrix.
53 Standard_EXPORT void Set (const OpenGl_Mat4& theProjectionMatrix);
55 //! Returns current projection matrix.
56 Standard_EXPORT const OpenGl_Mat4& ProjectionMatrix() const;
58 //! Returns inverse of current projection matrix.
59 Standard_EXPORT const OpenGl_Mat4& ProjectionMatrixInverse() const;
63 OpenGl_Mat4 myProjectionMatrix; //!< OCCT projection matrix
64 mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix
65 bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
69 //! Defines state of OCCT model-world transformation.
70 class OpenGl_ModelWorldState : public OpenGl_StateInterface
74 //! Creates uninitialized model-world state.
75 Standard_EXPORT OpenGl_ModelWorldState();
77 //! Sets new model-world matrix.
78 Standard_EXPORT void Set (const OpenGl_Mat4& theModelWorldMatrix);
80 //! Returns current model-world matrix.
81 Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrix() const;
83 //! Returns inverse of current model-world matrix.
84 Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrixInverse() const;
88 OpenGl_Mat4 myModelWorldMatrix; //!< OCCT model-world matrix
89 mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix
90 bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
94 //! Defines state of OCCT world-view transformation.
95 class OpenGl_WorldViewState : public OpenGl_StateInterface
99 //! Creates uninitialized world-view state.
100 Standard_EXPORT OpenGl_WorldViewState();
102 //! Sets new world-view matrix.
103 Standard_EXPORT void Set (const OpenGl_Mat4& theWorldViewMatrix);
105 //! Returns current world-view matrix.
106 Standard_EXPORT const OpenGl_Mat4& WorldViewMatrix() const;
108 //! Returns inverse of current world-view matrix.
109 Standard_EXPORT const OpenGl_Mat4& WorldViewMatrixInverse() const;
113 OpenGl_Mat4 myWorldViewMatrix; //!< OCCT world-view matrix
114 mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix
115 bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
119 //! Defines state of OCCT light sources.
120 class OpenGl_LightSourceState : public OpenGl_StateInterface
124 //! Creates uninitialized state of light sources.
125 OpenGl_LightSourceState() {}
127 //! Sets new light sources.
128 void Set (const Handle(Graphic3d_LightSet)& theLightSources) { myLightSources = theLightSources; }
130 //! Returns current list of light sources.
131 const Handle(Graphic3d_LightSet)& LightSources() const { return myLightSources; }
135 Handle(Graphic3d_LightSet) myLightSources; //!< List of OCCT light sources
139 //! Defines generic state of OCCT clipping state.
140 class OpenGl_ClippingState
144 //! Creates new clipping state.
145 Standard_EXPORT OpenGl_ClippingState();
147 //! Returns current state index.
148 Standard_Size Index() const { return myIndex; }
150 //! Updates current state.
151 Standard_EXPORT void Update();
153 //! Reverts current state.
154 Standard_EXPORT void Revert();
158 Standard_Size myIndex; //!< Current state index
159 Standard_Size myNextIndex; //!< Next state index
160 NCollection_List<Standard_Size> myStateStack; //!< Stack of previous states
164 //! Defines generic state of order-independent transparency rendering properties.
165 class OpenGl_OitState : public OpenGl_StateInterface
169 //! Creates new uniform state.
170 OpenGl_OitState() : myToEnableWrite (false), myDepthFactor (0.5f) {}
172 //! Sets the uniform values.
173 //! @param theToEnableWrite [in] flag indicating whether color and coverage
174 //! values for OIT processing should be written by shader program.
175 //! @param theDepthFactor [in] scalar factor [0-1] defining influence of depth
176 //! component of a fragment to its final coverage coefficient.
177 void Set (const bool theToEnableWrite,
178 const float theDepthFactor)
180 myToEnableWrite = theToEnableWrite;
181 myDepthFactor = static_cast<float> (Max (0.f, Min (1.f, theDepthFactor)));
184 //! Returns flag indicating whether writing of output for OIT processing
185 //! should be enabled/disabled.
186 bool ToEnableWrite() const { return myToEnableWrite; }
188 //! Returns factor defining influence of depth component of a fragment
189 //! to its final coverage coefficient.
190 float DepthFactor() const { return myDepthFactor; }
194 bool myToEnableWrite; //!< writing color and coverage.
195 float myDepthFactor; //!< factor of depth influence to coverage.
198 #endif // _OpenGl_State_HeaderFile