All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
surfaceShader.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_SURFACESHADER_H
25 #define HDST_SURFACESHADER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hdSt/shaderCode.h"
31 #include "pxr/imaging/hd/bufferSource.h"
32 
33 #include "pxr/imaging/garch/gl.h"
34 
35 #include "pxr/usd/sdf/path.h"
36 
37 #include "pxr/base/vt/value.h"
38 #include "pxr/base/tf/token.h"
39 
40 #include <boost/shared_ptr.hpp>
41 
42 #include <vector>
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 
47 class HdSceneDelegate;
48 
49 typedef boost::shared_ptr<class HdBufferArrayRange> HdBufferArrayRangeSharedPtr;
50 typedef boost::shared_ptr<class HdStSurfaceShader> HdStSurfaceShaderSharedPtr;
51 typedef boost::shared_ptr<class HdResourceRegistry> HdResourceRegistrySharedPtr;
52 
62 public:
63  HDST_API
65  HDST_API
66  virtual ~HdStSurfaceShader();
67 
68 
69  // ---------------------------------------------------------------------- //
71  // ---------------------------------------------------------------------- //
72  HDST_API
73  virtual std::string GetSource(TfToken const &shaderStageKey) const override;
74  HDST_API
75  virtual HdMaterialParamVector const& GetParams() const override;
76  HDST_API
77  virtual HdBufferArrayRangeSharedPtr const& GetShaderData() const override;
78  HDST_API
79  virtual TextureDescriptorVector GetTextures() const override;
80  HDST_API
81  virtual void BindResources(HdSt_ResourceBinder const &binder, int program)
82  override;
83  HDST_API
84  virtual void UnbindResources(HdSt_ResourceBinder const &binder, int program)
85  override;
86  HDST_API
87  virtual void AddBindings(HdBindingRequestVector *customBindings) override;
88  HDST_API
89  virtual ID ComputeHash() const override;
90 
91  HDST_API
92  virtual TfToken GetMaterialTag() const override;
93 
94 
96  HDST_API
97  void SetFragmentSource(const std::string &source);
98  HDST_API
99  void SetGeometrySource(const std::string &source);
100  HDST_API
101  void SetParams(const HdMaterialParamVector &params);
102  HDST_API
103  void SetTextureDescriptors(const TextureDescriptorVector &texDesc);
104  HDST_API
105  void SetBufferSources(HdBufferSourceVector &bufferSources,
106  HdResourceRegistrySharedPtr const &resourceRegistry);
107 
108  HDST_API
109  void SetMaterialTag(TfToken const &materialTag);
110 
112  HDST_API
113  virtual void Reload();
114 
115 protected:
116  HDST_API
117  void _SetSource(TfToken const &shaderStageKey, std::string const &source);
118 
119 private:
120  std::string _fragmentSource;
121  std::string _geometrySource;
122 
123  // Shader Parameters
124  HdMaterialParamVector _params;
125  HdBufferSpecVector _paramSpec;
126  HdBufferArrayRangeSharedPtr _paramArray;
127 
128  TextureDescriptorVector _textureDescriptors;
129 
130  TfToken _materialTag;
131 
132  // No copying
133  HdStSurfaceShader(const HdStSurfaceShader &) = delete;
134  HdStSurfaceShader &operator =(const HdStSurfaceShader &) = delete;
135 };
136 
137 
138 PXR_NAMESPACE_CLOSE_SCOPE
139 
140 #endif //HDST_SURFACESHADER_H
virtual HDST_API std::string GetSource(TfToken const &shaderStageKey) const override
Returns the shader source provided by this shader for shaderStageKey.
virtual HDST_API HdBufferArrayRangeSharedPtr const & GetShaderData() const override
Returns a buffer which stores parameter fallback values and texture handles.
virtual HDST_API void AddBindings(HdBindingRequestVector *customBindings) override
Add custom bindings (used by codegen)
virtual HDST_API void Reload()
If the prim is based on asset, reload that asset.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
virtual HDST_API TfToken GetMaterialTag() const override
Material tags can be set in the meta-data of a glslfx file to control what rprim collection that prim...
Adapter class providing data exchange with the client scene graph.
virtual HDST_API HdMaterialParamVector const & GetParams() const override
Returns the shader parameters for this shader.
A scene-based SurfaceShader object.
Definition: surfaceShader.h:61
A base class representing the implementation (code) of a shader, used in conjunction with HdRenderPas...
Definition: shaderCode.h:59
HDST_API void SetFragmentSource(const std::string &source)
Setter method for prim.
virtual HDST_API void BindResources(HdSt_ResourceBinder const &binder, int program) override
Binds shader-specific resources to program XXX: this interface is meant to be used for bridging the G...
virtual HDST_API void UnbindResources(HdSt_ResourceBinder const &binder, int program) override
Unbinds shader-specific resources.
virtual HDST_API ID ComputeHash() const override
Returns the hash value of this shader.