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 time_state;
21 struct xrt_tracking;
22 
23 
24 /*!
25  * A per-lens view information.
26  *
27  * @ingroup xrt_iface
28  */
29 struct xrt_view
30 {
31  /*!
32  * Viewpport position on the screen, in absolute screen coordinates,
33  * this field is only used by @ref comp to setup the device rendering.
34  *
35  * If the view is being rotated by xrt_view.rot 90° right in the
36  * distortion shader then `display.w_pixels == viewport.h_pixels` &
37  * `display.h_pixels == viewport.w_pixels`.
38  */
39  struct
40  {
41  uint32_t x_pixels;
42  uint32_t y_pixels;
43  uint32_t w_pixels;
44  uint32_t h_pixels;
45  } viewport;
46 
47  /*!
48  * Pixel and phyisical properties of this display, not in absolute
49  * screen coordinates that the compositor sees. So before any rotation
50  * is applied by xrt_view::rot.
51  *
52  * The xrt_view::display::w_pixels & xrt_view::display::h_pixels
53  * become the recommdnded image size for this view.
54  */
55  struct
56  {
57  uint32_t w_pixels;
58  uint32_t h_pixels;
59  float w_meters;
60  float h_meters;
61  } display;
62 
63  /*!
64  * Position in meters relative to display origin, before any rotation
65  * is applied by xrt_view::rot.
66  */
67  struct
68  {
69  float x_meters;
70  float y_meters;
71  } lens_center;
72 
73  /*!
74  * Rotation 2d matrix used to rotate the position of the output of the
75  * distortion shaders onto the screen. Should the distortion shader be
76  * based on mesh then this matrix rotates the vertex positions.
77  */
79 
80  /*!
81  * Fov expressed in OpenXR.
82  */
83  struct xrt_fov fov;
84 };
85 
86 /*!
87  * All of the device components that deals with interfacing to a users head.
88  *
89  * HMD is probably a bad name for the future but for now will have to do.
90  *
91  * @ingroup xrt_iface
92  */
94 {
95  /*!
96  * The hmd screen, right now hardcoded to one.
97  */
98  struct
99  {
100  int w_pixels;
101  int h_pixels;
102  //! Nominal frame interval
104  } screens[1];
105 
106  /*!
107  * Display information.
108  *
109  * For now hardcoded display to two.
110  */
111  struct xrt_view views[2];
112 
113  /*!
114  * Supported blend modes, a bitfield.
115  */
116  enum xrt_blend_mode blend_mode;
117 
118  /*!
119  * Distortion information.
120  */
121  struct
122  {
123  //! Supported distortion models, a bitfield.
124  enum xrt_distortion_model models;
125  //! Preferred disortion model, single value.
126  enum xrt_distortion_model preferred;
127 
128  struct
129  {
130  //! Panotools universal distortion k.
131  float distortion_k[4];
132  //! Panotools post distortion scale, <r, g, b, _>.
133  float aberration_k[4];
134  //! Panotools warp scale.
135  float warp_scale;
136  } pano;
137 
138  struct
139  {
140  float aspect_x_over_y;
141  float grow_for_undistort;
142 
143  //! Left/right
144  float undistort_r2_cutoff[2];
145 
146  //! Left/right, x/y
147  float center[2][2];
148 
149  //! left/right, r/g/b, a/b/c
150  float coefficients[2][3][3];
151  } vive;
152 
153  struct
154  {
155  //! Data.
156  float *vertices;
157  //! Number of vertices.
158  size_t num_vertices;
159  //! Stride of vertices
160  size_t stride;
161  //! 1 or 3 for (chromatic aberration).
163 
164  //! Indices, for triangle strip.
165  int *indices;
166  //! Number of indices for the triangle strip.
167  size_t num_indices[2];
168  //! Offsets for the indices.
169  size_t offset_indices[2];
170  //! Total number of indices.
172  } mesh;
173  } distortion;
174 };
175 
176 /*!
177  * A single named input, that sits on a @ref xrt_device.
178  *
179  * @ingroup xrt_iface
180  */
181 struct xrt_input
182 {
183  //! Is this input active.
184  bool active;
185 
186  int64_t timestamp;
187 
188  enum xrt_input_name name;
189 
190  union xrt_input_value value;
191 };
192 
194 {
195  enum xrt_output_name name;
196 };
197 
198 /*!
199  * A single HMD or input device.
200  *
201  * @ingroup xrt_iface
202  */
204 {
205  //! Enum identifier of the device.
206  enum xrt_device_name name;
207 
208  //! A string describing the device.
209  char str[XRT_DEVICE_NAME_LEN];
210 
211  //! Null if this device does not interface with the users head.
213 
214  //! Always set, pointing to the tracking system for this device.
216 
217  //! Number of inputs.
218  size_t num_inputs;
219  //! Array of input structs.
220  struct xrt_input *inputs;
221 
222  //! Number of outputs.
223  size_t num_outputs;
224  //! Array of output structs.
226 
227 
228  /*!
229  * Update any attached inputs.
230  *
231  * @param[in] xdev The device.
232  * @param[in] timekeeping Shared time synchronization struct.
233  */
234  void (*update_inputs)(struct xrt_device *xdev,
235  struct time_state *timekeeping);
236 
237  /*!
238  * Get relationship of a tracked device to the device "base space".
239  *
240  * Right now the base space is assumed to be local space.
241  *
242  * This is very very WIP and will need to be made a lot more advanced.
243  *
244  * @param[in] xdev The device.
245  * @param[in] name Some devices may have multiple poses on
246  * them, select the one using this field. For
247  * HMDs use @p XRT_INPUT_GENERIC_HEAD_POSE.
248  * @param[in] timekeeping Shared time synchronization struct.
249  * @param[out] out_timestamp Timestamp when this relation was captured.
250  * @param[out] out_relation The relation read from the device.
251  *
252  * @see xrt_input_name
253  */
254  void (*get_tracked_pose)(struct xrt_device *xdev,
255  enum xrt_input_name name,
256  struct time_state *timekeeping,
257  int64_t *out_timestamp,
258  struct xrt_space_relation *out_relation);
259 
260  /*!
261  * Set a output value.
262  *
263  * @see xrt_output_name
264  */
265  void (*set_output)(struct xrt_device *xdev,
266  enum xrt_output_name name,
267  struct time_state *timekeeping,
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 #ifdef __cplusplus
296 }
297 #endif
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:212
size_t num_uv_channels
1 or 3 for (chromatic aberration).
Definition: xrt_device.h:162
A 3 element vector with single floats.
Definition: xrt_defines.h:131
A union of all input types.
Definition: xrt_defines.h:466
A pose composed of a position and orientation.
Definition: xrt_defines.h:229
enum xrt_device_name name
Enum identifier of the device.
Definition: xrt_device.h:206
struct xrt_view::@77 display
Pixel and phyisical properties of this display, not in absolute screen coordinates that the composito...
xrt_distortion_model
Which distortion model does the device expose, used both as a bitfield and value. ...
Definition: xrt_defines.h:47
int * indices
Indices, for triangle strip.
Definition: xrt_device.h:165
float * vertices
Data.
Definition: xrt_device.h:156
float warp_scale
Panotools warp scale.
Definition: xrt_device.h:135
size_t stride
Stride of vertices.
Definition: xrt_device.h:160
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:334
size_t num_vertices
Number of vertices.
Definition: xrt_device.h:158
struct xrt_input * inputs
Array of input structs.
Definition: xrt_device.h:220
uint64_t nominal_frame_interval_ns
Nominal frame interval.
Definition: xrt_device.h:103
A union of all output types.
Definition: xrt_defines.h:507
size_t total_num_indices
Total number of indices.
Definition: xrt_device.h:171
Common defines and enums for XRT.
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:494
Time-keeping state structure.
Definition: u_time.cpp:46
size_t num_inputs
Number of inputs.
Definition: xrt_device.h:218
All of the device components that deals with interfacing to a users head.
Definition: xrt_device.h:93
xrt_blend_mode
Which blend mode does the device support, used as both a bitfield and value.
Definition: xrt_defines.h:34
struct xrt_view::@76 viewport
Viewpport position on the screen, in absolute screen coordinates, this field is only used by Composit...
Describes a projection matrix fov.
Definition: xrt_defines.h:240
struct xrt_tracking_origin * tracking_origin
Always set, pointing to the tracking system for this device.
Definition: xrt_device.h:215
size_t num_outputs
Number of outputs.
Definition: xrt_device.h:223
A per-lens view information.
Definition: xrt_device.h:29
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
struct xrt_output * outputs
Array of output structs.
Definition: xrt_device.h:225
Definition: xrt_device.h:193
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:78
bool active
Is this input active.
Definition: xrt_device.h:184
A single named input, that sits on a xrt_device.
Definition: xrt_device.h:181
struct xrt_fov fov
Fov expressed in OpenXR.
Definition: xrt_device.h:83
A single HMD or input device.
Definition: xrt_device.h:203
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
struct xrt_view::@78 lens_center
Position in meters relative to display origin, before any rotation is applied by xrt_view::rot.