0024250: TKOpenGl - per-pixel lighting using GLSL program (Phong shading)
[occt.git] / src / OpenGl / OpenGl_ShaderManager.hxx
CommitLineData
30f0ad28 1// Created on: 2013-09-26
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2013 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20#ifndef _OpenGl_ShaderManager_HeaderFile
21#define _OpenGl_ShaderManager_HeaderFile
22
23#include <Graphic3d_ShaderProgram_Handle.hxx>
24
25#include <NCollection_DataMap.hxx>
26#include <NCollection_Sequence.hxx>
27
28#include <Handle_OpenGl_ShaderManager.hxx>
29#include <OpenGl_ShaderProgram.hxx>
30#include <OpenGl_ShaderStates.hxx>
31
32//! List of shader programs.
33typedef NCollection_Sequence<Handle(OpenGl_ShaderProgram)> OpenGl_ShaderProgramList;
34
35//! Map to declare per-program states of OCCT materials.
36typedef NCollection_DataMap<Handle(OpenGl_ShaderProgram), OpenGl_MaterialState> OpenGl_MaterialStates;
37
38//! This class is responsible for managing shader programs.
39class OpenGl_ShaderManager : public Standard_Transient
40{
41 friend class OpenGl_ShaderProgram;
42
43public:
44
45 //! Creates new empty shader manager.
46 Standard_EXPORT OpenGl_ShaderManager (OpenGl_Context* theContext);
47
48 //! Releases resources of shader manager.
49 Standard_EXPORT virtual ~OpenGl_ShaderManager();
50
392ac980 51 //! Creates new shader program or re-use shared instance.
52 //! @param theProxy [IN] program definition
53 //! @param theShareKey [OUT] sharing key
54 //! @param theProgram [OUT] OpenGL program
55 Standard_EXPORT void Create (const Handle(Graphic3d_ShaderProgram)& theProxy,
56 TCollection_AsciiString& theShareKey,
57 Handle(OpenGl_ShaderProgram)& theProgram);
30f0ad28 58
59 //! Unregisters specified shader program.
392ac980 60 Standard_EXPORT void Unregister (TCollection_AsciiString& theShareKey,
61 Handle(OpenGl_ShaderProgram)& theProgram);
30f0ad28 62
63 //! Returns list of registered shader programs.
64 Standard_EXPORT const OpenGl_ShaderProgramList& ShaderPrograms() const;
65
66 //! Returns true if no program objects are registered in the manager.
67 Standard_EXPORT Standard_Boolean IsEmpty() const;
68
69 DEFINE_STANDARD_RTTI (OpenGl_ShaderManager)
70
71protected:
72
73 OpenGl_MaterialStates myMaterialStates; //!< Per-program state of OCCT material
74 OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation
75 OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation
76 OpenGl_WorldViewState myWorldViewState; //!< State of OCCT world-view transformation
77 OpenGl_LightSourceState myClippingState; //!< State of OCCT clipping planes
78 OpenGl_LightSourceState myLightSourceState; //!< State of OCCT light sources
79
80public:
81
82 //! Returns current state of OCCT light sources.
83 Standard_EXPORT const OpenGl_LightSourceState& LightSourceState() const;
84
85 //! Updates state of OCCT light sources.
86 Standard_EXPORT void UpdateLightSourceStateTo (const OpenGl_ListOfLight* theLights);
87
88 //! Pushes current state of OCCT light sources to specified program.
89 Standard_EXPORT void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
90
91public:
92
93 //! Returns current state of OCCT projection transform.
94 Standard_EXPORT const OpenGl_ProjectionState& ProjectionState() const;
95
96 //! Updates state of OCCT projection transform.
97 Standard_EXPORT void UpdateProjectionStateTo (const Tmatrix3& theProjectionMatrix);
98
99 //! Reverts state of OCCT projection transform.
100 Standard_EXPORT void RevertProjectionStateTo (const Tmatrix3& theProjectionMatrix);
101
102 //! Pushes current state of OCCT projection transform to specified program.
103 Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
104
105public:
106
107 //! Returns current state of OCCT model-world transform.
108 Standard_EXPORT const OpenGl_ModelWorldState& ModelWorldState() const;
109
110 //! Updates state of OCCT model-world transform.
111 Standard_EXPORT void UpdateModelWorldStateTo (const Tmatrix3& theModelWorldMatrix);
112
113 //! Reverts state of OCCT model-world transform.
114 Standard_EXPORT void RevertModelWorldStateTo (const Tmatrix3& theModelWorldMatrix);
115
116 //! Pushes current state of OCCT model-world transform to specified program.
117 Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
118
119public:
120
121 //! Returns current state of OCCT world-view transform.
122 Standard_EXPORT const OpenGl_WorldViewState& WorldViewState() const;
123
124 //! Updates state of OCCT world-view transform.
125 Standard_EXPORT void UpdateWorldViewStateTo (const Tmatrix3& theWorldViewMatrix);
126
127 //! Reverts state of OCCT world-view transform.
128 Standard_EXPORT void RevertWorldViewStateTo (const Tmatrix3& theWorldViewMatrix);
129
130 //! Pushes current state of OCCT world-view transform to specified program.
131 Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
132
133public:
134
135 //! Updates state of OCCT clipping planes.
136 Standard_EXPORT void UpdateClippingState();
137
138 //! Reverts state of OCCT clipping planes.
139 Standard_EXPORT void RevertClippingState();
140
141 //! Pushes current state of OCCT clipping planes to specified program.
142 Standard_EXPORT void PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
143
144public:
145
146 //! Resets state of OCCT material for all programs.
147 Standard_EXPORT void ResetMaterialStates();
148
149 //! Updates state of OCCT material for specified program.
150 Standard_EXPORT void UpdateMaterialStateTo (const Handle(OpenGl_ShaderProgram)& theProgram,
151 const OpenGl_Element* theAspect);
152
153 //! Pushes current state of OCCT material to specified program.
154 Standard_EXPORT void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
155
156 //! Returns current state of OCCT material for specified program.
157 Standard_EXPORT const OpenGl_MaterialState* MaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
158
159public:
160
161 //! Pushes current state of OCCT graphics parameters to specified program.
162 Standard_EXPORT void PushState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
163
392ac980 164public:
165
166 //! Overwrites context
167 void SetContext (OpenGl_Context* theCtx)
168 {
169 myContext = theCtx;
170 }
171
30f0ad28 172protected:
173
174 OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs
175 OpenGl_Context* myContext; //!< The OpenGL context
176
177private:
178
179 Standard_Boolean myIsPP; //!< Is any program object bound (programmable pipeline)?
180
181};
182
183#endif // _OpenGl_ShaderManager_HeaderFile