All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
types.h
1//
2// Copyright 2016 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_TYPES_H
8#define PXR_IMAGING_HD_TYPES_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/enums.h"
13#include "pxr/imaging/hd/version.h"
14#include "pxr/base/vt/value.h"
15#include <algorithm>
16#include <cmath>
17#include <cstddef>
18#include <cstdint>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
37enum HdWrap
38{
39 HdWrapClamp,
40 HdWrapRepeat,
41 HdWrapBlack,
42 HdWrapMirror,
43
44 HdWrapNoOpinion,
45 HdWrapLegacyNoOpinionFallbackRepeat, // deprecated
46
47 HdWrapUseMetadata = HdWrapNoOpinion, // deprecated alias
48 HdWrapLegacy = HdWrapLegacyNoOpinionFallbackRepeat // deprecated alias
49};
50
64enum HdMinFilter
65{
66 HdMinFilterNearest,
67 HdMinFilterLinear,
68 HdMinFilterNearestMipmapNearest,
69 HdMinFilterLinearMipmapNearest,
70 HdMinFilterNearestMipmapLinear,
71 HdMinFilterLinearMipmapLinear,
72};
73
83enum HdMagFilter
84{
85 HdMagFilterNearest,
86 HdMagFilterLinear,
87};
88
99enum HdBorderColor
100{
101 HdBorderColorTransparentBlack,
102 HdBorderColorOpaqueBlack,
103 HdBorderColorOpaqueWhite,
104};
105
111public:
112 HdWrap wrapS;
113 HdWrap wrapT;
114 HdWrap wrapR;
115 HdMinFilter minFilter;
116 HdMagFilter magFilter;
117 HdBorderColor borderColor;
118 bool enableCompare;
119 HdCompareFunction compareFunction;
120 uint32_t maxAnisotropy;
121
122 HD_API
124
125 HD_API
126 HdSamplerParameters(HdWrap wrapS, HdWrap wrapT, HdWrap wrapR,
127 HdMinFilter minFilter, HdMagFilter magFilter,
128 HdBorderColor borderColor=HdBorderColorTransparentBlack,
129 bool enableCompare=false,
130 HdCompareFunction compareFunction=HdCmpFuncNever,
131 uint32_t maxAnisotropy=16);
132
133 HD_API
134 bool operator==(const HdSamplerParameters &other) const;
135
136 HD_API
137 bool operator!=(const HdSamplerParameters &other) const;
138};
139
143typedef uint32_t HdDirtyBits;
144
145// GL Spec 2.3.5.2 (signed case, eq 2.4)
146inline int HdConvertFloatToFixed(float v, int b)
147{
148 return int(
149 std::round(
150 std::min(std::max(v, -1.0f), 1.0f) * (float(1 << (b-1)) - 1.0f)));
151}
152
153// GL Spec 2.3.5.1 (signed case, eq 2.2)
154inline float HdConvertFixedToFloat(int v, int b)
155{
156 return float(
157 std::max(-1.0f,
158 (v / (float(1 << (b-1)) - 1.0f))));
159}
160
169{
171
172 template <typename Vec3Type>
173 HdVec4f_2_10_10_10_REV(Vec3Type const &value) {
174 x = HdConvertFloatToFixed(value[0], 10);
175 y = HdConvertFloatToFixed(value[1], 10);
176 z = HdConvertFloatToFixed(value[2], 10);
177 w = 0;
178 }
179
180 HdVec4f_2_10_10_10_REV(int const value) {
181 HdVec4f_2_10_10_10_REV const* other =
182 reinterpret_cast<HdVec4f_2_10_10_10_REV const*>(&value);
183 x = other->x;
184 y = other->y;
185 z = other->z;
186 w = other->w;
187 }
188
189 template <typename Vec3Type>
190 Vec3Type GetAsVec() const {
191 return Vec3Type(HdConvertFixedToFloat(x, 10),
192 HdConvertFixedToFloat(y, 10),
193 HdConvertFixedToFloat(z, 10));
194 }
195
196 int GetAsInt() const {
197 int const* asInt = reinterpret_cast<int const*>(this);
198 return *asInt;
199 }
200
201 bool operator==(const HdVec4f_2_10_10_10_REV &other) const {
202 return (other.w == w &&
203 other.z == z &&
204 other.y == y &&
205 other.x == x);
206 }
207 bool operator!=(const HdVec4f_2_10_10_10_REV &other) const {
208 return !(*this == other);
209 }
210
211 int x : 10;
212 int y : 10;
213 int z : 10;
214 int w : 2;
215};
216
272enum HdType
273{
274 HdTypeInvalid=-1,
275
277 HdTypeBool=0,
278 HdTypeUInt8,
279 HdTypeUInt16,
280 HdTypeInt8,
281 HdTypeInt16,
282
284 HdTypeInt32,
286 HdTypeInt32Vec2,
288 HdTypeInt32Vec3,
290 HdTypeInt32Vec4,
291
293 HdTypeUInt32,
295 HdTypeUInt32Vec2,
297 HdTypeUInt32Vec3,
299 HdTypeUInt32Vec4,
300
302 HdTypeFloat,
304 HdTypeFloatVec2,
306 HdTypeFloatVec3,
308 HdTypeFloatVec4,
310 HdTypeFloatMat3,
312 HdTypeFloatMat4,
313
315 HdTypeDouble,
317 HdTypeDoubleVec2,
319 HdTypeDoubleVec3,
321 HdTypeDoubleVec4,
323 HdTypeDoubleMat3,
325 HdTypeDoubleMat4,
326
327 HdTypeHalfFloat,
328 HdTypeHalfFloatVec2,
329 HdTypeHalfFloatVec3,
330 HdTypeHalfFloatVec4,
331
335 HdTypeInt32_2_10_10_10_REV,
336
337 HdTypeCount
338};
339
344 HdType type;
345 size_t count;
346
347 bool operator< (HdTupleType const& rhs) const {
348 return (type < rhs.type) || (type == rhs.type && count < rhs.count);
349 }
350 bool operator== (HdTupleType const& rhs) const {
351 return type == rhs.type && count == rhs.count;
352 }
353 bool operator!= (HdTupleType const& rhs) const {
354 return !(*this == rhs);
355 }
356};
357
358// Support TfHash.
359template <class HashState>
360void
361TfHashAppend(HashState &h, HdTupleType const &tt)
362{
363 h.Append(tt.type, tt.count);
364}
365
368HD_API
369const void* HdGetValueData(const VtValue &);
370
374HD_API
375HdTupleType HdGetValueTupleType(const VtValue &);
376
381HD_API
382HdType HdGetComponentType(HdType);
383
386HD_API
387size_t HdGetComponentCount(HdType t);
388
390HD_API
391size_t HdDataSizeOfType(HdType);
392
394HD_API
395size_t HdDataSizeOfTupleType(HdTupleType);
396
408enum HdFormat
409{
410 HdFormatInvalid=-1,
411
412 // UNorm8 - a 1-byte value representing a float between 0 and 1.
413 // float value = (unorm / 255.0f);
414 HdFormatUNorm8=0,
415 HdFormatUNorm8Vec2,
416 HdFormatUNorm8Vec3,
417 HdFormatUNorm8Vec4,
418
419 // SNorm8 - a 1-byte value representing a float between -1 and 1.
420 // float value = max(snorm / 127.0f, -1.0f);
421 HdFormatSNorm8,
422 HdFormatSNorm8Vec2,
423 HdFormatSNorm8Vec3,
424 HdFormatSNorm8Vec4,
425
426 // Float16 - a 2-byte IEEE half-precision float.
427 HdFormatFloat16,
428 HdFormatFloat16Vec2,
429 HdFormatFloat16Vec3,
430 HdFormatFloat16Vec4,
431
432 // Float32 - a 4-byte IEEE float.
433 HdFormatFloat32,
434 HdFormatFloat32Vec2,
435 HdFormatFloat32Vec3,
436 HdFormatFloat32Vec4,
437
438 // Int16 - a 2-byte signed integer
439 HdFormatInt16,
440 HdFormatInt16Vec2,
441 HdFormatInt16Vec3,
442 HdFormatInt16Vec4,
443
444 // UInt16 - a 2-byte unsigned integer
445 HdFormatUInt16,
446 HdFormatUInt16Vec2,
447 HdFormatUInt16Vec3,
448 HdFormatUInt16Vec4,
449
450 // Int32 - a 4-byte signed integer
451 HdFormatInt32,
452 HdFormatInt32Vec2,
453 HdFormatInt32Vec3,
454 HdFormatInt32Vec4,
455
456 // Depth-stencil format
457 HdFormatFloat32UInt8,
458
459 HdFormatCount
460};
461
463HD_API
464HdFormat HdGetComponentFormat(HdFormat f);
465
467HD_API
468size_t HdGetComponentCount(HdFormat f);
469
472HD_API
473size_t HdDataSizeOfFormat(HdFormat f);
474
478using HdDepthStencilType = std::pair<float, uint32_t>;
479
480PXR_NAMESPACE_CLOSE_SCOPE
481
482#endif // PXR_IMAGING_HD_TYPES_H
Collection of standard parameters such as wrap modes to sample a texture.
Definition: types.h:110
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:343
HdVec4f_2_10_10_10_REV is a compact representation of a GfVec4f.
Definition: types.h:169