Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dxrmanager_openxr_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DXRMANAGER_OPENXR_P_H
5#define QQUICK3DXRMANAGER_OPENXR_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3DXr/private/qabstractopenxrgraphics_p.h>
19#include <QtQuick3DXr/private/qtquick3dxrglobal_p.h>
20
21#include <QtCore/qmap.h>
22#include <QtCore/qlist.h>
23#include <QtCore/qversionnumber.h>
24#include <QtCore/qpointer.h>
25
26#include <QtGui/private/qtgui-config_p.h>
27#if QT_CONFIG(graphicsframecapture)
28#include <QtGui/private/qgraphicsframecapture_p.h>
29#endif
30
31#ifdef XR_USE_PLATFORM_ANDROID
32# include <QtCore/QJniObject>
33#endif
34
35QT_BEGIN_NAMESPACE
36
37class QQuick3DXrEyeCamera;
38class QQuick3DXrOrigin;
39class QQuick3DViewport;
43
45{
46 Q_DECLARE_PUBLIC(QQuick3DXrManager)
47public:
50
52
53 [[nodiscard]] bool supportsPassthrough() const;
54
55 bool isValid() const { return m_graphics != nullptr; }
56
57 bool isReady() const { return true; }
58
59 void setupWindow(QQuickWindow *window);
60
61 bool isGraphicsInitialized() const;
62 bool setupGraphics(QQuickWindow *window);
63
64 void update();
65
66 void processXrEvents();
67
68 void doRenderFrame();
69
70 bool finalizeGraphics(QRhi *rhi);
71
72 void setSamples(int samples);
73
75 QString runtimeName() const;
77
78 void setMultiViewRenderingEnabled(bool enable);
79 bool isMultiViewRenderingEnabled() const { return m_multiviewRendering; }
80
81 [[nodiscard]] bool setPassthroughEnabled(bool enable);
82 bool isPassthroughEnabled() const { return m_enablePassthrough; }
83
84 void setDepthSubmissionEnabled(bool enable);
85 bool isDepthSubmissionEnabled() const { return m_compositionLayerDepthSupported && m_submitLayerDepth; }
86
87 void setReferenceSpace(QtQuick3DXr::ReferenceSpace newReferenceSpace);
89
90 void getDefaultClipDistances(float &nearClip, float &farClip) const;
91
92 QString errorString() const { return m_errorString; }
93
94private:
95 friend class QQuick3DXrRuntimeInfo;
96
97 bool initialize();
98 void teardown();
99
100 void destroySwapchain();
101 void setErrorString(XrResult result, const char *callName);
102 void checkXrExtensions(const char* layerName, int indent = 0);
103 void checkXrLayers();
104
105 XrResult createXrInstance();
106 void checkXrInstance();
107
108 void setupDebugMessenger();
109
110 XrResult initializeSystem();
111
112 void checkViewConfiguration();
113 [[nodiscard]] bool checkXrResult(const XrResult &result);
114 void checkEnvironmentBlendMode(XrViewConfigurationType type);
115
116 void pollEvents(bool *exitRenderLoop, bool *requestRestart);
117 void pollActions();
118
119 void checkReferenceSpaces();
120 bool isReferenceSpaceAvailable(XrReferenceSpaceType type);
121
122 bool setupAppSpace();
123 void updateAppSpace(XrTime predictedDisplayTime);
124 bool setupViewSpace();
125 bool resetEmulatedFloorHeight(XrTime predictedDisplayTime);
126
127 bool createSwapchains();
128
129 bool renderLayer(XrTime predictedDisplayTime,
130 XrDuration predictedDisplayPeriod,
131 XrCompositionLayerProjection &layer);
132 void doRender(const XrSwapchainSubImage &subImage,
133 const XrSwapchainImageBaseHeader *swapchainImage,
134 const XrSwapchainImageBaseHeader *depthSwapchainImage = nullptr);
135
136 void updateCameraHelper(QQuick3DXrEyeCamera *camera, const XrCompositionLayerProjectionView &layerView);
137 void updateCameraNonMultiview(int eye, const XrCompositionLayerProjectionView &layerView);
138 void updateCameraMultiview(int projectionLayerViewStartIndex, int count);
139
140 void setupMetaQuestColorSpaces();
141 void setupMetaQuestRefreshRates();
142 void setupMetaQuestFoveation();
143
144 // Passthrough
145 XrPassthroughFB m_passthroughFeature{XR_NULL_HANDLE};
146 void createMetaQuestPassthrough();
147 void destroyMetaQuestPassthrough();
148 void startMetaQuestPassthrough();
149 void pauseMetaQuestPassthrough();
150
151 XrPassthroughLayerFB m_passthroughLayer{XR_NULL_HANDLE};
152 void createMetaQuestPassthroughLayer();
153 void destroyMetaQuestPassthroughLayer();
154 void pauseMetaQuestPassthroughLayer();
155 void resumeMetaQuestPassthroughLayer();
156
157 XrTime m_previousTime = 0;
158
159 struct Swapchain {
160 XrSwapchain handle;
161 quint32 width;
162 quint32 height;
163 quint32 arraySize;
164 };
165
166 QVector<XrViewConfigurationView> m_configViews;
167 QVector<XrCompositionLayerProjectionView> m_projectionLayerViews;
168 QVector<XrCompositionLayerDepthInfoKHR> m_layerDepthInfos;
169 QVector<Swapchain> m_swapchains;
170 QVector<Swapchain> m_depthSwapchains;
173 QVector<XrView> m_views;
174
175 QString m_errorString;
176 QString m_runtimeName;
177 QVersionNumber m_runtimeVersion;
178 QStringList m_enabledApiLayers;
179 QStringList m_enabledExtensions;
180
181 XrEventDataBuffer m_eventDataBuffer;
182
183 XrInstance m_instance{XR_NULL_HANDLE};
184 XrSession m_session{XR_NULL_HANDLE};
185 XrSpace m_appSpace{XR_NULL_HANDLE};
186 XrReferenceSpaceType m_requestedReferenceSpace = XR_REFERENCE_SPACE_TYPE_STAGE;
187 XrReferenceSpaceType m_referenceSpace = XR_REFERENCE_SPACE_TYPE_LOCAL;
188 bool m_isEmulatingLocalFloor = false;
189 bool m_isFloorResetPending = false;
190 XrSpace m_viewSpace{XR_NULL_HANDLE};
191 XrFormFactor m_formFactor{XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY};
192 XrViewConfigurationType m_viewConfigType{XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
193 XrEnvironmentBlendMode m_environmentBlendMode{XR_ENVIRONMENT_BLEND_MODE_OPAQUE};
194 XrSystemId m_systemId{XR_NULL_SYSTEM_ID};
195
196 // Application's current lifecycle state according to the runtime
197 XrSessionState m_sessionState{XR_SESSION_STATE_UNKNOWN};
198
199 QVector<XrReferenceSpaceType> m_availableReferenceSpace;
200
201 QPointer<QQuick3DXrInputManager> m_inputManager;
202
203 int64_t m_colorSwapchainFormat = -1;
204 int64_t m_depthSwapchainFormat = -1;
205 int m_samples = 1;
206
207 bool m_passThroughEnabled = false;
208 bool m_passthroughSupported = false;
209 bool m_enablePassthrough = false;
210 bool m_multiviewRendering = true;
211 bool m_spaceExtensionSupported = false;
212 QQuick3DXrAnchorManager *m_spaceExtension = nullptr;
213 bool m_colorspaceExtensionSupported = false;
214 bool m_displayRefreshRateExtensionSupported = false;
215 bool m_foveationExtensionSupported = false;
216#ifdef Q_OS_ANDROID
218#endif
219 XrFoveationLevelFB m_foveationLevel = XR_FOVEATION_LEVEL_HIGH_FB;
220 bool m_compositionLayerDepthSupported = false;
221 bool m_submitLayerDepth = false;
222 bool m_handtrackingExtensionSupported = false;
223 bool m_handtrackingAimExtensionSupported = false;
224 bool m_isGraphicsInitialized = false;
225
226 bool m_sessionRunning{false};
227
228 QQuick3DXrManager *q_ptr = nullptr;
229#ifdef XR_USE_PLATFORM_ANDROID
231 JavaVM* m_javaVM = nullptr;
232#endif // XR_USE_PLATFORM_ANDROID
233
234#ifdef XR_EXT_debug_utils
237#endif
238
239#if QT_CONFIG(graphicsframecapture)
241#endif
242
243 QAbstractOpenXRGraphics *m_graphics = nullptr;
244
245};
246
247QT_END_NAMESPACE
248
249#endif // QQUICK3DXRMANAGER_OPENXR_P_H
QQuick3DXrManagerPrivate(QQuick3DXrManager &manager)
void setupWindow(QQuickWindow *window)
QtQuick3DXr::ReferenceSpace getReferenceSpace() const
void setReferenceSpace(QtQuick3DXr::ReferenceSpace newReferenceSpace)
bool setupGraphics(QQuickWindow *window)
static QQuick3DXrManagerPrivate * get(QQuick3DXrManager *manager)
void getDefaultClipDistances(float &nearClip, float &farClip) const
static bool isMultiviewRenderingDisabled()
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher)
#define MAKE_TO_STRING_FUNC(enumType)
static bool isApiLayerSupported(const char *layerName, const QVector< XrApiLayerProperties > &apiLayerProperties)
#define ENUM_CASE_STR(name, val)
static QtQuick3DXr::ReferenceSpace getReferenceSpaceType(XrReferenceSpaceType referenceSpace)
static bool isExtensionSupported(const char *extensionName, const QVector< XrExtensionProperties > &instanceExtensionProperties, uint32_t *extensionVersion=nullptr)