aboutsummaryrefslogtreecommitdiffstats
path: root/src/xr/quick3dxr/qquick3dxrview.cpp
blob: 7a1780e49ab9db6314f7f2936b6ab264222e9cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "qtquick3dxrglobal_p.h"
#include "qquick3dxritem_p.h"
#include "qquick3dxrview_p.h"
#include <QQuickWindow>
#include <QQuickItem>
#include <QLoggingCategory>

#include <QtQuick3DUtils/private/qssgassert_p.h>

#include "qquick3dxrinputmanager_p.h"

QT_BEGIN_NAMESPACE

Q_DECLARE_LOGGING_CATEGORY(lcQuick3DXr);

/*!
    \qmltype XrView
    \inherits Node
    \inqmlmodule QtQuick3D.Xr
    \brief Sets up the view for an Xr application.

    An XrView sets up the view for an XR application.
    The following snippet is from the \l{\qxr Simple Example} and shows
    how to use the type.

    \quotefromfile xr_simple/main.qml
    \printto XrOrigin

    \section1 Platform notes

    \section2 Meta Quest Devices

    To \l{XrView::passthroughEnabled}{enable passthrough} you need to add the
    following permisson your app's \c AndroidManifest.xml file:

    \badcode
    <uses-feature android:name="com.oculus.feature.PASSTHROUGH" android:required="false"/>
    \endcode

*/

QQuick3DXrView::QQuick3DXrView()
    : m_xrRuntimeInfo(&m_xrManager)
{
    init();
}

QQuick3DXrView::~QQuick3DXrView()
{
    m_inDestructor = true;
}

/*!
    \qmlproperty XrOrigin QtQuick3D.Xr::XrView::xrOrigin
    \brief Holds the active XR origin.

    The XR origin is the point in the scene that is considered the origin of the
    XR coordinate system. The XR origin is used to position tracked objects like
    the camera and controllers in the scene. An application can have multiple XrOrigins
    but only one can be active at a time.

    \note This property must be set for the scene to be rendered in XR.

    \sa XrOrigin
*/

QQuick3DXrOrigin *QQuick3DXrView::xrOrigin() const
{
    return m_xrOrigin;
}

/*!
    \qmlproperty SceneEnvironment QtQuick3D.Xr::XrView::environment
    \summary Holds the SceneEnvironment for the XR view.
*/

QQuick3DSceneEnvironment *QQuick3DXrView::environment() const
{
    return m_xrManager.m_vrViewport ? m_xrManager.m_vrViewport->environment() : nullptr;
}

QQuick3DViewport *QQuick3DXrView::view3d() const
{
    return m_xrManager.m_vrViewport;
}

/*!
    \qmlproperty bool QtQuick3D.Xr::XrView::passthroughEnabled
    \summary Holds whether passthrough is enabled for the XR view.
*/
bool QQuick3DXrView::passthroughEnabled() const
{
    return m_xrManager.isPassthroughEnabled();
}

/*!
    \qmlproperty QQuick3DXrRuntimeInfo QtQuick3D.Xr::XrView::runtimeInfo
    \summary Provides information about the XR runtime for the XR view.
*/

QQuick3DXrRuntimeInfo *QQuick3DXrView::runtimeInfo() const
{
    return &m_xrRuntimeInfo;
}

void QQuick3DXrView::setEnvironment(QQuick3DSceneEnvironment *environment)
{
    QQuick3DViewport *view = m_xrManager.m_vrViewport;

    // If the view is not created yet, we can't set the environment which means we need to
    // set it again once the view is created...
    if (!view) {
        m_pendingSceneEnvironment = environment;
        return;
    }

    auto oldEnvironment = view->environment();
    if (oldEnvironment == environment)
        return;

    if (oldEnvironment)
        disconnect(oldEnvironment);

    view->setEnvironment(environment);

    // The view will always have an environment, setting the environment to null will just mean the default environment
    // is used. So querying the environment from the view is always valid (and we should do it here to make sure we're
    // in sync with the view).
    environment = view->environment();

    handleClearColorChanged();
    handleAAChanged();

    connect(environment, &QQuick3DSceneEnvironment::backgroundModeChanged, this, &QQuick3DXrView::handleClearColorChanged);
    connect(environment, &QQuick3DSceneEnvironment::clearColorChanged, this, &QQuick3DXrView::handleClearColorChanged);
    connect(environment, &QQuick3DSceneEnvironment::antialiasingModeChanged, this, &QQuick3DXrView::handleAAChanged);
    connect(environment, &QQuick3DSceneEnvironment::antialiasingQualityChanged, this, &QQuick3DXrView::handleAAChanged);

    emit environmentChanged(environment);
}

