14 #include <openxr/openxr.h>
17 #include "gpu/gl/GLBackend.h"
19 #if defined(Q_OS_LINUX)
20 #define XR_USE_PLATFORM_XLIB
28 #elif defined(Q_OS_WIN)
29 #define XR_USE_PLATFORM_WIN32
33 #error "Unimplemented platform"
37 #define XR_USE_GRAPHICS_API_OPENGL
38 #include <openxr/openxr_platform.h>
40 #include <glm/glm.hpp>
41 #include <glm/gtx/quaternion.hpp>
43 #include "controllers/Pose.h"
47 constexpr XrPosef XR_INDENTITY_POSE = {
48 .orientation = { .x = 0, .y = 0, .z = 0, .w = 1.0 },
49 .position = { .x = 0, .y = 0, .z = 0 },
52 constexpr XrViewConfigurationType XR_VIEW_CONFIG_TYPE = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
56 XrInstance _instance = XR_NULL_HANDLE;
57 XrSession _session = XR_NULL_HANDLE;
58 XrSystemId _systemId = XR_NULL_SYSTEM_ID;
60 XrSpace _stageSpace = XR_NULL_HANDLE;
61 XrSpace _viewSpace = XR_NULL_HANDLE;
62 XrPath _handPaths[HAND_COUNT];
64 controller::Pose _lastHeadPose;
65 std::optional<XrTime> _lastPredictedDisplayTime;
68 bool _shouldQuit =
false;
69 bool _shouldRunFrameCycle =
false;
70 bool _isDisplayActive =
false;
72 bool _isSupported =
false;
75 bool _isSessionRunning =
false;
77 std::array<bool, HAND_COUNT> _vivePoseHack = {
false,
false };
81 bool _userPresenceAvailable =
false;
84 bool _hmdMounted =
true;
86 bool _handTrackingSupported =
false;
87 PFN_xrCreateHandTrackerEXT xrCreateHandTrackerEXT =
nullptr;
88 PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT =
nullptr;
89 PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT =
nullptr;
91 bool _palmPoseSupported =
false;
93 bool _MNDX_xdevSpaceSupported =
false;
94 PFN_xrCreateXDevListMNDX xrCreateXDevListMNDX =
nullptr;
95 PFN_xrGetXDevListGenerationNumberMNDX xrGetXDevListGenerationNumberMNDX =
nullptr;
96 PFN_xrEnumerateXDevsMNDX xrEnumerateXDevsMNDX =
nullptr;
97 PFN_xrGetXDevPropertiesMNDX xrGetXDevPropertiesMNDX =
nullptr;
98 PFN_xrDestroyXDevListMNDX xrDestroyXDevListMNDX =
nullptr;
99 PFN_xrCreateXDevSpaceMNDX xrCreateXDevSpaceMNDX =
nullptr;
101 bool _HTCX_viveTrackerInteractionSupported =
false;
102 PFN_xrEnumerateViveTrackerPathsHTCX xrEnumerateViveTrackerPathsHTCX =
nullptr;
105 XrSessionState _lastSessionState = XR_SESSION_STATE_UNKNOWN;
107 XrPath _viveControllerPath = XR_NULL_PATH;
113 bool initPostGraphics();
116 bool requestExitSession();
120 bool initPreGraphics();
127 bool updateSessionState(XrSessionState newState);
130 inline static glm::vec3 xrVecToGlm(
const XrVector3f& v) {
131 return glm::vec3(v.x, v.y, v.z);
134 inline static glm::quat xrQuatToGlm(
const XrQuaternionf& q) {
135 return glm::quat(q.w, q.x, q.y, q.z);
138 bool xrCheck(XrInstance instance, XrResult result,
const char* message);
Preview header for XR_MNDX_xdev_space extension.