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
67 HDST_API
68 virtual bool IsValid() const = 0;
69
72 HDST_API
73 virtual HdStTextureType GetTextureType() const = 0;
74
75 HDST_API
76 virtual ~HdStTextureObject();
77
78protected:
80 const HdStTextureIdentifier &textureId,
81 HdSt_TextureObjectRegistry * textureObjectRegistry);
82
83 HDST_API
84 HdStResourceRegistry* _GetResourceRegistry() const;
85
86 HDST_API
87 Hgi* _GetHgi() const;
88
89 HDST_API
90 std::string _GetDebugName(const HdStTextureIdentifier &textureId) const;
91
92 HDST_API
93 bool
94 _GetPremultiplyAlpha(const HdStSubtextureIdentifier * const subId) const;
95
96 HDST_API
98 _GetSourceColorSpace(const HdStSubtextureIdentifier * const subId) const;
99
102 HDST_API
103 virtual void _Load() = 0;
104
107 HDST_API
108 virtual void _Commit() = 0;
109
113 HDST_API
114 void _AdjustTotalTextureMemory(int64_t memDiff);
115
118 HDST_API
120
123 HDST_API
125
126private:
127 friend class HdSt_TextureObjectRegistry;
128
129 HdSt_TextureObjectRegistry * const _textureObjectRegistry;
130 const HdStTextureIdentifier _textureId;
131 size_t _targetMemory;
132};
133
139{
140public:
141 HDST_API
142 ~HdStUvTextureObject() override;
143
149 return _gpuTexture;
150 }
151
155 const std::pair<HdWrap, HdWrap> &GetWrapParameters() const {
156 return _wrapParameters;
157 }
158
159 HDST_API
160 HdStTextureType GetTextureType() const override final;
161
162protected:
163 HDST_API
165 const HdStTextureIdentifier &textureId,
166 HdSt_TextureObjectRegistry * textureObjectRegistry);
167
168 HDST_API
169 void _SetWrapParameters(
170 const std::pair<HdWrap, HdWrap> &wrapParameters);
171
172 HDST_API
173 void _SetCpuData(std::unique_ptr<HdStTextureCpuData> &&);
174 HDST_API
175 HdStTextureCpuData * _GetCpuData() const;
176
177 HDST_API
178 void _CreateTexture(const HgiTextureDesc &desc);
179 HDST_API
180 void _GenerateMipmaps();
181 HDST_API
182 void _DestroyTexture();
183
184private:
185 std::pair<HdWrap, HdWrap> _wrapParameters;
186 std::unique_ptr<HdStTextureCpuData> _cpuData;
187 HgiTextureHandle _gpuTexture;
188};
189
194class HdStAssetUvTextureObject final : public HdStUvTextureObject
195{
196public:
197 HDST_API
198 HdStAssetUvTextureObject(
199 const HdStTextureIdentifier &textureId,
200 HdSt_TextureObjectRegistry *textureObjectRegistry);
201
202 HDST_API
203 ~HdStAssetUvTextureObject() override;
204
205 HDST_API
206 bool IsValid() const override;
207
208protected:
209 HDST_API
210 void _Load() override;
211
212 HDST_API
213 void _Commit() override;
214
215private:
216 bool _valid;
217};
218
224{
225public:
226 HDST_API
228 const HdStTextureIdentifier &textureId,
229 HdSt_TextureObjectRegistry *textureObjectRegistry);
230
231 HDST_API
232 ~HdStFieldTextureObject() override;
233
239 return _gpuTexture;
240 }
241
246 const GfBBox3d &GetBoundingBox() const { return _bbox; }
247
253 return _samplingTransform;
254 }
255
256 HDST_API
257 bool IsValid() const override;
258
259 HDST_API
260 HdStTextureType GetTextureType() const override;
261
262protected:
263 HDST_API
264 void _Load() override;
265
266 HDST_API
267 void _Commit() override;
268
269private:
270 std::unique_ptr<HdStTextureCpuData> _cpuData;
271 GfBBox3d _bbox;
272 GfMatrix4d _samplingTransform;
273 HgiTextureHandle _gpuTexture;
274 bool _valid;
275};
276
282{
283public:
284 HDST_API
285 ~HdStCubemapTextureObject() override;
286
292 return _gpuTexture;
293 }
294
295 HDST_API
296 HdStTextureType GetTextureType() const final;
297
298protected:
299 HDST_API
301 const HdStTextureIdentifier &textureId,
302 HdSt_TextureObjectRegistry * textureObjectRegistry);
303
304 HDST_API
305 void _SetCpuData(std::unique_ptr<HdStTextureCpuData> &&);
306 HDST_API
307 HdStTextureCpuData * _GetCpuData() const;
308
309 HDST_API
310 void _CreateTexture(const HgiTextureDesc &desc);
311 HDST_API
312 void _GenerateMipmaps();
313 HDST_API
314 void _DestroyTexture();
315
316private:
317 std::unique_ptr<HdStTextureCpuData> _cpuData;
318 HgiTextureHandle _gpuTexture;
319};
320
321template<HdStTextureType textureType>
322struct HdSt_TypedTextureObjectHelper;
323
329template<HdStTextureType textureType>
331 typename HdSt_TypedTextureObjectHelper<textureType>::type;
332
333template<>
334struct HdSt_TypedTextureObjectHelper<HdStTextureType::Uv> {
335 using type = HdStUvTextureObject;
336};
337
338template<>
339struct HdSt_TypedTextureObjectHelper<HdStTextureType::Field> {
340 using type = HdStFieldTextureObject;
341};
342
343template<>
344struct HdSt_TypedTextureObjectHelper<HdStTextureType::Cubemap> {
345 using type = HdStCubemapTextureObject;
346};
347
348PXR_NAMESPACE_CLOSE_SCOPE
349
350#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)
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 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.
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