/*!
    \qmlproperty bool QtQuick3D.Xr::XrView::passthroughSupported
    \summary Indicates whether passthrough is supported for the XR view.
*/

bool QQuick3DXrView::passthroughSupported() const
{
    if (!m_xrManager.isValid())
        return false;

    return m_xrManager.supportsPassthrough();
}

void QQuick3DXrView::setPassthroughEnabled(bool enable)
{
    if (!m_xrManager.isValid()) {
        qWarning("Attempted to set passthrough mode without a valid XR manager");
        return;
    }

    // bail if passthrough is not supported
    if (enable && !m_xrManager.supportsPassthrough()) {
        qWarning("Enabling Passthrough is not supported.");
        return;
    }

    const bool orgPassthroughEnabled = m_xrManager.isPassthroughEnabled();
    m_xrManager.setPassthroughEnabled(enable);

    if (orgPassthroughEnabled != m_xrManager.isPassthroughEnabled())
        emit passthroughEnabledChanged();
}

/*!
    \qmlproperty enumeration QtQuick3D.Xr::XrView::fixedFoveation
    \brief Controls the level of fixed foveated rendering for the XrView.
    \default XrView.HighFoveation

    Foveated rendering reduces GPU load by reducing image quality (resolution)
    in areas where the difference is less perceptible to the eye. With fixed
    foveated rendering, the areas with reduced visual fidelity are fixed and do
    not change. On some platforms, there is no concept of fixed foveated
    rendering or control over it. For example, VisionOS-based devices perform
    dynamic, eye-tracked foveation; thus, the value of this property is
    ignored in practice. Other devices, such as the Meta Quest 3, only
    support fixed foveation, which makes this property relevant.

    The value can be one of:
    \value XrView.NoFoveation 0, no foveation.
    \value XrView.LowFoveation 1, low foveation.
    \value XrView.MediumFoveation 2, medium foveation.
    \value XrView.HighFoveation 3, high foveation.

    Where supported, the default is \c HighFoveation. Therefore, changing this
    value in applications should be rarely needed in practice.
*/

QQuick3DXrView::FoveationLevel QQuick3DXrView::fixedFoveation() const
{
    return FoveationLevel(m_xrManager.getFixedFoveationLevel());
}

void QQuick3DXrView::setFixedFoveation(FoveationLevel level)
{
    const auto orgFoviationLevel = m_xrManager.getFixedFoveationLevel();
    m_xrManager.setFixedFoveationLevel(QtQuick3DXr::FoveationLevel(level));
    if (orgFoviationLevel != m_xrManager.getFixedFoveationLevel())
        emit fixedFoveationChanged();
}

/*!
    \qmlproperty bool QtQuick3D.Xr::XrView::isQuitOnSessionEndEnabled
    \brief Holds whether the application should quit when the XR session ends.
*/

bool QQuick3DXrView::isQuitOnSessionEndEnabled() const
{
    return m_quitOnSessionEnd;
}

void QQuick3DXrView::setQuitOnSessionEnd(bool enable)
{
    if (m_quitOnSessionEnd == enable)
        return;

    m_quitOnSessionEnd = enable;
    emit quitOnSessionEndChanged();
}
/*!
    \qmlproperty RenderStats QtQuick3D.Xr::XrView::renderStats
    \summary Holds rendering statistics for the XR view.
*/

QQuick3DRenderStats *QQuick3DXrView::renderStats() const
{
    return m_xrManager.m_vrViewport ? m_xrManager.m_vrViewport->renderStats() : nullptr;
}

void QQuick3DXrView::updateViewportGeometry()
{
    auto contentItem = m_xrManager.m_quickWindow->contentItem();
    auto viewport = m_xrManager.m_vrViewport;
    if (viewport->height() != contentItem->height())
        viewport->setHeight(contentItem->height());
    if (viewport->width() != contentItem->width())
        viewport->setWidth(contentItem->width());
    if (viewport->x() != contentItem->x())
        viewport->setX(contentItem->x());
    if (viewport->y() != contentItem->y())
        viewport->setY(contentItem->y());
}

