Monado OpenXR Runtime
xrt_device.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Header defining a xrt HMD device.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup xrt_iface
8  */
9 
10 #pragma once
11 
12 #define XRT_DEVICE_NAME_LEN 256
13 
14 #include "xrt/xrt_defines.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 struct xrt_tracking;
21 
22 
23 /*!
24  * A per-lens view information.
25  *
26  * @ingroup xrt_iface
27  */
28 struct xrt_view
29 {
30  /*!
31  * Viewpport position on the screen, in absolute screen coordinates,
32  * this field is only used by @ref comp to setup the device rendering.
33  *
34  * If the view is being rotated by xrt_view.rot 90° right in the
35  * distortion shader then `display.w_pixels == viewport.h_pixels` &
36  * `display.h_pixels == viewport.w_pixels`.
37  */
38  struct
39  {
40  uint32_t x_pixels;
41  uint32_t y_pixels;
42  uint32_t w_pixels;
43  uint32_t h_pixels;
44  } viewport;
45 
46  /*!
47  * Pixel and phyisical properties of this display, not in absolute
48  * screen coordinates that the compositor sees. So before any rotation
49  * is applied by xrt_view::rot.
50  *
51  * The xrt_view::display::w_pixels & xrt_view::display::h_pixels
52  * become the recommdnded image size for this view.
53  */
54  struct
55  {
56  uint32_t w_pixels;
57  uint32_t h_pixels;
58  float w_meters;
59  float h_meters;
60  } display;
61 
62  /*!
63  * Position in meters relative to display origin, before any rotation
64  * is applied by xrt_view::rot.
65  */
66  struct
67  {
68  float x_meters;
69  float y_meters;
70  } lens_center;
71 
72  /*!
73  * Rotation 2d matrix used to rotate the position of the output of the
74  * distortion shaders onto the screen. Should the distortion shader be
75  * based on mesh then this matrix rotates the vertex positions.
76  */
78 
79  /*!
80  * Fov expressed in OpenXR.
81  */
82  struct xrt_fov fov;
83 };
84 
85 /*!
86  * All of the device components that deals with interfacing to a users head.
87  *
88  * HMD is probably a bad name for the future but for now will have to do.
89  *
90  * @ingroup xrt_iface
91  */
93 {
94  /*!
95  * The hmd screen, right now hardcoded to one.
96  */
97  struct
98  {
99  int w_pixels;
100  int h_pixels;
101  //! Nominal frame interval
103  } screens[1];
104 
105  /*!
106  * Display information.
107  *
108  * For now hardcoded display to two.
109  */
110  struct xrt_view views[2];
111 
112  /*!
113  * Supported blend modes, a bitfield.
114  */
115  enum xrt_blend_mode blend_mode;
116 
117  /*!
118  * Distortion information.
119  */
120  struct
121  {
122  //! Supported distortion models, a bitfield.
123  enum xrt_distortion_model models;
124  //! Preferred disortion model, single value.
125  enum xrt_distortion_model preferred;
126 
127  struct
128  {
129  //! Panotools universal distortion k.
130  float distortion_k[4];
131  //! Panotools post distortion scale, <r, g, b, _>.
132  float aberration_k[4];
133  //! Panotools warp scale.
134  float warp_scale;
135  } pano;
136 
137  struct
138  {
141 
142  //! Left/right
143  float undistort_r2_cutoff[2];
144 
145  //! Left/right, x/y
146  float center[2][2];
147 
148  //! left/right, r/g/b, a/b/c
149  float coefficients[2][3][3];
150  } vive;
151 
152  struct
153  {
154  //! Data.
155  float *vertices;
156  //! Number of vertices.
157  size_t num_vertices;
158  //! Stride of vertices
159  size_t stride;
160  //! 1 or 3 for (chromatic aberration).
162 
163  //! Indices, for triangle strip.
164  int *indices;
165  //! Number of indices for the triangle strip.
166  size_t num_indices[2];
167  //! Offsets for the indices.
168  size_t offset_indices[2];
169  //! Total number of indices.
171  } mesh;
172  } distortion;
173 };
174 
175 /*!
176  * A single named input, that sits on a @ref xrt_device.
177  *
178  * @ingroup xrt_iface
179  */
180 struct xrt_input
181 {
182  //! Is this input active.
183  bool active;
184 
185  int64_t timestamp;
186 
187  enum xrt_input_name name;
188 
189  union xrt_input_value value;
190 };
191 
193 {
194  enum xrt_output_name name;
195 };
196 
197 /*!
198  * A single HMD or input device.
199  *
200  * @ingroup xrt_iface
201  */
203 {
204  //! Enum identifier of the device.
205  enum xrt_device_name name;
206 
207  //! A string describing the device.
209 
210  //! Null if this device does not interface with the users head.
212 
213  //! Always set, pointing to the tracking system for this device.
215 
216  //! Number of inputs.
217  size_t num_inputs;
218  //! Array of input structs.
219  struct xrt_input *inputs;
220 
221  //! Number of outputs.
222  size_t num_outputs;
223  //! Array of output structs.
225 
226 
227  /*!
228  * Update any attached inputs.
229  *
230  * @param[in] xdev The device.
231  * @param[in] timekeeping Shared time synchronization struct.
232  */
233  void (*update_inputs)(struct xrt_device *xdev);
234 
235  /*!
236  * Get relationship of a tracked device to the device "base space".
237  *
238  * Right now the base space is assumed to be local space.
239  *
240  * This is very very WIP and will need to be made a lot more advanced.
241  *
242  * @param[in] xdev The device.
243  * @param[in] name Some devices may have multiple poses on
244  * them, select the one using this field. For
245  * HMDs use @p XRT_INPUT_GENERIC_HEAD_POSE.
246  * @param[in] at_timestamp_ns If the device can predict or has a history
247  * of positions, this is when the caller
248  * wants the pose to be from.
249  * @param[out] out_relation_timestamp_ns Timestamp when this relation
250  * was captured.
251  * @param[out] out_relation The relation read from the device.
252  *
253  * @see xrt_input_name
254  */
255  void (*get_tracked_pose)(struct xrt_device *xdev,
256  enum xrt_input_name name,
257  uint64_t at_timestamp_ns,
258  uint64_t *out_relation_timestamp_ns,
259  struct xrt_space_relation *out_relation);
260 
261  /*!
262  * Set a output value.
263  *
264  * @see xrt_output_name
265  */
266  void (*set_output)(struct xrt_device *xdev,
267  enum xrt_output_name name,
268  union xrt_output_value *value);
269 
270  /*!
271  * Get the per view pose in relation to the view space. Does not do any
272  * device level tracking, use get_tracked_pose for that.
273  *
274  * @param eye_relation The interpupillary relation as a 3D position,
275  * most simple stereo devices would just want to set
276  * out_puse->position.[x|y|z] = ipd.[x|y|z] / 2.0f.
277  * Not to be confused with IPD that is absolute
278  * distance, this is a full 3D relation.
279  * @param index Index of view.
280  * @param out_pose Output pose, see ipd argument, and in addition
281  * orientation most likely identity rotation.
282  */
283  void (*get_view_pose)(struct xrt_device *xdev,
284  struct xrt_vec3 *eye_relation,
285  uint32_t view_index,
286  struct xrt_pose *out_pose);
287 
288  /*!
289  * Destroy device.
290  */
291  void (*destroy)(struct xrt_device *xdev);
292 };
293 
294 /*!
295  * Helper function for @ref xrt_device::update_inputs.
296  */
297 static inline void
298 xrt_device_update_inputs(struct xrt_device *xdev)
299 {
300  xdev->update_inputs(xdev);
301 }
302 
303 /*!
304  * Helper function for @ref xrt_device::get_tracked_pose.
305  */
306 static inline void
307 xrt_device_get_tracked_pose(struct xrt_device *xdev,
308  enum xrt_input_name name,
309  uint64_t requested_timestamp_ns,
310  uint64_t *out_actual_timestamp_ns,
311  struct xrt_space_relation *out_relation)
312 {
313  xdev->get_tracked_pose(xdev, name, requested_timestamp_ns,
314  out_actual_timestamp_ns, out_relation);
315 }
316 
317 /*!
318  * Helper function for @ref xrt_device::set_output.
319  */
320 static inline void
321 xrt_device_set_output(struct xrt_device *xdev,
322  enum xrt_output_name name,
323  union xrt_output_value *value)
324 {
325  xdev->set_output(xdev, name, value);
326 }
327 
328 /*!
329  * Helper function for @ref xrt_device::get_view_pose.
330  */
331 static inline void
332 xrt_device_get_view_pose(struct xrt_device *xdev,
333  struct xrt_vec3 *eye_relation,
334  uint32_t view_index,
335  struct xrt_pose *out_pose)
336 {
337  xdev->get_view_pose(xdev, eye_relation, view_index, out_pose);
338 }
339 
340 /*!
341  * Helper function for @ref xrt_device::destroy.
342  */
343 static inline void
344 xrt_device_destroy(struct xrt_device **xdev_ptr)
345 {
346  struct xrt_device *xdev = *xdev_ptr;
347  if (xdev == NULL) {
348  return;
349  }
350 
351  xdev->destroy(xdev);
352  *xdev_ptr = NULL;
353 }
354 
355 
356 #ifdef __cplusplus
357 }
358 #endif
int w_pixels
Definition: xrt_device.h:99
A tracking system or device origin.
Definition: xrt_tracking.h:53
struct xrt_hmd_parts * hmd
Null if this device does not interface with the users head.
Definition: xrt_device.h:211
void(* update_inputs)(struct xrt_device *xdev)
Update any attached inputs.
Definition: xrt_device.h:233
size_t num_uv_channels
1 or 3 for (chromatic aberration).
Definition: xrt_device.h:161
A 3 element vector with single floats.
Definition: xrt_defines.h:133
A union of all input types.
Definition: xrt_defines.h:504
A pose composed of a position and orientation.
Definition: xrt_defines.h:231
enum xrt_device_name name
Enum identifier of the device.
Definition: xrt_device.h:205
void(* destroy)(struct xrt_device *xdev)
Destroy device.
Definition: xrt_device.h:291
xrt_distortion_model
Which distortion model does the device expose, used both as a bitfield and value. ...
Definition: xrt_defines.h:48
float aspect_x_over_y
Definition: xrt_device.h:139
int * indices
Indices, for triangle strip.
Definition: xrt_device.h:164
float * vertices
Data.
Definition: xrt_device.h:155
float warp_scale
Panotools warp scale.
Definition: xrt_device.h:134
size_t stride
Stride of vertices.
Definition: xrt_device.h:159
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:336
void(* set_output)(struct xrt_device *xdev, enum xrt_output_name name, union xrt_output_value *value)
Set a output value.
Definition: xrt_device.h:266
size_t num_vertices
Number of vertices.
Definition: xrt_device.h:157
struct xrt_view::@85 viewport
Viewpport position on the screen, in absolute screen coordinates, this field is only used by Composit...
float grow_for_undistort
Definition: xrt_device.h:140
struct xrt_input * inputs
Array of input structs.
Definition: xrt_device.h:219
uint64_t nominal_frame_interval_ns
Nominal frame interval.
Definition: xrt_device.h:102
struct xrt_view::@86 display
Pixel and phyisical properties of this display, not in absolute screen coordinates that the composito...
A union of all output types.
Definition: xrt_defines.h:547
size_t total_num_indices
Total number of indices.
Definition: xrt_device.h:170
Common defines and enums for XRT.
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:532
int h_pixels
Definition: xrt_device.h:100
float h_meters
Definition: xrt_device.h:59
float y_meters
Definition: xrt_device.h:69
size_t num_inputs
Number of inputs.
Definition: xrt_device.h:217
All of the device components that deals with interfacing to a users head.
Definition: xrt_device.h:92
xrt_blend_mode
Which blend mode does the device support, used as both a bitfield and value.
Definition: xrt_defines.h:35
Describes a projection matrix fov.
Definition: xrt_defines.h:242
struct xrt_tracking_origin * tracking_origin
Always set, pointing to the tracking system for this device.
Definition: xrt_device.h:214
size_t num_outputs
Number of outputs.
Definition: xrt_device.h:222
float x_meters
Definition: xrt_device.h:68
A per-lens view information.
Definition: xrt_device.h:28
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
struct xrt_output * outputs
Array of output structs.
Definition: xrt_device.h:224
Definition: xrt_device.h:192
struct xrt_matrix_2x2 rot
Rotation 2d matrix used to rotate the position of the output of the distortion shaders onto the scree...
Definition: xrt_device.h:77
void(* get_tracked_pose)(struct xrt_device *xdev, enum xrt_input_name name, uint64_t at_timestamp_ns, uint64_t *out_relation_timestamp_ns, struct xrt_space_relation *out_relation)
Get relationship of a tracked device to the device "base space".
Definition: xrt_device.h:255
uint32_t y_pixels
Definition: xrt_device.h:41
bool active
Is this input active.
Definition: xrt_device.h:183
A single named input, that sits on a xrt_device.
Definition: xrt_device.h:180
uint32_t w_pixels
Definition: xrt_device.h:42
struct xrt_fov fov
Fov expressed in OpenXR.
Definition: xrt_device.h:82
A single HMD or input device.
Definition: xrt_device.h:202
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:255
void(* get_view_pose)(struct xrt_device *xdev, struct xrt_vec3 *eye_relation, uint32_t view_index, struct xrt_pose *out_pose)
Get the per view pose in relation to the view space.
Definition: xrt_device.h:283
xrt_input_name
Name of a input with a baked in type.
Definition: xrt_defines.h:421
int64_t timestamp
Definition: xrt_device.h:185
float w_meters
Definition: xrt_device.h:58
uint32_t x_pixels
Definition: xrt_device.h:40
struct xrt_view::@87 lens_center
Position in meters relative to display origin, before any rotation is applied by xrt_view::rot.
uint32_t h_pixels
Definition: xrt_device.h:43
#define XRT_DEVICE_NAME_LEN
Definition: xrt_device.h:12