HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
textureHandle.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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 HD_ST_TEXTURE_HANDLE_H
25 #define HD_ST_TEXTURE_HANDLE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 
30 #include "pxr/imaging/hd/enums.h"
31 #include "pxr/imaging/hd/types.h"
32 
33 #include <memory>
34 
36 
37 using HdStShaderCodePtr =
38  std::weak_ptr<class HdStShaderCode>;
40  std::shared_ptr<class HdStTextureObject>;
42  std::shared_ptr<class HdStSamplerObject>;
43 
45  std::shared_ptr<class HdStTextureHandle>;
46 
48 
49 /// \class HdStTextureHandle
50 ///
51 /// Represents a texture and sampler that will be allocated and loaded
52 /// from a texture file during commit, possibly a texture sampler
53 /// handle and a memory request. It is intended for HdStShaderCode and
54 /// HdStShaderCode::AddResourcesFromTextures() is called whenever
55 /// the underlying texture and sampler gets allocated and (re-)loaded
56 /// so that the shader code can react to, e.g., changing texture
57 /// sampler handle for bindless or changing texture metadata such as a
58 /// field bounding box for volumes.
59 ///
61 {
62 public:
63  /// See HdStResourceRegistry::AllocateTextureHandle for details.
64  HDST_API
66  HdStTextureObjectSharedPtr const &textureObject,
67  const HdSamplerParameters &samplerParams,
68  size_t memoryRequest,
69  bool createBindlessHandle,
70  HdStShaderCodePtr const & shaderCode,
71  HdSt_TextureHandleRegistry *textureHandleRegistry);
72 
73  HDST_API
75 
76  /// Get texture object.
77  ///
78  /// Can be accessed after commit.
80  return _textureObject;
81  }
82 
83  /// Get sampler object.
84  ///
85  /// Can be accessed after commit.
87  return _samplerObject;
88  }
89 
90  /// Get sampler parameters.
91  ///
93  return _samplerParams;
94  }
95 
96  /// Get how much memory this handle requested for the texture.
97  ///
98  size_t GetMemoryRequest() const {
99  return _memoryRequest;
100  }
101 
102  /// Get the shader code associated with this handle.
103  ///
105  return _shaderCode;
106  }
107 
108  /// Allocate sampler for this handle (not thread-safe).
109  ///
110  /// This also creates the texture sampler handle (for bindless
111  /// textures) and updates it on subsequent calls.
112  ///
113  HDST_API
115 
116 private:
117  HdStTextureObjectSharedPtr _textureObject;
118  HdStSamplerObjectSharedPtr _samplerObject;
119  HdSamplerParameters _samplerParams;
120  size_t _memoryRequest;
121  bool _createBindlessHandle;
122  HdStShaderCodePtr _shaderCode;
123  HdSt_TextureHandleRegistry *_textureHandleRegistry;
124 };
125 
127 
128 #endif
std::weak_ptr< class HdStShaderCode > HdStShaderCodePtr
HdStShaderCodePtr const & GetShaderCode() const
HDST_API void ReallocateSamplerIfNecessary()
size_t GetMemoryRequest() const
Definition: textureHandle.h:98
HDST_API HdStTextureHandle(HdStTextureObjectSharedPtr const &textureObject, const HdSamplerParameters &samplerParams, size_t memoryRequest, bool createBindlessHandle, HdStShaderCodePtr const &shaderCode, HdSt_TextureHandleRegistry *textureHandleRegistry)
See HdStResourceRegistry::AllocateTextureHandle for details.
HdStSamplerObjectSharedPtr const & GetSamplerObject() const
Definition: textureHandle.h:86
std::shared_ptr< class HdStTextureObject > HdStTextureObjectSharedPtr
HdStTextureObjectSharedPtr const & GetTextureObject() const
Definition: textureHandle.h:79
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
std::shared_ptr< class HdStTextureHandle > HdStTextureHandleSharedPtr
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
std::shared_ptr< class HdStSamplerObject > HdStSamplerObjectSharedPtr
Definition: samplerObject.h:47
HdSamplerParameters const & GetSamplerParameters() const
Definition: textureHandle.h:92
HDST_API ~HdStTextureHandle()