void QQuick3DXrView::handleSessionEnded()
{
    emit sessionEnded();
    if (m_quitOnSessionEnd)
        QCoreApplication::quit();
}

void QQuick3DXrView::handleClearColorChanged()
{
    auto env = environment();

    if (env) {
        if (env->backgroundMode() == QQuick3DSceneEnvironment::Color)
            m_xrManager.m_quickWindow->setColor(env->clearColor());
        else if (env->backgroundMode() == QQuick3DSceneEnvironment::Transparent)
            m_xrManager.m_quickWindow->setColor(Qt::transparent);
    }
}

void QQuick3DXrView::handleAAChanged()
{
    auto env = environment();
    int samples = 1;
    if (env && env->antialiasingMode() == QQuick3DSceneEnvironment::MSAA) {
        switch (env->antialiasingQuality()) {
        case QQuick3DSceneEnvironment::Medium:
            samples = 2;
            break;
        case QQuick3DSceneEnvironment::High:
            samples = 4;
            break;
        case QQuick3DSceneEnvironment::VeryHigh:
            samples = 8;
            break;
        }
    }
    m_xrManager.setSamples(samples);
}

bool QQuick3DXrView::init()
{
    if (m_isInitialized) {
        qWarning("Already initialized!");
        return false;
    }

    connect(&m_xrManager, &QQuick3DXrManager::sessionEnded, this, &QQuick3DXrView::handleSessionEnded);
    connect(&m_xrManager, &QQuick3DXrManager::frameReady, this, &QQuick3DXrView::frameReady);
    connect(&m_xrManager, &QQuick3DXrManager::referenceSpaceChanged, this, &QQuick3DXrView::referenceSpaceChanged);
    connect(&m_xrManager, &QQuick3DXrManager::multiViewRenderingEnabledChanged, this, &QQuick3DXrView::multiViewRenderingEnabledChanged);
    connect(&m_xrManager, &QQuick3DXrManager::initialized, this, &QQuick3DXrView::init, Qt::UniqueConnection);

    if (!m_xrManager.isReady() && !m_xrManager.initialize()) {
        qCDebug(lcQuick3DXr, "Waiting for XR platform to be initialized");

        return false;
    }

    if (!m_xrManager.initialize()) {
        QString errorString = m_xrManager.errorString();
        if (errorString.isEmpty())
            errorString = tr("Failed to initialize XR platform");
        qWarning("\n%s\n", qPrintable(errorString));
        QMetaObject::invokeMethod(this, "initializeFailed", Qt::QueuedConnection, errorString);
        return false;
    }

    // Create View3D
    QSSG_CHECK_X(m_xrManager.m_vrViewport == nullptr, "View3D already created!");
    auto viewport = new QQuick3DViewport(QQuick3DViewport::PrivateInstanceType::XrViewInstance);
    viewport->setRenderMode(QQuick3DViewport::Underlay);
    auto contentItem = m_xrManager.m_quickWindow->contentItem();
    viewport->setParentItem(contentItem);
    m_xrManager.m_vrViewport = viewport;
    viewport->setImportScene(this);

    contentItem->forceActiveFocus(Qt::MouseFocusReason);

    connect(contentItem, &QQuickItem::heightChanged, this, &QQuick3DXrView::updateViewportGeometry);
    connect(contentItem, &QQuickItem::widthChanged, this, &QQuick3DXrView::updateViewportGeometry);
    connect(contentItem, &QQuickItem::xChanged, this, &QQuick3DXrView::updateViewportGeometry);
    connect(contentItem, &QQuickItem::yChanged, this, &QQuick3DXrView::updateViewportGeometry);

    QQuick3DSceneEnvironment *env = environment();
    if (env) {
        connect(env, &QQuick3DSceneEnvironment::backgroundModeChanged, this, &QQuick3DXrView::handleClearColorChanged);
        connect(env, &QQuick3DSceneEnvironment::clearColorChanged, this, &QQuick3DXrView::handleClearColorChanged);
        connect(env, &QQuick3DSceneEnvironment::antialiasingModeChanged, this, &QQuick3DXrView::handleAAChanged);
        connect(env, &QQuick3DSceneEnvironment::antialiasingQualityChanged, this, &QQuick3DXrView::handleAAChanged);
    }

    // NOTE: If we've called async, we need to make sure the environment, etc. is set again
    setEnvironment(m_pendingSceneEnvironment);
    m_pendingSceneEnvironment = nullptr;

    m_xrManager.update();

    m_isInitialized = true;

    return m_isInitialized;
}

