0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / OpenGl / OpenGl_ShaderStates.hxx
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
5bd54bef 16#ifndef OpenGl_ShaderStates_HeaderFile
17#define OpenGl_ShaderStates_HeaderFile
30f0ad28 18
78c4e836 19#include <Graphic3d_RenderTransparentMethod.hxx>
992ed6b3 20#include <Graphic3d_LightSet.hxx>
30f0ad28 21#include <OpenGl_Element.hxx>
c827ea3a 22#include <OpenGl_Vec.hxx>
ca102800 23
d84e8669 24class OpenGl_ShadowMapArray;
25
30f0ad28 26//! Defines interface for OpenGL state.
27class OpenGl_StateInterface
28{
29public:
30
8cf06aa2 31 //! Creates new state.
96fffdc6 32 Standard_EXPORT OpenGl_StateInterface();
30f0ad28 33
34 //! Returns current state index.
8cf06aa2 35 Standard_Size Index() const { return myIndex; }
30f0ad28 36
8cf06aa2 37 //! Increment current state.
38 void Update() { ++myIndex; }
30f0ad28 39
40protected:
41
8cf06aa2 42 Standard_Size myIndex; //!< current state index
30f0ad28 43
44};
45
46//! Defines state of OCCT projection transformation.
47class OpenGl_ProjectionState : public OpenGl_StateInterface
48{
49public:
50
51 //! Creates uninitialized projection state.
96fffdc6 52 Standard_EXPORT OpenGl_ProjectionState();
30f0ad28 53
54 //! Sets new projection matrix.
96fffdc6 55 Standard_EXPORT void Set (const OpenGl_Mat4& theProjectionMatrix);
30f0ad28 56
57 //! Returns current projection matrix.
14a356b1 58 const OpenGl_Mat4& ProjectionMatrix() const { return myProjectionMatrix; }
30f0ad28 59
60 //! Returns inverse of current projection matrix.
96fffdc6 61 Standard_EXPORT const OpenGl_Mat4& ProjectionMatrixInverse() const;
30f0ad28 62
63private:
64
c827ea3a 65 OpenGl_Mat4 myProjectionMatrix; //!< OCCT projection matrix
66 mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix
14a356b1 67 mutable bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
30f0ad28 68
69};
70
71//! Defines state of OCCT model-world transformation.
72class OpenGl_ModelWorldState : public OpenGl_StateInterface
73{
74public:
75
76 //! Creates uninitialized model-world state.
96fffdc6 77 Standard_EXPORT OpenGl_ModelWorldState();
30f0ad28 78
79 //! Sets new model-world matrix.
96fffdc6 80 Standard_EXPORT void Set (const OpenGl_Mat4& theModelWorldMatrix);
30f0ad28 81
82 //! Returns current model-world matrix.
14a356b1 83 const OpenGl_Mat4& ModelWorldMatrix() const { return myModelWorldMatrix; }
30f0ad28 84
85 //! Returns inverse of current model-world matrix.
96fffdc6 86 Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrixInverse() const;
30f0ad28 87
88private:
89
c827ea3a 90 OpenGl_Mat4 myModelWorldMatrix; //!< OCCT model-world matrix
91 mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix
14a356b1 92 mutable bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
30f0ad28 93
94};
95
96//! Defines state of OCCT world-view transformation.
97class OpenGl_WorldViewState : public OpenGl_StateInterface
98{
99public:
100
101 //! Creates uninitialized world-view state.
96fffdc6 102 Standard_EXPORT OpenGl_WorldViewState();
e135a155 103
30f0ad28 104 //! Sets new world-view matrix.
96fffdc6 105 Standard_EXPORT void Set (const OpenGl_Mat4& theWorldViewMatrix);
30f0ad28 106
107 //! Returns current world-view matrix.
14a356b1 108 const OpenGl_Mat4& WorldViewMatrix() const { return myWorldViewMatrix; }
30f0ad28 109
110 //! Returns inverse of current world-view matrix.
96fffdc6 111 Standard_EXPORT const OpenGl_Mat4& WorldViewMatrixInverse() const;
30f0ad28 112
113private:
114
c827ea3a 115 OpenGl_Mat4 myWorldViewMatrix; //!< OCCT world-view matrix
116 mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix
14a356b1 117 mutable bool myInverseNeedUpdate; //!< Is inversed matrix outdated?
30f0ad28 118
119};
120
121//! Defines state of OCCT light sources.
122class OpenGl_LightSourceState : public OpenGl_StateInterface
123{
124public:
125
126 //! Creates uninitialized state of light sources.
d84e8669 127 OpenGl_LightSourceState() : mySpecIBLMapLevels (0), myToCastShadows (Standard_True) {}
30f0ad28 128
129 //! Sets new light sources.
992ed6b3 130 void Set (const Handle(Graphic3d_LightSet)& theLightSources) { myLightSources = theLightSources; }
30f0ad28 131
132 //! Returns current list of light sources.
992ed6b3 133 const Handle(Graphic3d_LightSet)& LightSources() const { return myLightSources; }
30f0ad28 134
67312b79 135 //! Returns number of mipmap levels used in specular IBL map.
136 //! 0 by default or in case of using non-PBR shading model.
137 Standard_Integer SpecIBLMapLevels() const { return mySpecIBLMapLevels; }
138
139 //! Sets number of mipmap levels used in specular IBL map.
140 void SetSpecIBLMapLevels(Standard_Integer theSpecIBLMapLevels) { mySpecIBLMapLevels = theSpecIBLMapLevels; }
141
d84e8669 142 //! Returns TRUE if shadowmap is set.
143 bool HasShadowMaps() const { return myToCastShadows && !myShadowMaps.IsNull(); }
144
145 //! Returns shadowmap.
146 const Handle(OpenGl_ShadowMapArray)& ShadowMaps() const { return myShadowMaps; }
147
148 //! Sets shadowmap.
149 void SetShadowMaps (const Handle(OpenGl_ShadowMapArray)& theMap) { myShadowMaps = theMap; }
150
151 //! Returns TRUE if shadowmap should be enabled when available; TRUE by default.
152 bool ToCastShadows() const { return myToCastShadows; }
153
154 //! Set if shadowmap should be enabled when available.
155 void SetCastShadows (bool theToCast) { myToCastShadows = theToCast; }
156
30f0ad28 157private:
158
67312b79 159 Handle(Graphic3d_LightSet) myLightSources; //!< List of OCCT light sources
160 Standard_Integer mySpecIBLMapLevels; //!< Number of mipmap levels used in specular IBL map (0 by default or in case of using non-PBR shading model)
d84e8669 161 Handle(OpenGl_ShadowMapArray) myShadowMaps; //!< active shadowmap
162 Standard_Boolean myToCastShadows; //!< enable/disable shadowmap
30f0ad28 163
164};
165
30f0ad28 166//! Defines generic state of OCCT clipping state.
8cf06aa2 167class OpenGl_ClippingState
30f0ad28 168{
169public:
170
171 //! Creates new clipping state.
96fffdc6 172 Standard_EXPORT OpenGl_ClippingState();
30f0ad28 173
8cf06aa2 174 //! Returns current state index.
175 Standard_Size Index() const { return myIndex; }
176
177 //! Updates current state.
96fffdc6 178 Standard_EXPORT void Update();
8cf06aa2 179
180 //! Reverts current state.
96fffdc6 181 Standard_EXPORT void Revert();
8cf06aa2 182
183protected:
184
185 Standard_Size myIndex; //!< Current state index
186 Standard_Size myNextIndex; //!< Next state index
187 NCollection_List<Standard_Size> myStateStack; //!< Stack of previous states
188
30f0ad28 189};
190
a1073ae2 191//! Defines generic state of order-independent transparency rendering properties.
192class OpenGl_OitState : public OpenGl_StateInterface
193{
194public:
195
196 //! Creates new uniform state.
78c4e836 197 OpenGl_OitState() : myOitMode (Graphic3d_RTM_BLEND_UNORDERED), myDepthFactor (0.5f) {}
a1073ae2 198
199 //! Sets the uniform values.
200 //! @param theToEnableWrite [in] flag indicating whether color and coverage
201 //! values for OIT processing should be written by shader program.
202 //! @param theDepthFactor [in] scalar factor [0-1] defining influence of depth
203 //! component of a fragment to its final coverage coefficient.
78c4e836 204 void Set (Graphic3d_RenderTransparentMethod theMode,
a1073ae2 205 const float theDepthFactor)
206 {
78c4e836 207 myOitMode = theMode;
208 myDepthFactor = static_cast<float> (Max (0.f, Min (1.f, theDepthFactor)));
a1073ae2 209 }
210
211 //! Returns flag indicating whether writing of output for OIT processing
212 //! should be enabled/disabled.
78c4e836 213 Graphic3d_RenderTransparentMethod ActiveMode() const { return myOitMode; }
a1073ae2 214
215 //! Returns factor defining influence of depth component of a fragment
216 //! to its final coverage coefficient.
217 float DepthFactor() const { return myDepthFactor; }
218
219private:
220
78c4e836 221 Graphic3d_RenderTransparentMethod myOitMode; //!< active OIT method for the main GLSL program
222 float myDepthFactor; //!< factor of depth influence to coverage
a1073ae2 223};
224
30f0ad28 225#endif // _OpenGl_State_HeaderFile