summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2021-01-11 11:30:56 +0000
committerMike Krus <mike.krus@kdab.com>2021-01-27 15:35:09 +0000
commit14b84adf81aa61f80012001d44d3269e65a64f6f (patch)
treebb51680de9687e507f715fb57d537fcaf3a1afaa
parenta7f627b29b2792154bc2a45f31bd32b74fd508b4 (diff)
Make Qt3DWindow handle default surface format more gracefully
The default is now to use the same rules as QtQuick. If nothing is specified, will use RHI and the best surface for the platform (Metal on Mac, DX on Windows, Vulkan if available, etc). If Qt3D's OpenGL backend is requested via QT3D_RENDERER, will always use OpenGL surface. If QSG_RHI_BACKEND is set, will honour that if possible. Otherwise will use the API requested in the constructor (which defaults to using auto detection). Pick-to: 6.0 Change-Id: I8941a081940c073dfcf66711a8628e8ef6fd0915 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/extras/defaults/qt3dwindow.cpp34
-rw-r--r--src/extras/defaults/qt3dwindow.h2
2 files changed, 26 insertions, 10 deletions
diff --git a/src/extras/defaults/qt3dwindow.cpp b/src/extras/defaults/qt3dwindow.cpp
index 1ac1d6b60..1b809c168 100644
--- a/src/extras/defaults/qt3dwindow.cpp
+++ b/src/extras/defaults/qt3dwindow.cpp
@@ -269,10 +269,32 @@ void setupWindowSurface(QWindow *window, Qt3DRender::API api) noexcept
}
}
+ // Default to using RHI backend is not specified We want to set the
+ // variable to ensure any 3rd party relying on it to detect which rendering
+ // backend is in use will get a valid value.
+ bool useRhi = true;
+ if (qEnvironmentVariableIsEmpty("QT3D_RENDERER"))
+ qputenv("QT3D_RENDERER", "rhi");
+ else
+ useRhi = qEnvironmentVariable("QT3D_RENDERER") == QStringLiteral("rhi");
+
+ if (!useRhi)
+ api = Qt3DRender::API::OpenGL;
+
// We have to set the environment so that the backend is able to read it.
- // Qt6: FIXME
- switch (api)
- {
+ if (api == Qt3DRender::API::RHI && useRhi) {
+#if defined(Q_OS_WIN)
+ api = Qt3DRender::API::DirectX;
+#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+ api = Qt3DRender::API::Metal;
+#elif QT_CONFIG(opengl)
+ api = Qt3DRender::API::OpenGL;
+#else
+ api = Qt3DRender::API::Vulkan;
+#endif
+ }
+
+ switch (api) {
case Qt3DRender::API::OpenGL:
qputenv("QSG_RHI_BACKEND", "opengl");
window->setSurfaceType(QSurface::OpenGLSurface);
@@ -303,12 +325,6 @@ void setupWindowSurface(QWindow *window, Qt3DRender::API api) noexcept
break;
}
- // Default to using RHI backend is not specified We want to set the
- // variable to ensure any 3rd party relying on it to detect which rendering
- // backend is in use will get a valid value.
- if (qEnvironmentVariableIsEmpty("QT3D_RENDERER"))
- qputenv("QT3D_RENDERER", "rhi");
-
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
const QByteArray renderingBackend = qgetenv("QT3D_RENDERER");
const bool usesRHI = renderingBackend.isEmpty() || renderingBackend == QByteArrayLiteral("rhi");
diff --git a/src/extras/defaults/qt3dwindow.h b/src/extras/defaults/qt3dwindow.h
index c982746a8..55a686dbe 100644
--- a/src/extras/defaults/qt3dwindow.h
+++ b/src/extras/defaults/qt3dwindow.h
@@ -91,7 +91,7 @@ class Q_3DEXTRASSHARED_EXPORT Qt3DWindow : public QWindow
{
Q_OBJECT
public:
- Qt3DWindow(QScreen *screen = nullptr, Qt3DRender::API = Qt3DRender::API::OpenGL);
+ Qt3DWindow(QScreen *screen = nullptr, Qt3DRender::API = Qt3DRender::API::RHI);
~Qt3DWindow();
void registerAspect(Qt3DCore::QAbstractAspect *aspect);