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// Qt-Security score:significant reason:default
4
5
6#ifndef QQUICK3DXRMANAGER_OPENXR_P_H
7#define QQUICK3DXRMANAGER_OPENXR_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQuick3DXr/private/qabstractopenxrgraphics_p.h>
21#include <QtQuick3DXr/private/qtquick3dxrglobal_p.h>
22
23#include <QtCore/qmap.h>
24#include <QtCore/qlist.h>
25#include <QtCore/qversionnumber.h>
26#include <QtCore/qpointer.h>
27
28#include <QtGui/private/qtgui-config_p.h>
29#if QT_CONFIG(graphicsframecapture)
30#include <QtGui/private/qgraphicsframecapture_p.h>
31#endif
32
33#ifdef XR_USE_PLATFORM_ANDROID
34# include <QtCore/QJniObject>
35#endif
36
37QT_BEGIN_NAMESPACE
38
39class QQuick3DXrEyeCamera;
40class QQuick3DXrOrigin;
41class QQuick3DViewport;
46class QThread;
47
49{
50 Q_DECLARE_PUBLIC(QQuick3DXrManager)
51public:
54
56
57 [[nodiscard]] bool supportsPassthrough() const;
59 bool supportsFBPassthrough() const;
60
61 bool isValid() const { return m_graphics != nullptr; }
62
63 bool isReady() const { return true; }
64
65 void setupWindow(QQuickWindow *window);
66
67 bool isGraphicsInitialized() const;
68 bool setupGraphics(QQuickWindow *window);
69
70 void update();
71
72 void processXrEvents();
73
74 void doRenderFrame();
75
76 bool finalizeGraphics(QRhi *rhi);
77
78 void setSamples(int samples);
79
81 QString runtimeName() const;
83
84 void setMultiViewRenderingEnabled(bool enable);
85 bool isMultiViewRenderingEnabled() const { return m_multiviewRendering; }
86
87 [[nodiscard]] bool setPassthroughEnabled(bool enable);
88 bool isPassthroughEnabled() const;
89
90 void setFBPassthroughEnabled(bool enable);
91 bool setTransparentBlendMode(bool enable);
92
93 void setDepthSubmissionEnabled(bool enable);
94 bool isDepthSubmissionEnabled() const { return m_compositionLayerDepthSupported && m_submitLayerDepth; }
95
96 void setReferenceSpace(QtQuick3DXr::ReferenceSpace newReferenceSpace);
98
99 void getDefaultClipDistances(float &nearClip, float &farClip) const;
100
101 QString errorString() const { return m_errorString; }
102
103private:
104 friend class QQuick3DXrRuntimeInfo;
105
106 bool initialize();
107 void teardown();
108
109 void initWorkerThread();
110 void destroyWorkerThread();
111 void onFrameWaitCompleted(XrResult result, const XrFrameState &frameState);
112 void doRenderFrameAferWait(const XrFrameState &frameState);
113
114 void destroySwapchain();
115 void setErrorString(XrResult result, const char *callName);
116 void checkXrExtensions(const char* layerName, int indent = 0);
117 void checkXrLayers();
118
119 XrResult createXrInstance();
120 void checkXrInstance();
121
122 void setupDebugMessenger();
123
124 XrResult initializeSystem();
125
126 void checkViewConfiguration();
127 [[nodiscard]] bool checkXrResult(const XrResult &result);
128 void checkEnvironmentBlendMode(XrViewConfigurationType type);
129
130 void pollEvents(bool *exitRenderLoop, bool *requestRestart);
131 void pollActions();
132
133 void checkReferenceSpaces();
134 bool isReferenceSpaceAvailable(XrReferenceSpaceType type);
135
136 bool setupAppSpace();
137 void updateAppSpace(XrTime predictedDisplayTime);
138 bool setupViewSpace();
139 bool resetEmulatedFloorHeight(XrTime predictedDisplayTime);
140
141 bool createSwapchains();
142
143 bool renderLayer(XrTime predictedDisplayTime,
144 XrDuration predictedDisplayPeriod,
145 XrCompositionLayerProjection &layer);
146 void doRender(const XrSwapchainSubImage &subImage,
147 const XrSwapchainImageBaseHeader *swapchainImage,
148 const XrSwapchainImageBaseHeader *depthSwapchainImage = nullptr);
149
150 void updateCameraHelper(QQuick3DXrEyeCamera *camera, const XrCompositionLayerProjectionView &layerView);
151 void updateCameraNonMultiview(int eye, const XrCompositionLayerProjectionView &layerView);
152 void updateCameraMultiview(int projectionLayerViewStartIndex, int count);
153
154 void setupMetaQuestColorSpaces();
155 void setupMetaQuestRefreshRates();
156 void setupMetaQuestFoveation();
157
158 // Passthrough
159 XrPassthroughFB m_passthroughFeature{XR_NULL_HANDLE};
160 void createMetaQuestPassthrough();
161 void destroyMetaQuestPassthrough();
162 void startMetaQuestPassthrough();
163 void pauseMetaQuestPassthrough();
164
165 XrPassthroughLayerFB m_passthroughLayer{XR_NULL_HANDLE};
166 void createMetaQuestPassthroughLayer();
167 void destroyMetaQuestPassthroughLayer();
168 void pauseMetaQuestPassthroughLayer();
169 void resumeMetaQuestPassthroughLayer();
170
171 XrTime m_previousTime = 0;
172
173 struct Swapchain {
174 XrSwapchain handle;
175 quint32 width;
176 quint32 height;
177 quint32 arraySize;
178 };
179
180 QVector<XrViewConfigurationView> m_configViews;
181 QVector<XrCompositionLayerProjectionView> m_projectionLayerViews;
182 QVector<XrCompositionLayerDepthInfoKHR> m_layerDepthInfos;
183 QVector<Swapchain> m_swapchains;
184 QVector<Swapchain> m_depthSwapchains;
187 QVector<XrView> m_views;
188
189 QString m_errorString;
190 QString m_runtimeName;
191 QVersionNumber m_runtimeVersion;
192 QStringList m_enabledApiLayers;
193 QStringList m_enabledExtensions;
194
195 XrEventDataBuffer m_eventDataBuffer;
196
197 XrInstance m_instance{XR_NULL_HANDLE};
198 XrSession m_session{XR_NULL_HANDLE};
199 XrSpace m_appSpace{XR_NULL_HANDLE};
200 XrReferenceSpaceType m_requestedReferenceSpace = XR_REFERENCE_SPACE_TYPE_STAGE;
201 XrReferenceSpaceType m_referenceSpace = XR_REFERENCE_SPACE_TYPE_LOCAL;
202 bool m_isEmulatingLocalFloor = false;
203 bool m_isFloorResetPending = false;
204 XrSpace m_viewSpace{XR_NULL_HANDLE};
205 XrFormFactor m_formFactor{XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY};
206 XrViewConfigurationType m_viewConfigType{XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
207 XrEnvironmentBlendMode m_environmentBlendMode{XR_ENVIRONMENT_BLEND_MODE_OPAQUE};
208 XrSystemId m_systemId{XR_NULL_SYSTEM_ID};
209
210 // Application's current lifecycle state according to the runtime
211 XrSessionState m_sessionState{XR_SESSION_STATE_UNKNOWN};
212
213 QVector<XrReferenceSpaceType> m_availableReferenceSpace;
214
215 QPointer<QQuick3DXrInputManager> m_inputManager;
216
217 int64_t m_colorSwapchainFormat = -1;
218 int64_t m_depthSwapchainFormat = -1;
219 int m_samples = 1;
220
221 bool m_fbPassthroughEnabled = false;
222 bool m_multiviewRendering = true;
223 bool m_spaceExtensionSupported = false;
224 QQuick3DXrAnchorManager *m_spaceExtension = nullptr;
225 bool m_colorspaceExtensionSupported = false;
226 bool m_displayRefreshRateExtensionSupported = false;
227 bool m_foveationExtensionSupported = false;
228#ifdef Q_OS_ANDROID
230#endif
231 XrFoveationLevelFB m_foveationLevel = XR_FOVEATION_LEVEL_HIGH_FB;
232 bool m_compositionLayerDepthSupported = false;
233 bool m_submitLayerDepth = false;
234 bool m_handtrackingExtensionSupported = false;
235 bool m_handtrackingAimExtensionSupported = false;
236 bool m_overlayExtensionSupported = false;
237 bool m_isGraphicsInitialized = false;
238
239 bool m_sessionRunning{false};
240
241 QQuick3DXrManager *q_ptr = nullptr;
242#ifdef XR_USE_PLATFORM_ANDROID
244 JavaVM* m_javaVM = nullptr;
245#endif // XR_USE_PLATFORM_ANDROID
246
247#ifdef XR_EXT_debug_utils
250#endif
251
252#if QT_CONFIG(graphicsframecapture)
254#endif
255
256 QAbstractOpenXRGraphics *m_graphics = nullptr;
257
258 bool m_waitingForFrame = false;
259 bool m_wantUpdate = false;
260 QQuick3DOpenXRThreadWorker *m_worker = nullptr;
261 QThread *m_workerThread = nullptr;
262 QVector<XrEnvironmentBlendMode> m_blendModes;
263};
264
265QT_END_NAMESPACE
266
267#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)
static QQuick3DXrInputManagerPrivate * get(QQuick3DXrInputManager *inputManager)
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(lcQIORing)
#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)