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_ShaderObject_HeaderFile |
17 | #define _Graphic3d_ShaderObject_HeaderFile |
18 | |
30f0ad28 |
19 | #include <Graphic3d_TypeOfShaderObject.hxx> |
4bf072e4 |
20 | #include <NCollection_Sequence.hxx> |
21 | #include <OSD_Path.hxx> |
494782f6 |
22 | |
23 | //! Forward declaration |
30f0ad28 |
24 | |
25 | //! This class is responsible for managing shader objects. |
26 | class Graphic3d_ShaderObject : public Standard_Transient |
27 | { |
4bf072e4 |
28 | public: |
29 | //! Structure defining shader uniform or in/out variable. |
30 | struct ShaderVariable |
31 | { |
32 | TCollection_AsciiString Name; //!< variable name |
33 | Standard_Integer Stages; //!< active stages as Graphic3d_TypeOfShaderObject bits; |
34 | //! for in/out variables, intermediate stages will be automatically filled |
35 | |
36 | //! Create new shader variable. |
37 | ShaderVariable (const TCollection_AsciiString& theVarName, Standard_Integer theShaderStageBits) : Name (theVarName), Stages (theShaderStageBits) {} |
38 | |
39 | //! Empty constructor. |
40 | ShaderVariable() : Stages (0) {} |
41 | }; |
42 | |
43 | //! List of variable of shader program. |
44 | typedef NCollection_Sequence<ShaderVariable> ShaderVariableList; |
45 | |
46 | public: |
47 | |
48 | //! Creates new shader object from specified file. |
49 | Standard_EXPORT static Handle(Graphic3d_ShaderObject) CreateFromFile (const Graphic3d_TypeOfShaderObject theType, |
50 | const TCollection_AsciiString& thePath); |
51 | |
52 | //! Creates new shader object from specified source. |
53 | Standard_EXPORT static Handle(Graphic3d_ShaderObject) CreateFromSource (const Graphic3d_TypeOfShaderObject theType, |
54 | const TCollection_AsciiString& theSource); |
55 | |
56 | //! This is a preprocessor for Graphic3d_ShaderObject::CreateFromSource() function. |
57 | //! Creates a new shader object from specified source according to list of uniforms and in/out variables. |
58 | //! @param theSource shader object source code to modify |
59 | //! @param theType shader object type to create |
60 | //! @param theUniforms list of uniform variables |
61 | //! @param theStageInOuts list of stage in/out variables |
62 | //! @param theInName name of input variables block; |
63 | //! can be empty for accessing each variable without block prefix |
64 | //! (mandatory for stages accessing both inputs and outputs) |
65 | //! @param theOutName name of output variables block; |
66 | //! can be empty for accessing each variable without block prefix |
67 | //! (mandatory for stages accessing both inputs and outputs) |
68 | //! @param theNbGeomInputVerts number of geometry shader input vertexes |
69 | Standard_EXPORT static Handle(Graphic3d_ShaderObject) CreateFromSource (TCollection_AsciiString& theSource, |
70 | Graphic3d_TypeOfShaderObject theType, |
71 | const ShaderVariableList& theUniforms, |
72 | const ShaderVariableList& theStageInOuts, |
73 | const TCollection_AsciiString& theInName = TCollection_AsciiString(), |
74 | const TCollection_AsciiString& theOutName = TCollection_AsciiString(), |
75 | Standard_Integer theNbGeomInputVerts = 0); |
76 | |
30f0ad28 |
77 | private: |
78 | |
79 | //! Creates new shader object of specified type. |
80 | Standard_EXPORT Graphic3d_ShaderObject (const Graphic3d_TypeOfShaderObject theType); |
81 | |
82 | public: |
83 | |
84 | //! Releases resources of shader object. |
85 | Standard_EXPORT virtual ~Graphic3d_ShaderObject(); |
86 | |
87 | //! Checks if the shader object is valid or not. |
88 | Standard_EXPORT virtual Standard_Boolean IsDone() const; |
89 | |
90 | //! Returns the full path to the shader source. |
91 | const OSD_Path& Path() const { return myPath; } |
92 | |
93 | //! Returns the source code of the shader object. |
94 | const TCollection_AsciiString& Source() const { return mySource; } |
95 | |
96 | //! Returns type of the shader object. |
97 | Graphic3d_TypeOfShaderObject Type() const { return myType; } |
98 | |
99 | //! Returns unique ID used to manage resource in graphic driver. |
100 | const TCollection_AsciiString& GetId() const { return myID; } |
101 | |
30f0ad28 |
102 | public: |
103 | |
92efcf78 |
104 | DEFINE_STANDARD_RTTIEXT(Graphic3d_ShaderObject,Standard_Transient) |
30f0ad28 |
105 | |
106 | protected: |
107 | |
108 | TCollection_AsciiString myID; //!< the ID of shader object |
109 | TCollection_AsciiString mySource; //!< the source code of shader object |
110 | OSD_Path myPath; //!< the path to shader source (may be empty) |
111 | |
112 | private: |
113 | |
114 | //! The type of shader object. |
115 | Graphic3d_TypeOfShaderObject myType; |
116 | }; |
117 | |
494782f6 |
118 | DEFINE_STANDARD_HANDLE (Graphic3d_ShaderObject, Standard_Transient) |
119 | |
30f0ad28 |
120 | #endif |