0024624: Lost word in license statement in source files
[occt.git] / src / Graphic3d / Graphic3d_ShaderProgram.hxx
CommitLineData
30f0ad28 1// Created on: 2013-09-20
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 _Graphic3d_ShaderProgram_HeaderFile
17#define _Graphic3d_ShaderProgram_HeaderFile
18
19#include <Graphic3d_ShaderObject_Handle.hxx>
20#include <Graphic3d_ShaderProgram_Handle.hxx>
21#include <Graphic3d_ShaderVariable.hxx>
22#include <NCollection_Sequence.hxx>
23
24//! List of shader objects.
25typedef NCollection_Sequence<Handle(Graphic3d_ShaderObject)> Graphic3d_ShaderObjectList;
26
27//! List of custom uniform shader variables.
28typedef NCollection_Sequence<Handle(Graphic3d_ShaderVariable)> Graphic3d_ShaderVariableList;
29
30//! This class is responsible for managing shader programs.
31class Graphic3d_ShaderProgram : public Standard_Transient
32{
392ac980 33
34public:
35
36 //! The list of built-in GLSL programs
37 enum ShaderName
38 {
39 ShaderName_UNKNOWN, //!< undefined program
40 ShaderName_Phong //!< per-pixel lighting (Phong shading)
41 };
42
30f0ad28 43public:
44
45 //! Creates new empty program object.
46 Standard_EXPORT Graphic3d_ShaderProgram();
47
392ac980 48 //! Creates program object from pre-defined shaders.
49 //! Raises Standard_Failure exception if shader resources are unavailable.
50 Standard_EXPORT Graphic3d_ShaderProgram (const Graphic3d_ShaderProgram::ShaderName theName);
51
30f0ad28 52 //! Releases resources of program object.
53 Standard_EXPORT virtual ~Graphic3d_ShaderProgram();
54
55 //! Releases resources of program object.
56 Standard_EXPORT void Destroy() const;
57
58 //! Checks if the program object is valid or not.
59 Standard_EXPORT virtual Standard_Boolean IsDone() const;
60
61 //! Returns unique ID used to manage resource in graphic driver.
62 const TCollection_AsciiString& GetId() const { return myID; }
63
64 //! Attaches shader object to the program object.
65 Standard_EXPORT Standard_Boolean AttachShader (const Handle(Graphic3d_ShaderObject)& theShader);
66
67 //! Detaches shader object from the program object.
68 Standard_EXPORT Standard_Boolean DetachShader (const Handle(Graphic3d_ShaderObject)& theShader);
69
70 //! Returns list of attached shader objects.
71 const Graphic3d_ShaderObjectList& ShaderObjects() const { return myShaderObjects; }
72
73 //! Returns list of custom uniform variables.
74 const Graphic3d_ShaderVariableList& Variables() const { return myVariables; }
75
76 //! Pushes custom uniform variable to the program.
77 template<class T>
78 Standard_Boolean PushVariable (const TCollection_AsciiString& theName,
79 const T& theValue);
80
81 //! Removes all custom uniform variables from the program.
82 Standard_EXPORT void ClearVariables();
83
392ac980 84public:
85
86 //! The path to GLSL programs determined from CSF_ShadersDirectory or CASROOT environment variables.
87 //! @return the root folder with default GLSL programs.
88 Standard_EXPORT static const TCollection_AsciiString& ShadersFolder();
89
30f0ad28 90public:
91
92 DEFINE_STANDARD_RTTI (Graphic3d_ShaderProgram)
93
94private:
95
96 TCollection_AsciiString myID; //!< The unique identifier of program object.
97 Graphic3d_ShaderObjectList myShaderObjects; //!< the list of attached shader objects.
98 Graphic3d_ShaderVariableList myVariables; //!< the list of custom uniform variables.
99
100};
101
102// =======================================================================
103// function : PushVariable
104// purpose : Pushes custom uniform variable to the program
105// =======================================================================
106template<class T> inline
107Standard_Boolean Graphic3d_ShaderProgram::PushVariable (const TCollection_AsciiString& theName,
108 const T& theValue)
109{
110 Handle(Graphic3d_ShaderVariable) aVariable = Graphic3d_ShaderVariable::Create (theName, theValue);
111 if (aVariable.IsNull() || !aVariable->IsDone())
112 {
113 return Standard_False;
114 }
115
116 myVariables.Append (aVariable);
117 return Standard_True;
118}
119
120#endif