HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
material.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_MATERIAL_H
25 #define PXR_IMAGING_HD_ST_MATERIAL_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
32 #include "pxr/imaging/hf/perfLog.h"
33 
34 #include <memory>
35 
37 
38 using HdStSurfaceShaderSharedPtr = std::shared_ptr<class HdStSurfaceShader>;
39 
40 class HioGlslfx;
41 
42 class HdStMaterial final: public HdMaterial
43 {
44 public:
45  HF_MALLOC_TAG_NEW("new HdStMaterial");
46 
47  HDST_API
48  HdStMaterial(SdfPath const& id);
49  HDST_API
50  ~HdStMaterial() override;
51 
52  /// Synchronizes state from the delegate to this object.
53  HDST_API
54  void Sync(HdSceneDelegate *sceneDelegate,
55  HdRenderParam *renderParam,
56  HdDirtyBits *dirtyBits) override;
57 
58  HDST_API
59  void Finalize(HdRenderParam *renderParam) override;
60 
61  /// Returns the minimal set of dirty bits to place in the
62  /// change tracker for use in the first sync of this prim.
63  /// Typically this would be all dirty bits.
64  HDST_API
65  HdDirtyBits GetInitialDirtyBitsMask() const override;
66 
67  /// Obtains the render delegate specific representation of the shader.
68  HDST_API
70 
71  /// Summary flag. Returns true if the material is bound to one or more
72  /// textures and any of those textures is a ptex texture.
73  /// If no textures are bound or all textures are uv textures, then
74  /// the method returns false.
75  inline bool HasPtex() const;
76 
77  /// Returns true if the material specifies limit surface evaluation.
78  inline bool HasLimitSurfaceEvaluation() const;
79 
80  // Returns true if the material has a displacement terminal.
81  inline bool HasDisplacement() const;
82 
83  // Returns the material's render pass tag.
84  inline const TfToken& GetMaterialTag() const;
85 
86  /// Replaces the shader code object with an externally created one
87  /// Used to set the fallback shader for prim.
88  /// This class takes ownership of the passed in object.
89  HDST_API
91 
92 private:
93  // Processes the texture descriptors from a material network to
94  // create textures using the Storm texture system.
95  //
96  // Adds buffer specs/sources necessary for textures, e.g., bindless
97  // handles or sampling transform for field textures.
98  void _ProcessTextureDescriptors(
99  HdSceneDelegate * sceneDelegate,
100  HdStResourceRegistrySharedPtr const& resourceRegistry,
101  std::weak_ptr<HdStShaderCode> const &shaderCode,
103  HdStShaderCode::NamedTextureHandleVector * texturesFromStorm,
104  HdBufferSpecVector * specs,
106 
107  bool
108  _GetHasLimitSurfaceEvaluation(VtDictionary const & metadata) const;
109 
110  void _InitFallbackShader();
111 
112  static HioGlslfx *_fallbackGlslfx;
113 
114  HdStSurfaceShaderSharedPtr _surfaceShader;
115 
116  bool _isInitialized : 1;
117  bool _hasPtex : 1;
118  bool _hasLimitSurfaceEvaluation : 1;
119  bool _hasDisplacement : 1;
120 
121  TfToken _materialTag;
122  size_t _textureHash;
123 
124  HdStMaterialNetwork _networkProcessor;
125 };
126 
127 inline bool HdStMaterial::HasPtex() const
128 {
129  return _hasPtex;
130 }
131 
133 {
134  return _hasLimitSurfaceEvaluation;
135 }
136 
137 inline bool HdStMaterial::HasDisplacement() const
138 {
139  return _hasDisplacement;
140 }
141 
143 {
144  return _materialTag;
145 }
146 
148 
149 #endif // PXR_IMAGING_HD_ST_MATERIAL_H
uint32_t HdDirtyBits
Definition: types.h:127
HDST_API HdStMaterial(SdfPath const &id)
std::vector< HdBufferSourceSharedPtr > HdBufferSourceSharedPtrVector
Definition: bufferSource.h:44
bool HasDisplacement() const
Definition: material.h:137
HF_MALLOC_TAG_NEW("new HdStMaterial")
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
const TfToken & GetMaterialTag() const
Definition: material.h:142
GLsizei GLenum * sources
Definition: glcorearb.h:2541
Definition: token.h:87
bool HasPtex() const
Definition: material.h:127
HDST_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Synchronizes state from the delegate to this object.
HDST_API void SetSurfaceShader(HdStSurfaceShaderSharedPtr &shaderCode)
std::shared_ptr< class HdStSurfaceShader > HdStSurfaceShaderSharedPtr
Definition: material.h:38
Definition: path.h:288
std::vector< struct HdBufferSpec > HdBufferSpecVector
bool HasLimitSurfaceEvaluation() const
Returns true if the material specifies limit surface evaluation.
Definition: material.h:132
HDST_API HdStShaderCodeSharedPtr GetShaderCode() const
Obtains the render delegate specific representation of the shader.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
std::vector< NamedTextureHandle > NamedTextureHandleVector
Definition: shaderCode.h:154
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDST_API ~HdStMaterial() override
std::shared_ptr< class HdStResourceRegistry > HdStResourceRegistrySharedPtr
Definition: commandBuffer.h:47
std::vector< TextureDescriptor > TextureDescriptorVector
std::shared_ptr< class HdStShaderCode > HdStShaderCodeSharedPtr
Definition: drawItem.h:34
HDST_API void Finalize(HdRenderParam *renderParam) override