All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shaderCode.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_SHADER_CODE_H
25 #define HDST_SHADER_CODE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/version.h"
30 
31 #include "pxr/imaging/hd/materialParam.h"
32 #include "pxr/imaging/hdSt/resourceBinder.h" // XXX: including a private class
33 #include "pxr/base/tf/token.h"
34 
35 #include <boost/shared_ptr.hpp>
36 
37 #include <string>
38 #include <vector>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
43 typedef std::vector<class HdBindingRequest> HdBindingRequestVector;
44 
45 typedef boost::shared_ptr<class HdStShaderCode> HdStShaderCodeSharedPtr;
46 typedef std::vector<HdStShaderCodeSharedPtr> HdStShaderCodeSharedPtrVector;
47 
48 typedef boost::shared_ptr<class HdStTextureResourceHandle>
49  HdStTextureResourceHandleSharedPtr;
50 
51 
60 public:
61  typedef size_t ID;
62 
63  HDST_API
65  HDST_API
66  virtual ~HdStShaderCode();
67 
69  virtual ID ComputeHash() const = 0;
70 
72  HDST_API
73  static ID ComputeHash(HdStShaderCodeSharedPtrVector const &shaders);
74 
77  virtual std::string GetSource(TfToken const &shaderStageKey) const = 0;
78 
79  // XXX: Should be pure-virtual
81  HDST_API
82  virtual HdMaterialParamVector const& GetParams() const;
83 
84  struct TextureDescriptor {
85  TfToken name;
86  HdStTextureResourceHandleSharedPtr handle;
87  enum { TEXTURE_2D, TEXTURE_3D, TEXTURE_UDIM_ARRAY, TEXTURE_UDIM_LAYOUT,
88  TEXTURE_PTEX_TEXEL, TEXTURE_PTEX_LAYOUT };
89  int type;
90  };
91  typedef std::vector<TextureDescriptor> TextureDescriptorVector;
92 
93  // XXX: DOC
94  HDST_API
95  virtual TextureDescriptorVector GetTextures() const;
96 
97  // XXX: Should be pure-virtual
100  HDST_API
101  virtual HdBufferArrayRangeSharedPtr const& GetShaderData() const;
102 
106  virtual void BindResources(HdSt_ResourceBinder const &binder,
107  int program) = 0;
108 
110  virtual void UnbindResources(HdSt_ResourceBinder const &binder,
111  int program) = 0;
112 
114  virtual void AddBindings(HdBindingRequestVector* customBindings) = 0;
115 
117  HDST_API
118  static bool CanAggregate(HdStShaderCodeSharedPtr const &shaderA,
119  HdStShaderCodeSharedPtr const &shaderB);
120 
126  HDST_API
127  virtual TfToken GetMaterialTag() const;
128 
129 private:
130 
131  // No copying
132  HdStShaderCode(const HdStShaderCode &) = delete;
133  HdStShaderCode &operator =(const HdStShaderCode &) = delete;
134 };
135 
136 
137 PXR_NAMESPACE_CLOSE_SCOPE
138 
139 #endif //HDST_SHADER_H
static HDST_API bool CanAggregate(HdStShaderCodeSharedPtr const &shaderA, HdStShaderCodeSharedPtr const &shaderB)
Returns if the two shaders can be aggregated in a same drawbatch or not.
virtual HDST_API TfToken GetMaterialTag() const
Material tags can be set in the meta-data of a glslfx file to control what rprim collection that prim...
virtual HDST_API HdBufferArrayRangeSharedPtr const & GetShaderData() const
Returns a buffer which stores parameter fallback values and texture handles.
virtual std::string GetSource(TfToken const &shaderStageKey) const =0
Returns the shader source provided by this shader for shaderStageKey.
virtual void AddBindings(HdBindingRequestVector *customBindings)=0
Add custom bindings (used by codegen)
virtual void UnbindResources(HdSt_ResourceBinder const &binder, int program)=0
Unbinds shader-specific resources.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
virtual void BindResources(HdSt_ResourceBinder const &binder, int program)=0
Binds shader-specific resources to program XXX: this interface is meant to be used for bridging the G...
virtual HDST_API HdMaterialParamVector const & GetParams() const
Returns the shader parameters for this shader.
A base class representing the implementation (code) of a shader, used in conjunction with HdRenderPas...
Definition: shaderCode.h:59
virtual ID ComputeHash() const =0
Returns the hash value of this shader.