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. |
29 | typedef NCollection_Sequence<Handle(OpenGl_ShaderProgram)> OpenGl_ShaderProgramList; |
30 | |
31 | //! Map to declare per-program states of OCCT materials. |
32 | typedef NCollection_DataMap<Handle(OpenGl_ShaderProgram), OpenGl_MaterialState> OpenGl_MaterialStates; |
33 | |
34 | //! This class is responsible for managing shader programs. |
35 | class OpenGl_ShaderManager : public Standard_Transient |
36 | { |
37 | friend class OpenGl_ShaderProgram; |
38 | |
39 | public: |
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 | |
67 | protected: |
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 | |
76 | public: |
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 | |
87 | public: |
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. |
93 | Standard_EXPORT void UpdateProjectionStateTo (const Tmatrix3& theProjectionMatrix); |
94 | |
95 | //! Reverts state of OCCT projection transform. |
96 | Standard_EXPORT void RevertProjectionStateTo (const Tmatrix3& theProjectionMatrix); |
97 | |
98 | //! Pushes current state of OCCT projection transform to specified program. |
99 | Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const; |
100 | |
101 | public: |
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. |
107 | Standard_EXPORT void UpdateModelWorldStateTo (const Tmatrix3& theModelWorldMatrix); |
108 | |
109 | //! Reverts state of OCCT model-world transform. |
110 | Standard_EXPORT void RevertModelWorldStateTo (const Tmatrix3& theModelWorldMatrix); |
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 | |
115 | public: |
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. |
121 | Standard_EXPORT void UpdateWorldViewStateTo (const Tmatrix3& theWorldViewMatrix); |
122 | |
123 | //! Reverts state of OCCT world-view transform. |
124 | Standard_EXPORT void RevertWorldViewStateTo (const Tmatrix3& theWorldViewMatrix); |
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 | |
129 | public: |
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 | |
140 | public: |
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 | |
155 | public: |
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 |
160 | public: |
161 | |
162 | //! Overwrites context |
163 | void SetContext (OpenGl_Context* theCtx) |
164 | { |
165 | myContext = theCtx; |
166 | } |
167 | |
30f0ad28 |
168 | protected: |
169 | |
170 | OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs |
171 | OpenGl_Context* myContext; //!< The OpenGL context |
172 | |
173 | private: |
174 | |
175 | Standard_Boolean myIsPP; //!< Is any program object bound (programmable pipeline)? |
176 | |
177 | }; |
178 | |
179 | #endif // _OpenGl_ShaderManager_HeaderFile |