summaryrefslogtreecommitdiffstats
path: root/src/extras
diff options
context:
space:
mode:
authorJean-Michaël Celerier <jean-michael.celerier@kdab.com>2020-04-17 15:32:58 +0200
committerJean-Michaël Celerier <jean-michael.celerier@kdab.com>2020-04-22 09:37:39 +0200
commitbc85979d57b61ded28439f09cd0641eb92e6b3ba (patch)
treed89fab21fb468c50cc24003781030aef59a4895a /src/extras
parent4d3cb0012c1c80520f87a8ca84b7f66484178a4e (diff)
rhi: Make Qt3DQuickWindow work with RHI
Change-Id: Ic9bb79e780006e49d1baa13fd15f52344b81c86b Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/extras')
-rw-r--r--src/extras/defaults/qt3dwindow.cpp161
-rw-r--r--src/extras/defaults/qt3dwindow.h3
2 files changed, 76 insertions, 88 deletions
diff --git a/src/extras/defaults/qt3dwindow.cpp b/src/extras/defaults/qt3dwindow.cpp
index fa48dba50..6d1ab8327 100644
--- a/src/extras/defaults/qt3dwindow.cpp
+++ b/src/extras/defaults/qt3dwindow.cpp
@@ -60,6 +60,7 @@
#include <Qt3DInput/qinputsettings.h>
#include <Qt3DLogic/qlogicaspect.h>
#include <Qt3DRender/qcamera.h>
+#include <Qt3DRender/private/vulkaninstance_p.h>
#include <qopenglcontext.h>
#include <private/qrendersettings_p.h>
@@ -105,95 +106,9 @@ Qt3DWindow::Qt3DWindow(QScreen *screen, Qt3DRender::API api)
if (!d->parentWindow)
d->connectToScreen(screen ? screen : d->topLevelScreen.data());
- // If the user pass an API through the environment, we use that over the one passed as argument.
- const auto userRequestedApi = qgetenv("QT3D_RHI_DEFAULT_API").toLower();
- if (!userRequestedApi.isEmpty()) {
- if (userRequestedApi == QByteArrayLiteral("opengl")) {
- api = Qt3DRender::API::OpenGL;
- } else if (userRequestedApi == QByteArrayLiteral("vulkan")) {
- api = Qt3DRender::API::Vulkan;
- } else if (userRequestedApi == QByteArrayLiteral("metal")) {
- api = Qt3DRender::API::Metal;
- } else if (userRequestedApi == QByteArrayLiteral("d3d11")) {
- api = Qt3DRender::API::DirectX;
- } else if (userRequestedApi == QByteArrayLiteral("null")) {
- api = Qt3DRender::API::Null;
- }
- }
-
- // We have to set the environment so that the backend is able to read it.
- // Qt6: FIXME
- switch (api)
- {
- case Qt3DRender::API::OpenGL:
- qputenv("QT3D_RHI_DEFAULT_API", "opengl");
- setSurfaceType(QSurface::OpenGLSurface);
- break;
- case Qt3DRender::API::DirectX:
- qputenv("QT3D_RHI_DEFAULT_API", "d3d11");
- setSurfaceType(QSurface::OpenGLSurface);
- break;
- case Qt3DRender::API::Null:
- qputenv("QT3D_RHI_DEFAULT_API", "null");
- setSurfaceType(QSurface::OpenGLSurface);
- break;
- case Qt3DRender::API::Metal:
- qputenv("QT3D_RHI_DEFAULT_API", "metal");
- setSurfaceType(QSurface::MetalSurface);
- break;
-#if QT_CONFIG(vulkan)
- case Qt3DRender::API::Vulkan:
- {
- static QVulkanInstance inst;
-#ifndef Q_OS_ANDROID
- inst.setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation");
-#else
- inst.setLayers(QByteArrayList()
- << "VK_LAYER_GOOGLE_threading"
- << "VK_LAYER_LUNARG_parameter_validation"
- << "VK_LAYER_LUNARG_object_tracker"
- << "VK_LAYER_LUNARG_core_validation"
- << "VK_LAYER_LUNARG_image"
- << "VK_LAYER_LUNARG_swapchain"
- << "VK_LAYER_GOOGLE_unique_objects");
-#endif
- inst.setExtensions(QByteArrayList()
- << "VK_KHR_get_physical_device_properties2");
- Q_ASSERT (inst.create());
- setVulkanInstance(&inst);
-
- qputenv("QT3D_RHI_DEFAULT_API", "vulkan");
- setSurfaceType(QSurface::VulkanSurface);
- break;
- }
-#endif
- default:
- break;
- }
-
+ setupWindowSurface(this, api);
resize(1024, 768);
-
- QSurfaceFormat format = QSurfaceFormat::defaultFormat();
-#ifdef QT_OPENGL_ES_2
- format.setRenderableType(QSurfaceFormat::OpenGLES);
-#else
- if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
- format.setVersion(4, 3);
- format.setProfile(QSurfaceFormat::CoreProfile);
- }
-#endif
- if (!userRequestedApi.isEmpty()) {
- // This is used for RHI
- format.setVersion(1, 0);
- }
-
- format.setDepthBufferSize(24);
- format.setSamples(4);
- format.setStencilBufferSize(8);
- setFormat(format);
- QSurfaceFormat::setDefaultFormat(format);
-
d->m_aspectEngine->registerAspect(d->m_renderAspect);
d->m_aspectEngine->registerAspect(d->m_inputAspect);
d->m_aspectEngine->registerAspect(d->m_logicAspect);
@@ -301,7 +216,6 @@ void Qt3DWindow::showEvent(QShowEvent *e)
d->m_initialized = true;
}
-
QWindow::showEvent(e);
}
@@ -331,6 +245,77 @@ bool Qt3DWindow::event(QEvent *e)
return QWindow::event(e);
}
+void setupWindowSurface(QWindow *window, Qt3DRender::API api) noexcept
+{
+ // If the user pass an API through the environment, we use that over the one passed as argument.
+ const auto userRequestedApi = qgetenv("QT3D_RHI_DEFAULT_API").toLower();
+ if (!userRequestedApi.isEmpty()) {
+ if (userRequestedApi == QByteArrayLiteral("opengl")) {
+ api = Qt3DRender::API::OpenGL;
+ } else if (userRequestedApi == QByteArrayLiteral("vulkan")) {
+ api = Qt3DRender::API::Vulkan;
+ } else if (userRequestedApi == QByteArrayLiteral("metal")) {
+ api = Qt3DRender::API::Metal;
+ } else if (userRequestedApi == QByteArrayLiteral("d3d11")) {
+ api = Qt3DRender::API::DirectX;
+ } else if (userRequestedApi == QByteArrayLiteral("null")) {
+ api = Qt3DRender::API::Null;
+ }
+ }
+
+ // We have to set the environment so that the backend is able to read it.
+ // Qt6: FIXME
+ switch (api)
+ {
+ case Qt3DRender::API::OpenGL:
+ qputenv("QT3D_RHI_DEFAULT_API", "opengl");
+ window->setSurfaceType(QSurface::OpenGLSurface);
+ break;
+ case Qt3DRender::API::DirectX:
+ qputenv("QT3D_RHI_DEFAULT_API", "d3d11");
+ window->setSurfaceType(QSurface::OpenGLSurface);
+ break;
+ case Qt3DRender::API::Null:
+ qputenv("QT3D_RHI_DEFAULT_API", "null");
+ window->setSurfaceType(QSurface::OpenGLSurface);
+ break;
+ case Qt3DRender::API::Metal:
+ qputenv("QT3D_RHI_DEFAULT_API", "metal");
+ window->setSurfaceType(QSurface::MetalSurface);
+ break;
+#if QT_CONFIG(vulkan)
+ case Qt3DRender::API::Vulkan:
+ {
+ qputenv("QT3D_RHI_DEFAULT_API", "vulkan");
+ window->setSurfaceType(QSurface::VulkanSurface);
+ window->setVulkanInstance(&Qt3DRender::staticVulkanInstance());
+ break;
+ }
+#endif
+ default:
+ break;
+ }
+ QSurfaceFormat format = QSurfaceFormat::defaultFormat();
+#ifdef QT_OPENGL_ES_2
+ format.setRenderableType(QSurfaceFormat::OpenGLES);
+#else
+ if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
+ format.setVersion(4, 3);
+ format.setProfile(QSurfaceFormat::CoreProfile);
+ }
+#endif
+ if (!userRequestedApi.isEmpty()) {
+ // This is used for RHI
+ format.setVersion(1, 0);
+ }
+
+ format.setDepthBufferSize(24);
+ format.setSamples(4);
+ format.setStencilBufferSize(8);
+ window->setFormat(format);
+ QSurfaceFormat::setDefaultFormat(format);
+}
+
} // Qt3DExtras
QT_END_NAMESPACE
diff --git a/src/extras/defaults/qt3dwindow.h b/src/extras/defaults/qt3dwindow.h
index 0d277e119..c982746a8 100644
--- a/src/extras/defaults/qt3dwindow.h
+++ b/src/extras/defaults/qt3dwindow.h
@@ -119,6 +119,9 @@ private:
Q_DECLARE_PRIVATE(Qt3DWindow)
};
+Q_3DEXTRASSHARED_EXPORT
+void setupWindowSurface(QWindow* window, Qt3DRender::API) noexcept;
+
} // Qt3DExtras
QT_END_NAMESPACE