HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glslProgram.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
25 #define PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/version.h"
29 #include "pxr/imaging/hdSt/api.h"
30 #include "pxr/imaging/hgi/buffer.h"
32 #include "pxr/imaging/hgi/enums.h"
33 
35 
37 using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
38 
40 
41 /// \class HdStGLSLProgram
42 ///
43 /// An instance of a glsl program.
44 ///
45 class HdStGLSLProgram final
46 {
47 public:
48  typedef size_t ID;
49 
50  HDST_API
51  HdStGLSLProgram(TfToken const &role, HdStResourceRegistry*const registry);
52  HDST_API
54 
55  /// Compile shader source for a shader stage.
56  HDST_API
57  bool CompileShader(HgiShaderStage stage, std::string const & source);
58 
59  /// Compile shader source for a shader stage from an HgiShaderFunctionDesc.
60  HDST_API
61  bool CompileShader(HgiShaderFunctionDesc const &desc);
62 
63  /// Link the compiled shaders together.
64  HDST_API
65  bool Link();
66 
67  /// Validate if this program is a valid progam in the current context.
68  HDST_API
69  bool Validate() const;
70 
71  /// Returns HgiShaderProgramHandle for the shader program.
72  HgiShaderProgramHandle const &GetProgram() const { return _program; }
73 
74  /// Convenience method to get a shared compute shader program
75  HDST_API
77  TfToken const &shaderToken,
78  HdStResourceRegistry *resourceRegistry);
79 
80  HDST_API
82  TfToken const &shaderFileName,
83  TfToken const &shaderToken,
84  HdStResourceRegistry *resourceRegistry);
85 
87  std::function<void(HgiShaderFunctionDesc &computeDesc)>;
88 
89  HDST_API
91  TfToken const &shaderToken,
92  HdStResourceRegistry *resourceRegistry,
93  PopulateDescriptorCallback populateDescriptor);
94 
95  HDST_API
97  TfToken const &shaderToken,
98  std::string const &defines,
99  HdStResourceRegistry *resourceRegistry,
100  PopulateDescriptorCallback populateDescriptor);
101 
102  HDST_API
104  TfToken const &shaderFileName,
105  TfToken const &shaderToken,
106  std::string const &defines,
107  HdStResourceRegistry *resourceRegistry,
108  PopulateDescriptorCallback populateDescriptor);
109 
110  /// Returns the role of the GPU data in this resource.
111  TfToken const & GetRole() const {return _role;}
112 
113 private:
114  HdStResourceRegistry *const _registry;
115  TfToken _role;
116 
117  HgiShaderProgramDesc _programDesc;
118  HgiShaderProgramHandle _program;
119 
120  // An identifier for uniquely identifying the program, for debugging
121  // purposes - programs that fail to compile for one reason or another
122  // will get deleted, and their GL program IDs reused, so we can't use
123  // that to identify it uniquely
124  size_t _debugID;
125 };
126 
127 
129 
130 #endif // PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
TfToken const & GetRole() const
Returns the role of the GPU data in this resource.
Definition: glslProgram.h:111
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
std::function< void(HgiShaderFunctionDesc &computeDesc)> PopulateDescriptorCallback
Definition: glslProgram.h:87
Definition: token.h:87
HDST_API bool CompileShader(HgiShaderStage stage, std::string const &source)
Compile shader source for a shader stage.
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
HDST_API bool Link()
Link the compiled shaders together.
std::shared_ptr< class HdStGLSLProgram > HdStGLSLProgramSharedPtr
HDST_API ~HdStGLSLProgram()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
HDST_API HdStGLSLProgram(TfToken const &role, HdStResourceRegistry *const registry)
HgiShaderProgramHandle const & GetProgram() const
Returns HgiShaderProgramHandle for the shader program.
Definition: glslProgram.h:72
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDST_API bool Validate() const
Validate if this program is a valid progam in the current context.
static HDST_API HdStGLSLProgramSharedPtr GetComputeProgram(TfToken const &shaderToken, HdStResourceRegistry *resourceRegistry)
Convenience method to get a shared compute shader program.
HgiBits HgiShaderStage
Definition: enums.h:371