Loading...
Searching...
No Matches
textureObject.h
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_TEXTURE_OBJECT_H
8#define PXR_IMAGING_HD_ST_TEXTURE_OBJECT_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdSt/api.h"
12
13#include "pxr/imaging/hdSt/textureIdentifier.h"
14#include "pxr/imaging/hdSt/enums.h"
15#include "pxr/imaging/hd/types.h"
16
17#include "pxr/imaging/hgi/handle.h"
19
20#include "pxr/base/gf/bbox3d.h"
22
23#include <memory>
24
25PXR_NAMESPACE_OPEN_SCOPE
26
27class Hgi;
29class HdSt_TextureObjectRegistry;
30struct HgiTextureDesc;
33
34using HdStTextureObjectSharedPtr = std::shared_ptr<class HdStTextureObject>;
35
42 public std::enable_shared_from_this<HdStTextureObject>
43{
44public:
48 GetTextureIdentifier() const { return _textureId; }
49
52 size_t GetTargetMemory() const { return _targetMemory; }
53
59 HDST_API
60 void SetTargetMemory(size_t);
61
63 HDST_API
64 virtual size_t GetCommittedSize() const = 0;
65
71 HDST_API
72 virtual bool IsValid() const = 0;
73
76 HDST_API
77 virtual HdStTextureType GetTextureType() const = 0;
78
79 HDST_API
80 virtual ~HdStTextureObject();
81
82protected:
84 const HdStTextureIdentifier &textureId,
85 HdSt_TextureObjectRegistry * textureObjectRegistry);
86
87 HDST_API
88 HdStResourceRegistry* _GetResourceRegistry() const;
89
90 HDST_API
91 Hgi* _GetHgi() const;
92
93 HDST_API
94 std::string _GetDebugName(const HdStTextureIdentifier &textureId) const;
95
96 HDST_API
97 bool
98 _GetPremultiplyAlpha(const HdStSubtextureIdentifier * const subId) const;
99
100 HDST_API
102 _GetSourceColorSpace(const HdStSubtextureIdentifier * const subId) const;
103
106 HDST_API
107 virtual void _Load() = 0;
108
111 HDST_API
112 virtual void _Commit() = 0;
113
117 HDST_API
118 void _AdjustTotalTextureMemory(int64_t memDiff);
119
122 HDST_API
124
127 HDST_API
129
130private:
131 friend class HdSt_TextureObjectRegistry;
132
133 HdSt_TextureObjectRegistry * const _textureObjectRegistry;
134 const HdStTextureIdentifier _textureId;
135 size_t _targetMemory;
136};
137
143{
144public:
145 HDST_API
146 ~HdStUvTextureObject() override;
147
153 return _gpuTexture;
154 }
155
159 const std::pair<HdWrap, HdWrap> &GetWrapParameters() const {
160 return _wrapParameters;
161 }
162
163 HDST_API
164 HdStTextureType GetTextureType() const override final;
165
166 HDST_API
167 size_t GetCommittedSize() const override;
168
169protected:
170 HDST_API
172 const HdStTextureIdentifier &textureId,
173 HdSt_TextureObjectRegistry * textureObjectRegistry);
174
175 HDST_API
176 void _SetWrapParameters(
177 const std::pair<HdWrap, HdWrap> &wrapParameters);
178
179 HDST_API
180 void _SetCpuData(std::unique_ptr<HdStTextureCpuData> &&);
181 HDST_API
182 HdStTextureCpuData * _GetCpuData() const;
183
184 HDST_API
185 void _CreateTexture(const HgiTextureDesc &desc);
186 HDST_API
187 void _GenerateMipmaps();
188 HDST_API
189 void _DestroyTexture();
190
191private:
192 std::pair<HdWrap, HdWrap> _wrapParameters;
193 std::unique_ptr<HdStTextureCpuData> _cpuData;
194 HgiTextureHandle _gpuTexture;
195};
196
201class HdStAssetUvTextureObject final : public HdStUvTextureObject
202{
203public:
204 HDST_API
205 HdStAssetUvTextureObject(
206 const HdStTextureIdentifier &textureId,
207 HdSt_TextureObjectRegistry *textureObjectRegistry);
208
209 HDST_API
210 ~HdStAssetUvTextureObject() override;
211
212 HDST_API
213 bool IsValid() const override;
214
215protected:
216 HDST_API
217 void _Load() override;
218
219 HDST_API
220 void _Commit() override;
221
222private:
223 bool _valid;
224};
225
231{
232public:
233 HDST_API
235 const HdStTextureIdentifier &textureId,
236 HdSt_TextureObjectRegistry *textureObjectRegistry);
237
238 HDST_API
239 ~HdStFieldTextureObject() override;
240
246 return _gpuTexture;
247 }
248
253 const GfBBox3d &GetBoundingBox() const { return _bbox; }
254
260 return _samplingTransform;
261 }
262
263 HDST_API
264 bool IsValid() const override;
265
266 HDST_API
267 HdStTextureType GetTextureType() const override;
268
269 HDST_API
270 size_t GetCommittedSize() const override;
271
272protected:
273 HDST_API
274 void _Load() override;
275
276 HDST_API
277 void _Commit() override;
278
279private:
280 std::unique_ptr<HdStTextureCpuData> _cpuData;
281 GfBBox3d _bbox;
282 GfMatrix4d _samplingTransform;
283 HgiTextureHandle _gpuTexture;
284 bool _valid;
285};
286
292{
293public:
294 HDST_API
295 ~HdStCubemapTextureObject() override;
296
302 return _gpuTexture;
303 }
304
305 HDST_API
306 HdStTextureType GetTextureType() const final;
307
308 HDST_API
309 size_t GetCommittedSize() const override;
310
311protected:
312 HDST_API
314 const HdStTextureIdentifier &textureId,
315 HdSt_TextureObjectRegistry * textureObjectRegistry);
316
317 HDST_API
318 void _SetCpuData(std::unique_ptr<HdStTextureCpuData> &&);
319 HDST_API
320 HdStTextureCpuData * _GetCpuData() const;
321
322 HDST_API
323 void _CreateTexture(const HgiTextureDesc &desc);
324 HDST_API
325 void _GenerateMipmaps();
326 HDST_API
327 void _DestroyTexture();
328
329private:
330 std::unique_ptr<HdStTextureCpuData> _cpuData;
331 HgiTextureHandle _gpuTexture;
332};
333
334template<HdStTextureType textureType>
335struct HdSt_TypedTextureObjectHelper;
336
342template<HdStTextureType textureType>
344 typename HdSt_TypedTextureObjectHelper<textureType>::type;
345
346template<>
347struct HdSt_TypedTextureObjectHelper<HdStTextureType::Uv> {
348 using type = HdStUvTextureObject;
349};
350
351template<>
352struct HdSt_TypedTextureObjectHelper<HdStTextureType::Field> {
353 using type = HdStFieldTextureObject;
354};
355
356template<>
357struct HdSt_TypedTextureObjectHelper<HdStTextureType::Cubemap> {
358 using type = HdStCubemapTextureObject;
359};
360
361PXR_NAMESPACE_CLOSE_SCOPE
362
363#endif
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:67
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
A base class for cubemap textures.
HDST_API HdStTextureType GetTextureType() const final
Get texture type.
HgiTextureHandle const & GetTexture() const
Get the handle to the actual GPU resource.
A uvw texture with a bounding box describing how to transform it.
HDST_API void _Load() override
Load texture to CPU (thread-safe)
HDST_API bool IsValid() const override
Is texture valid? Only correct after commit phase.
HDST_API void _Commit() override
Commit texture to GPU (not thread-safe)
HDST_API size_t GetCommittedSize() const override
Returns the actual amount of memory committed to the GPU.
const GfBBox3d & GetBoundingBox() const
The box the texture fills out.
HDST_API HdStTextureType GetTextureType() const override
Get texture type.
HgiTextureHandle const & GetTexture() const
Get the handle to the actual GPU resource.
const GfMatrix4d & GetSamplingTransform() const
The sampling transform.
A central registry of all GPU resources.
Base class for additional information to identify a texture in a file that can contain several textur...
Represents CPU data that can be stored in a HdStUvTextureObject, mostly, likely during the load phase...
Class to identify a texture file or a texture within the texture file (e.g., a frame in a movie).
Base class for a texture object.
Definition: textureObject.h:43
size_t GetTargetMemory() const
Get the target memory for the texture.
Definition: textureObject.h:52
virtual HDST_API size_t GetCommittedSize() const =0
Returns the actual amount of memory committed to the GPU.
virtual HDST_API HdStTextureType GetTextureType() const =0
Get texture type.
HDST_API void _AdjustTotalTextureMemory(int64_t memDiff)
Add signed number to total texture memory amount maintained by registry.
HDST_API void _AddToTotalTextureMemory(const HgiTextureHandle &texture)
Compute memory of texture and add to total texture memory amount maintained by registry.
virtual HDST_API void _Load()=0
Load texture to CPU (thread-safe)
HDST_API void _SubtractFromTotalTextureMemory(const HgiTextureHandle &texture)
Compute memory of texture and subtract to total texture memory amount maintained by registry.
HDST_API void SetTargetMemory(size_t)
Set the target memory (in bytes).
virtual HDST_API bool IsValid() const =0
Is texture valid? Only correct after commit phase.
const HdStTextureIdentifier & GetTextureIdentifier() const
Get texture identifier.
Definition: textureObject.h:48
virtual HDST_API void _Commit()=0
Commit texture to GPU (not thread-safe)
A template alias such that, e.g., HdStUvTextureObject can be accessed as HdStTypedTextureObject<HdStT...
A base class for uv textures.
HDST_API HdStTextureType GetTextureType() const override final
Get texture type.
HDST_API size_t GetCommittedSize() const override
Returns the actual amount of memory committed to the GPU.
const std::pair< HdWrap, HdWrap > & GetWrapParameters() const
Opinion about wrapS and wrapT parameters from the texture file.
HgiTextureHandle const & GetTexture() const
Get the handle to the actual GPU resource.
Hydra Graphics Interface.
Definition: hgi.h:95
SourceColorSpace
Specifies the source color space in which the texture is encoded, with "Auto" indicating the texture ...
Definition: image.h:54
Standard pointer typedefs.
STL namespace.
Describes the properties needed to create a GPU texture.
Definition: texture.h:91