1 // Created on: 2013-09-26
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013 OPEN CASCADE SAS
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.
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.
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.
20 #ifndef _OpenGl_ShaderManager_HeaderFile
21 #define _OpenGl_ShaderManager_HeaderFile
23 #include <Graphic3d_ShaderProgram_Handle.hxx>
25 #include <NCollection_DataMap.hxx>
26 #include <NCollection_Sequence.hxx>
28 #include <Handle_OpenGl_ShaderManager.hxx>
29 #include <OpenGl_ShaderProgram.hxx>
30 #include <OpenGl_ShaderStates.hxx>
32 //! List of shader programs.
33 typedef NCollection_Sequence<Handle(OpenGl_ShaderProgram)> OpenGl_ShaderProgramList;
35 //! Map to declare per-program states of OCCT materials.
36 typedef NCollection_DataMap<Handle(OpenGl_ShaderProgram), OpenGl_MaterialState> OpenGl_MaterialStates;
38 //! This class is responsible for managing shader programs.
39 class OpenGl_ShaderManager : public Standard_Transient
41 friend class OpenGl_ShaderProgram;
45 //! Creates new empty shader manager.
46 Standard_EXPORT OpenGl_ShaderManager (OpenGl_Context* theContext);
48 //! Releases resources of shader manager.
49 Standard_EXPORT virtual ~OpenGl_ShaderManager();
51 //! Creates new shader program.
52 Standard_EXPORT Handle(OpenGl_ShaderProgram) Create (const Handle(Graphic3d_ShaderProgram)& theProxyProgram = NULL);
54 //! Unregisters specified shader program.
55 Standard_EXPORT void Unregister (Handle(OpenGl_ShaderProgram)& theProgram);
57 //! Returns list of registered shader programs.
58 Standard_EXPORT const OpenGl_ShaderProgramList& ShaderPrograms() const;
60 //! Returns true if no program objects are registered in the manager.
61 Standard_EXPORT Standard_Boolean IsEmpty() const;
63 DEFINE_STANDARD_RTTI (OpenGl_ShaderManager)
67 OpenGl_MaterialStates myMaterialStates; //!< Per-program state of OCCT material
68 OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation
69 OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation
70 OpenGl_WorldViewState myWorldViewState; //!< State of OCCT world-view transformation
71 OpenGl_LightSourceState myClippingState; //!< State of OCCT clipping planes
72 OpenGl_LightSourceState myLightSourceState; //!< State of OCCT light sources
76 //! Returns current state of OCCT light sources.
77 Standard_EXPORT const OpenGl_LightSourceState& LightSourceState() const;
79 //! Updates state of OCCT light sources.
80 Standard_EXPORT void UpdateLightSourceStateTo (const OpenGl_ListOfLight* theLights);
82 //! Pushes current state of OCCT light sources to specified program.
83 Standard_EXPORT void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
87 //! Returns current state of OCCT projection transform.
88 Standard_EXPORT const OpenGl_ProjectionState& ProjectionState() const;
90 //! Updates state of OCCT projection transform.
91 Standard_EXPORT void UpdateProjectionStateTo (const Tmatrix3& theProjectionMatrix);
93 //! Reverts state of OCCT projection transform.
94 Standard_EXPORT void RevertProjectionStateTo (const Tmatrix3& theProjectionMatrix);
96 //! Pushes current state of OCCT projection transform to specified program.
97 Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
101 //! Returns current state of OCCT model-world transform.
102 Standard_EXPORT const OpenGl_ModelWorldState& ModelWorldState() const;
104 //! Updates state of OCCT model-world transform.
105 Standard_EXPORT void UpdateModelWorldStateTo (const Tmatrix3& theModelWorldMatrix);
107 //! Reverts state of OCCT model-world transform.
108 Standard_EXPORT void RevertModelWorldStateTo (const Tmatrix3& theModelWorldMatrix);
110 //! Pushes current state of OCCT model-world transform to specified program.
111 Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
115 //! Returns current state of OCCT world-view transform.
116 Standard_EXPORT const OpenGl_WorldViewState& WorldViewState() const;
118 //! Updates state of OCCT world-view transform.
119 Standard_EXPORT void UpdateWorldViewStateTo (const Tmatrix3& theWorldViewMatrix);
121 //! Reverts state of OCCT world-view transform.
122 Standard_EXPORT void RevertWorldViewStateTo (const Tmatrix3& theWorldViewMatrix);
124 //! Pushes current state of OCCT world-view transform to specified program.
125 Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
129 //! Updates state of OCCT clipping planes.
130 Standard_EXPORT void UpdateClippingState();
132 //! Reverts state of OCCT clipping planes.
133 Standard_EXPORT void RevertClippingState();
135 //! Pushes current state of OCCT clipping planes to specified program.
136 Standard_EXPORT void PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
140 //! Resets state of OCCT material for all programs.
141 Standard_EXPORT void ResetMaterialStates();
143 //! Updates state of OCCT material for specified program.
144 Standard_EXPORT void UpdateMaterialStateTo (const Handle(OpenGl_ShaderProgram)& theProgram,
145 const OpenGl_Element* theAspect);
147 //! Pushes current state of OCCT material to specified program.
148 Standard_EXPORT void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
150 //! Returns current state of OCCT material for specified program.
151 Standard_EXPORT const OpenGl_MaterialState* MaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
155 //! Pushes current state of OCCT graphics parameters to specified program.
156 Standard_EXPORT void PushState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
160 OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs
161 OpenGl_Context* myContext; //!< The OpenGL context
165 Standard_Boolean myIsPP; //!< Is any program object bound (programmable pipeline)?
169 #endif // _OpenGl_ShaderManager_HeaderFile