/*!
    \qmlmethod pickResult XrView::rayPick(vector3d origin, vector3d direction)

    This method will \e shoot a ray into the scene starting at \a origin and in
    \a direction and return information about the nearest intersection with an
    object in the scene.

    For example, pass the position and forward vector of
    any object in a scene to see what object is in front of an item. This
    makes it possible to do picking from any point in the scene.
 */
QQuick3DPickResult QQuick3DXrView::rayPick(const QVector3D &origin, const QVector3D &direction) const
{
    return m_xrManager.m_vrViewport->rayPick(origin, direction);
}

/*!
    \qmlmethod List<pickResult> XrView::rayPickAll(vector3d origin, vector3d direction)

    This method will \e shoot a ray into the scene starting at \a origin and in
    \a direction and return a list of information about the nearest intersections with
    objects in the scene.
    The list is presorted by distance from the origin along the direction
    vector with the nearest intersections appearing first and the furthest
    appearing last.

    This can, for instance, be called with the position and forward vector of
    any object in a scene to see what objects are in front of an item. This
    makes it possible to do picking from any point in the scene.
 */
QList<QQuick3DPickResult> QQuick3DXrView::rayPickAll(const QVector3D &origin, const QVector3D &direction) const
{
    return m_xrManager.m_vrViewport->rayPickAll(origin, direction);
}

/*!
    \qmlmethod XrView::setTouchpoint(Item target, point position, int pointId, bool pressed)

    Sends a synthetic touch event to \a target, moving the touch point with ID \a pointId to \a position,
    with \a pressed determining if the point is pressed.
    Also sends the appropriate touch release event if \a pointId was previously active on a different
    item.
*/

void QQuick3DXrView::setTouchpoint(QQuickItem *target, const QPointF &position, int pointId, bool pressed)
{
    view3d()->setTouchpoint(target, position, pointId, pressed);
}

// TODO: Maybe do a proper QQuick3DXrViewPrivate instead
struct QQuick3DXrView::XrTouchState
{
    QHash<int, QQuick3DXrItem::TouchState> points;
};

/*!
    \qmlmethod vector3d XrView::processTouch(vector3d position, int pointId)

    This method will search for an XrItem near \a position and send a virtual
    touch event with touch point ID \a pointId if \a position maps to a point
    on the surface.

    The return value is the offset between \a position and the touched point on
    the surface. This can be used to prevent a hand model from passing through
    an XrItem.

    \sa XrHandModel

*/

QVector3D QQuick3DXrView::processTouch(const QVector3D &pos, int pointId)
{
    QVector3D offset;
    if (m_xrItems.isEmpty())
        return offset;

    if (!m_touchState)
        m_touchState = new XrTouchState;
    QQuick3DXrItem::TouchState &state = m_touchState->points[pointId];
    state.pointId = pointId; // in case it's a new point that was default-constructed

    auto *prevTarget = state.target;
    bool grabbed = false;
    if (prevTarget) {
        grabbed = prevTarget->handleVirtualTouch(this, pos, &state, &offset);
    }
    for (auto *item : std::as_const(m_xrItems)) {
        if (grabbed)
            break;
        if (item != prevTarget)
            grabbed = item->handleVirtualTouch(this, pos, &state, &offset);
    }

    return offset;
}

/*!
    \qmlmethod object XrView::touchpointState(int pointId)

    This method returns the state of the touch point with ID \a pointId.
    The state is represented by a map from property names to values:

    \table
    \header
    \li Key
    \li Type
    \li Description
    \row
    \li \c grabbed
    \li \c bool
    \li Is the point grabbed by an item? If \c false, all other values are \c undefined.
    \row
    \li \c target
    \li XrItem
    \li The item that is grabbing the touch point.
    \row
    \li \c pressed
    \li \c bool
    \li Is the touch point pressed?
    \row
    \li \c cursorPos
    \li \c point
    \li The 2D position of the touch point within \c target
    \row
    \li \c touchDistance
    \li \c real
    \li The distance from the plane to the touch point. It will be \c 0 if \c pressed is \c true.
    \endtable

 */

