Monado OpenXR Runtime
xrt_defines.h
Go to the documentation of this file.
1 // Copyright 2019-2020, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Common defines and enums for XRT.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup xrt_iface
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_compiler.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
19 /*!
20  * A base class for reference counted objects.
21  *
22  * @ingroup xrt_iface
23  */
25 {
26  uint32_t count;
27 };
28 
29 /*!
30  * Which blend mode does the device support, used as both a bitfield and value.
31  *
32  * @ingroup xrt_iface
33  */
35 {
36  // clang-format off
37  XRT_BLEND_MODE_OPAQUE = 1 << 0,
38  XRT_BLEND_MODE_ADDITIVE = 1 << 1,
39  XRT_BLEND_MODE_ALPHA_BLEND = 1 << 2,
40  // clang-format on
41 };
42 
43 /*!
44  * Which distortion model does the device expose,
45  * used both as a bitfield and value.
46  */
48 {
49  // clang-format off
50  XRT_DISTORTION_MODEL_NONE = 1 << 0,
51  XRT_DISTORTION_MODEL_PANOTOOLS = 1 << 1,
52  XRT_DISTORTION_MODEL_VIVE = 1 << 2,
53  XRT_DISTORTION_MODEL_MESHUV = 1 << 3,
54  // clang-format on
55 };
56 
57 /*!
58  * Common formats, use `u_format_*` functions to reason about them.
59  */
61 {
62  XRT_FORMAT_R8G8B8X8,
63  XRT_FORMAT_R8G8B8A8,
64  XRT_FORMAT_R8G8B8,
65  XRT_FORMAT_R8G8,
66  XRT_FORMAT_R8,
67 
68  XRT_FORMAT_L8, // Luminence, R = L, G = L, B = L.
69 
70  XRT_FORMAT_BITMAP_8X1, // One bit format tiled in 8x1 blocks.
71  XRT_FORMAT_BITMAP_8X8, // One bit format tiled in 8X8 blocks.
72 
73  XRT_FORMAT_YUV888,
74  XRT_FORMAT_YUV422,
75 
76  XRT_FORMAT_MJPEG,
77 };
78 
79 /*!
80  * What type of stereo format a frame has.
81  *
82  * @ingroup xrt_iface
83  */
85 {
86  XRT_STEREO_FORMAT_NONE,
87  XRT_STEREO_FORMAT_SBS, //!< Side by side.
88  XRT_STEREO_FORMAT_INTERLEAVED, //!< Interleaved pixels.
89  XRT_STEREO_FORMAT_OAU, //!< Over & Under.
90 };
91 
92 /*!
93  * A quaternion with single floats.
94  *
95  * @ingroup xrt_iface math
96  */
97 struct xrt_quat
98 {
99  float x;
100  float y;
101  float z;
102  float w;
103 };
104 
105 /*!
106  * A 1 element vector with single floats.
107  *
108  * @ingroup xrt_iface math
109  */
110 struct xrt_vec1
111 {
112  float x;
113 };
114 
115 /*!
116  * A 2 element vector with single floats.
117  *
118  * @ingroup xrt_iface math
119  */
120 struct xrt_vec2
121 {
122  float x;
123  float y;
124 };
125 
126 /*!
127  * A 3 element vector with single floats.
128  *
129  * @ingroup xrt_iface math
130  */
131 struct xrt_vec3
132 {
133  float x;
134  float y;
135  float z;
136 };
137 
138 /*!
139  * A 3 element vector with 32 bit integers.
140  *
141  * @ingroup xrt_iface math
142  */
144 {
145  int32_t x;
146  int32_t y;
147  int32_t z;
148 };
149 
150 /*!
151  * A 2 element vector with 32 bit integers.
152  *
153  * @ingroup xrt_iface math
154  */
156 {
157  int32_t x;
158  int32_t y;
159 };
160 
161 /*!
162  * A 3 element colour with 8 bits per channel.
163  *
164  * @ingroup xrt_iface math
165  */
167 {
168  uint8_t r;
169  uint8_t g;
170  uint8_t b;
171 };
172 
173 /*!
174  * A 4 element colour with 8 bits per channel.
175  *
176  * @ingroup xrt_iface math
177  */
179 {
180  uint8_t r;
181  uint8_t g;
182  uint8_t b;
183  uint8_t a;
184 };
185 
186 /*!
187  * A 3 element colour with floating point channels.
188  *
189  * @ingroup xrt_iface math
190  */
192 {
193  float r;
194  float g;
195  float b;
196 };
197 
198 /*!
199  * A 4 element colour with floating point channels.
200  *
201  * @ingroup xrt_iface math
202  */
204 {
205  float r;
206  float g;
207  float b;
208  float a;
209 };
210 
211 /*!
212  * Image size.
213  *
214  * @ingroup xrt_iface math
215  */
216 struct xrt_size
217 {
218  int w;
219  int h;
220 };
221 
222 /*!
223  * A pose composed of a position and orientation.
224  *
225  * @see xrt_qaut
226  * @see xrt_vec3
227  * @ingroup xrt_iface math
228  */
229 struct xrt_pose
230 {
231  struct xrt_quat orientation;
232  struct xrt_vec3 position;
233 };
234 
235 /*!
236  * Describes a projection matrix fov.
237  *
238  * @ingroup xrt_iface math
239  */
240 struct xrt_fov
241 {
242  float angle_left;
243  float angle_right;
244  float angle_up;
245  float angle_down;
246 };
247 
248 /*!
249  * A tightly packed 2x2 matrix of floats.
250  *
251  * @ingroup xrt_iface math
252  */
254 {
255  union {
256  float v[4];
257  struct xrt_vec2 vecs[2];
258  };
259 };
260 
261 /*!
262  * A tightly packed 3x3 matrix of floats.
263  *
264  * @ingroup xrt_iface math
265  */
267 {
268  float v[9];
269 };
270 
271 /*!
272  * A tightly packed 4x4 matrix of floats.
273  *
274  * @ingroup xrt_iface math
275  */
277 {
278  float v[16];
279 };
280 
281 /*!
282  * A range of API versions supported.
283  *
284  * @ingroup xrt_iface math
285  */
287 {
288  uint32_t min_major;
289  uint32_t min_minor;
290  uint32_t min_patch;
291 
292  uint32_t max_major;
293  uint32_t max_minor;
294  uint32_t max_patch;
295 };
296 
297 /*!
298  * Flags of which components of a @ref xrt_space_relation is valid.
299  *
300  * @see xrt_space_relation
301  * @ingroup xrt_iface math
302  */
304 {
305  XRT_SPACE_RELATION_ORIENTATION_VALID_BIT = 0x00000001,
306  XRT_SPACE_RELATION_POSITION_VALID_BIT = 0x00000002,
307  XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT = 0x00000004,
308  XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT = 0x00000008,
309  XRT_SPACE_RELATION_LINEAR_ACCELERATION_VALID_BIT = 0x00000010,
310  XRT_SPACE_RELATION_ANGULAR_ACCELERATION_VALID_BIT = 0x00000020,
311  XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT = 0x00000040,
312  XRT_SPACE_RELATION_POSITION_TRACKED_BIT = 0x00000080,
313  XRT_SPACE_RELATION_BITMASK_ALL =
314  XRT_SPACE_RELATION_ORIENTATION_VALID_BIT |
315  XRT_SPACE_RELATION_POSITION_VALID_BIT |
316  XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT |
317  XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT |
318  XRT_SPACE_RELATION_LINEAR_ACCELERATION_VALID_BIT |
319  XRT_SPACE_RELATION_ANGULAR_ACCELERATION_VALID_BIT |
320  XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT |
321  XRT_SPACE_RELATION_POSITION_TRACKED_BIT,
322  XRT_SPACE_RELATION_BITMASK_NONE = 0
323 };
324 
325 /*!
326  * A relation with two spaces, includes velocity and acceleration.
327  *
328  * @see xrt_quat
329  * @see xrt_vec3
330  * @see xrt_pose
331  * @see xrt_space_relation_flags
332  * @ingroup xrt_iface math
333  */
335 {
336  enum xrt_space_relation_flags relation_flags;
337  struct xrt_pose pose;
338  struct xrt_vec3 linear_velocity;
339  struct xrt_vec3 angular_velocity;
340  struct xrt_vec3 linear_acceleration;
341  struct xrt_vec3 angular_acceleration;
342 };
343 
344 
345 /*
346  *
347  * Input related enums and structs.
348  *
349  */
350 
351 /*!
352  * A enum that is used to name devices so that the
353  * state trackers can reason about the devices easier.
354  */
356 {
357  XRT_DEVICE_GENERIC_HMD = 1,
358 
359  XRT_DEVICE_PSMV = 2,
360  XRT_DEVICE_HYDRA = 3,
361  XRT_DEVICE_DAYDREAM = 4,
362 };
363 
364 /*!
365  * Base type of this inputs.
366  *
367  * @ingroup xrt_iface
368  */
370 {
371  // clang-format off
372  //! Float input in [0, 1]
374  //! Float input in [-1, 1]
376  //! Vec2 input, components in [-1, 1]
378  //! Vec3 input, components in [-1, 1]
380  //! Boolean (digital, binary) input
382  //! A tracked pose
384  // clang-format on
385 };
386 
387 /*!
388  * @brief Create an enum value for xrt_input_name that packs an ID and input
389  * type.
390  *
391  * @param id an integer
392  * @param type The suffix of an xrt_input_type value name: `XRT_INPUT_TYPE_` is
393  * prepended automatically.
394  *
395  * @see xrt_input_name
396  * @ingroup xrt_iface
397  */
398 #define XRT_INPUT_NAME(id, type) ((id << 8) | XRT_INPUT_TYPE_##type)
399 
400 /*!
401  * @brief Extract the xrt_input_type from an xrt_input_name.
402  *
403  * @param name A xrt_input_name value
404  *
405  * @see xrt_input_name
406  * @see xrt_input_type
407  * @ingroup xrt_iface
408  */
409 #define XRT_GET_INPUT_TYPE(name) (name & 0xff)
410 
411 /*!
412  * Name of a input with a baked in type.
413  *
414  * @see xrt_input_type
415  * @ingroup xrt_iface
416  */
418 {
419  // clang-format off
420  XRT_INPUT_GENERIC_HEAD_POSE = XRT_INPUT_NAME(0x0000, POSE),
421  XRT_INPUT_GENERIC_HEAD_DETECT = XRT_INPUT_NAME(0x0001, BOOLEAN),
422 
423  XRT_INPUT_PSMV_PS_CLICK = XRT_INPUT_NAME(0x0020, BOOLEAN),
424  XRT_INPUT_PSMV_MOVE_CLICK = XRT_INPUT_NAME(0x0021, BOOLEAN),
425  XRT_INPUT_PSMV_START_CLICK = XRT_INPUT_NAME(0x0022, BOOLEAN),
426  XRT_INPUT_PSMV_SELECT_CLICK = XRT_INPUT_NAME(0x0023, BOOLEAN),
427  XRT_INPUT_PSMV_SQUARE_CLICK = XRT_INPUT_NAME(0x0024, BOOLEAN),
428  XRT_INPUT_PSMV_CROSS_CLICK = XRT_INPUT_NAME(0x0025, BOOLEAN),
429  XRT_INPUT_PSMV_CIRCLE_CLICK = XRT_INPUT_NAME(0x0026, BOOLEAN),
430  XRT_INPUT_PSMV_TRIANGLE_CLICK = XRT_INPUT_NAME(0x0027, BOOLEAN),
431  XRT_INPUT_PSMV_TRIGGER_VALUE = XRT_INPUT_NAME(0x0028, VEC1_ZERO_TO_ONE),
432  XRT_INPUT_PSMV_BODY_CENTER_POSE = XRT_INPUT_NAME(0x0029, POSE),
433  XRT_INPUT_PSMV_BALL_CENTER_POSE = XRT_INPUT_NAME(0x002A, POSE),
434  XRT_INPUT_PSMV_BALL_TIP_POSE = XRT_INPUT_NAME(0x002B, POSE),
435 
436  XRT_INPUT_HYDRA_1_CLICK = XRT_INPUT_NAME(0x0030, BOOLEAN),
437  XRT_INPUT_HYDRA_2_CLICK = XRT_INPUT_NAME(0x0031, BOOLEAN),
438  XRT_INPUT_HYDRA_3_CLICK = XRT_INPUT_NAME(0x0032, BOOLEAN),
439  XRT_INPUT_HYDRA_4_CLICK = XRT_INPUT_NAME(0x0033, BOOLEAN),
440  XRT_INPUT_HYDRA_MIDDLE_CLICK = XRT_INPUT_NAME(0x0034, BOOLEAN),
441  XRT_INPUT_HYDRA_BUMPER_CLICK = XRT_INPUT_NAME(0x0035, BOOLEAN),
442  XRT_INPUT_HYDRA_JOYSTICK_CLICK = XRT_INPUT_NAME(0x0036, BOOLEAN),
443  XRT_INPUT_HYDRA_JOYSTICK_VALUE = XRT_INPUT_NAME(0x0037, VEC2_MINUS_ONE_TO_ONE),
444  XRT_INPUT_HYDRA_TRIGGER_VALUE = XRT_INPUT_NAME(0x0038, VEC1_ZERO_TO_ONE),
445  XRT_INPUT_HYDRA_POSE = XRT_INPUT_NAME(0x0039, POSE),
446 
447  XRT_INPUT_DAYDREAM_TOUCHPAD_CLICK = XRT_INPUT_NAME(0x0040, BOOLEAN),
448  XRT_INPUT_DAYDREAM_BAR_CLICK = XRT_INPUT_NAME(0x0041, BOOLEAN),
449  XRT_INPUT_DAYDREAM_CIRCLE_CLICK = XRT_INPUT_NAME(0x0042, BOOLEAN),
450  XRT_INPUT_DAYDREAM_VOLUP_CLICK = XRT_INPUT_NAME(0x0043, BOOLEAN),
451  XRT_INPUT_DAYDREAM_VOLDN_CLICK = XRT_INPUT_NAME(0x0044, BOOLEAN),
452  //! @todo This should be merged and be tagged as a touchpad, maybe.
454  XRT_INPUT_DAYDREAM_TOUCHPAD_VALUE_Y = XRT_INPUT_NAME(0x0046, VEC1_ZERO_TO_ONE),
455  XRT_INPUT_DAYDREAM_POSE = XRT_INPUT_NAME(0x0047, POSE),
456 
457  // clang-format on
458 };
459 
460 /*!
461  * A union of all input types.
462  *
463  * @see xrt_input_type
464  * @ingroup xrt_iface math
465  */
467  struct xrt_vec1 vec1;
468  struct xrt_vec2 vec2;
469  struct xrt_vec3 vec3;
470  bool boolean;
471 };
472 
473 
474 /*!
475  * Base type of this output.
476  *
477  * @ingroup xrt_iface
478  */
480 {
481  // clang-format off
482  XRT_OUTPUT_TYPE_VIBRATION = 0x00,
483  // clang-format on
484 };
485 
486 #define XRT_OUTPUT_NAME(id, type) ((id << 8) | XRT_OUTPUT_TYPE_##type)
487 
488 /*!
489  * Name of a output with a baked in type.
490  *
491  * @see xrt_output_type
492  * @ingroup xrt_iface
493  */
495 {
496  // clang-format off
497  XRT_OUTPUT_NAME_PSMV_RUMBLE_VIBRATION = XRT_OUTPUT_NAME(0x0020, VIBRATION),
498  // clang-format on
499 };
500 
501 /*!
502  * A union of all output types.
503  *
504  * @see xrt_output_type
505  * @ingroup xrt_iface math
506  */
508  struct
509  {
510  float frequency;
511  float amplitude;
512  } vibration;
513 };
514 
515 
516 /*
517  *
518  * Inline functions
519  *
520  */
521 
522 static inline bool
523 xrt_reference_dec(struct xrt_reference *xref)
524 {
525  int count = xrt_atomic_dec_return(&xref->count);
526  return count == 0;
527 }
528 
529 static inline void
530 xrt_reference_inc(struct xrt_reference *xref)
531 {
532  xrt_atomic_inc_return(&xref->count);
533 }
534 
535 
536 #ifdef __cplusplus
537 }
538 #endif
Over & Under.
Definition: xrt_defines.h:89
A tracked pose.
Definition: xrt_defines.h:383
A 3 element vector with single floats.
Definition: xrt_defines.h:131
A 3 element colour with 8 bits per channel.
Definition: xrt_defines.h:166
A union of all input types.
Definition: xrt_defines.h:466
A pose composed of a position and orientation.
Definition: xrt_defines.h:229
Float input in [-1, 1].
Definition: xrt_defines.h:375
A 2 element vector with single floats.
Definition: xrt_defines.h:120
xrt_input_type
Base type of this inputs.
Definition: xrt_defines.h:369
Vec2 input, components in [-1, 1].
Definition: xrt_defines.h:377
xrt_distortion_model
Which distortion model does the device expose, used both as a bitfield and value. ...
Definition: xrt_defines.h:47
A tightly packed 3x3 matrix of floats.
Definition: xrt_defines.h:266
A quaternion with single floats.
Definition: xrt_defines.h:97
xrt_stereo_format
What type of stereo format a frame has.
Definition: xrt_defines.h:84
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:334
Vec3 input, components in [-1, 1].
Definition: xrt_defines.h:379
A 2 element vector with 32 bit integers.
Definition: xrt_defines.h:155
A 1 element vector with single floats.
Definition: xrt_defines.h:110
A union of all output types.
Definition: xrt_defines.h:507
A range of API versions supported.
Definition: xrt_defines.h:286
Boolean (digital, binary) input.
Definition: xrt_defines.h:381
A 4 element colour with floating point channels.
Definition: xrt_defines.h:203
A 3 element vector with 32 bit integers.
Definition: xrt_defines.h:143
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:494
xrt_output_type
Base type of this output.
Definition: xrt_defines.h:479
Image size.
Definition: xrt_defines.h:216
A tightly packed 4x4 matrix of floats.
Definition: xrt_defines.h:276
#define XRT_INPUT_NAME(id, type)
Create an enum value for xrt_input_name that packs an ID and input type.
Definition: xrt_defines.h:398
xrt_blend_mode
Which blend mode does the device support, used as both a bitfield and value.
Definition: xrt_defines.h:34
Describes a projection matrix fov.
Definition: xrt_defines.h:240
A 3 element colour with floating point channels.
Definition: xrt_defines.h:191
A 4 element colour with 8 bits per channel.
Definition: xrt_defines.h:178
xrt_device_name
A enum that is used to name devices so that the state trackers can reason about the devices easier...
Definition: xrt_defines.h:355
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition: xrt_defines.h:60
Side by side.
Definition: xrt_defines.h:87
A base class for reference counted objects.
Definition: xrt_defines.h:24
xrt_space_relation_flags
Flags of which components of a xrt_space_relation is valid.
Definition: xrt_defines.h:303
Header holding common defines.
Float input in [0, 1].
Definition: xrt_defines.h:373
Definition: xrt_defines.h:453
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:253
xrt_input_name
Name of a input with a baked in type.
Definition: xrt_defines.h:417
Interleaved pixels.
Definition: xrt_defines.h:88