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  HdStShaderCodePtr const & shaderCode,
70  HdSt_TextureHandleRegistry *textureHandleRegistry);
71 
72  HDST_API
74 
75  /// Get texture object.
76  ///
77  /// Can be accessed after commit.
79  return _textureObject;
80  }
81 
82  /// Get sampler object.
83  ///
84  /// Can be accessed after commit.
86  return _samplerObject;
87  }
88 
89  /// Get sampler parameters.
90  ///
92  return _samplerParams;
93  }
94 
95  /// Get how much memory this handle requested for the texture.
96  ///
97  size_t GetMemoryRequest() const {
98  return _memoryRequest;
99  }
100 
101  /// Get the shader code associated with this handle.
102  ///
104  return _shaderCode;
105  }
106 
107  /// Allocate sampler for this handle (not thread-safe).
108  ///
109  HDST_API
111 
112  /// Get whether bindless texture handles are enabled.
113  ///
114  bool UseBindlessHandles() const;
115 
116 private:
117  HdStTextureObjectSharedPtr _textureObject;
118  HdStSamplerObjectSharedPtr _samplerObject;
119  HdSamplerParameters _samplerParams;
120  size_t _memoryRequest;
121  HdStShaderCodePtr _shaderCode;
122  HdSt_TextureHandleRegistry *_textureHandleRegistry;
123 };
124 
126 
127 #endif
std::weak_ptr< class HdStShaderCode > HdStShaderCodePtr
bool UseBindlessHandles() const
HdStShaderCodePtr const & GetShaderCode() const
HDST_API void ReallocateSamplerIfNecessary()
size_t GetMemoryRequest() const
Definition: textureHandle.h:97
HDST_API HdStTextureHandle(HdStTextureObjectSharedPtr const &textureObject, const HdSamplerParameters &samplerParams, size_t memoryRequest, HdStShaderCodePtr const &shaderCode, HdSt_TextureHandleRegistry *textureHandleRegistry)
See HdStResourceRegistry::AllocateTextureHandle for details.
HdStSamplerObjectSharedPtr const & GetSamplerObject() const
Definition: textureHandle.h:85
std::shared_ptr< class HdStTextureObject > HdStTextureObjectSharedPtr
HdStTextureObjectSharedPtr const & GetTextureObject() const
Definition: textureHandle.h:78
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
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:91
HDST_API ~HdStTextureHandle()