6#include <QtCore/QCoreApplication>
7#include <QtCore/QDebug>
8#include <QtCore/qjsonobject.h>
9#include <QtCore/qjsonarray.h>
13#include <QtQuick/private/qquickwindow_p.h>
14#include <QtQuick/QQuickRenderControl>
15#include <QtQuick/QQuickRenderTarget>
16#include <QtQuick/QQuickItem>
18#include <QtQuick3D/private/qquick3dnode_p.h>
19#include <QtQuick3D/private/qquick3dviewport_p.h>
25#if defined(Q_OS_VISIONOS)
26# include <QtQuick3DXr/private/qquick3dxrmanager_visionos_p.h>
50 delete m_renderControl;
51 delete m_animationDriver;
67 if (!
d->initialize()) {
69 m_errorString =
QStringLiteral(
"Waiting for the renderer to start.");
71 m_errorString =
QStringLiteral(
"Failed to initialize the XR manager.");
77 return setupGraphics();
101 return d->isPassthroughEnabled();
107 d->setMultiviewRenderingEnabled(
enable);
113 return d->isMultiViewRenderingEnabled();
119 return d->isMultiViewRenderingSupported();
124#if defined(Q_OS_VISIONOS)
135#if defined(Q_OS_VISIONOS)
140 const XrFoveationLevelFB xrLevel = XrFoveationLevelFB(
level);
141 if (
d->m_foveationLevel == xrLevel)
144 d->m_foveationLevel = xrLevel;
145 d->setupMetaQuestFoveation();
152 return d->getReferenceSpace();
159 d->setReferenceSpace(newReferenceSpace);
165 return d->isDepthSubmissionEnabled();
171 d->setDepthSubmissionEnabled(
enable);
177 return d->errorString();
186void QQuick3DXrManager::update()
192void QQuick3DXrManager::processSpatialEvents(
const QJsonObject &events)
194 static qint64 lastId = -1;
197 for (
const auto &
event : eventArray) {
208 qWarning() <<
"kind is " << kind <<
"!";
216 if (!selectionRayObj.isEmpty()) {
296 d->processXrEvents();
306 return d->m_inputManager.data();
309bool QQuick3DXrManager::setupGraphics()
315 if (
d->isGraphicsInitialized())
318 preSetupQuickScene();
320 if (!
d->setupGraphics(m_quickWindow))
323 if (!setupQuickScene())
326 QRhi *rhi = m_quickWindow->rhi();
327 QSSG_ASSERT_X(rhi !=
nullptr,
"No RHI handle!",
return false);
329 return d->finalizeGraphics(rhi);
332void QQuick3DXrManager::renderFrame()
340void QQuick3DXrManager::preSetupQuickScene()
342 if (!m_renderControl)
348bool QQuick3DXrManager::setupQuickScene()
352 d->setupWindow(m_quickWindow);
354 if (!m_animationDriver) {
359 const bool initSuccess = m_renderControl->
initialize();
361 qWarning(
"Quick 3D XR: Failed to create renderControl (failed to initialize RHI?)");
365 QRhi *rhi = m_renderControl->
rhi();
367 qWarning(
"Quick3D XR: No QRhi from renderControl. This should not happen.");
374 qDebug(
"Quick3D XR: multiview rendering requested via the environment");
381void QQuick3DXrManager::checkOrigin()
389 auto origin = qobject_cast<QQuick3DXrOrigin *>(node);
392 for (
auto child : node->childItems()) {
393 origin = findOriginNode(
child);
399 auto origin = findOriginNode(m_vrViewport->
importScene());
404 m_xrOrigin =
nullptr;
411bool QQuick3DXrManager::supportsPassthrough()
const
414 return d->supportsPassthrough();
void install()
Installs this animation driver.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
Type
This enum type defines the valid event types in Qt.
Type type() const
Returns the event type.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
QJsonValue value(const QString &key) const
Returns a QJsonValue representing the value for the key key.
QJsonObject toObject() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QJsonArray toArray() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
double toDouble(double defaultValue=0) const
Converts the value to a double and returns it.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
\inmodule QtCore\reentrant
\qmltype Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DObject \inherits QtObject
QQuick3DNode * importScene
void processPointerEventFromRay(const QVector3D &origin, const QVector3D &direction, QPointerEvent *event)
void setDepthSubmissionEnabled(bool enable)
bool isPassthroughEnabled() const
void setFixedFoveationLevel(QtQuick3DXr::FoveationLevel level)
bool isMultiViewRenderingSupported() const
QString errorString() const
QtQuick3DXr::FoveationLevel getFixedFoveationLevel() const
bool isDepthSubmissionEnabled() const
void setMultiviewRenderingEnabled(bool enable)
QQuick3DXrManager(QObject *parent=nullptr)
void setSamples(int samples)
void setPassthroughEnabled(bool enabled)
bool isMultiViewRenderingEnabled() const
void setReferenceSpace(QtQuick3DXr::ReferenceSpace newReferenceSpace)
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QtQuick3DXr::ReferenceSpace getReferenceSpace() const
The QQuickRenderControl class provides a mechanism for rendering the Qt Quick scenegraph onto an offs...
bool initialize()
Initializes the scene graph resources.
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
const char * backendName() const
\macro QT_RESTRICTED_CAST_FROM_ASCII
The QVector3D class represents a vector or vertex in 3D space.
Combined button and popup list for selecting options.
GLenum GLuint GLint level
GLenum GLenum GLsizei const GLuint GLboolean enabled
#define QSSG_ASSERT_X(cond, msg, action)
#define QStringLiteral(str)
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
static double toDouble(Value v)
QNetworkRequest request(url)