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/version.h"
30 #include "pxr/base/vt/value.h"
31 #include <algorithm>
32 #include <cmath>
33 #include <cstddef>
34 #include <cstdint>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
53 enum HdWrap
54 {
55  HdWrapClamp,
56  HdWrapRepeat,
57  HdWrapBlack,
58  HdWrapMirror,
59 
60  HdWrapNoOpinion,
61  HdWrapLegacyNoOpinionFallbackRepeat, // deprecated
62 
63  HdWrapUseMetadata = HdWrapNoOpinion, // deprecated alias
64  HdWrapLegacy = HdWrapLegacyNoOpinionFallbackRepeat // deprecated alias
65 };
66 
80 enum HdMinFilter
81 {
82  HdMinFilterNearest,
83  HdMinFilterLinear,
84  HdMinFilterNearestMipmapNearest,
85  HdMinFilterLinearMipmapNearest,
86  HdMinFilterNearestMipmapLinear,
87  HdMinFilterLinearMipmapLinear,
88 };
89 
99 enum HdMagFilter
100 {
101  HdMagFilterNearest,
102  HdMagFilterLinear,
103 };
104 
110 public:
111  HdWrap wrapS;
112  HdWrap wrapT;
113  HdWrap wrapR;
114  HdMinFilter minFilter;
115  HdMagFilter magFilter;
116 
117  HD_API
118  bool operator==(const HdSamplerParameters &other) const;
119 
120  HD_API
121  bool operator!=(const HdSamplerParameters &other) const;
122 };
123 
127 typedef uint32_t HdDirtyBits;
128 
129 // GL Spec 2.3.5.2 (signed case, eq 2.4)
130 inline int HdConvertFloatToFixed(float v, int b)
131 {
132  return int(
133  std::round(
134  std::min(std::max(v, -1.0f), 1.0f) * (float(1 << (b-1)) - 1.0f)));
135 }
136 
137 // GL Spec 2.3.5.1 (signed case, eq 2.2)
138 inline float HdConvertFixedToFloat(int v, int b)
139 {
140  return float(
141  std::max(-1.0f,
142  (v / (float(1 << (b-1)) - 1.0f))));
143 }
144 
153 {
155 
156  template <typename Vec3Type>
157  HdVec4f_2_10_10_10_REV(Vec3Type const &value) {
158  x = HdConvertFloatToFixed(value[0], 10);
159  y = HdConvertFloatToFixed(value[1], 10);
160  z = HdConvertFloatToFixed(value[2], 10);
161  w = 0;
162  }
163 
164  HdVec4f_2_10_10_10_REV(int const value) {
165  HdVec4f_2_10_10_10_REV const* other =
166  reinterpret_cast<HdVec4f_2_10_10_10_REV const*>(&value);
167  x = other->x;
168  y = other->y;
169  z = other->z;
170  w = other->w;
171  }
172 
173  template <typename Vec3Type>
174  Vec3Type GetAsVec() const {
175  return Vec3Type(HdConvertFixedToFloat(x, 10),
176  HdConvertFixedToFloat(y, 10),
177  HdConvertFixedToFloat(z, 10));
178  }
179 
180  int GetAsInt() const {
181  int const* asInt = reinterpret_cast<int const*>(this);
182  return *asInt;
183  }
184 
185  bool operator==(const HdVec4f_2_10_10_10_REV &other) const {
186  return (other.w == w &&
187  other.z == z &&
188  other.y == y &&
189  other.x == x);
190  }
191  bool operator!=(const HdVec4f_2_10_10_10_REV &other) const {
192  return !(*this == other);
193  }
194 
195  int x : 10;
196  int y : 10;
197  int z : 10;
198  int w : 2;
199 };
200 
256 enum HdType
257 {
258  HdTypeInvalid=-1,
259 
261  HdTypeBool=0,
262  HdTypeUInt8,
263  HdTypeUInt16,
264  HdTypeInt8,
265  HdTypeInt16,
266 
268  HdTypeInt32,
270  HdTypeInt32Vec2,
272  HdTypeInt32Vec3,
274  HdTypeInt32Vec4,
275 
277  HdTypeUInt32,
279  HdTypeUInt32Vec2,
281  HdTypeUInt32Vec3,
283  HdTypeUInt32Vec4,
284 
286  HdTypeFloat,
288  HdTypeFloatVec2,
290  HdTypeFloatVec3,
292  HdTypeFloatVec4,
294  HdTypeFloatMat3,
296  HdTypeFloatMat4,
297 
299  HdTypeDouble,
301  HdTypeDoubleVec2,
303  HdTypeDoubleVec3,
305  HdTypeDoubleVec4,
307  HdTypeDoubleMat3,
309  HdTypeDoubleMat4,
310 
311  HdTypeHalfFloat,
312  HdTypeHalfFloatVec2,
313  HdTypeHalfFloatVec3,
314  HdTypeHalfFloatVec4,
315 
319  HdTypeInt32_2_10_10_10_REV,
320 };
321 
325 struct HdTupleType {
326  HdType type;
327  size_t count;
328 
329  bool operator< (HdTupleType const& rhs) const {
330  return (type < rhs.type) || (type == rhs.type && count < rhs.count);
331  }
332  bool operator== (HdTupleType const& rhs) const {
333  return type == rhs.type && count == rhs.count;
334  }
335  bool operator!= (HdTupleType const& rhs) const {
336  return !(*this == rhs);
337  }
338 };
339 
340 // Support TfHash.
341 template <class HashState>
342 void
343 TfHashAppend(HashState &h, HdTupleType const &tt)
344 {
345  h.Append(tt.type, tt.count);
346 }
347 
350 HD_API
351 const void* HdGetValueData(const VtValue &);
352 
356 HD_API
357 HdTupleType HdGetValueTupleType(const VtValue &);
358 
363 HD_API
364 HdType HdGetComponentType(HdType);
365 
368 HD_API
369 size_t HdGetComponentCount(HdType t);
370 
372 HD_API
373 size_t HdDataSizeOfType(HdType);
374 
376 HD_API
377 size_t HdDataSizeOfTupleType(HdTupleType);
378 
390 enum HdFormat
391 {
392  HdFormatInvalid=-1,
393 
394  // UNorm8 - a 1-byte value representing a float between 0 and 1.
395  // float value = (unorm / 255.0f);
396  HdFormatUNorm8=0,
397  HdFormatUNorm8Vec2,
398  HdFormatUNorm8Vec3,
399  HdFormatUNorm8Vec4,
400 
401  // SNorm8 - a 1-byte value representing a float between -1 and 1.
402  // float value = max(snorm / 127.0f, -1.0f);
403  HdFormatSNorm8,
404  HdFormatSNorm8Vec2,
405  HdFormatSNorm8Vec3,
406  HdFormatSNorm8Vec4,
407 
408  // Float16 - a 2-byte IEEE half-precision float.
409  HdFormatFloat16,
410  HdFormatFloat16Vec2,
411  HdFormatFloat16Vec3,
412  HdFormatFloat16Vec4,
413 
414  // Float32 - a 4-byte IEEE float.
415  HdFormatFloat32,
416  HdFormatFloat32Vec2,
417  HdFormatFloat32Vec3,
418  HdFormatFloat32Vec4,
419 
420  // Int16 - a 2-byte signed integer
421  HdFormatInt16,
422  HdFormatInt16Vec2,
423  HdFormatInt16Vec3,
424  HdFormatInt16Vec4,
425 
426  // UInt16 - a 2-byte unsigned integer
427  HdFormatUInt16,
428  HdFormatUInt16Vec2,
429  HdFormatUInt16Vec3,
430  HdFormatUInt16Vec4,
431 
432  // Int32 - a 4-byte signed integer
433  HdFormatInt32,
434  HdFormatInt32Vec2,
435  HdFormatInt32Vec3,
436  HdFormatInt32Vec4,
437 
438  // Depth-stencil format
439  HdFormatFloat32UInt8,
440 
441  HdFormatCount
442 };
443 
445 HD_API
446 HdFormat HdGetComponentFormat(HdFormat f);
447 
449 HD_API
450 size_t HdGetComponentCount(HdFormat f);
451 
454 HD_API
455 size_t HdDataSizeOfFormat(HdFormat f);
456 
457 PXR_NAMESPACE_CLOSE_SCOPE
458 
459 #endif // PXR_IMAGING_HD_TYPES_H
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:325
HdVec4f_2_10_10_10_REV is a compact representation of a GfVec4f.
Definition: types.h:152
Collection of standard parameters such as wrap modes to sample a texture.
Definition: types.h:109
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:168