All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glslProgram.h
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 HDST_GLSL_PROGRAM_H
25 #define HDST_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/hdSt/resourceGL.h"
31 
32 #include <boost/shared_ptr.hpp>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
37 typedef boost::shared_ptr<class HdStGLSLProgram> HdStGLSLProgramSharedPtr;
38 
43 // XXX: this design is transitional and will be revised soon.
45 {
46 public:
47  typedef size_t ID;
48 
49  HDST_API
50  HdStGLSLProgram(TfToken const &role);
51  HDST_API
52  ~HdStGLSLProgram();
53 
55  HDST_API
56  static ID ComputeHash(TfToken const & sourceFile);
57 
59  HDST_API
60  bool CompileShader(GLenum type, std::string const & source);
61 
63  HDST_API
64  bool Link();
65 
67  HDST_API
68  bool Validate() const;
69 
71  HdStResourceGL const &GetProgram() const { return _program; }
72 
75  return _uniformBuffer;
76  }
77 
79  HDST_API
80  static HdStGLSLProgramSharedPtr GetComputeProgram(
81  TfToken const &shaderToken,
82  HdStResourceRegistry *resourceRegistry);
83 
84  HDST_API
85  static HdStGLSLProgramSharedPtr GetComputeProgram(
86  TfToken const &shaderFileName,
87  TfToken const &shaderToken,
88  HdStResourceRegistry *resourceRegistry);
89 
90 private:
91  HdStResourceGL _program;
92  HdStResourceGL _uniformBuffer;
93  // An identifier for uniquely identifying the program, for debugging
94  // purposes - programs that fail to compile for one reason or another
95  // will get deleted, and their GL program IDs reused, so we can't use
96  // that to identify it uniquely
97  size_t _debugID;
98 };
99 
100 
101 PXR_NAMESPACE_CLOSE_SCOPE
102 
103 #endif // HDST_GLSL_PROGRAM_H
static HDST_API ID ComputeHash(TfToken const &sourceFile)
Returns the hash value of the program for sourceFile.
HdStResourceGL const & GetGlobalUniformBuffer() const
Returns HdResource of the global uniform buffer object for this program.
Definition: glslProgram.h:74
An instance of a glsl program.
Definition: glslProgram.h:44
HdStResourceGL const & GetProgram() const
Returns HdResource of the program object.
Definition: glslProgram.h:71
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
A central registry of all GPU resources.
HDST_API bool Link()
Link the compiled shaders together.
HDST_API bool CompileShader(GLenum type, std::string const &source)
Compile shader source of type.
static HDST_API HdStGLSLProgramSharedPtr GetComputeProgram(TfToken const &shaderToken, HdStResourceRegistry *resourceRegistry)
Convenience method to get a shared compute shader program.
HDST_API bool Validate() const
Validate if this program is a valid progam in the current context.
Base class for simple OpenGL resource objects.
Definition: resourceGL.h:47