Loading...
Searching...
No Matches
textureObject.h
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_TEXTURE_OBJECT_H
25#define PXR_IMAGING_HD_ST_TEXTURE_OBJECT_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hdSt/api.h"
29
30#include "pxr/imaging/hdSt/textureIdentifier.h"
31#include "pxr/imaging/hd/enums.h"
32#include "pxr/imaging/hd/types.h"
33
34#include "pxr/imaging/hgi/handle.h"
36
37#include "pxr/base/gf/bbox3d.h"
39
40#include <memory>
41
42PXR_NAMESPACE_OPEN_SCOPE
43
44class Hgi;
46class HdSt_TextureObjectRegistry;
47struct HgiTextureDesc;
50
51using HdStTextureObjectSharedPtr = std::shared_ptr<class HdStTextureObject>;
52
59 public std::enable_shared_from_this<HdStTextureObject>
60{
61public:
65 GetTextureIdentifier() const { return _textureId; }
66
69 size_t GetTargetMemory() const { return _targetMemory; }
70
76 HDST_API
77 void SetTargetMemory(size_t);
78
84 HDST_API
85 virtual bool IsValid() const = 0;
86
89 HDST_API
90 virtual HdTextureType GetTextureType() const = 0;
91
92 HDST_API
93 virtual ~HdStTextureObject();
94
95protected:
97 const HdStTextureIdentifier &textureId,
98 HdSt_TextureObjectRegistry * textureObjectRegistry);
99
100 HDST_API
101 HdStResourceRegistry* _GetResourceRegistry() const;
102
103 HDST_API
104 Hgi* _GetHgi() const;
105
106 HDST_API
107 std::string _GetDebugName(const HdStTextureIdentifier &textureId) const;
108
109 HDST_API
110 bool
111 _GetPremultiplyAlpha(const HdStSubtextureIdentifier * const subId) const;
112
113 HDST_API
115 _GetSourceColorSpace(const HdStSubtextureIdentifier * const subId) const;
116
119 HDST_API
120 virtual void _Load() = 0;
121
124 HDST_API
125 virtual void _Commit() = 0;
126
130 HDST_API
131 void _AdjustTotalTextureMemory(int64_t memDiff);
132
135 HDST_API
137
140 HDST_API
142
143private:
144 friend class HdSt_TextureObjectRegistry;
145
146 HdSt_TextureObjectRegistry * const _textureObjectRegistry;
147 const HdStTextureIdentifier _textureId;
148 size_t _targetMemory;
149};
150
156{
157public:
158 ~HdStUvTextureObject() override;
159
165 return _gpuTexture;
166 }
167
171 const std::pair<HdWrap, HdWrap> &GetWrapParameters() const {
172 return _wrapParameters;
173 }
174
175 HDST_API
176 HdTextureType GetTextureType() const override final;
177
178protected:
180 const HdStTextureIdentifier &textureId,
181 HdSt_TextureObjectRegistry * textureObjectRegistry);
182
183 void _SetWrapParameters(
184 const std::pair<HdWrap, HdWrap> &wrapParameters);
185
186 void _SetCpuData(std::unique_ptr<HdStTextureCpuData> &&);
187 HdStTextureCpuData * _GetCpuData() const;
188
189 void _CreateTexture(const HgiTextureDesc &desc);
190 void _GenerateMipmaps();
191 void _DestroyTexture();
192
193private:
194 std::pair<HdWrap, HdWrap> _wrapParameters;
195 std::unique_ptr<HdStTextureCpuData> _cpuData;
196 HgiTextureHandle _gpuTexture;
197};
198
203class HdStAssetUvTextureObject final : public HdStUvTextureObject
204{
205public:
206 HDST_API
207 HdStAssetUvTextureObject(
208 const HdStTextureIdentifier &textureId,
209 HdSt_TextureObjectRegistry *textureObjectRegistry);
210
211 HDST_API
212 ~HdStAssetUvTextureObject() override;
213
214 HDST_API
215 bool IsValid() const override;
216
217protected:
218 HDST_API
219 void _Load() override;
220
221 HDST_API
222 void _Commit() override;
223
224private:
225 bool _valid;
226};
227
233{
234public:
235 HDST_API
237 const HdStTextureIdentifier &textureId,
238 HdSt_TextureObjectRegistry *textureObjectRegistry);
239
240 HDST_API
241 ~HdStFieldTextureObject() override;
242
248 return _gpuTexture;
249 }
250
255 const GfBBox3d &GetBoundingBox() const { return _bbox; }
256
262 return _samplingTransform;
263 }
264
265 HDST_API
266 bool IsValid() const override;
267
268 HDST_API
269 HdTextureType GetTextureType() const override;
270
271protected:
272 HDST_API
273 void _Load() override;
274
275 HDST_API
276 void _Commit() override;
277
278private:
279 std::unique_ptr<HdStTextureCpuData> _cpuData;
280 GfBBox3d _bbox;
281 GfMatrix4d _samplingTransform;
282 HgiTextureHandle _gpuTexture;
283 bool _valid;
284};
285
286template<HdTextureType textureType>
287struct HdSt_TypedTextureObjectHelper;
288
294template<HdTextureType textureType>
296 typename HdSt_TypedTextureObjectHelper<textureType>::type;
297
298template<>
299struct HdSt_TypedTextureObjectHelper<HdTextureType::Uv> {
300 using type = HdStUvTextureObject;
301};
302
303template<>
304struct HdSt_TypedTextureObjectHelper<HdTextureType::Field> {
305 using type = HdStFieldTextureObject;
306};
307
308PXR_NAMESPACE_CLOSE_SCOPE
309
310#endif
Basic type: arbitrarily oriented 3D bounding box.
Definition: bbox3d.h:84
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
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 HdTextureType GetTextureType() const override
Get texture type.
const GfBBox3d & GetBoundingBox() const
The box the texture fills out.
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:60
size_t GetTargetMemory() const
Get the target memory for the texture.
Definition: textureObject.h:69
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 HdTextureType GetTextureType() const =0
Get texture type.
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:65
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<HdTex...
A base class for uv textures.
HDST_API HdTextureType 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:111
SourceColorSpace
Specifies the source color space in which the texture is encoded, with "Auto" indicating the texture ...
Definition: image.h:71
Standard pointer typedefs.
STL namespace.
Describes the properties needed to create a GPU texture.
Definition: texture.h:108