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 #include "util/u_time.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 
20 /*!
21  * A base class for reference counted objects.
22  *
23  * @ingroup xrt_iface
24  */
26 {
27  uint32_t count;
28 };
29 
30 /*!
31  * Which blend mode does the device support, used as both a bitfield and value.
32  *
33  * @ingroup xrt_iface
34  */
36 {
37  // clang-format off
41  // clang-format on
42 };
43 
44 /*!
45  * Which distortion model does the device expose,
46  * used both as a bitfield and value.
47  */
49 {
50  // clang-format off
55  // clang-format on
56 };
57 
58 /*!
59  * Common formats, use `u_format_*` functions to reason about them.
60  */
62 {
68 
69  XRT_FORMAT_L8, // Luminence, R = L, G = L, B = L.
70 
71  XRT_FORMAT_BITMAP_8X1, // One bit format tiled in 8x1 blocks.
72  XRT_FORMAT_BITMAP_8X8, // One bit format tiled in 8X8 blocks.
73 
77 
79 };
80 
81 /*!
82  * What type of stereo format a frame has.
83  *
84  * @ingroup xrt_iface
85  */
87 {
89  XRT_STEREO_FORMAT_SBS, //!< Side by side.
90  XRT_STEREO_FORMAT_INTERLEAVED, //!< Interleaved pixels.
91  XRT_STEREO_FORMAT_OAU, //!< Over & Under.
92 };
93 
94 /*!
95  * A quaternion with single floats.
96  *
97  * @ingroup xrt_iface math
98  */
99 struct xrt_quat
100 {
101  float x;
102  float y;
103  float z;
104  float w;
105 };
106 
107 /*!
108  * A 1 element vector with single floats.
109  *
110  * @ingroup xrt_iface math
111  */
112 struct xrt_vec1
113 {
114  float x;
115 };
116 
117 /*!
118  * A 2 element vector with single floats.
119  *
120  * @ingroup xrt_iface math
121  */
122 struct xrt_vec2
123 {
124  float x;
125  float y;
126 };
127 
128 /*!
129  * A 3 element vector with single floats.
130  *
131  * @ingroup xrt_iface math
132  */
133 struct xrt_vec3
134 {
135  float x;
136  float y;
137  float z;
138 };
139 
140 /*!
141  * A 3 element vector with 32 bit integers.
142  *
143  * @ingroup xrt_iface math
144  */
146 {
147  int32_t x;
148  int32_t y;
149  int32_t z;
150 };
151 
152 /*!
153  * A 2 element vector with 32 bit integers.
154  *
155  * @ingroup xrt_iface math
156  */
158 {
159  int32_t x;
160  int32_t y;
161 };
162 
163 /*!
164  * A 3 element colour with 8 bits per channel.
165  *
166  * @ingroup xrt_iface math
167  */
169 {
170  uint8_t r;
171  uint8_t g;
172  uint8_t b;
173 };
174 
175 /*!
176  * A 4 element colour with 8 bits per channel.
177  *
178  * @ingroup xrt_iface math
179  */
181 {
182  uint8_t r;
183  uint8_t g;
184  uint8_t b;
185  uint8_t a;
186 };
187 
188 /*!
189  * A 3 element colour with floating point channels.
190  *
191  * @ingroup xrt_iface math
192  */
194 {
195  float r;
196  float g;
197  float b;
198 };
199 
200 /*!
201  * A 4 element colour with floating point channels.
202  *
203  * @ingroup xrt_iface math
204  */
206 {
207  float r;
208  float g;
209  float b;
210  float a;
211 };
212 
213 /*!
214  * Image size.
215  *
216  * @ingroup xrt_iface math
217  */
218 struct xrt_size
219 {
220  int w;
221  int h;
222 };
223 
224 /*!
225  * A pose composed of a position and orientation.
226  *
227  * @see xrt_qaut
228  * @see xrt_vec3
229  * @ingroup xrt_iface math
230  */
231 struct xrt_pose
232 {
233  struct xrt_quat orientation;
234  struct xrt_vec3 position;
235 };
236 
237 /*!
238  * Describes a projection matrix fov.
239  *
240  * @ingroup xrt_iface math
241  */
242 struct xrt_fov
243 {
244  float angle_left;
245  float angle_right;
246  float angle_up;
247  float angle_down;
248 };
249 
250 /*!
251  * A tightly packed 2x2 matrix of floats.
252  *
253  * @ingroup xrt_iface math
254  */
256 {
257  union {
258  float v[4];
259  struct xrt_vec2 vecs[2];
260  };
261 };
262 
263 /*!
264  * A tightly packed 3x3 matrix of floats.
265  *
266  * @ingroup xrt_iface math
267  */
269 {
270  float v[9];
271 };
272 
273 /*!
274  * A tightly packed 4x4 matrix of floats.
275  *
276  * @ingroup xrt_iface math
277  */
279 {
280  float v[16];
281 };
282 
283 /*!
284  * A range of API versions supported.
285  *
286  * @ingroup xrt_iface math
287  */
289 {
290  uint32_t min_major;
291  uint32_t min_minor;
292  uint32_t min_patch;
293 
294  uint32_t max_major;
295  uint32_t max_minor;
296  uint32_t max_patch;
297 };
298 
299 /*!
300  * Flags of which components of a @ref xrt_space_relation is valid.
301  *
302  * @see xrt_space_relation
303  * @ingroup xrt_iface math
304  */
306 {
325 };
326 
327 /*!
328  * A relation with two spaces, includes velocity and acceleration.
329  *
330  * @see xrt_quat
331  * @see xrt_vec3
332  * @see xrt_pose
333  * @see xrt_space_relation_flags
334  * @ingroup xrt_iface math
335  */
337 {
338  enum xrt_space_relation_flags relation_flags;
339  struct xrt_pose pose;
340  struct xrt_vec3 linear_velocity;
341  struct xrt_vec3 angular_velocity;
342  struct xrt_vec3 linear_acceleration;
343  struct xrt_vec3 angular_acceleration;
344 };
345 
346 
347 /*
348  *
349  * Input related enums and structs.
350  *
351  */
352 
353 /*!
354  * A enum that is used to name devices so that the
355  * state trackers can reason about the devices easier.
356  */
358 {
360 
366 };
367 
368 /*!
369  * Base type of this inputs.
370  *
371  * @ingroup xrt_iface
372  */
374 {
375  // clang-format off
376  //! Float input in [0, 1]
378  //! Float input in [-1, 1]
380  //! Vec2 input, components in [-1, 1]
382  //! Vec3 input, components in [-1, 1]
384  //! Boolean (digital, binary) input
386  //! A tracked pose
388  // clang-format on
389 };
390 
391 /*!
392  * @brief Create an enum value for xrt_input_name that packs an ID and input
393  * type.
394  *
395  * @param id an integer
396  * @param type The suffix of an xrt_input_type value name: `XRT_INPUT_TYPE_` is
397  * prepended automatically.
398  *
399  * @see xrt_input_name
400  * @ingroup xrt_iface
401  */
402 #define XRT_INPUT_NAME(id, type) ((id << 8) | XRT_INPUT_TYPE_##type)
403 
404 /*!
405  * @brief Extract the xrt_input_type from an xrt_input_name.
406  *
407  * @param name A xrt_input_name value
408  *
409  * @see xrt_input_name
410  * @see xrt_input_type
411  * @ingroup xrt_iface
412  */
413 #define XRT_GET_INPUT_TYPE(name) (name & 0xff)
414 
415 /*!
416  * Name of a input with a baked in type.
417  *
418  * @see xrt_input_type
419  * @ingroup xrt_iface
420  */
422 {
423  // clang-format off
426 
435  XRT_INPUT_PSMV_TRIGGER_VALUE = XRT_INPUT_NAME(0x0028, VEC1_ZERO_TO_ONE),
439 
447  XRT_INPUT_HYDRA_JOYSTICK_VALUE = XRT_INPUT_NAME(0x0037, VEC2_MINUS_ONE_TO_ONE),
448  XRT_INPUT_HYDRA_TRIGGER_VALUE = XRT_INPUT_NAME(0x0038, VEC1_ZERO_TO_ONE),
450 
456  //! @todo This should be merged and be tagged as a touchpad, maybe.
460 
467  XRT_INPUT_INDEX_SQUEEZE_VALUE = XRT_INPUT_NAME(0x0056, VEC1_ZERO_TO_ONE),
468  XRT_INPUT_INDEX_SQUEEZE_FORCE = XRT_INPUT_NAME(0x0057, VEC1_ZERO_TO_ONE),
470  XRT_INPUT_INDEX_TRIGGER_VALUE = XRT_INPUT_NAME(0x0059, VEC1_ZERO_TO_ONE),
472  XRT_INPUT_INDEX_THUMBSTICK_X = XRT_INPUT_NAME(0x005B, VEC1_ZERO_TO_ONE),
473  XRT_INPUT_INDEX_THUMBSTICK_Y = XRT_INPUT_NAME(0x005C, VEC1_ZERO_TO_ONE),
476  XRT_INPUT_INDEX_TRACKPAD_X = XRT_INPUT_NAME(0x005F, VEC1_ZERO_TO_ONE),
477  XRT_INPUT_INDEX_TRACKPAD_Y = XRT_INPUT_NAME(0x0060, VEC1_ZERO_TO_ONE),
478  XRT_INPUT_INDEX_TRACKPAD_FORCE = XRT_INPUT_NAME(0x0061, VEC1_ZERO_TO_ONE),
482 
487  XRT_INPUT_VIVE_TRIGGER_VALUE = XRT_INPUT_NAME(0x0074, VEC1_ZERO_TO_ONE),
488  XRT_INPUT_VIVE_TRACKPAD_X = XRT_INPUT_NAME(0x0075, VEC1_ZERO_TO_ONE),
489  XRT_INPUT_VIVE_TRACKPAD_Y = XRT_INPUT_NAME(0x0076, VEC1_ZERO_TO_ONE),
494 
495  // clang-format on
496 };
497 
498 /*!
499  * A union of all input types.
500  *
501  * @see xrt_input_type
502  * @ingroup xrt_iface math
503  */
505  struct xrt_vec1 vec1;
506  struct xrt_vec2 vec2;
507  struct xrt_vec3 vec3;
508  bool boolean;
509 };
510 
511 
512 /*!
513  * Base type of this output.
514  *
515  * @ingroup xrt_iface
516  */
518 {
519  // clang-format off
521  // clang-format on
522 };
523 
524 #define XRT_OUTPUT_NAME(id, type) ((id << 8) | XRT_OUTPUT_TYPE_##type)
525 
526 /*!
527  * Name of a output with a baked in type.
528  *
529  * @see xrt_output_type
530  * @ingroup xrt_iface
531  */
533 {
534  // clang-format off
538  // clang-format on
539 };
540 
541 /*!
542  * A union of all output types.
543  *
544  * @see xrt_output_type
545  * @ingroup xrt_iface math
546  */
548  struct
549  {
550  float frequency;
551  float amplitude;
553  } vibration;
554 };
555 
556 
557 /*
558  *
559  * Inline functions
560  *
561  */
562 
563 static inline bool
564 xrt_reference_dec(struct xrt_reference *xref)
565 {
566  int count = xrt_atomic_dec_return(&xref->count);
567  return count == 0;
568 }
569 
570 static inline void
571 xrt_reference_inc(struct xrt_reference *xref)
572 {
573  xrt_atomic_inc_return(&xref->count);
574 }
575 
576 
577 #ifdef __cplusplus
578 }
579 #endif
Definition: xrt_defines.h:440
Definition: xrt_defines.h:449
Definition: xrt_defines.h:447
Over & Under.
Definition: xrt_defines.h:91
Definition: xrt_defines.h:465
Definition: xrt_defines.h:39
Definition: xrt_defines.h:445
Definition: xrt_defines.h:520
Definition: xrt_defines.h:474
Definition: xrt_defines.h:362
Definition: xrt_defines.h:458
Definition: xrt_defines.h:430
Definition: xrt_defines.h:484
Definition: xrt_defines.h:40
Definition: xrt_defines.h:324
float angle_right
Definition: xrt_defines.h:245
Definition: xrt_defines.h:363
A tracked pose.
Definition: xrt_defines.h:387
Definition: xrt_defines.h:459
float b
Definition: xrt_defines.h:209
Definition: xrt_defines.h:65
Definition: xrt_defines.h:425
Definition: xrt_defines.h:470
A 3 element vector with single floats.
Definition: xrt_defines.h:133
A 3 element colour with 8 bits per channel.
Definition: xrt_defines.h:168
A union of all input types.
Definition: xrt_defines.h:504
int64_t time_duration_ns
Integer duration type in nanoseconds.
Definition: u_time.h:45
int32_t y
Definition: xrt_defines.h:148
A pose composed of a position and orientation.
Definition: xrt_defines.h:231
Float input in [-1, 1].
Definition: xrt_defines.h:379
Definition: xrt_defines.h:63
Definition: xrt_defines.h:434
Definition: xrt_defines.h:485
Definition: xrt_defines.h:488
Definition: xrt_defines.h:71
A 2 element vector with single floats.
Definition: xrt_defines.h:122
xrt_input_type
Base type of this inputs.
Definition: xrt_defines.h:373
Definition: xrt_defines.h:489
Definition: xrt_defines.h:315
Vec2 input, components in [-1, 1].
Definition: xrt_defines.h:381
xrt_distortion_model
Which distortion model does the device expose, used both as a bitfield and value. ...
Definition: xrt_defines.h:48
float z
Definition: xrt_defines.h:137
Definition: xrt_defines.h:424
Definition: xrt_defines.h:313
Definition: xrt_defines.h:535
float r
Definition: xrt_defines.h:195
Definition: xrt_defines.h:473
#define XRT_OUTPUT_NAME(id, type)
Definition: xrt_defines.h:524
uint8_t r
Definition: xrt_defines.h:182
int32_t x
Definition: xrt_defines.h:147
A tightly packed 3x3 matrix of floats.
Definition: xrt_defines.h:268
Definition: xrt_defines.h:466
A quaternion with single floats.
Definition: xrt_defines.h:99
uint8_t a
Definition: xrt_defines.h:185
xrt_stereo_format
What type of stereo format a frame has.
Definition: xrt_defines.h:86
Definition: xrt_defines.h:481
uint32_t min_major
Definition: xrt_defines.h:290
uint32_t max_minor
Definition: xrt_defines.h:295
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:336
int h
Definition: xrt_defines.h:221
Definition: xrt_defines.h:491
Definition: xrt_defines.h:54
Definition: xrt_defines.h:314
Vec3 input, components in [-1, 1].
Definition: xrt_defines.h:383
Definition: xrt_defines.h:451
Time-keeping: a clock that is steady, convertible to system time, and ideally high-resolution.
Definition: xrt_defines.h:477
Definition: xrt_defines.h:88
float w
Definition: xrt_defines.h:104
uint32_t min_patch
Definition: xrt_defines.h:292
Definition: xrt_defines.h:431
A 2 element vector with 32 bit integers.
Definition: xrt_defines.h:157
A 1 element vector with single floats.
Definition: xrt_defines.h:112
A union of all output types.
Definition: xrt_defines.h:547
A range of API versions supported.
Definition: xrt_defines.h:288
Boolean (digital, binary) input.
Definition: xrt_defines.h:385
float g
Definition: xrt_defines.h:196
Definition: xrt_defines.h:443
A 4 element colour with floating point channels.
Definition: xrt_defines.h:205
A 3 element vector with 32 bit integers.
Definition: xrt_defines.h:145
float y
Definition: xrt_defines.h:136
Definition: xrt_defines.h:428
Definition: xrt_defines.h:436
Definition: xrt_defines.h:478
Definition: xrt_defines.h:448
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:532
Definition: xrt_defines.h:493
xrt_output_type
Base type of this output.
Definition: xrt_defines.h:517
Image size.
Definition: xrt_defines.h:218
Definition: xrt_defines.h:480
float x
Definition: xrt_defines.h:124
Definition: xrt_defines.h:74
A tightly packed 4x4 matrix of floats.
Definition: xrt_defines.h:278
Definition: xrt_defines.h:361
Definition: xrt_defines.h:52
Definition: xrt_defines.h:487
#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:402
Definition: xrt_defines.h:463
Definition: xrt_defines.h:64
Definition: xrt_defines.h:442
float a
Definition: xrt_defines.h:210
Definition: xrt_defines.h:427
Definition: xrt_defines.h:429
uint32_t max_patch
Definition: xrt_defines.h:296
float angle_down
Definition: xrt_defines.h:247
float frequency
Definition: xrt_defines.h:550
uint32_t min_minor
Definition: xrt_defines.h:291
Definition: xrt_defines.h:433
int32_t z
Definition: xrt_defines.h:149
Definition: xrt_defines.h:462
Definition: xrt_defines.h:441
Definition: xrt_defines.h:308
Definition: xrt_defines.h:475
Definition: xrt_defines.h:38
bool boolean
Definition: xrt_defines.h:508
int32_t x
Definition: xrt_defines.h:159
xrt_blend_mode
Which blend mode does the device support, used as both a bitfield and value.
Definition: xrt_defines.h:35
uint8_t g
Definition: xrt_defines.h:183
float y
Definition: xrt_defines.h:102
Definition: xrt_defines.h:455
Definition: xrt_defines.h:437
Definition: xrt_defines.h:479
Definition: xrt_defines.h:76
Definition: xrt_defines.h:464
float r
Definition: xrt_defines.h:207
Definition: xrt_defines.h:483
float angle_up
Definition: xrt_defines.h:246
float z
Definition: xrt_defines.h:103
Describes a projection matrix fov.
Definition: xrt_defines.h:242
float amplitude
Definition: xrt_defines.h:551
Definition: xrt_defines.h:444
Definition: xrt_defines.h:359
uint8_t b
Definition: xrt_defines.h:172
Definition: xrt_defines.h:476
A 3 element colour with floating point channels.
Definition: xrt_defines.h:193
A 4 element colour with 8 bits per channel.
Definition: xrt_defines.h:180
Definition: xrt_defines.h:307
uint8_t r
Definition: xrt_defines.h:170
float y
Definition: xrt_defines.h:125
Definition: xrt_defines.h:438
Definition: xrt_defines.h:471
Definition: xrt_defines.h:452
float x
Definition: xrt_defines.h:135
int w
Definition: xrt_defines.h:220
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:357
Definition: xrt_defines.h:365
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition: xrt_defines.h:61
uint8_t g
Definition: xrt_defines.h:171
Side by side.
Definition: xrt_defines.h:89
A base class for reference counted objects.
Definition: xrt_defines.h:25
float b
Definition: xrt_defines.h:197
Definition: xrt_defines.h:461
Definition: xrt_defines.h:486
Definition: xrt_defines.h:69
Definition: xrt_defines.h:537
Definition: xrt_defines.h:454
Definition: xrt_defines.h:446
xrt_space_relation_flags
Flags of which components of a xrt_space_relation is valid.
Definition: xrt_defines.h:305
Definition: xrt_defines.h:435
time_duration_ns duration
Definition: xrt_defines.h:552
uint8_t b
Definition: xrt_defines.h:184
Header holding common defines.
uint32_t count
Definition: xrt_defines.h:27
Float input in [0, 1].
Definition: xrt_defines.h:377
Definition: xrt_defines.h:75
Definition: xrt_defines.h:467
Definition: xrt_defines.h:53
float angle_left
Definition: xrt_defines.h:244
int32_t y
Definition: xrt_defines.h:160
Definition: xrt_defines.h:51
Definition: xrt_defines.h:490
Definition: xrt_defines.h:66
Definition: xrt_defines.h:468
Definition: xrt_defines.h:472
Definition: xrt_defines.h:457
uint32_t max_major
Definition: xrt_defines.h:294
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:255
Definition: xrt_defines.h:67
float x
Definition: xrt_defines.h:101
xrt_input_name
Name of a input with a baked in type.
Definition: xrt_defines.h:421
Definition: xrt_defines.h:364
Interleaved pixels.
Definition: xrt_defines.h:90
Definition: xrt_defines.h:492
Definition: xrt_defines.h:453
float x
Definition: xrt_defines.h:114
Definition: xrt_defines.h:78
Definition: xrt_defines.h:469
Definition: xrt_defines.h:536
float g
Definition: xrt_defines.h:208
Definition: xrt_defines.h:72
Definition: xrt_defines.h:432