#define Q_TOUCHPOINT_STATE(prop) { QStringLiteral(#prop), QVariant::fromValue(it->prop) }
QVariantMap QQuick3DXrView::touchpointState(int pointId) const
{
    auto constexpr end = QHash<int, QQuick3DXrItem::TouchState>::const_iterator();
    auto it = m_touchState ? m_touchState->points.constFind(pointId) : end;

    if (it == end)
        return { { QStringLiteral("grabbed"), QVariant::fromValue(false) } };

    return { Q_TOUCHPOINT_STATE(target),
             Q_TOUCHPOINT_STATE(grabbed),
             Q_TOUCHPOINT_STATE(pressed),
             Q_TOUCHPOINT_STATE(cursorPos),
             Q_TOUCHPOINT_STATE(touchDistance) };
}
#undef Q_TOUCHPOINT_STATE

/*!
    \qmlproperty enumeration QtQuick3D.Xr::XrView::referenceSpace
    \brief Gets or sets the reference space for the XR view.

     It can be one of:
     \value XrView.ReferenceSpaceUnknown
     \value XrView.ReferenceSpaceLocal Origin is at the default view position (typically defined by a "reset view" operation).
     \value XrView.ReferenceSpaceStage Origin is at floor height in the center of the user's defined area.
     \value XrView.ReferenceSpaceLocalFloor Origin is at floor height, below the default view position.

    \c ReferenceSpaceLocal is mainly useful for seated applications where the content is not positioned
    relative to the floor, for example floating menus. The content will move when the user resets the view.

    \c ReferenceSpaceStage is mainly useful for room-scale applications where the user will move freely within the
    playing area. The content will not move when the user resets the view.

    \c ReferenceSpaceLocalFloor is mainly useful for stationary applications (seated or standing) where the content is
    positioned relative to the floor. The content will move when the user resets the view.

    \default XrView.ReferenceSpaceLocal
*/

QQuick3DXrView::ReferenceSpace QQuick3DXrView::referenceSpace() const
{
    return ReferenceSpace(m_xrManager.getReferenceSpace());
}

void QQuick3DXrView::setReferenceSpace(ReferenceSpace newReferenceSpace)
{
    m_xrManager.setReferenceSpace(QtQuick3DXr::ReferenceSpace(newReferenceSpace));
}

bool QQuick3DXrView::depthSubmissionEnabled() const
{
    if (!m_xrManager.isValid()) {
        qWarning("Attempted to check depth submission mode without a valid XR manager");
        return false;
    }

    return m_xrManager.isDepthSubmissionEnabled();
}

/*!
    \qmlproperty bool QtQuick3D.Xr::XrView::multiViewRenderingSupported

    \brief This read-only property reports the availability of \l{Multiview Rendering}.

    \sa multiViewRenderingEnabled
 */
bool QQuick3DXrView::isMultiViewRenderingSupported() const
{
    if (!m_xrManager.isValid())
        return false;

    return m_xrManager.isMultiViewRenderingSupported();
}

/*!
    \qmlproperty bool QtQuick3D.Xr::XrView::multiViewRenderingEnabled

    \brief This is a read-only property that reports if \l{Multiview Rendering} is enabled for the XR view.

    \default true

    This property tells you if multiview rendering is actually in use at run time.
    When not supported, the value will flip back to \c false.

    Enabling multiview rendering is recommended. It can improve performance and reduce
    CPU and GPU power usage. It defaults to disabled to ensure maximum
    compatibility. Developers are encouraged to verify that their application
    renders as expected with multiViewRenderingEnabled set to \c true and then
    leave it set afterward.

    \note Certain Qt Quick and Quick 3D features that involve shader code that is
    provided by the application may need this code to be modified to be multiview
    compatible. Examples of these are custom 2D and 3D materials and
    postprocessing effects. The \l {Multiview Rendering} documentation provides
    more information on this and how to disable multiview rendering.

    \sa multiViewRenderingSupported {Multiview Rendering}
*/
bool QQuick3DXrView::multiViewRenderingEnabled() const
{
    if (!m_xrManager.isValid())
        return false;

    return m_xrManager.isMultiViewRenderingEnabled();
}

void QQuick3DXrView::registerXrItem(QQuick3DXrItem *newXrItem)
{
    m_xrItems.append(newXrItem);
}

