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