Monado OpenXR Runtime
Loading...
Searching...
No Matches
openvr_devices.hpp
Go to the documentation of this file.
1// Copyright 2026, Beyley Cardellio
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Implementation of a dynamic OpenVR devices array using the xrt_system_devices interface.
6 *
7 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
8 * @ingroup openvr
9 */
10
11#pragma once
12
13#include "xrt/xrt_device.h"
14#include "xrt/xrt_system.h"
15#include "xrt/xrt_space.h"
16
17#include "util/u_time.h"
18
20
21#include "openvr_events.hpp"
22
23#include "openvr_interfaces_unified.h"
24
25#include <array>
26#include <optional>
27#include <memory>
28
29
30namespace xrt::state_trackers::openvr {
31
32struct Devices;
33
34struct Device
35{
36public: // Fields
37 xrt_device *xdev{nullptr};
38 vr::TrackedDeviceClass tracked_class{vr::TrackedDeviceClass_Invalid};
39
40 // @todo: Select the correct pose input for the device type
41 xrt_space *pose_space{nullptr};
42
43public: // Methods
44 Device() = default;
45 Device(openvr_logger &logger, Devices &devices, xrt_device *xdev);
46
47 // Delete the move constructor and move assignment operator to prevent accidental moves which would cause the
48 // pose_space reference counting to be messed up.
49 Device(Device &&) = delete;
50 Device &
51 operator=(Device &&) = delete;
52
53 ~Device()
54 {
55 xrt_space_reference(&this->pose_space, nullptr);
56 }
57};
58
59struct Devices
60{
61public: // Fields
62 xrt_space_overseer *xso{nullptr};
63 xrt_system_devices *xsysd{nullptr};
64
65 std::shared_ptr<Events> events{};
66
67 std::array<Device, vr::k_unMaxTrackedDeviceCount> device_array{};
68
69 /*!
70 * Mapping of OpenVR tracking universe origins to `xrt_space`s, populated during session creation.
71 * All spaces will fall back to `root` if the specific space best matching a universe is not available.
72 */
73 std::array<xrt_space *, vr::ETrackingUniverseOrigin::TrackingUniverseRawAndUncalibrated + 1> space_mappings{};
74
75private: // Methods
76 void
77 AddDevice(openvr_logger &logger, vr::TrackedDeviceIndex_t index, xrt_device *xdev);
78
79public: // Methods
80 Devices() = default;
81 Devices(openvr_logger &logger,
83 xrt_system_devices *xsysd,
84 std::shared_ptr<Events> &events);
85
86 /*!
87 * Retrieves a device by its tracked device index.
88 *
89 * @param index The index of the tracked device.
90 * @return An optional containing the device if it exists, or std::nullopt if it does not.
91 */
92 std::optional<Device *>
93 GetDevice(vr::TrackedDeviceIndex_t index);
94
95 void
96 TrackDevices(openvr_logger &logger,
97 timepoint_ns when_ns,
98 vr::ETrackingUniverseOrigin universe,
99 vr::TrackedDevicePose_t *poses,
100 uint32_t pose_count);
101
102 bool
103 GetDeviceStringProperty(openvr_logger &logger,
104 vr::TrackedDeviceIndex_t device_index,
105 vr::ETrackedDeviceProperty prop,
106 std::string &out_str,
107 vr::ETrackedPropertyError *pError);
108};
109
110}; // namespace xrt::state_trackers::openvr
int64_t timepoint_ns
Integer timestamp type.
Definition u_time.h:77
Implementation of OpenVR event handling and related functionality.
Logging functions.
Definition openvr_devices.hpp:35
Definition openvr_devices.hpp:60
std::optional< Device * > GetDevice(vr::TrackedDeviceIndex_t index)
Retrieves a device by its tracked device index.
Definition openvr_devices.cpp:119
std::array< xrt_space *, vr::ETrackingUniverseOrigin::TrackingUniverseRawAndUncalibrated+1 > space_mappings
Mapping of OpenVR tracking universe origins to xrt_spaces, populated during session creation.
Definition openvr_devices.hpp:73
Definition openvr_logger.hpp:30
A single HMD or input device.
Definition xrt_device.h:311
Object that oversees and manages spaces, one created for each XR system.
Definition xrt_space.h:97
A space very similar to a OpenXR XrSpace but not a full one-to-one mapping, but used to power XrSpace...
Definition xrt_space.h:32
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition xrt_system.h:215
Time-keeping: a clock that is steady, convertible to system time, and ideally high-resolution.
Header defining an xrt display or controller device.
Header defining xrt space and space overseer.
Header for system objects.