Loading...
Searching...
No Matches
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
121 HD_API
123
124 HD_API
125 HdSamplerParameters(HdWrap wrapS, HdWrap wrapT, HdWrap wrapR,
126 HdMinFilter minFilter, HdMagFilter magFilter,
127 HdBorderColor borderColor=HdBorderColorTransparentBlack,
128 bool enableCompare=false,
129 HdCompareFunction compareFunction=HdCmpFuncNever);
130
131 HD_API
132 bool operator==(const HdSamplerParameters &other) const;
133
134 HD_API
135 bool operator!=(const HdSamplerParameters &other) const;
136};
137
141typedef uint32_t HdDirtyBits;
142
143// GL Spec 2.3.5.2 (signed case, eq 2.4)
144inline int HdConvertFloatToFixed(float v, int b)
145{
146 return int(
147 std::round(
148 std::min(std::max(v, -1.0f), 1.0f) * (float(1 << (b-1)) - 1.0f)));
149}
150
151// GL Spec 2.3.5.1 (signed case, eq 2.2)
152inline float HdConvertFixedToFloat(int v, int b)
153{
154 return float(
155 std::max(-1.0f,
156 (v / (float(1 << (b-1)) - 1.0f))));
157}
158
167{
169
170 template <typename Vec3Type>
171 HdVec4f_2_10_10_10_REV(Vec3Type const &value) {
172 x = HdConvertFloatToFixed(value[0], 10);
173 y = HdConvertFloatToFixed(value[1], 10);
174 z = HdConvertFloatToFixed(value[2], 10);
175 w = 0;
176 }
177
178 HdVec4f_2_10_10_10_REV(int const value) {
179 HdVec4f_2_10_10_10_REV const* other =
180 reinterpret_cast<HdVec4f_2_10_10_10_REV const*>(&value);
181 x = other->x;
182 y = other->y;
183 z = other->z;
184 w = other->w;
185 }
186
187 template <typename Vec3Type>
188 Vec3Type GetAsVec() const {
189 return Vec3Type(HdConvertFixedToFloat(x, 10),
190 HdConvertFixedToFloat(y, 10),
191 HdConvertFixedToFloat(z, 10));
192 }
193
194 int GetAsInt() const {
195 int const* asInt = reinterpret_cast<int const*>(this);
196 return *asInt;
197 }
198
199 bool operator==(const HdVec4f_2_10_10_10_REV &other) const {
200 return (other.w == w &&
201 other.z == z &&
202 other.y == y &&
203 other.x == x);
204 }
205 bool operator!=(const HdVec4f_2_10_10_10_REV &other) const {
206 return !(*this == other);
207 }
208
209 int x : 10;
210 int y : 10;
211 int z : 10;
212 int w : 2;
213};
214
270enum HdType
271{
272 HdTypeInvalid=-1,
273
275 HdTypeBool=0,
276 HdTypeUInt8,
277 HdTypeUInt16,
278 HdTypeInt8,
279 HdTypeInt16,
280
282 HdTypeInt32,
284 HdTypeInt32Vec2,
286 HdTypeInt32Vec3,
288 HdTypeInt32Vec4,
289
291 HdTypeUInt32,
293 HdTypeUInt32Vec2,
295 HdTypeUInt32Vec3,
297 HdTypeUInt32Vec4,
298
300 HdTypeFloat,
302 HdTypeFloatVec2,
304 HdTypeFloatVec3,
306 HdTypeFloatVec4,
308 HdTypeFloatMat3,
310 HdTypeFloatMat4,
311
313 HdTypeDouble,
315 HdTypeDoubleVec2,
317 HdTypeDoubleVec3,
319 HdTypeDoubleVec4,
321 HdTypeDoubleMat3,
323 HdTypeDoubleMat4,
324
325 HdTypeHalfFloat,
326 HdTypeHalfFloatVec2,
327 HdTypeHalfFloatVec3,
328 HdTypeHalfFloatVec4,
329
333 HdTypeInt32_2_10_10_10_REV,
334
335 HdTypeCount
336};
337
342 HdType type;
343 size_t count;
344
345 bool operator< (HdTupleType const& rhs) const {
346 return (type < rhs.type) || (type == rhs.type && count < rhs.count);
347 }
348 bool operator== (HdTupleType const& rhs) const {
349 return type == rhs.type && count == rhs.count;
350 }
351 bool operator!= (HdTupleType const& rhs) const {
352 return !(*this == rhs);
353 }
354};
355
356// Support TfHash.
357template <class HashState>
358void
359TfHashAppend(HashState &h, HdTupleType const &tt)
360{
361 h.Append(tt.type, tt.count);
362}
363
366HD_API
367const void* HdGetValueData(const VtValue &);
368
372HD_API
373HdTupleType HdGetValueTupleType(const VtValue &);
374
379HD_API
380HdType HdGetComponentType(HdType);
381
384HD_API
385size_t HdGetComponentCount(HdType t);
386
388HD_API
389size_t HdDataSizeOfType(HdType);
390
392HD_API
393size_t HdDataSizeOfTupleType(HdTupleType);
394
406enum HdFormat
407{
408 HdFormatInvalid=-1,
409
410 // UNorm8 - a 1-byte value representing a float between 0 and 1.
411 // float value = (unorm / 255.0f);
412 HdFormatUNorm8=0,
413 HdFormatUNorm8Vec2,
414 HdFormatUNorm8Vec3,
415 HdFormatUNorm8Vec4,
416
417 // SNorm8 - a 1-byte value representing a float between -1 and 1.
418 // float value = max(snorm / 127.0f, -1.0f);
419 HdFormatSNorm8,
420 HdFormatSNorm8Vec2,
421 HdFormatSNorm8Vec3,
422 HdFormatSNorm8Vec4,
423
424 // Float16 - a 2-byte IEEE half-precision float.
425 HdFormatFloat16,
426 HdFormatFloat16Vec2,
427 HdFormatFloat16Vec3,
428 HdFormatFloat16Vec4,
429
430 // Float32 - a 4-byte IEEE float.
431 HdFormatFloat32,
432 HdFormatFloat32Vec2,
433 HdFormatFloat32Vec3,
434 HdFormatFloat32Vec4,
435
436 // Int16 - a 2-byte signed integer
437 HdFormatInt16,
438 HdFormatInt16Vec2,
439 HdFormatInt16Vec3,
440 HdFormatInt16Vec4,
441
442 // UInt16 - a 2-byte unsigned integer
443 HdFormatUInt16,
444 HdFormatUInt16Vec2,
445 HdFormatUInt16Vec3,
446 HdFormatUInt16Vec4,
447
448 // Int32 - a 4-byte signed integer
449 HdFormatInt32,
450 HdFormatInt32Vec2,
451 HdFormatInt32Vec3,
452 HdFormatInt32Vec4,
453
454 // Depth-stencil format
455 HdFormatFloat32UInt8,
456
457 HdFormatCount
458};
459
461HD_API
462HdFormat HdGetComponentFormat(HdFormat f);
463
465HD_API
466size_t HdGetComponentCount(HdFormat f);
467
470HD_API
471size_t HdDataSizeOfFormat(HdFormat f);
472
476using HdDepthStencilType = std::pair<float, uint32_t>;
477
478PXR_NAMESPACE_CLOSE_SCOPE
479
480#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:341
HdVec4f_2_10_10_10_REV is a compact representation of a GfVec4f.
Definition: types.h:167