Monado OpenXR Runtime
oxr_roles.h
Go to the documentation of this file.
1// Copyright 2018-2024, Collabora, Ltd.
2// Copyright 2023-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Helper functions for device role getting.
7 * @ingroup oxr_main
8 */
9
10#pragma once
11
12#include "oxr_objects.h"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/*!
19 * Helper struct that wraps xrt_system_roles for OpenXR state tracker usage.
20 *
21 * Is intended to be used on the stack and have a short lifetime, so no
22 * references of it should be kept. Is mainly used in xrSyncActions and in
23 * xrAttachSessionActionSets, where it is used to get the current roles of the
24 * devices that the session is using.
25 *
26 * @see xrt_system_roles
27 * @ingroup oxr_main
28 */
30{
31 //! To access the @ref xrt_system_devices struct.
32 struct oxr_system *sys;
33
34 //! The roles of the devices that the session is using.
36};
37
38/*!
39 * Initialize an oxr_roles struct on the stack.
40 *
41 * @ingroup oxr_main
42 */
43XRT_CHECK_RESULT XrResult
44oxr_roles_init_on_stack(struct oxr_logger *log, struct oxr_roles *roles, struct oxr_system *sys);
45
46
47/*
48 *
49 * Static device roles.
50 *
51 */
52
53// clang-format off
54static inline struct xrt_device *get_static_role_head(struct oxr_system *sys) { return sys->xsysd->static_roles.head; }
55static inline struct xrt_device *get_static_role_eyes(struct oxr_system *sys) { return sys->xsysd->static_roles.eyes; }
56static inline struct xrt_device *get_static_role_face(struct oxr_system* sys) { return sys->xsysd->static_roles.face; }
57static inline struct xrt_device *get_static_role_body(struct oxr_system* sys) { return sys->xsysd->static_roles.body; }
58static inline struct xrt_device *get_static_role_hand_tracking_unobstructed_left(struct oxr_system* sys) { return sys->xsysd->static_roles.hand_tracking.unobstructed.left; }
59static inline struct xrt_device *get_static_role_hand_tracking_unobstructed_right(struct oxr_system* sys) { return sys->xsysd->static_roles.hand_tracking.unobstructed.right; }
60static inline struct xrt_device *get_static_role_hand_tracking_conforming_left(struct oxr_system* sys) { return sys->xsysd->static_roles.hand_tracking.conforming.left; }
61static inline struct xrt_device *get_static_role_hand_tracking_conforming_right(struct oxr_system* sys) { return sys->xsysd->static_roles.hand_tracking.conforming.right; }
62// clang-format on
63
64#define GET_STATIC_XDEV_BY_ROLE(SYS, ROLE) (get_static_role_##ROLE((SYS)))
65
66
67/*
68 *
69 * Dynamic device roles.
70 *
71 */
72
73// clang-format off
74#define STATIC_WRAP(ROLE) \
75 static inline struct xrt_device *get_role_##ROLE(const struct oxr_roles *roles) \
76 { \
77 return get_static_role_##ROLE(roles->sys); \
78 }
79STATIC_WRAP(head)
80STATIC_WRAP(eyes)
81STATIC_WRAP(face)
82STATIC_WRAP(body)
83STATIC_WRAP(hand_tracking_unobstructed_left)
84STATIC_WRAP(hand_tracking_unobstructed_right)
85STATIC_WRAP(hand_tracking_conforming_left)
86STATIC_WRAP(hand_tracking_conforming_right)
87#undef STATIC_WRAP
88// clang-format on
89
90#define MAKE_GET_DYN_ROLES_FN(ROLE) \
91 static inline struct xrt_device *get_role_##ROLE(const struct oxr_roles *roles) \
92 { \
93 const int32_t xdev_idx = roles->roles.ROLE; \
94 struct xrt_system_devices *xsysd = roles->sys->xsysd; \
95 if (xdev_idx < 0 || xdev_idx >= (int32_t)xsysd->xdev_count) { \
96 return NULL; \
97 } \
98 return xsysd->xdevs[xdev_idx]; \
99 }
100MAKE_GET_DYN_ROLES_FN(left)
101MAKE_GET_DYN_ROLES_FN(right)
102MAKE_GET_DYN_ROLES_FN(gamepad)
103#undef MAKE_GET_DYN_ROLES_FN
104
105#define GET_XDEV_BY_ROLE(ROLES, ROLE) (get_role_##ROLE((ROLES)))
106
107
108/*
109 *
110 * Dynamic profile roles.
111 *
112 */
113
114static inline enum xrt_device_name
115get_role_profile_head(const struct oxr_roles *roles)
116{
117 return XRT_DEVICE_INVALID;
118}
119static inline enum xrt_device_name
120get_role_profile_eyes(const struct oxr_roles *roles)
121{
122 return XRT_DEVICE_INVALID;
123}
124static inline enum xrt_device_name
125get_role_profile_face(const struct oxr_roles *roles)
126{
127 return XRT_DEVICE_INVALID;
128}
129static inline enum xrt_device_name
130get_role_profile_body(const struct oxr_roles *roles)
131{
132 return XRT_DEVICE_INVALID;
133}
134static inline enum xrt_device_name
135get_role_profile_hand_tracking_unobstructed_left(const struct oxr_roles *roles)
136{
137 return XRT_DEVICE_INVALID;
138}
139static inline enum xrt_device_name
140get_role_profile_hand_tracking_unobstructed_right(const struct oxr_roles *roles)
141{
142 return XRT_DEVICE_INVALID;
143}
144
145static inline enum xrt_device_name
146get_role_profile_hand_tracking_conforming_left(const struct oxr_roles *roles)
147{
148 return XRT_DEVICE_INVALID;
149}
150static inline enum xrt_device_name
151get_role_profile_hand_tracking_conforming_right(const struct oxr_roles *roles)
152{
153 return XRT_DEVICE_INVALID;
154}
155
156#define MAKE_GET_DYN_ROLE_PROFILE_FN(ROLE) \
157 static inline enum xrt_device_name get_role_profile_##ROLE(const struct oxr_roles *roles) \
158 { \
159 return roles->roles.ROLE##_profile; \
160 }
161MAKE_GET_DYN_ROLE_PROFILE_FN(left)
162MAKE_GET_DYN_ROLE_PROFILE_FN(right)
163MAKE_GET_DYN_ROLE_PROFILE_FN(gamepad)
164#undef MAKE_GET_DYN_ROLES_FN
165
166#define GET_PROFILE_NAME_BY_ROLE(ROLES, ROLE) (get_role_profile_##ROLE((ROLES)))
167
168
169#ifdef __cplusplus
170}
171#endif
XRT_CHECK_RESULT XrResult oxr_roles_init_on_stack(struct oxr_logger *log, struct oxr_roles *roles, struct oxr_system *sys)
Initialize an oxr_roles struct on the stack.
Definition: oxr_roles.c:15
The objects representing OpenXR handles, and prototypes for internal functions used in the state trac...
Logger struct that lives on the stack, one for each call client call.
Definition: oxr_logger.h:40
Helper struct that wraps xrt_system_roles for OpenXR state tracker usage.
Definition: oxr_roles.h:30
struct xrt_system_roles roles
The roles of the devices that the session is using.
Definition: oxr_roles.h:35
struct oxr_system * sys
To access the xrt_system_devices struct.
Definition: oxr_roles.h:32
Single or multiple devices grouped together to form a system that sessions can be created from.
Definition: oxr_objects.h:1524
struct xrt_system_devices * xsysd
System devices used in all session types.
Definition: oxr_objects.h:1531
A single HMD or input device.
Definition: xrt_device.h:310
struct xrt_system_devices::@265::@266 hand_tracking
Devices providing optical (or otherwise more directly measured than from controller estimation) hand ...
struct xrt_system_devices::@265 static_roles
Observing pointers for devices in some static (unchangeable) roles.
struct xrt_device * head
An observing pointer to the device serving as the "head" (and HMD).
Definition: xrt_system.h:243
struct xrt_device * face
An observing pointer to the device providing face tracking (optional).
Definition: xrt_system.h:255
struct xrt_device * eyes
An observing pointer to the device providing eye tracking (optional).
Definition: xrt_system.h:249
struct xrt_device * left
An observing pointer to the device providing unobstructed hand-tracking for the left hand (optional).
Definition: xrt_system.h:278
struct xrt_device * right
An observing pointer to the device providing unobstructed hand-tracking for the right hand (optional)...
Definition: xrt_system.h:287
struct xrt_device * body
An observing pointer to the device providing body tracking (optional).
Definition: xrt_system.h:261
Data associating a device index (in xrt_system_devices::xdevs) with a given "role" for dynamic role s...
Definition: xrt_system.h:154
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:724