From b4447c39a95bc03d7874a323e179d0f8cda83255 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 19 Jun 2020 14:45:41 +0200 Subject: Fix up exposing the swapchain to Quick3D Quick3D is broken in combination with QQuickRenderControl. This is because just exposing the swapchain is not enough - there is no swapchain with QQuickRenderControl. Rather, one needs access to the command buffer and render target then. Change-Id: I6c06ad3d83ab0018b9f985073757a3378dbce24b Reviewed-by: Andy Nichols --- src/quick/scenegraph/coreapi/qsgrendererinterface.cpp | 15 +++++++++++++-- src/quick/scenegraph/coreapi/qsgrendererinterface.h | 2 ++ src/quick/scenegraph/qsgrhisupport.cpp | 17 +++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) (limited to 'src/quick') diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp index 6970aa0afb..efbab4086c 100644 --- a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp +++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp @@ -113,8 +113,19 @@ QT_BEGIN_NAMESPACE the scenegraph, when applicable. This value was introduced in Qt 5.14. \value RhiSwapchainResource The resource is a pointer to a QRhiSwapchain - instance that is associated with the window. This value was introduced in - Qt 6.0. + instance that is associated with the window. The value is null when the + window is used in combination with QQuickRenderControl. This value was + introduced in Qt 6.0. + + \value RhiRedirectCommandBuffer The resource is a pointer to a + QRhiCommandBuffer instance that is associated with the window and its + QQuickRenderControl. The value is null when the window is not associated + with a QQuickRenderControl. This value was introduced in Qt 6.0. + + \value RhiRedirectRenderTarget The resource is a pointer to a + QRhiTextureRenderTarget instance that is associated with the window and its + QQuickRenderControl. The value is null when the window is not associated + with a QQuickRenderControl. This value was introduced in Qt 6.0. \value PhysicalDeviceResource The resource is a pointer to the pysical device object used by the scenegraph, when applicable. For example, a diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.h b/src/quick/scenegraph/coreapi/qsgrendererinterface.h index 9d7b9a5738..c001ecc2db 100644 --- a/src/quick/scenegraph/coreapi/qsgrendererinterface.h +++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.h @@ -68,6 +68,8 @@ public: PainterResource, RhiResource, RhiSwapchainResource, + RhiRedirectCommandBuffer, + RhiRedirectRenderTarget, PhysicalDeviceResource, OpenGLContextResource, DeviceContextResource, diff --git a/src/quick/scenegraph/qsgrhisupport.cpp b/src/quick/scenegraph/qsgrhisupport.cpp index 007739d2d7..618e1f1411 100644 --- a/src/quick/scenegraph/qsgrhisupport.cpp +++ b/src/quick/scenegraph/qsgrhisupport.cpp @@ -441,10 +441,23 @@ const void *QSGRhiSupport::rifResource(QSGRendererInterface::Resource res, const QQuickWindow *w) { QRhi *rhi = rc->rhi(); - if (res == QSGRendererInterface::RhiResource || !rhi) + if (!rhi) + return nullptr; + + // Accessing the underlying QRhi* objects are essential both for Qt Quick + // 3D and advanced solutions, such as VR engine integrations. + switch (res) { + case QSGRendererInterface::RhiResource: return rhi; - if (res == QSGRendererInterface::RhiSwapchainResource) + case QSGRendererInterface::RhiSwapchainResource: return QQuickWindowPrivate::get(w)->swapchain; + case QSGRendererInterface::RhiRedirectCommandBuffer: + return QQuickWindowPrivate::get(w)->redirect.commandBuffer; + case QSGRendererInterface::RhiRedirectRenderTarget: + return QQuickWindowPrivate::get(w)->redirect.rt.renderTarget; + default: + break; + } const QRhiNativeHandles *nat = rhi->nativeHandles(); if (!nat) -- cgit v1.2.3