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 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_DYNAMIC_UV_TEXTURE_OBJECT_H
25 #define PXR_IMAGING_HD_ST_DYNAMIC_UV_TEXTURE_OBJECT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 
31 
33 
35 
36 /// \class HdStDynamicUvTextureObject
37 ///
38 /// A uv texture that is managed but not populated by the Storm texture system.
39 ///
40 /// Clients can allocate an instance of this class through
41 /// HdStResourceRegistry::AllocateTextureHandle or AllocateTextureObject
42 /// by passing an HdStTextureIdentifier with a
43 /// HdStDynamicUvSubtextureIdentifier.
44 ///
45 /// The client can allocate the GPU resource with CreateTexture and populate it
46 /// by either giving data in the HgiTextureDesc or binding the texture as target
47 /// for a computation or render.
48 ///
49 /// Bindless texture sampler handles can only be created correctly if
50 /// a client has created the texture before the texture commit phase
51 /// is finished.
52 ///
54 {
55 public:
56  HDST_API
58  const HdStTextureIdentifier &textureId,
59  HdSt_TextureObjectRegistry *textureObjectRegistry);
60 
61  HDST_API
62  ~HdStDynamicUvTextureObject() override;
63 
64  /// Allocate GPU resource using the texture descriptor. Populate
65  /// if data are given in the descriptor.
66  ///
67  void CreateTexture(const HgiTextureDesc &desc) {
68  _CreateTexture(desc);
69  }
70 
71  /// Make GPU generate mipmaps.
72  ///
74  {
76  }
77 
78  /// Release GPU resource.
79  void DestroyTexture() {
81  }
82 
83  /// Set wrap mode hints used when a texture node's wrap mode
84  /// is use metadata.
85  ///
86  /// This is typically called from HdStDynamicUvTextureImplementation::Load
87  /// when the texture file has wrap mode hints.
88  void SetWrapParameters(const std::pair<HdWrap, HdWrap> &wrapParameters) {
89  _SetWrapParameters(wrapParameters);
90  }
91 
92  /// Save CPU data for this texture (transfering ownership).
93  ///
94  /// This is typically called from HdStDynamicUvTextureImplementation::Load
95  /// so that the CPU data can be uploaded during commit.
96  ///
97  /// To free the CPU data, call with nullptr.
98  ///
99  void SetCpuData(std::unique_ptr<HdStTextureCpuData> &&cpuData) {
100  _SetCpuData(std::move(cpuData));
101  }
102 
103  /// Get the CPU data stored for this texture.
104  ///
105  /// Typically used in HdStDynamicUvTextureImplementation::Commit to
106  /// commit CPU data to GPU.
108  return _GetCpuData();
109  }
110 
111  /// Always returns true - so that samplers for this texture are
112  /// created.
113  ///
114  HDST_API
115  bool IsValid() const override;
116 
117 protected:
118  HDST_API
119  void _Load() override;
120 
121  HDST_API
122  void _Commit() override;
123 
124 private:
125  HdStDynamicUvTextureImplementation * _GetImpl() const;
126 };
127 
129 
130 #endif
HdStTextureCpuData * GetCpuData() const
HDST_API HdStDynamicUvTextureObject(const HdStTextureIdentifier &textureId, HdSt_TextureObjectRegistry *textureObjectRegistry)
HDST_API ~HdStDynamicUvTextureObject() override
HDST_API void _Load() override
void _CreateTexture(const HgiTextureDesc &desc)
HDST_API void _Commit() override
HDST_API bool IsValid() const override
void CreateTexture(const HgiTextureDesc &desc)
void _SetCpuData(std::unique_ptr< HdStTextureCpuData > &&)
void _SetWrapParameters(const std::pair< HdWrap, HdWrap > &wrapParameters)
void DestroyTexture()
Release GPU resource.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
HdStTextureCpuData * _GetCpuData() const
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
void SetWrapParameters(const std::pair< HdWrap, HdWrap > &wrapParameters)
void SetCpuData(std::unique_ptr< HdStTextureCpuData > &&cpuData)