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;
44class QThread;
45
47{
48 Q_DECLARE_PUBLIC(QQuick3DXrManager)
49public:
52
54
55 [[nodiscard]] bool supportsPassthrough() const;
56
57 bool isValid() const { return m_graphics != nullptr; }
58
59 bool isReady() const { return true; }
60
61 void setupWindow(QQuickWindow *window);
62
63 bool isGraphicsInitialized() const;
64 bool setupGraphics(QQuickWindow *window);
65
66 void update();
67
68 void processXrEvents();
69
70 void doRenderFrame();
71
72 bool finalizeGraphics(QRhi *rhi);
73
74 void setSamples(int samples);
75
77 QString runtimeName() const;
79
80 void setMultiViewRenderingEnabled(bool enable);
81 bool isMultiViewRenderingEnabled() const { return m_multiviewRendering; }
82
83 [[nodiscard]] bool setPassthroughEnabled(bool enable);
84 bool isPassthroughEnabled() const { return m_enablePassthrough; }
85
86 void setDepthSubmissionEnabled(bool enable);
87 bool isDepthSubmissionEnabled() const { return m_compositionLayerDepthSupported && m_submitLayerDepth; }
88
89 void setReferenceSpace(QtQuick3DXr::ReferenceSpace newReferenceSpace);
91
92 void getDefaultClipDistances(float &nearClip, float &farClip) const;
93
94 QString errorString() const { return m_errorString; }
95
96private:
97 friend class QQuick3DXrRuntimeInfo;
98
99 bool initialize();
100 void teardown();
101
102 void initWorkerThread();
103 void destroyWorkerThread();
104 void onFrameWaitCompleted(XrResult result, const XrFrameState &frameState);
105 void doRenderFrameAferWait(const XrFrameState &frameState);
106
107 void destroySwapchain();
108 void setErrorString(XrResult result, const char *callName);
109 void checkXrExtensions(const char* layerName, int indent = 0);
110 void checkXrLayers();
111
112 XrResult createXrInstance();
113 void checkXrInstance();
114
115 void setupDebugMessenger();
116
117 XrResult initializeSystem();
118
119 void checkViewConfiguration();
120 [[nodiscard]] bool checkXrResult(const XrResult &result);
121 void checkEnvironmentBlendMode(XrViewConfigurationType type);
122
123 void pollEvents(bool *exitRenderLoop, bool *requestRestart);
124 void pollActions();
125
126 void checkReferenceSpaces();
127 bool isReferenceSpaceAvailable(XrReferenceSpaceType type);
128
129 bool setupAppSpace();
130 void updateAppSpace(XrTime predictedDisplayTime);
131 bool setupViewSpace();
132 bool resetEmulatedFloorHeight(XrTime predictedDisplayTime);
133
134 bool createSwapchains();
135
136 bool renderLayer(XrTime predictedDisplayTime,
137 XrDuration predictedDisplayPeriod,
138 XrCompositionLayerProjection &layer);
139 void doRender(const XrSwapchainSubImage &subImage,
140 const XrSwapchainImageBaseHeader *swapchainImage,
141 const XrSwapchainImageBaseHeader *depthSwapchainImage = nullptr);
142
143 void updateCameraHelper(QQuick3DXrEyeCamera *camera, const XrCompositionLayerProjectionView &layerView);
144 void updateCameraNonMultiview(int eye, const XrCompositionLayerProjectionView &layerView);
145 void updateCameraMultiview(int projectionLayerViewStartIndex, int count);
146
147 void setupMetaQuestColorSpaces();
148 void setupMetaQuestRefreshRates();
149 void setupMetaQuestFoveation();
150
151 // Passthrough
152 XrPassthroughFB m_passthroughFeature{XR_NULL_HANDLE};
153 void createMetaQuestPassthrough();
154 void destroyMetaQuestPassthrough();
155 void startMetaQuestPassthrough();
156 void pauseMetaQuestPassthrough();
157
158 XrPassthroughLayerFB m_passthroughLayer{XR_NULL_HANDLE};
159 void createMetaQuestPassthroughLayer();
160 void destroyMetaQuestPassthroughLayer();
161 void pauseMetaQuestPassthroughLayer();
162 void resumeMetaQuestPassthroughLayer();
163
164 XrTime m_previousTime = 0;
165
166 struct Swapchain {
167 XrSwapchain handle;
168 quint32 width;
169 quint32 height;
170 quint32 arraySize;
171 };
172
173 QVector<XrViewConfigurationView> m_configViews;
174 QVector<XrCompositionLayerProjectionView> m_projectionLayerViews;
175 QVector<XrCompositionLayerDepthInfoKHR> m_layerDepthInfos;
176 QVector<Swapchain> m_swapchains;
177 QVector<Swapchain> m_depthSwapchains;
180 QVector<XrView> m_views;
181
182 QString m_errorString;
183 QString m_runtimeName;
184 QVersionNumber m_runtimeVersion;
185 QStringList m_enabledApiLayers;
186 QStringList m_enabledExtensions;
187
188 XrEventDataBuffer m_eventDataBuffer;
189
190 XrInstance m_instance{XR_NULL_HANDLE};
191 XrSession m_session{XR_NULL_HANDLE};
192 XrSpace m_appSpace{XR_NULL_HANDLE};
193 XrReferenceSpaceType m_requestedReferenceSpace = XR_REFERENCE_SPACE_TYPE_STAGE;
194 XrReferenceSpaceType m_referenceSpace = XR_REFERENCE_SPACE_TYPE_LOCAL;
195 bool m_isEmulatingLocalFloor = false;
196 bool m_isFloorResetPending = false;
197 XrSpace m_viewSpace{XR_NULL_HANDLE};
198 XrFormFactor m_formFactor{XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY};
199 XrViewConfigurationType m_viewConfigType{XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
200 XrEnvironmentBlendMode m_environmentBlendMode{XR_ENVIRONMENT_BLEND_MODE_OPAQUE};
201 XrSystemId m_systemId{XR_NULL_SYSTEM_ID};
202
203 // Application's current lifecycle state according to the runtime
204 XrSessionState m_sessionState{XR_SESSION_STATE_UNKNOWN};
205
206 QVector<XrReferenceSpaceType> m_availableReferenceSpace;
207
208 QPointer<QQuick3DXrInputManager> m_inputManager;
209
210 int64_t m_colorSwapchainFormat = -1;
211 int64_t m_depthSwapchainFormat = -1;
212 int m_samples = 1;
213
214 bool m_passThroughEnabled = false;
215 bool m_passthroughSupported = false;
216 bool m_enablePassthrough = false;
217 bool m_multiviewRendering = true;
218 bool m_spaceExtensionSupported = false;
219 QQuick3DXrAnchorManager *m_spaceExtension = nullptr;
220 bool m_colorspaceExtensionSupported = false;
221 bool m_displayRefreshRateExtensionSupported = false;
222 bool m_foveationExtensionSupported = false;
223#ifdef Q_OS_ANDROID
225#endif
226 XrFoveationLevelFB m_foveationLevel = XR_FOVEATION_LEVEL_HIGH_FB;
227 bool m_compositionLayerDepthSupported = false;
228 bool m_submitLayerDepth = false;
229 bool m_handtrackingExtensionSupported = false;
230 bool m_handtrackingAimExtensionSupported = false;
231 bool m_isGraphicsInitialized = false;
232
233 bool m_sessionRunning{false};
234
235 QQuick3DXrManager *q_ptr = nullptr;
236#ifdef XR_USE_PLATFORM_ANDROID
238 JavaVM* m_javaVM = nullptr;
239#endif // XR_USE_PLATFORM_ANDROID
240
241#ifdef XR_EXT_debug_utils
244#endif
245
246#if QT_CONFIG(graphicsframecapture)
248#endif
249
250 QAbstractOpenXRGraphics *m_graphics = nullptr;
251
252 bool m_waitingForFrame = false;
253 bool m_wantUpdate = false;
254 QQuick3DOpenXRThreadWorker *m_worker = nullptr;
255 QThread *m_workerThread = nullptr;
256};
257
258QT_END_NAMESPACE
259
260#endif // QQUICK3DXRMANAGER_OPENXR_P_H
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
static constexpr QEvent::Type asQEvent(QQuick3DOpenXRThreadWorker::Event event)
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 const char s_workerThreadName[]
static QtQuick3DXr::ReferenceSpace getReferenceSpaceType(XrReferenceSpaceType referenceSpace)
static std::pair< XrResult, XrFrameState > waitForNextFrame(XrSession session)
static bool isExtensionSupported(const char *extensionName, const QVector< XrExtensionProperties > &instanceExtensionProperties, uint32_t *extensionVersion=nullptr)