HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
subtextureIdentifier.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_SUBTEXTURE_IDENTIFIER_H
8 #define PXR_IMAGING_HD_ST_SUBTEXTURE_IDENTIFIER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 
13 #include "pxr/base/tf/token.h"
14 
15 #include <memory>
16 
18 
20 class HdStDynamicCubemapTextureImplementation;
21 
22 ///
23 /// \class HdStSubtextureIdentifier
24 ///
25 /// Base class for additional information to identify a texture in a
26 /// file that can contain several textures (e.g., frames in a movie or
27 /// grids in an OpenVDB file).
28 ///
30 {
31 public:
32  using ID = size_t;
33 
34  HDST_API
35  virtual std::unique_ptr<HdStSubtextureIdentifier> Clone() const = 0;
36 
37  HDST_API
38  virtual ~HdStSubtextureIdentifier();
39 
40 protected:
41  HDST_API
42  friend size_t hash_value(const HdStSubtextureIdentifier &subId);
43 
44  virtual ID _Hash() const = 0;
45 };
46 
48 size_t hash_value(const HdStSubtextureIdentifier &subId);
49 
50 ///
51 /// \class HdStFieldBaseSubtextureIdentifier
52 ///
53 /// Base class for information identifying a grid in a volume field
54 /// file. Parallels FieldBase in usdVol.
55 ///
57 {
58 public:
59  /// Get field name.
60  ///
61  HDST_API
62  TfToken const &GetFieldName() const { return _fieldName; }
63 
64  /// Get field index.
65  ///
66  HDST_API
67  int GetFieldIndex() const { return _fieldIndex; }
68 
69  HDST_API
71 
72 protected:
73  HDST_API
74  HdStFieldBaseSubtextureIdentifier(TfToken const &fieldName, int fieldIndex);
75 
76  HDST_API
77  ID _Hash() const override;
78 
79 private:
80  TfToken _fieldName;
81  int _fieldIndex;
82 };
83 
84 ///
85 /// \class HdStAssetUvSubtextureIdentifier
86 ///
87 /// Specifies whether a UV texture should be loaded flipped vertically, whether
88 /// it should be loaded with pre-multiplied alpha values, and the color space
89 /// in which the texture is encoded.
90 ///
91 /// The former functionality allows the texture system to support both the
92 /// legacy HwUvTexture_1 (flipVertically = true) and UsdUvTexture
93 /// (flipVertically = false) which have opposite conventions for the
94 /// vertical orientation.
95 ///
98 {
99 public:
100  /// C'tor takes bool whether flipping vertically, whether to pre-multiply
101  /// by alpha, and the texture's source color space
102  HDST_API
103  explicit HdStAssetUvSubtextureIdentifier(bool flipVertically,
104  bool premultiplyAlpha,
105  const TfToken& sourceColorSpace);
106 
107  HDST_API
108  std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
109 
110  HDST_API
111  bool GetFlipVertically() const { return _flipVertically; }
112 
113  HDST_API
114  bool GetPremultiplyAlpha() const { return _premultiplyAlpha; }
115 
116  HDST_API
117  TfToken GetSourceColorSpace() const { return _sourceColorSpace; }
118 
119  HDST_API
121 
122 protected:
123  HDST_API
124  ID _Hash() const override;
125 
126 private:
127  bool _flipVertically;
128  bool _premultiplyAlpha;
129  TfToken _sourceColorSpace;
130 };
131 
132 ///
133 /// \class HdStDynamicUvSubtextureIdentifier
134 ///
135 /// Used as a tag that the Storm texture system returns a
136 /// HdStDynamicUvTextureObject that is populated by a client rather
137 /// than by the Storm texture system.
138 ///
139 /// Clients can subclass this class and provide their own
140 /// HdStDynamicUvTextureImplementation to create UV texture with custom
141 /// load and commit behavior.
142 ///
143 /// testHdStDynamicUvTexture.cpp is an example of how custom load and
144 /// commit behavior can be implemented.
145 ///
146 /// AOV's are another example. In presto, these are baked by
147 /// HdStDynamicUvTextureObject's. In this case, the
148 /// HdStDynamicUvTextureObject's do not provide custom load or commit
149 /// behavior (null-ptr returned by GetTextureImplementation). Instead,
150 /// GPU memory is allocated by explicitly calling
151 /// HdStDynamicUvTextureObject::CreateTexture in
152 /// HdStRenderBuffer::Sync/Allocate and the texture is filled by using
153 /// it as render target in various render passes.
154 ///
156 {
157 public:
158  HDST_API
160 
161  HDST_API
163 
164  HDST_API
165  std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
166 
167  /// Textures can return their own HdStDynamicUvTextureImplementation
168  /// to customize the load and commit behavior.
169  HDST_API
171 
172 protected:
173  HDST_API
174  ID _Hash() const override;
175 };
176 
177 ///
178 /// \class HdStPtexSubtextureIdentifier
179 ///
180 /// Specifies whether a Ptex texture should be loaded with pre-multiplied alpha
181 /// values.
182 ///
184  : public HdStSubtextureIdentifier
185 {
186 public:
187  /// C'tor takes bool whether to pre-multiply by alpha
188  HDST_API
189  explicit HdStPtexSubtextureIdentifier(bool premultiplyAlpha);
190 
191  HDST_API
192  std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
193 
194  HDST_API
195  bool GetPremultiplyAlpha() const { return _premultiplyAlpha; }
196 
197  HDST_API
199 
200 protected:
201  HDST_API
202  ID _Hash() const override;
203 
204 private:
205  bool _premultiplyAlpha;
206 };
207 
208 ///
209 /// \class HdStUdimSubtextureIdentifier
210 ///
211 /// Specifies whether a Udim texture should be loaded with pre-multiplied alpha
212 /// values and the color space in which the texture is encoded.
213 ///
215  : public HdStSubtextureIdentifier
216 {
217 public:
218  /// C'tor takes bool whether to pre-multiply by alpha and the texture's
219  /// source color space
220  HDST_API
221  explicit HdStUdimSubtextureIdentifier(bool premultiplyAlpha,
222  const TfToken& sourceColorSpace);
223 
224  HDST_API
225  std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
226 
227  HDST_API
228  bool GetPremultiplyAlpha() const { return _premultiplyAlpha; }
229 
230  HDST_API
231  TfToken GetSourceColorSpace() const { return _sourceColorSpace; }
232 
233  HDST_API
235 
236 protected:
237  HDST_API
238  ID _Hash() const override;
239 
240 private:
241  bool _premultiplyAlpha;
242  TfToken _sourceColorSpace;
243 };
244 
245 ///
246 /// \class HdStDynamicCubemapSubtextureIdentifier
247 ///
248 /// Used as a tag that the Storm texture system returns a
249 /// HdStDynamicUvTextureObject that is populated by a client rather
250 /// than by the Storm texture system.
251 ///
252 /// Clients can subclass this class and provide their own
253 /// HdStDynamicUvTextureImplementation to create cubemap texture with
254 /// custom load and commit behavior.
255 ///
257 {
258 public:
259  HDST_API
261 
262  HDST_API
264 
265  HDST_API
266  std::unique_ptr<HdStSubtextureIdentifier> Clone() const override;
267 
268  /// Textures can return their own HdStDynamicUvTextureImplementation
269  /// to customize the load and commit behavior.
270  HDST_API
272  GetTextureImplementation() const;
273 
274 protected:
275  HDST_API
276  ID _Hash() const override;
277 };
278 
280 
281 #endif
HDST_API ~HdStDynamicCubemapSubtextureIdentifier() override
HDST_API ~HdStUdimSubtextureIdentifier() override
HDST_API ID _Hash() const override
HDST_API ID _Hash() const override
virtual HDST_API ~HdStSubtextureIdentifier()
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
HDST_API std::unique_ptr< HdStSubtextureIdentifier > Clone() const override
virtual HDST_API HdStDynamicUvTextureImplementation * GetTextureImplementation() const
HDST_API bool GetFlipVertically() const
HDST_API bool GetPremultiplyAlpha() const
HDST_API size_t hash_value(const HdStSubtextureIdentifier &subId)
Definition: token.h:70
HDST_API std::unique_ptr< HdStSubtextureIdentifier > Clone() const override
HDST_API friend size_t hash_value(const HdStSubtextureIdentifier &subId)
HDST_API ~HdStAssetUvSubtextureIdentifier() override
HDST_API bool GetPremultiplyAlpha() const
HDST_API HdStUdimSubtextureIdentifier(bool premultiplyAlpha, const TfToken &sourceColorSpace)
HDST_API TfToken GetSourceColorSpace() const
HDST_API HdStPtexSubtextureIdentifier(bool premultiplyAlpha)
C'tor takes bool whether to pre-multiply by alpha.
virtual HDST_API HdStDynamicUvTextureImplementation * GetTextureImplementation() const
HDST_API TfToken GetSourceColorSpace() const
HDST_API ID _Hash() const override
HDST_API std::unique_ptr< HdStSubtextureIdentifier > Clone() const override
HDST_API ID _Hash() const override
virtual ID _Hash() const =0
HDST_API std::unique_ptr< HdStSubtextureIdentifier > Clone() const override
HDST_API bool GetPremultiplyAlpha() const
HDST_API HdStFieldBaseSubtextureIdentifier(TfToken const &fieldName, int fieldIndex)
virtual HDST_API std::unique_ptr< HdStSubtextureIdentifier > Clone() const =0
#define HDST_API
Definition: api.h:23
HDST_API ~HdStDynamicUvSubtextureIdentifier() override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDST_API ~HdStFieldBaseSubtextureIdentifier() override=0
HDST_API ~HdStPtexSubtextureIdentifier() override
HDST_API HdStAssetUvSubtextureIdentifier(bool flipVertically, bool premultiplyAlpha, const TfToken &sourceColorSpace)
HDST_API ID _Hash() const override
HDST_API ID _Hash() const override
HDST_API TfToken const & GetFieldName() const
HDST_API std::unique_ptr< HdStSubtextureIdentifier > Clone() const override