0024530: TKMesh - remove unused package IntPoly
[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//
973c2be1 5// This file is part of Open CASCADE Technology software library.
30f0ad28 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public 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.
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_ShaderManager_HeaderFile
17#define _OpenGl_ShaderManager_HeaderFile
18
19#include <Graphic3d_ShaderProgram_Handle.hxx>
20
21#include <NCollection_DataMap.hxx>
22#include <NCollection_Sequence.hxx>
23
24#include <Handle_OpenGl_ShaderManager.hxx>
25#include <OpenGl_ShaderProgram.hxx>
26#include <OpenGl_ShaderStates.hxx>
27
28//! List of shader programs.
29typedef NCollection_Sequence<Handle(OpenGl_ShaderProgram)> OpenGl_ShaderProgramList;
30
31//! Map to declare per-program states of OCCT materials.
32typedef NCollection_DataMap<Handle(OpenGl_ShaderProgram), OpenGl_MaterialState> OpenGl_MaterialStates;
33
34//! This class is responsible for managing shader programs.
35class OpenGl_ShaderManager : public Standard_Transient
36{
37 friend class OpenGl_ShaderProgram;
38
39public:
40
41 //! Creates new empty shader manager.
42 Standard_EXPORT OpenGl_ShaderManager (OpenGl_Context* theContext);
43
44 //! Releases resources of shader manager.
45 Standard_EXPORT virtual ~OpenGl_ShaderManager();
46
392ac980 47 //! Creates new shader program or re-use shared instance.
48 //! @param theProxy [IN] program definition
49 //! @param theShareKey [OUT] sharing key
50 //! @param theProgram [OUT] OpenGL program
51 Standard_EXPORT void Create (const Handle(Graphic3d_ShaderProgram)& theProxy,
52 TCollection_AsciiString& theShareKey,
53 Handle(OpenGl_ShaderProgram)& theProgram);
30f0ad28 54
55 //! Unregisters specified shader program.
392ac980 56 Standard_EXPORT void Unregister (TCollection_AsciiString& theShareKey,
57 Handle(OpenGl_ShaderProgram)& theProgram);
30f0ad28 58
59 //! Returns list of registered shader programs.
60 Standard_EXPORT const OpenGl_ShaderProgramList& ShaderPrograms() const;
61
62 //! Returns true if no program objects are registered in the manager.
63 Standard_EXPORT Standard_Boolean IsEmpty() const;
64
65 DEFINE_STANDARD_RTTI (OpenGl_ShaderManager)
66
67protected:
68
69 OpenGl_MaterialStates myMaterialStates; //!< Per-program state of OCCT material
70 OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation
71 OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation
72 OpenGl_WorldViewState myWorldViewState; //!< State of OCCT world-view transformation
73 OpenGl_LightSourceState myClippingState; //!< State of OCCT clipping planes
74 OpenGl_LightSourceState myLightSourceState; //!< State of OCCT light sources
75
76public:
77
78 //! Returns current state of OCCT light sources.
79 Standard_EXPORT const OpenGl_LightSourceState& LightSourceState() const;
80
81 //! Updates state of OCCT light sources.
82 Standard_EXPORT void UpdateLightSourceStateTo (const OpenGl_ListOfLight* theLights);
83
84 //! Pushes current state of OCCT light sources to specified program.
85 Standard_EXPORT void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
86
87public:
88
89 //! Returns current state of OCCT projection transform.
90 Standard_EXPORT const OpenGl_ProjectionState& ProjectionState() const;
91
92 //! Updates state of OCCT projection transform.
b5ac8292 93 Standard_EXPORT void UpdateProjectionStateTo (const Tmatrix3* theProjectionMatrix);
30f0ad28 94
95 //! Reverts state of OCCT projection transform.
b5ac8292 96 Standard_EXPORT void RevertProjectionStateTo (const Tmatrix3* theProjectionMatrix);
30f0ad28 97
98 //! Pushes current state of OCCT projection transform to specified program.
99 Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
100
101public:
102
103 //! Returns current state of OCCT model-world transform.
104 Standard_EXPORT const OpenGl_ModelWorldState& ModelWorldState() const;
105
106 //! Updates state of OCCT model-world transform.
b5ac8292 107 Standard_EXPORT void UpdateModelWorldStateTo (const Tmatrix3* theModelWorldMatrix);
30f0ad28 108
109 //! Reverts state of OCCT model-world transform.
b5ac8292 110 Standard_EXPORT void RevertModelWorldStateTo (const Tmatrix3* theModelWorldMatrix);
30f0ad28 111
112 //! Pushes current state of OCCT model-world transform to specified program.
113 Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
114
115public:
116
117 //! Returns current state of OCCT world-view transform.
118 Standard_EXPORT const OpenGl_WorldViewState& WorldViewState() const;
119
120 //! Updates state of OCCT world-view transform.
b5ac8292 121 Standard_EXPORT void UpdateWorldViewStateTo (const Tmatrix3* theWorldViewMatrix);
30f0ad28 122
123 //! Reverts state of OCCT world-view transform.
b5ac8292 124 Standard_EXPORT void RevertWorldViewStateTo (const Tmatrix3* theWorldViewMatrix);
30f0ad28 125
126 //! Pushes current state of OCCT world-view transform to specified program.
127 Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
128
129public:
130
131 //! Updates state of OCCT clipping planes.
132 Standard_EXPORT void UpdateClippingState();
133
134 //! Reverts state of OCCT clipping planes.
135 Standard_EXPORT void RevertClippingState();
136
137 //! Pushes current state of OCCT clipping planes to specified program.
138 Standard_EXPORT void PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
139
140public:
141
142 //! Resets state of OCCT material for all programs.
143 Standard_EXPORT void ResetMaterialStates();
144
145 //! Updates state of OCCT material for specified program.
146 Standard_EXPORT void UpdateMaterialStateTo (const Handle(OpenGl_ShaderProgram)& theProgram,
147 const OpenGl_Element* theAspect);
148
149 //! Pushes current state of OCCT material to specified program.
150 Standard_EXPORT void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
151
152 //! Returns current state of OCCT material for specified program.
153 Standard_EXPORT const OpenGl_MaterialState* MaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
154
155public:
156
157 //! Pushes current state of OCCT graphics parameters to specified program.
158 Standard_EXPORT void PushState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
159
392ac980 160public:
161
162 //! Overwrites context
163 void SetContext (OpenGl_Context* theCtx)
164 {
165 myContext = theCtx;
166 }
167
30f0ad28 168protected:
169
170 OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs
171 OpenGl_Context* myContext; //!< The OpenGL context
172
173private:
174
175 Standard_Boolean myIsPP; //!< Is any program object bound (programmable pipeline)?
176
177};
178
179#endif // _OpenGl_ShaderManager_HeaderFile