void QQuick3DXrView::unregisterXrItem(QQuick3DXrItem *xrItem)
{
    m_xrItems.removeAll(xrItem);
}

/*!
    \qmlproperty bool QtQuick3D.Xr::XrView::depthSubmissionEnabled
    \brief Controls whether submitting the depth buffer to the XR compositor
    is enabled.
    \default false

    By default, the depth buffer used by the 3D scene in the XrView is not exposed
    to the XR compositor. However, in some platforms, depth submission is implicit
    and cannot be disabled or controlled by the application. An example of this is
    VisionOS. Changing this property has no effect on those platforms. Elsewhere,
    with OpenXR in particular, support depends on the OpenXR implementation used
    at run time.

    It is always safe to set depthSubmissionEnabled to \c true. It will just have
    no effect when not supported by the underlying stack. To be sure, you can
    inspect the debug output to see if depth submission is in use.
    Submitting the depth buffer may improve reprojections that the XR compositor
    may perform. Reprojection could happen, for example, when the system cannot
    maintain the target frame rate and thus has to resort to predicting frame
    contents to improve and stabilize the user's perception of the
    scene and reduce possible motion sickness. However, the application and
    Qt have no control over data usage. It could also happen that
    submitting depth data has no practical effects and is ignored by the
    underlying XR runtime and compositor.

    In practice, submitting the depth buffer implies rendering into a depth
    texture provided by the XR runtime instead of the intermediate texture/render buffer
    created and managed by Qt. Rendering into a depth texture has certain lower-level
    consequences that can have a performance impact:

    When using \l{QtQuick3D::SceneEnvironment::antialiasingMode}{multisample antialiasing}
    (MSAA), enabling depth submission implies rendering into a multisample depth
    texture and resolving the samples into the non-multisample depth texture provided by
    the XR runtime. Without depth submission,
    the resolve step would not be necessary. In addition, some 3D APIs
    do not support resolving multisample depth-stencil data (see
    the \l{QRhi::ResolveDepthStencil} flag for details). Without this support,
    attempts to  enable depth submission in combination with MSAA are gracefully ignored.

    Even when MSAA is not used, enabling depth submission triggers writing out
    depth data with 3D APIs that have control over this. The store operation for
    depth/stencil data is typically indicated by Qt as unnecessary, which can
    have positive performance impacts on tiled GPU architectures. This is not
    done with depth submission because depth data must always be written out
    from Qt's perspective.

    \note We recommended that developers test their applications with depth
    submission enabled, evaluate the advantages and disadvantages, and make a
    conscious choice based on their testing if they wish to enable it or not.
*/

void QQuick3DXrView::setDepthSubmissionEnabled(bool enable)
{
    if (!m_xrManager.isValid()) {
        qWarning("Attempted to set depth submission mode without a valid XR manager");
        return;
    }

    const bool orgDepthSubmission = m_xrManager.isDepthSubmissionEnabled();

    m_xrManager.setDepthSubmissionEnabled(enable);

    if (orgDepthSubmission != m_xrManager.isDepthSubmissionEnabled())
        emit depthSubmissionEnabledChanged();
}

void QQuick3DXrView::setXROrigin(QQuick3DXrOrigin *newXrOrigin)
{
    if (m_xrOrigin == newXrOrigin)
        return;

    QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DXrView::setXROrigin, newXrOrigin, m_xrOrigin);

    m_xrOrigin = newXrOrigin;

    // Make sure the XrOrigin has a parent item, if it hasn't, we're it.
    if (m_xrOrigin && !m_xrOrigin->parentItem())
        m_xrOrigin->setParentItem(this);

    m_xrManager.setXROrigin(m_xrOrigin);

    emit xrOriginChanged();
}

QQuick3DViewport *QQuick3DXrViewPrivate::getView3d(QQuick3DXrView *view)
{
    QSSG_ASSERT(view != nullptr, return nullptr);
    return view->view3d();
}

/*!
    \qmlsignal XrView::initializeFailed(const QString &errorString)

    Emitted when initialization fails, and there is a new \a errorString
    describing the failure.
 */

/*!
    \qmlsignal XrView::sessionEnded()

    Emitted when the session ends.
 */

/*!
    \qmlsignal XrView::frameReady()
    \internal

    Emitted when a new frame is ready.
 */

QT_END_NAMESPACE