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