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