All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 HD_TYPES_H
25 #define 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 
41 typedef uint32_t HdDirtyBits;
42 
43 // GL Spec 2.3.5.2 (signed case, eq 2.4)
44 inline int HdConvertFloatToFixed(float v, int b)
45 {
46  return int(
47  std::round(
48  std::min(std::max(v, -1.0f), 1.0f) * (float(1 << (b-1)) - 1.0f)));
49 }
50 
51 // GL Spec 2.3.5.1 (signed case, eq 2.2)
52 inline float HdConvertFixedToFloat(int v, int b)
53 {
54  return float(
55  std::max(-1.0f,
56  (v / (float(1 << (b-1)) - 1.0f))));
57 }
58 
67 {
69 
70  template <typename Vec3Type>
71  HdVec4f_2_10_10_10_REV(Vec3Type const &value) {
72  x = HdConvertFloatToFixed(value[0], 10);
73  y = HdConvertFloatToFixed(value[1], 10);
74  z = HdConvertFloatToFixed(value[2], 10);
75  w = 0;
76  }
77 
78  HdVec4f_2_10_10_10_REV(int const value) {
79  HdVec4f_2_10_10_10_REV const* other =
80  reinterpret_cast<HdVec4f_2_10_10_10_REV const*>(&value);
81  x = other->x;
82  y = other->y;
83  z = other->z;
84  w = other->w;
85  }
86 
87  template <typename Vec3Type>
88  Vec3Type GetAsVec() const {
89  return Vec3Type(HdConvertFixedToFloat(x, 10),
90  HdConvertFixedToFloat(y, 10),
91  HdConvertFixedToFloat(z, 10));
92  }
93 
94  int GetAsInt() const {
95  int const* asInt = reinterpret_cast<int const*>(this);
96  return *asInt;
97  }
98 
99  bool operator==(const HdVec4f_2_10_10_10_REV &other) const {
100  return (other.w == w &&
101  other.z == z &&
102  other.y == y &&
103  other.x == x);
104  }
105  bool operator!=(const HdVec4f_2_10_10_10_REV &other) const {
106  return !(*this == other);
107  }
108 
109  int x : 10;
110  int y : 10;
111  int z : 10;
112  int w : 2;
113 };
114 
170 enum HdType
171 {
172  HdTypeInvalid=-1,
173 
175  HdTypeBool=0,
176  HdTypeUInt8,
177  HdTypeUInt16,
178  HdTypeInt8,
179  HdTypeInt16,
180 
182  HdTypeInt32,
184  HdTypeInt32Vec2,
186  HdTypeInt32Vec3,
188  HdTypeInt32Vec4,
189 
191  HdTypeUInt32,
193  HdTypeUInt32Vec2,
195  HdTypeUInt32Vec3,
197  HdTypeUInt32Vec4,
198 
200  HdTypeFloat,
202  HdTypeFloatVec2,
204  HdTypeFloatVec3,
206  HdTypeFloatVec4,
208  HdTypeFloatMat3,
210  HdTypeFloatMat4,
211 
213  HdTypeDouble,
215  HdTypeDoubleVec2,
217  HdTypeDoubleVec3,
219  HdTypeDoubleVec4,
221  HdTypeDoubleMat3,
223  HdTypeDoubleMat4,
224 
225  HdTypeHalfFloat,
226  HdTypeHalfFloatVec2,
227  HdTypeHalfFloatVec3,
228  HdTypeHalfFloatVec4,
229 
233  HdTypeInt32_2_10_10_10_REV,
234 };
235 
239 struct HdTupleType {
240  HdType type;
241  size_t count;
242 
243  bool operator< (HdTupleType const& rhs) const {
244  return (type < rhs.type) || (type == rhs.type && count < rhs.count);
245  }
246  bool operator== (HdTupleType const& rhs) const {
247  return type == rhs.type && count == rhs.count;
248  }
249  bool operator!= (HdTupleType const& rhs) const {
250  return !(*this == rhs);
251  }
252 };
253 
256 HD_API
257 const void* HdGetValueData(const VtValue &);
258 
262 HD_API
263 HdTupleType HdGetValueTupleType(const VtValue &);
264 
269 HD_API
270 HdType HdGetComponentType(HdType);
271 
274 HD_API
275 size_t HdGetComponentCount(HdType t);
276 
278 HD_API
279 size_t HdDataSizeOfType(HdType);
280 
282 HD_API
283 size_t HdDataSizeOfTupleType(HdTupleType);
284 
296 enum HdFormat
297 {
298  HdFormatInvalid=-1,
299 
300  // UNorm8 - a 1-byte value representing a float between 0 and 1.
301  // float value = (unorm / 255.0f);
302  HdFormatUNorm8=0,
303  HdFormatUNorm8Vec2,
304  HdFormatUNorm8Vec3,
305  HdFormatUNorm8Vec4,
306 
307  // SNorm8 - a 1-byte value representing a float between -1 and 1.
308  // float value = max(snorm / 127.0f, -1.0f);
309  HdFormatSNorm8,
310  HdFormatSNorm8Vec2,
311  HdFormatSNorm8Vec3,
312  HdFormatSNorm8Vec4,
313 
314  // Float16 - a 2-byte IEEE half-precision float.
315  HdFormatFloat16,
316  HdFormatFloat16Vec2,
317  HdFormatFloat16Vec3,
318  HdFormatFloat16Vec4,
319 
320  // Float32 - a 4-byte IEEE float.
321  HdFormatFloat32,
322  HdFormatFloat32Vec2,
323  HdFormatFloat32Vec3,
324  HdFormatFloat32Vec4,
325 
326  // Int32 - a 4-byte signed integer
327  HdFormatInt32,
328  HdFormatInt32Vec2,
329  HdFormatInt32Vec3,
330  HdFormatInt32Vec4,
331 
332  HdFormatCount
333 };
334 
336 HD_API
337 HdFormat HdGetComponentFormat(HdFormat f);
338 
340 HD_API
341 size_t HdGetComponentCount(HdFormat f);
342 
345 HD_API
346 size_t HdDataSizeOfFormat(HdFormat f);
347 
348 PXR_NAMESPACE_CLOSE_SCOPE
349 
350 #endif // HD_TYPES_H
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:239
HdVec4f_2_10_10_10_REV is a compact representation of a GfVec4f.
Definition: types.h:66
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182