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  /// Link the compiled shaders together.
60  HDST_API
61  bool Link();
62 
63  /// Validate if this program is a valid progam in the current context.
64  HDST_API
65  bool Validate() const;
66 
67  /// Returns HdResource of the program object.
68  HgiShaderProgramHandle const &GetProgram() const { return _program; }
69 
70  /// Convenience method to get a shared compute shader program
71  HDST_API
73  TfToken const &shaderToken,
74  HdStResourceRegistry *resourceRegistry);
75 
76  HDST_API
78  TfToken const &shaderFileName,
79  TfToken const &shaderToken,
80  HdStResourceRegistry *resourceRegistry);
81 
83  std::function<void(HgiShaderFunctionDesc &computeDesc)>;
84 
85  HDST_API
87  TfToken const &shaderToken,
88  HdStResourceRegistry *resourceRegistry,
89  PopulateDescriptorCallback populateDescriptor);
90 
91  HDST_API
93  TfToken const &shaderToken,
94  std::string const &defines,
95  HdStResourceRegistry *resourceRegistry,
96  PopulateDescriptorCallback populateDescriptor);
97 
98  /// Returns the role of the GPU data in this resource.
99  TfToken const & GetRole() const {return _role;}
100 
101 private:
102  HdStResourceRegistry *const _registry;
103  TfToken _role;
104 
105  HgiShaderProgramDesc _programDesc;
106  HgiShaderProgramHandle _program;
107 
108  // An identifier for uniquely identifying the program, for debugging
109  // purposes - programs that fail to compile for one reason or another
110  // will get deleted, and their GL program IDs reused, so we can't use
111  // that to identify it uniquely
112  size_t _debugID;
113 };
114 
115 
117 
118 #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:99
std::function< void(HgiShaderFunctionDesc &computeDesc)> PopulateDescriptorCallback
Definition: glslProgram.h:83
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:802
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
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:1375
HDST_API HdStGLSLProgram(TfToken const &role, HdStResourceRegistry *const registry)
HgiShaderProgramHandle const & GetProgram() const
Returns HdResource of the program object.
Definition: glslProgram.h:68
#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:292