HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
types.h
Go to the documentation of this file.
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 
21 
22 /// \enum HdWrap
23 ///
24 /// Enumerates wrapping attributes type values.
25 ///
26 /// <ul>
27 /// <li>\b HdWrapClamp Clamp coordinate to range [1/(2N),1-1/(2N)] where N is the size of the texture in the direction of clamping</li>
28 /// <li>\b HdWrapRepeat Creates a repeating pattern</li>
29 /// <li>\b HdWrapBlack Clamp coordinate to range [-1/(2N),1+1/(2N)] where N is the size of the texture in the direction of clamping</li>
30 /// <li>\b HdWrapMirror Creates a mirrored repeating pattern.</li>
31 /// <li>\b HdWrapNoOpinion No opinion. The data texture can define its own wrap mode that we can use instead. Fallback to HdWrapBlack</li>
32 /// <li>\b HdWrapLegacyNoOpinionFallbackRepeat (deprecated) Similar to HdWrapNoOpinon but fallback to HdWrapRepeat</li>
33 /// <li>\b HdWrapUseMetadata (deprecated) Alias for HdWrapNoOpinion</li>
34 /// <li>\b HdWrapLegacy (deprecated) Alias for HdWrapLegacyNoOpinionFallbackRepeat</li>
35 /// </ul>
36 ///
37 enum HdWrap
38 {
43 
46 
47  HdWrapUseMetadata = HdWrapNoOpinion, // deprecated alias
49 };
50 
51 /// \enum HdMinFilter
52 ///
53 /// Enumerates minFilter attribute type values.
54 ///
55 /// <ul>
56 /// <li>\b HdMinFilterNearest Nearest to center of the pixel</li>
57 /// <li>\b HdMinFilterLinear Weighted average od the four texture elements closest to the pixel</li>
58 /// <li>\b HdMinFilterNearestMipmapNearest Nearest to center of the pixel from the nearest mipmaps</li>
59 /// <li>\b HdMinFilterLinearMipmapNeares Weighted average using texture elements from the nearest mipmaps</li>
60 /// <li>\b HdMinFilterNearestMipmapLinear Weighted average of the nearest pixels from the two nearest mipmaps</li>
61 /// <li>\b HdMinFilterLinearMipmapLinear WeightedAverage of the weighted averages from the nearest mipmaps</li>
62 /// </ul>
63 ///
65 {
72 };
73 
74 /// \enum HdMagFilter
75 ///
76 /// Enumerates magFilter attribute type values.
77 ///
78 /// <ul>
79 /// <li>HdFilterNearest Nearest to center of the pixel</li>
80 /// <li>HdFilterLinear Weighted average of the four texture elements closest to the pixel</li>
81 /// </ul>
82 ///
84 {
87 };
88 
89 /// \enum HdBorderColor
90 ///
91 /// Border color to use for clamped texture values.
92 ///
93 /// <ul>
94 /// <li>HdBorderColorTransparentBlack</li>
95 /// <li>HdBorderColorOpaqueBlack</li>
96 /// <li>HdBorderColorOpaqueWhite</li>
97 /// </ul>
98 ///
100 {
104 };
105 
106 /// \class HdSamplerParameters
107 ///
108 /// Collection of standard parameters such as wrap modes to sample a texture.
109 ///
111 public:
120  uint32_t maxAnisotropy;
121 
122  HD_API
124 
125  HD_API
129  bool enableCompare=false,
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 
140 ///
141 /// Type representing a set of dirty bits.
142 ///
143 typedef uint32_t HdDirtyBits;
144 
145 // GL Spec 2.3.5.2 (signed case, eq 2.4)
146 inline 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)
154 inline 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 
161 ///
162 /// HdVec4f_2_10_10_10_REV is a compact representation of a GfVec4f.
163 /// It uses 10 bits for x, y, and z, and 2 bits for w.
164 ///
165 /// XXX We expect this type to move again as we continue work on
166 /// refactoring the GL dependencies.
167 ///
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 
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),
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 
217 /// \enum HdType
218 ///
219 /// HdType describes the type of an attribute value used in Hd.
220 ///
221 /// HdType values have a specific machine representation and size.
222 /// See HdDataSizeOfType().
223 ///
224 /// HdType specifies a scalar, vector, or matrix type. Vector and
225 /// matrix types can be unpacked into the underlying "component"
226 /// type; see HdGetComponentType().
227 ///
228 /// HdType is intended to span the common set of attribute types
229 /// used in shading languages such as GLSL. However, it currently
230 /// does not include non-4x4 matrix types, nor struct types.
231 ///
232 /// Fixed-size array types are represented by the related class
233 /// HdTupleType. HdTupleType is used anywhere there is a
234 /// possibility of an array of values.
235 ///
236 /// ## Value arrays and attribute buffers
237 ///
238 /// Attribute data is often stored in linear buffers. These buffers
239 /// have multiple dimensions and it is important to distinguish them:
240 ///
241 /// - "Components" refer to the scalar components that comprise a vector
242 /// or matrix. For example, a vec3 has 3 components, a mat4 has
243 /// 16 components, and a float has a single component.
244 ///
245 /// - "Elements" refer to external concepts that entries in a buffer
246 /// associate with. Typically these are pieces of geometry,
247 /// such as faces or vertices.
248 ///
249 /// - "Arrays" refer to the idea that each element may associate
250 /// with a fixed-size array of values. For example, one approach
251 /// to motion blur might store a size-2 array of HdFloatMat4
252 /// values for each element of geometry, holding the transforms
253 /// at the beginning and ending of the camera shutter interval.
254 ///
255 /// Combining these concepts in an example, a primvar buffer might hold
256 /// data for 10 vertices (the elements) with each vertex having a
257 /// 2 entries (an array) of 4x4 matrices (with 16 components each).
258 /// As a packed linear buffer, this would occupy 10*2*16==320 floats.
259 ///
260 /// It is important to distinguish components from array entries,
261 /// and arrays from elements. HdType and HdTupleType only
262 /// addresses components and arrays; elements are tracked by buffers.
263 /// See for example HdBufferSource::GetNumElements().
264 ///
265 /// In other words, HdType and HdTupleType describe values.
266 /// Buffers describe elements and all other details regarding buffer
267 /// layout, such as offset/stride used to interleave attribute data.
268 ///
269 /// For more background, see the OpenGL discussion on data types:
270 /// - https://www.khronos.org/opengl/wiki/OpenGL_Type
271 ///
272 enum HdType
273 {
275 
276  /// Corresponds to GL_BOOL
282 
283  /// Corresponds to GL_INT
285  /// A 2-component vector with Int32-valued components.
287  /// A 3-component vector with Int32-valued components.
289  /// A 4-component vector with Int32-valued components.
291 
292  /// An unsigned 32-bit integer. Corresponds to GL_UNSIGNED_INT.
294  /// A 2-component vector with UInt32-valued components.
296  /// A 3-component vector with UInt32-valued components.
298  /// A 4-component vector with UInt32-valued components.
300 
301  /// Corresponds to GL_FLOAT
303  /// Corresponds to GL_FLOAT_VEC2
305  /// Corresponds to GL_FLOAT_VEC3
307  /// Corresponds to GL_FLOAT_VEC4
309  /// Corresponds to GL_FLOAT_MAT3
311  /// Corresponds to GL_FLOAT_MAT4
313 
314  /// Corresponds to GL_DOUBLE
316  /// Corresponds to GL_DOUBLE_VEC2
318  /// Corresponds to GL_DOUBLE_VEC3
320  /// Corresponds to GL_DOUBLE_VEC4
322  /// Corresponds to GL_DOUBLE_MAT3
324  /// Corresponds to GL_DOUBLE_MAT4
326 
331 
332  /// Packed, reverse-order encoding of a 4-component vector into Int32.
333  /// Corresponds to GL_INT_2_10_10_10_REV.
334  /// \see HdVec4f_2_10_10_10_REV
336 
338 };
339 
340 /// HdTupleType represents zero, one, or more values of the same HdType.
341 /// It can be used to represent fixed-size array types, as well as single
342 /// values. See HdType for more discussion about arrays.
343 struct HdTupleType {
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.
359 template <class HashState>
360 void
361 TfHashAppend(HashState &h, HdTupleType const &tt)
362 {
363  h.Append(tt.type, tt.count);
364 }
365 
366 /// Returns a direct pointer to the data held by a VtValue.
367 /// Returns nullptr if the VtValue is empty or holds a type unknown to Hd.
368 HD_API
369 const void* HdGetValueData(const VtValue &);
370 
371 /// Returns the HdTupleType that describes the given VtValue.
372 /// For scalar, vector, and matrix types, the count is 1.
373 /// For any VtArray type, the count is the number of array members.
374 HD_API
376 
377 /// Return the component type for the given value type.
378 /// For vectors and matrices, this is the scalar type of their components.
379 /// For scalars, this is the type itself.
380 /// As an example, the component type of HdTypeFloatMat4 is HdTypeFloat.
381 HD_API
383 
384 /// Return the count of components in the given value type.
385 /// For example, HdTypeFloatVec3 has 3 components.
386 HD_API
388 
389 /// Return the size, in bytes, of a single value of the given type.
390 HD_API
391 size_t HdDataSizeOfType(HdType);
392 
393 /// Return the size, in bytes, of a value with HdTupleType.
394 HD_API
396 
397 /// \enum HdFormat
398 ///
399 /// HdFormat describes the memory format of image buffers used in Hd.
400 /// It's similar to HdType but with more specific associated semantics.
401 ///
402 /// The list of supported formats is modelled after Vulkan and DXGI, though
403 /// Hydra only supports a subset. Endian-ness is explicitly not captured;
404 /// color data is assumed to always be RGBA.
405 ///
406 /// For reference, see:
407 /// https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkFormat
409 {
411 
412  // UNorm8 - a 1-byte value representing a float between 0 and 1.
413  // float value = (unorm / 255.0f);
418 
419  // SNorm8 - a 1-byte value representing a float between -1 and 1.
420  // float value = max(snorm / 127.0f, -1.0f);
425 
426  // Float16 - a 2-byte IEEE half-precision float.
431 
432  // Float32 - a 4-byte IEEE float.
437 
438  // Int16 - a 2-byte signed integer
443 
444  // UInt16 - a 2-byte unsigned integer
449 
450  // Int32 - a 4-byte signed integer
455 
456  // Depth-stencil format
458 
460 };
461 
462 /// Return the single-channel version of a given format.
463 HD_API
465 
466 /// Return the count of components in the given format.
467 HD_API
469 
470 /// Return the size of a single element of the given format.
471 /// For block formats, this will return 0.
472 HD_API
474 
475 ///
476 /// Type representing a depth-stencil value.
477 ///
478 using HdDepthStencilType = std::pair<float, uint32_t>;
479 
481 
482 #endif // PXR_IMAGING_HD_TYPES_H
uint32_t maxAnisotropy
Definition: types.h:120
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
HD_API size_t HdDataSizeOfType(HdType)
Return the size, in bytes, of a single value of the given type.
HdCompareFunction
Definition: enums.h:19
HdFormat
Definition: types.h:408
HdWrap
Definition: types.h:37
A 2-component vector with Int32-valued components.
Definition: types.h:286
bool operator==(const HdVec4f_2_10_10_10_REV &other) const
Definition: types.h:201
const GLdouble * v
Definition: glcorearb.h:837
size_t count
Definition: types.h:345
uint32_t HdDirtyBits
Definition: types.h:143
GLsizei const GLfloat * value
Definition: glcorearb.h:824
HD_API size_t HdDataSizeOfTupleType(HdTupleType)
Return the size, in bytes, of a value with HdTupleType.
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
Corresponds to GL_FLOAT_VEC3.
Definition: types.h:306
#define HD_API
Definition: api.h:23
A 4-component vector with Int32-valued components.
Definition: types.h:290
HD_API HdType HdGetComponentType(HdType)
HdCompareFunction compareFunction
Definition: types.h:119
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLint y
Definition: glcorearb.h:103
int HdConvertFloatToFixed(float v, int b)
Definition: types.h:146
Corresponds to GL_DOUBLE_VEC4.
Definition: types.h:321
bool operator!=(HdTupleType const &rhs) const
Definition: types.h:353
float HdConvertFixedToFloat(int v, int b)
Definition: types.h:154
A 3-component vector with Int32-valued components.
Definition: types.h:288
bool operator<(HdTupleType const &rhs) const
Definition: types.h:347
Corresponds to GL_DOUBLE_VEC3.
Definition: types.h:319
Corresponds to GL_INT.
Definition: types.h:284
int GetAsInt() const
Definition: types.h:196
std::pair< float, uint32_t > HdDepthStencilType
Definition: types.h:478
GLfloat f
Definition: glcorearb.h:1926
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
HdMinFilter
Definition: types.h:64
HdBorderColor
Definition: types.h:99
HD_API const void * HdGetValueData(const VtValue &)
HD_API HdTupleType HdGetValueTupleType(const VtValue &)
bool operator!=(const HdVec4f_2_10_10_10_REV &other) const
Definition: types.h:207
bool operator==(HdTupleType const &rhs) const
Definition: types.h:350
Corresponds to GL_FLOAT.
Definition: types.h:302
void TfHashAppend(HashState &h, HdTupleType const &tt)
Definition: types.h:361
A 3-component vector with UInt32-valued components.
Definition: types.h:297
vfloat4 round(const vfloat4 &a)
Definition: simd.h:7647
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
Corresponds to GL_BOOL.
Definition: types.h:277
HdVec4f_2_10_10_10_REV(Vec3Type const &value)
Definition: types.h:173
GLint GLenum GLint x
Definition: glcorearb.h:409
An unsigned 32-bit integer. Corresponds to GL_UNSIGNED_INT.
Definition: types.h:293
HdMagFilter
Definition: types.h:83
Corresponds to GL_DOUBLE_MAT3.
Definition: types.h:323
GLdouble t
Definition: glad.h:2397
Corresponds to GL_FLOAT_VEC2.
Definition: types.h:304
HdVec4f_2_10_10_10_REV(int const value)
Definition: types.h:180
HD_API bool operator!=(const HdSamplerParameters &other) const
Corresponds to GL_FLOAT_MAT4.
Definition: types.h:312
Corresponds to GL_FLOAT_MAT3.
Definition: types.h:310
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
A 4-component vector with UInt32-valued components.
Definition: types.h:299
IMATH_NAMESPACE::V2f IMATH_NAMESPACE::Box2i std::string this attribute is obsolete as of OpenEXR v3 float
HD_API HdFormat HdGetComponentFormat(HdFormat f)
Return the single-channel version of a given format.
HdMinFilter minFilter
Definition: types.h:115
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HD_API size_t HdGetComponentCount(HdType t)
Corresponds to GL_DOUBLE_VEC2.
Definition: types.h:317
Corresponds to GL_FLOAT_VEC4.
Definition: types.h:308
Corresponds to GL_DOUBLE_MAT4.
Definition: types.h:325
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HdBorderColor borderColor
Definition: types.h:117
Vec3Type GetAsVec() const
Definition: types.h:190
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
HdType
Definition: types.h:272
HdMagFilter magFilter
Definition: types.h:116
Definition: value.h:146
Corresponds to GL_DOUBLE.
Definition: types.h:315
GLint GLsizei count
Definition: glcorearb.h:405
HD_API size_t HdDataSizeOfFormat(HdFormat f)
HD_API bool operator==(const HdSamplerParameters &other) const
A 2-component vector with UInt32-valued components.
Definition: types.h:295
HdType type
Definition: types.h:344
HD_API HdSamplerParameters()
bool enableCompare
Definition: types.h:118