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 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 
37 
38 /// \enum HdWrap
39 ///
40 /// Enumerates wrapping attributes type values.
41 ///
42 /// <ul>
43 /// <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>
44 /// <li>\b HdWrapRepeat Creates a repeating pattern</li>
45 /// <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>
46 /// <li>\b HdWrapMirror Creates a mirrored repeating pattern.</li>
47 /// <li>\b HdWrapNoOpinion No opinion. The data texture can define its own wrap mode that we can use instead. Fallback to HdWrapBlack</li>
48 /// <li>\b HdWrapLegacyNoOpinionFallbackRepeat (deprecated) Similar to HdWrapNoOpinon but fallback to HdWrapRepeat</li>
49 /// <li>\b HdWrapUseMetadata (deprecated) Alias for HdWrapNoOpinion</li>
50 /// <li>\b HdWrapLegacy (deprecated) Alias for HdWrapLegacyNoOpinionFallbackRepeat</li>
51 /// </ul>
52 ///
53 enum HdWrap
54 {
59 
62 
63  HdWrapUseMetadata = HdWrapNoOpinion, // deprecated alias
65 };
66 
67 /// \enum HdMinFilter
68 ///
69 /// Enumerates minFilter attribute type values.
70 ///
71 /// <ul>
72 /// <li>\b HdMinFilterNearest Nearest to center of the pixel</li>
73 /// <li>\b HdMinFilterLinear Weighted average od the four texture elements closest to the pixel</li>
74 /// <li>\b HdMinFilterNearestMipmapNearest Nearest to center of the pixel from the nearest mipmaps</li>
75 /// <li>\b HdMinFilterLinearMipmapNeares Weighted average using texture elements from the nearest mipmaps</li>
76 /// <li>\b HdMinFilterNearestMipmapLinear Weighted average of the nearest pixels from the two nearest mipmaps</li>
77 /// <li>\b HdMinFilterLinearMipmapLinear WeightedAverage of the weighted averages from the nearest mipmaps</li>
78 /// </ul>
79 ///
81 {
88 };
89 
90 /// \enum HdMagFilter
91 ///
92 /// Enumerates magFilter attribute type values.
93 ///
94 /// <ul>
95 /// <li>HdFilterNearest Nearest to center of the pixel</li>
96 /// <li>HdFilterLinear Weighted average of the four texture elements closest to the pixel</li>
97 /// </ul>
98 ///
100 {
103 };
104 
105 /// \class HdSamplerParameters
106 ///
107 /// Collection of standard parameters such as wrap modes to sample a texture.
108 ///
110 public:
116 
117  HD_API
118  bool operator==(const HdSamplerParameters &other) const;
119 
120  HD_API
121  bool operator!=(const HdSamplerParameters &other) const;
122 };
123 
124 ///
125 /// Type representing a set of dirty bits.
126 ///
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 
145 ///
146 /// HdVec4f_2_10_10_10_REV is a compact representation of a GfVec4f.
147 /// It uses 10 bits for x, y, and z, and 2 bits for w.
148 ///
149 /// XXX We expect this type to move again as we continue work on
150 /// refactoring the GL dependencies.
151 ///
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 
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),
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 
201 /// \enum HdType
202 ///
203 /// HdType describes the type of an attribute value used in Hd.
204 ///
205 /// HdType values have a specific machine representation and size.
206 /// See HdDataSizeOfType().
207 ///
208 /// HdType specifies a scalar, vector, or matrix type. Vector and
209 /// matrix types can be unpacked into the underlying "component"
210 /// type; see HdGetComponentType().
211 ///
212 /// HdType is intended to span the common set of attribute types
213 /// used in shading languages such as GLSL. However, it currently
214 /// does not include non-4x4 matrix types, nor struct types.
215 ///
216 /// Fixed-size array types are represented by the related class
217 /// HdTupleType. HdTupleType is used anywhere there is a
218 /// possibility of an array of values.
219 ///
220 /// ## Value arrays and attribute buffers
221 ///
222 /// Attribute data is often stored in linear buffers. These buffers
223 /// have multiple dimensions and it is important to distinguish them:
224 ///
225 /// - "Components" refer to the scalar components that comprise a vector
226 /// or matrix. For example, a vec3 has 3 components, a mat4 has
227 /// 16 components, and a float has a single component.
228 ///
229 /// - "Elements" refer to external concepts that entries in a buffer
230 /// associate with. Typically these are pieces of geometry,
231 /// such as faces or vertices.
232 ///
233 /// - "Arrays" refer to the idea that each element may associate
234 /// with a fixed-size array of values. For example, one approach
235 /// to motion blur might store a size-2 array of HdFloatMat4
236 /// values for each element of geometry, holding the transforms
237 /// at the beginning and ending of the camera shutter interval.
238 ///
239 /// Combining these concepts in an example, a primvar buffer might hold
240 /// data for 10 vertices (the elements) with each vertex having a
241 /// 2 entries (an array) of 4x4 matrices (with 16 components each).
242 /// As a packed linear buffer, this would occupy 10*2*16==320 floats.
243 ///
244 /// It is important to distinguish components from array entries,
245 /// and arrays from elements. HdType and HdTupleType only
246 /// addresses components and arrays; elements are tracked by buffers.
247 /// See for example HdBufferSource::GetNumElements().
248 ///
249 /// In other words, HdType and HdTupleType describe values.
250 /// Buffers describe elements and all other details regarding buffer
251 /// layout, such as offset/stride used to interleave attribute data.
252 ///
253 /// For more background, see the OpenGL discussion on data types:
254 /// - https://www.khronos.org/opengl/wiki/OpenGL_Type
255 ///
256 enum HdType
257 {
259 
260  /// Corresponds to GL_BOOL
266 
267  /// Corresponds to GL_INT
269  /// A 2-component vector with Int32-valued components.
271  /// A 3-component vector with Int32-valued components.
273  /// A 4-component vector with Int32-valued components.
275 
276  /// An unsigned 32-bit integer. Corresponds to GL_UNSIGNED_INT.
278  /// A 2-component vector with UInt32-valued components.
280  /// A 3-component vector with UInt32-valued components.
282  /// A 4-component vector with UInt32-valued components.
284 
285  /// Corresponds to GL_FLOAT
287  /// Corresponds to GL_FLOAT_VEC2
289  /// Corresponds to GL_FLOAT_VEC3
291  /// Corresponds to GL_FLOAT_VEC4
293  /// Corresponds to GL_FLOAT_MAT3
295  /// Corresponds to GL_FLOAT_MAT4
297 
298  /// Corresponds to GL_DOUBLE
300  /// Corresponds to GL_DOUBLE_VEC2
302  /// Corresponds to GL_DOUBLE_VEC3
304  /// Corresponds to GL_DOUBLE_VEC4
306  /// Corresponds to GL_DOUBLE_MAT3
308  /// Corresponds to GL_DOUBLE_MAT4
310 
315 
316  /// Packed, reverse-order encoding of a 4-component vector into Int32.
317  /// Corresponds to GL_INT_2_10_10_10_REV.
318  /// \see HdVec4f_2_10_10_10_REV
320 };
321 
322 /// HdTupleType represents zero, one, or more values of the same HdType.
323 /// It can be used to represent fixed-size array types, as well as single
324 /// values. See HdType for more discussion about arrays.
325 struct HdTupleType {
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 /// Returns a direct pointer to the data held by a VtValue.
341 /// Returns nullptr if the VtValue is empty or holds a type unknown to Hd.
342 HD_API
343 const void* HdGetValueData(const VtValue &);
344 
345 /// Returns the HdTupleType that describes the given VtValue.
346 /// For scalar, vector, and matrix types, the count is 1.
347 /// For any VtArray type, the count is the number of array members.
348 HD_API
350 
351 /// Return the component type for the given value type.
352 /// For vectors and matrices, this is the scalar type of their components.
353 /// For scalars, this is the type itself.
354 /// As an example, the component type of HdTypeFloatMat4 is HdTypeFloat.
355 HD_API
357 
358 /// Return the count of components in the given value type.
359 /// For example, HdTypeFloatVec3 has 3 components.
360 HD_API
362 
363 /// Return the size, in bytes, of a single value of the given type.
364 HD_API
365 size_t HdDataSizeOfType(HdType);
366 
367 /// Return the size, in bytes, of a value with HdTupleType.
368 HD_API
370 
371 /// \enum HdFormat
372 ///
373 /// HdFormat describes the memory format of image buffers used in Hd.
374 /// It's similar to HdType but with more specific associated semantics.
375 ///
376 /// The list of supported formats is modelled after Vulkan and DXGI, though
377 /// Hydra only supports a subset. Endian-ness is explicitly not captured;
378 /// color data is assumed to always be RGBA.
379 ///
380 /// For reference, see:
381 /// https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#VkFormat
383 {
385 
386  // UNorm8 - a 1-byte value representing a float between 0 and 1.
387  // float value = (unorm / 255.0f);
392 
393  // SNorm8 - a 1-byte value representing a float between -1 and 1.
394  // float value = max(snorm / 127.0f, -1.0f);
399 
400  // Float16 - a 2-byte IEEE half-precision float.
405 
406  // Float32 - a 4-byte IEEE float.
411 
412  // Int32 - a 4-byte signed integer
417 
418  // Depth-stencil format
420 
422 };
423 
424 /// Return the single-channel version of a given format.
425 HD_API
427 
428 /// Return the count of components in the given format.
429 HD_API
431 
432 /// Return the size of a single element of the given format.
433 /// For block formats, this will return 0.
434 HD_API
436 
438 
439 #endif // PXR_IMAGING_HD_TYPES_H
vint4 max(const vint4 &a, const vint4 &b)
Definition: simd.h:4703
HD_API size_t HdDataSizeOfType(HdType)
Return the size, in bytes, of a single value of the given type.
HdFormat
Definition: types.h:382
HdWrap
Definition: types.h:53
A 2-component vector with Int32-valued components.
Definition: types.h:270
bool operator==(const HdVec4f_2_10_10_10_REV &other) const
Definition: types.h:185
size_t count
Definition: types.h:327
uint32_t HdDirtyBits
Definition: types.h:127
HD_API size_t HdDataSizeOfTupleType(HdTupleType)
Return the size, in bytes, of a value with HdTupleType.
Corresponds to GL_FLOAT_VEC3.
Definition: types.h:290
#define HD_API
Definition: api.h:40
A 4-component vector with Int32-valued components.
Definition: types.h:274
HD_API HdType HdGetComponentType(HdType)
const GLdouble * v
Definition: glew.h:1391
int HdConvertFloatToFixed(float v, int b)
Definition: types.h:130
Corresponds to GL_DOUBLE_VEC4.
Definition: types.h:305
bool operator!=(HdTupleType const &rhs) const
Definition: types.h:335
float HdConvertFixedToFloat(int v, int b)
Definition: types.h:138
A 3-component vector with Int32-valued components.
Definition: types.h:272
bool operator<(HdTupleType const &rhs) const
Definition: types.h:329
Corresponds to GL_DOUBLE_VEC3.
Definition: types.h:303
Corresponds to GL_INT.
Definition: types.h:268
GLdouble GLdouble z
Definition: glew.h:1559
int GetAsInt() const
Definition: types.h:180
HdMinFilter
Definition: types.h:80
GLclampf f
Definition: glew.h:3499
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
HD_API const void * HdGetValueData(const VtValue &)
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
HD_API HdTupleType HdGetValueTupleType(const VtValue &)
bool operator!=(const HdVec4f_2_10_10_10_REV &other) const
Definition: types.h:191
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
bool operator==(HdTupleType const &rhs) const
Definition: types.h:332
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Corresponds to GL_FLOAT.
Definition: types.h:286
A 3-component vector with UInt32-valued components.
Definition: types.h:281
vfloat4 round(const vfloat4 &a)
Definition: simd.h:7186
Corresponds to GL_BOOL.
Definition: types.h:261
HdVec4f_2_10_10_10_REV(Vec3Type const &value)
Definition: types.h:157
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
An unsigned 32-bit integer. Corresponds to GL_UNSIGNED_INT.
Definition: types.h:277
HdMagFilter
Definition: types.h:99
Corresponds to GL_DOUBLE_MAT3.
Definition: types.h:307
Corresponds to GL_FLOAT_VEC2.
Definition: types.h:288
HdVec4f_2_10_10_10_REV(int const value)
Definition: types.h:164
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
HD_API bool operator!=(const HdSamplerParameters &other) const
Corresponds to GL_FLOAT_MAT4.
Definition: types.h:296
Corresponds to GL_FLOAT_MAT3.
Definition: types.h:294
A 4-component vector with UInt32-valued components.
Definition: types.h:283
HD_API HdFormat HdGetComponentFormat(HdFormat f)
Return the single-channel version of a given format.
HdMinFilter minFilter
Definition: types.h:114
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
HD_API size_t HdGetComponentCount(HdType t)
Corresponds to GL_DOUBLE_VEC2.
Definition: types.h:301
Corresponds to GL_FLOAT_VEC4.
Definition: types.h:292
Corresponds to GL_DOUBLE_MAT4.
Definition: types.h:309
GLuint GLuint GLsizei count
Definition: glew.h:1253
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Vec3Type GetAsVec() const
Definition: types.h:174
#define const
Definition: zconf.h:214
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
HdType
Definition: types.h:256
HdMagFilter magFilter
Definition: types.h:115
GLsizei const GLfloat * value
Definition: glew.h:1849
GLdouble GLdouble t
Definition: glew.h:1398
Definition: value.h:174
Corresponds to GL_DOUBLE.
Definition: types.h:299
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:279
HdType type
Definition: types.h:326