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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef HD_ST_TEXTURE_HANDLE_H
8 #define HD_ST_TEXTURE_HANDLE_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 
13 #include "pxr/imaging/hd/enums.h"
14 #include "pxr/imaging/hd/types.h"
15 
16 #include <memory>
17 
19 
20 using HdStShaderCodePtr =
21  std::weak_ptr<class HdStShaderCode>;
23  std::shared_ptr<class HdStTextureObject>;
25  std::shared_ptr<class HdStSamplerObject>;
26 
28  std::shared_ptr<class HdStTextureHandle>;
29 
31 
32 /// \class HdStTextureHandle
33 ///
34 /// Represents a texture and sampler that will be allocated and loaded
35 /// from a texture file during commit, possibly a texture sampler
36 /// handle and a memory request. It is intended for HdStShaderCode and
37 /// HdStShaderCode::AddResourcesFromTextures() is called whenever
38 /// the underlying texture and sampler gets allocated and (re-)loaded
39 /// so that the shader code can react to, e.g., changing texture
40 /// sampler handle for bindless or changing texture metadata such as a
41 /// field bounding box for volumes.
42 ///
44 {
45 public:
46  /// See HdStResourceRegistry::AllocateTextureHandle for details.
47  HDST_API
49  HdStTextureObjectSharedPtr const &textureObject,
50  const HdSamplerParameters &samplerParams,
51  size_t memoryRequest,
52  HdStShaderCodePtr const & shaderCode,
53  HdSt_TextureHandleRegistry *textureHandleRegistry);
54 
55  HDST_API
57 
58  /// Get texture object.
59  ///
60  /// Can be accessed after commit.
62  return _textureObject;
63  }
64 
65  /// Get sampler object.
66  ///
67  /// Can be accessed after commit.
69  return _samplerObject;
70  }
71 
72  /// Get sampler parameters.
73  ///
75  return _samplerParams;
76  }
77 
78  /// Get how much memory this handle requested for the texture.
79  ///
80  size_t GetMemoryRequest() const {
81  return _memoryRequest;
82  }
83 
84  /// Get the shader code associated with this handle.
85  ///
87  return _shaderCode;
88  }
89 
90  /// Allocate sampler for this handle (not thread-safe).
91  ///
92  HDST_API
94 
95  /// Get whether bindless texture handles are enabled.
96  ///
97  bool UseBindlessHandles() const;
98 
99 private:
100  HdStTextureObjectSharedPtr _textureObject;
101  HdStSamplerObjectSharedPtr _samplerObject;
102  HdSamplerParameters _samplerParams;
103  size_t _memoryRequest;
104  HdStShaderCodePtr _shaderCode;
105  HdSt_TextureHandleRegistry *_textureHandleRegistry;
106 };
107 
109 
110 #endif
std::weak_ptr< class HdStShaderCode > HdStShaderCodePtr
bool UseBindlessHandles() const
HdStShaderCodePtr const & GetShaderCode() const
Definition: textureHandle.h:86
HDST_API void ReallocateSamplerIfNecessary()
size_t GetMemoryRequest() const
Definition: textureHandle.h:80
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:68
std::shared_ptr< class HdStTextureObject > HdStTextureObjectSharedPtr
HdStTextureObjectSharedPtr const & GetTextureObject() const
Definition: textureHandle.h:61
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
std::shared_ptr< class HdStTextureHandle > HdStTextureHandleSharedPtr
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::shared_ptr< class HdStSamplerObject > HdStSamplerObjectSharedPtr
Definition: samplerObject.h:30
HdSamplerParameters const & GetSamplerParameters() const
Definition: textureHandle.h:74
HDST_API ~HdStTextureHandle()