types.h
1 //
2 // Copyright 2016 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_TYPES_H
25 #define PXR_IMAGING_HD_TYPES_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/enums.h"
30 #include "pxr/imaging/hd/version.h"
31 #include "pxr/base/vt/value.h"
32 #include <algorithm>
33 #include <cmath>
34 #include <cstddef>
35 #include <cstdint>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
54 enum HdWrap
55 {
56  HdWrapClamp,
57  HdWrapRepeat,
58  HdWrapBlack,
59  HdWrapMirror,
60 
61  HdWrapNoOpinion,
62  HdWrapLegacyNoOpinionFallbackRepeat, // deprecated
63 
64  HdWrapUseMetadata = HdWrapNoOpinion, // deprecated alias
65  HdWrapLegacy = HdWrapLegacyNoOpinionFallbackRepeat // deprecated alias
66 };
67 
81 enum HdMinFilter
82 {
83  HdMinFilterNearest,
84  HdMinFilterLinear,
85  HdMinFilterNearestMipmapNearest,
86  HdMinFilterLinearMipmapNearest,
87  HdMinFilterNearestMipmapLinear,
88  HdMinFilterLinearMipmapLinear,
89 };
90 
100 enum HdMagFilter
101 {
102  HdMagFilterNearest,
103  HdMagFilterLinear,
104 };
105 
116 enum HdBorderColor
117 {
118  HdBorderColorTransparentBlack,
119  HdBorderColorOpaqueBlack,
120  HdBorderColorOpaqueWhite,
121 };
122 
128 public:
129  HdWrap wrapS;
130  HdWrap wrapT;
131  HdWrap wrapR;
132  HdMinFilter minFilter;
133  HdMagFilter magFilter;
134  HdBorderColor borderColor;
135  bool enableCompare;
136  HdCompareFunction compareFunction;
137 
138  HD_API
140 
141  HD_API
142  HdSamplerParameters(HdWrap wrapS, HdWrap wrapT, HdWrap wrapR,
143  HdMinFilter minFilter, HdMagFilter magFilter,
144  HdBorderColor borderColor=HdBorderColorTransparentBlack,
145  bool enableCompare=false,
146  HdCompareFunction compareFunction=HdCmpFuncNever);
147 
148  HD_API
149  bool operator==(const HdSamplerParameters &other) const;
150 
151  HD_API
152  bool operator!=(const HdSamplerParameters &other) const;
153 };
154 
158 typedef uint32_t HdDirtyBits;
159 
160 // GL Spec 2.3.5.2 (signed case, eq 2.4)
161 inline int HdConvertFloatToFixed(float v, int b)
162 {
163  return int(
164  std::round(
165  std::min(std::max(v, -1.0f), 1.0f) * (float(1 << (b-1)) - 1.0f)));
166 }
167 
168 // GL Spec 2.3.5.1 (signed case, eq 2.2)
169 inline float HdConvertFixedToFloat(int v, int b)
170 {
171  return float(
172  std::max(-1.0f,
173  (v / (float(1 << (b-1)) - 1.0f))));
174 }
175 
184 {
186 
187  template <typename Vec3Type>
188  HdVec4f_2_10_10_10_REV(Vec3Type const &value) {
189  x = HdConvertFloatToFixed(value[0], 10);
190  y = HdConvertFloatToFixed(value[1], 10);
191  z = HdConvertFloatToFixed(value[2], 10);
192  w = 0;
193  }
194 
195  HdVec4f_2_10_10_10_REV(int const value) {
196  HdVec4f_2_10_10_10_REV const* other =
197  reinterpret_cast<HdVec4f_2_10_10_10_REV const*>(&value);
198  x = other->x;
199  y = other->y;
200  z = other->z;
201  w = other->w;
202  }
203 
204  template <typename Vec3Type>
205  Vec3Type GetAsVec() const {
206  return Vec3Type(HdConvertFixedToFloat(x, 10),
207  HdConvertFixedToFloat(y, 10),
208  HdConvertFixedToFloat(z, 10));
209  }
210 
211  int GetAsInt() const {
212  int const* asInt = reinterpret_cast<int const*>(this);
213  return *asInt;
214  }
215 
216  bool operator==(const HdVec4f_2_10_10_10_REV &other) const {
217  return (other.w == w &&
218  other.z == z &&
219  other.y == y &&
220  other.x == x);
221  }
222  bool operator!=(const HdVec4f_2_10_10_10_REV &other) const {
223  return !(*this == other);
224  }
225 
226  int x : 10;
227  int y : 10;
228  int z : 10;
229  int w : 2;
230 };
231 
287 enum HdType
288 {
289  HdTypeInvalid=-1,
290 
292  HdTypeBool=0,
293  HdTypeUInt8,
294  HdTypeUInt16,
295  HdTypeInt8,
296  HdTypeInt16,
297 
299  HdTypeInt32,
301  HdTypeInt32Vec2,
303  HdTypeInt32Vec3,
305  HdTypeInt32Vec4,
306 
308  HdTypeUInt32,
310  HdTypeUInt32Vec2,
312  HdTypeUInt32Vec3,
314  HdTypeUInt32Vec4,
315 
317  HdTypeFloat,
319  HdTypeFloatVec2,
321  HdTypeFloatVec3,
323  HdTypeFloatVec4,
325  HdTypeFloatMat3,
327  HdTypeFloatMat4,
328 
330  HdTypeDouble,
332  HdTypeDoubleVec2,
334  HdTypeDoubleVec3,
336  HdTypeDoubleVec4,
338  HdTypeDoubleMat3,
340  HdTypeDoubleMat4,
341 
342  HdTypeHalfFloat,
343  HdTypeHalfFloatVec2,
344  HdTypeHalfFloatVec3,
345  HdTypeHalfFloatVec4,
346 
350  HdTypeInt32_2_10_10_10_REV,
351 
352  HdTypeCount
353 };
354 
358 struct HdTupleType {
359  HdType type;
360  size_t count;
361 
362  bool operator< (HdTupleType const& rhs) const {
363  return (type < rhs.type) || (type == rhs.type && count < rhs.count);
364  }
365  bool operator== (HdTupleType const& rhs) const {
366  return type == rhs.type && count == rhs.count;
367  }
368  bool operator!= (HdTupleType const& rhs) const {
369  return !(*this == rhs);
370  }
371 };
372 
373 // Support TfHash.
374 template <class HashState>
375 void
376 TfHashAppend(HashState &h, HdTupleType const &tt)
377 {
378  h.Append(tt.type, tt.count);
379 }
380 
383 HD_API
384 const void* HdGetValueData(const VtValue &);
385 
389 HD_API
390 HdTupleType HdGetValueTupleType(const VtValue &);
391 
396 HD_API
397 HdType HdGetComponentType(HdType);
398 
401 HD_API
402 size_t HdGetComponentCount(HdType t);
403 
405 HD_API
406 size_t HdDataSizeOfType(HdType);
407 
409 HD_API
410 size_t HdDataSizeOfTupleType(HdTupleType);
411 
423 enum HdFormat
424 {
425  HdFormatInvalid=-1,
426 
427  // UNorm8 - a 1-byte value representing a float between 0 and 1.
428  // float value = (unorm / 255.0f);
429  HdFormatUNorm8=0,
430  HdFormatUNorm8Vec2,
431  HdFormatUNorm8Vec3,
432  HdFormatUNorm8Vec4,
433 
434  // SNorm8 - a 1-byte value representing a float between -1 and 1.
435  // float value = max(snorm / 127.0f, -1.0f);
436  HdFormatSNorm8,
437  HdFormatSNorm8Vec2,
438  HdFormatSNorm8Vec3,
439  HdFormatSNorm8Vec4,
440 
441  // Float16 - a 2-byte IEEE half-precision float.
442  HdFormatFloat16,
443  HdFormatFloat16Vec2,
444  HdFormatFloat16Vec3,
445  HdFormatFloat16Vec4,
446 
447  // Float32 - a 4-byte IEEE float.
448  HdFormatFloat32,
449  HdFormatFloat32Vec2,
450  HdFormatFloat32Vec3,
451  HdFormatFloat32Vec4,
452 
453  // Int16 - a 2-byte signed integer
454  HdFormatInt16,
455  HdFormatInt16Vec2,
456  HdFormatInt16Vec3,
457  HdFormatInt16Vec4,
458 
459  // UInt16 - a 2-byte unsigned integer
460  HdFormatUInt16,
461  HdFormatUInt16Vec2,
462  HdFormatUInt16Vec3,
463  HdFormatUInt16Vec4,
464 
465  // Int32 - a 4-byte signed integer
466  HdFormatInt32,
467  HdFormatInt32Vec2,
468  HdFormatInt32Vec3,
469  HdFormatInt32Vec4,
470 
471  // Depth-stencil format
472  HdFormatFloat32UInt8,
473 
474  HdFormatCount
475 };
476 
478 HD_API
479 HdFormat HdGetComponentFormat(HdFormat f);
480 
482 HD_API
483 size_t HdGetComponentCount(HdFormat f);
484 
487 HD_API
488 size_t HdDataSizeOfFormat(HdFormat f);
489 
490 PXR_NAMESPACE_CLOSE_SCOPE
491 
492 #endif // PXR_IMAGING_HD_TYPES_H
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:358
HdVec4f_2_10_10_10_REV is a compact representation of a GfVec4f.
Definition: types.h:183
Collection of standard parameters such as wrap modes to sample a texture.
Definition: types.h:127
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166