HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dynamicUvTextureObject.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 PXR_IMAGING_HD_ST_DYNAMIC_UV_TEXTURE_OBJECT_H
8 #define PXR_IMAGING_HD_ST_DYNAMIC_UV_TEXTURE_OBJECT_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 
14 
16 
18 
19 /// \class HdStDynamicUvTextureObject
20 ///
21 /// A uv texture that is managed but not populated by the Storm texture system.
22 ///
23 /// Clients can allocate an instance of this class through
24 /// HdStResourceRegistry::AllocateTextureHandle or AllocateTextureObject
25 /// by passing an HdStTextureIdentifier with a
26 /// HdStDynamicUvSubtextureIdentifier.
27 ///
28 /// The client can allocate the GPU resource with CreateTexture and populate it
29 /// by either giving data in the HgiTextureDesc or binding the texture as target
30 /// for a computation or render.
31 ///
32 /// Bindless texture sampler handles can only be created correctly if
33 /// a client has created the texture before the texture commit phase
34 /// is finished.
35 ///
37 {
38 public:
39  HDST_API
41  const HdStTextureIdentifier &textureId,
42  HdSt_TextureObjectRegistry *textureObjectRegistry);
43 
44  HDST_API
45  ~HdStDynamicUvTextureObject() override;
46 
47  /// Allocate GPU resource using the texture descriptor. Populate
48  /// if data are given in the descriptor.
49  ///
50  void CreateTexture(const HgiTextureDesc &desc) {
51  _CreateTexture(desc);
52  }
53 
54  /// Make GPU generate mipmaps.
55  ///
57  {
59  }
60 
61  /// Release GPU resource.
62  void DestroyTexture() {
64  }
65 
66  /// Set wrap mode hints used when a texture node's wrap mode
67  /// is use metadata.
68  ///
69  /// This is typically called from HdStDynamicUvTextureImplementation::Load
70  /// when the texture file has wrap mode hints.
71  void SetWrapParameters(const std::pair<HdWrap, HdWrap> &wrapParameters) {
72  _SetWrapParameters(wrapParameters);
73  }
74 
75  /// Save CPU data for this texture (transfering ownership).
76  ///
77  /// This is typically called from HdStDynamicUvTextureImplementation::Load
78  /// so that the CPU data can be uploaded during commit.
79  ///
80  /// To free the CPU data, call with nullptr.
81  ///
82  void SetCpuData(std::unique_ptr<HdStTextureCpuData> &&cpuData) {
83  _SetCpuData(std::move(cpuData));
84  }
85 
86  /// Get the CPU data stored for this texture.
87  ///
88  /// Typically used in HdStDynamicUvTextureImplementation::Commit to
89  /// commit CPU data to GPU.
91  return _GetCpuData();
92  }
93 
94  /// Always returns true - so that samplers for this texture are
95  /// created.
96  ///
97  HDST_API
98  bool IsValid() const override;
99 
100 protected:
101  HDST_API
102  void _Load() override;
103 
104  HDST_API
105  void _Commit() override;
106 
107 private:
108  HdStDynamicUvTextureImplementation * _GetImpl() const;
109 };
110 
112 
113 #endif
HdStTextureCpuData * GetCpuData() const
HDST_API HdStDynamicUvTextureObject(const HdStTextureIdentifier &textureId, HdSt_TextureObjectRegistry *textureObjectRegistry)
HDST_API ~HdStDynamicUvTextureObject() override
HDST_API void _Load() override
HDST_API void _SetCpuData(std::unique_ptr< HdStTextureCpuData > &&)
HDST_API void _Commit() override
HDST_API void _DestroyTexture()
HDST_API bool IsValid() const override
HDST_API void _SetWrapParameters(const std::pair< HdWrap, HdWrap > &wrapParameters)
HDST_API HdStTextureCpuData * _GetCpuData() const
void CreateTexture(const HgiTextureDesc &desc)
void DestroyTexture()
Release GPU resource.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HDST_API void _GenerateMipmaps()
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
void SetWrapParameters(const std::pair< HdWrap, HdWrap > &wrapParameters)
void SetCpuData(std::unique_ptr< HdStTextureCpuData > &&cpuData)
HDST_API void _CreateTexture(const HgiTextureDesc &desc)