diff options
24 files changed, 78 insertions, 39 deletions
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp index f1fe397462..e40c509829 100644 --- a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp +++ b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp @@ -61,7 +61,7 @@ int main(int argc, char **argv) QApplication app(argc, argv); // this example and QQuickWidget are only functional when rendering with OpenGL - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); QCoreApplication::setApplicationName("Qt QQuickView/QQuickWidget Comparison Example"); QCoreApplication::setOrganizationName("QtProject"); diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp index 3bff5901f9..1c8b21f790 100644 --- a/examples/quick/quickwidgets/quickwidget/main.cpp +++ b/examples/quick/quickwidgets/quickwidget/main.cpp @@ -198,7 +198,7 @@ int main(int argc, char **argv) QApplication app(argc, argv); // this example and QQuickWidget are only functional when rendering with OpenGL - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); QCoreApplication::setApplicationName("Qt QQuickWidget Example"); QCoreApplication::setOrganizationName("QtProject"); diff --git a/examples/quick/rendercontrol/rendercontrol_d3d11/main.cpp b/examples/quick/rendercontrol/rendercontrol_d3d11/main.cpp index f9a1dbb75f..119b289500 100644 --- a/examples/quick/rendercontrol/rendercontrol_d3d11/main.cpp +++ b/examples/quick/rendercontrol/rendercontrol_d3d11/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char **argv) QCoreApplication::setApplicationVersion(QT_VERSION_STR); // only functional when Qt Quick is also using D3D11 - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D11Rhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11Rhi); Engine engine; if (!engine.create()) diff --git a/examples/quick/rendercontrol/rendercontrol_d3d11/window.cpp b/examples/quick/rendercontrol/rendercontrol_d3d11/window.cpp index ccbac5cbed..c574343a98 100644 --- a/examples/quick/rendercontrol/rendercontrol_d3d11/window.cpp +++ b/examples/quick/rendercontrol/rendercontrol_d3d11/window.cpp @@ -358,7 +358,7 @@ void Window::updateQuick() m_quickDirty = false; if (!m_quickInitialized) { - // In addition to setSceneGraphBackend, we need a call to + // In addition to setGraphicsApi(), we need a call to // setGraphicsDevice to tell Qt Quick what ID3D11Device(Context) to use // (i.e. we want it to use ours, not to create new ones). m_quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromDeviceAndContext(m_engine->device(), m_engine->context())); diff --git a/examples/quick/rendercontrol/rendercontrol_opengl/main.cpp b/examples/quick/rendercontrol/rendercontrol_opengl/main.cpp index 7a24d70ec5..11db82773b 100644 --- a/examples/quick/rendercontrol/rendercontrol_opengl/main.cpp +++ b/examples/quick/rendercontrol/rendercontrol_opengl/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char **argv) QGuiApplication app(argc, argv); // only functional when Qt Quick is also using OpenGL - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); WindowSingleThreaded window; window.resize(1024, 768); diff --git a/examples/quick/scenegraph/d3d11underqml/main.cpp b/examples/quick/scenegraph/d3d11underqml/main.cpp index bcefae6cb5..f2a224c1a2 100644 --- a/examples/quick/scenegraph/d3d11underqml/main.cpp +++ b/examples/quick/scenegraph/d3d11underqml/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D11Rhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11Rhi); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/fboitem/main.cpp b/examples/quick/scenegraph/fboitem/main.cpp index 5c4620c5b7..61510cdb93 100644 --- a/examples/quick/scenegraph/fboitem/main.cpp +++ b/examples/quick/scenegraph/fboitem/main.cpp @@ -58,7 +58,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/metaltextureimport/main.cpp b/examples/quick/scenegraph/metaltextureimport/main.cpp index 4fc010e710..2abc1c5671 100644 --- a/examples/quick/scenegraph/metaltextureimport/main.cpp +++ b/examples/quick/scenegraph/metaltextureimport/main.cpp @@ -54,7 +54,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/metalunderqml/main.cpp b/examples/quick/scenegraph/metalunderqml/main.cpp index cefb1c10a9..4a657a6bf4 100644 --- a/examples/quick/scenegraph/metalunderqml/main.cpp +++ b/examples/quick/scenegraph/metalunderqml/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/openglunderqml/main.cpp b/examples/quick/scenegraph/openglunderqml/main.cpp index c151af179e..d92cbb2d80 100644 --- a/examples/quick/scenegraph/openglunderqml/main.cpp +++ b/examples/quick/scenegraph/openglunderqml/main.cpp @@ -59,7 +59,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/vulkantextureimport/main.cpp b/examples/quick/scenegraph/vulkantextureimport/main.cpp index 5dc28eb8a3..d2eb5184dc 100644 --- a/examples/quick/scenegraph/vulkantextureimport/main.cpp +++ b/examples/quick/scenegraph/vulkantextureimport/main.cpp @@ -55,7 +55,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/vulkanunderqml/main.cpp b/examples/quick/scenegraph/vulkanunderqml/main.cpp index 6ed0efacdd..e4a3f36ca7 100644 --- a/examples/quick/scenegraph/vulkanunderqml/main.cpp +++ b/examples/quick/scenegraph/vulkanunderqml/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char **argv) QGuiApplication app(argc, argv); // This example needs Vulkan. It will not run otherwise. - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc b/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc index d07885e6ad..e330806c85 100644 --- a/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc +++ b/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc @@ -59,7 +59,7 @@ is always built-in. As of Qt 6.0 it is always enabled. On platforms where multiple graphics APIs are available, the scenegraph makes a platform-specific choice. If this is not desired, applications can force a specified graphics API by setting the environment variable \c{QSG_RHI_BACKEND} or via \l -QQuickWindow::setSceneGraphBackend() in combination with \l +QQuickWindow::setGraphicsApi() in combination with \l QSGRendererInterface::GraphicsApi. Switching to a different adaptation can be achieved in two ways: @@ -74,7 +74,7 @@ Switching to a different adaptation can be achieved in two ways: The following backends are supported: \list - \li Default - Request with the \c{""} string or a QSGRendererInterface::GraphicsApi enum value + \li Default - Request with the \c{"rhi"} string or a QSGRendererInterface::GraphicsApi enum value different than the ones listed below. \li Software - Request with the \c{"software"} string or the QSGRendererInterface::Software enum value. diff --git a/src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc b/src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc index b06c972ddf..a3022f0e2b 100644 --- a/src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc +++ b/src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc @@ -1020,7 +1020,7 @@ with multiple windows. will fail otherwise); \badcode - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi); \endcode See QSGRendererInterface::GraphicsApi. The enum values ending in \c Rhi are diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp index c2adc2ef10..75472c3e6e 100644 --- a/src/quick/items/qquickrendercontrol.cpp +++ b/src/quick/items/qquickrendercontrol.cpp @@ -262,7 +262,7 @@ int QQuickRenderControl::samples() const QQuickRenderControl exists. To control what graphics API Qt Quick uses, call - QQuickWindow::setSceneGraphBackend() with one of the + QQuickWindow::setGraphicsApi() with one of the QSGRendererInterface:GraphicsApi constants. That must be done before calling this function. diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 2cf3e09c5d..5c7c39edf6 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -4239,7 +4239,7 @@ bool QQuickWindow::isSceneGraphInitialized() const \since 6.0 - \sa QQuickRenderControl, setGraphicsDevice(), setSceneGraphBackend() + \sa QQuickRenderControl, setGraphicsDevice(), setGraphicsApi() */ void QQuickWindow::setRenderTarget(const QQuickRenderTarget &target) { @@ -5567,39 +5567,74 @@ QSGRendererInterface *QQuickWindow::rendererInterface() const } /*! - Requests the specified scene graph or RHI \a backend. Backends can either be - built-in or be installed in form of dynamically loaded plugins. When the - built-in, default graphics adaptation is used, \a backend specifies which - graphics API (OpenGL, Vulkan, Metal, or Direct3D) the scene graph should use - to render. In addition, the \c software backend is built-in as well, and can - be requested by setting \a api to QSGRendererInterface::Software. + Requests the specified graphics \a api. + + When the built-in, default graphics adaptation is used, \a api specifies + which graphics API (OpenGL, Vulkan, Metal, or Direct3D) the scene graph + should use to render. In addition, the \c software backend is built-in as + well, and can be requested by setting \a api to + QSGRendererInterface::Software. + + Unlike setSceneGraphBackend(), which can only be used to request a given + backend (shipped either built-in or installed as dynamically loaded + plugins), this function works with the higher level concept of graphics + APIs. It covers the backends that ship with Qt Quick, and thus have + corresponding values in the QSGRendererInterface::GraphicsApi enum. + + When this function is not called at all, and the equivalent environment + variable \c{QSG_RHI_BACKEND} is not set either, the scene graph will choose + the graphics API to use based on the platform. + + This function becomes important in applications that are only prepared for + rendering with a given API. For example, if there is native OpenGL or + Vulkan rendering done by the application, it will want to ensure Qt Quick + is rendering using OpenGL or Vulkan too. Such applications are expected to + call this function early in their main() function. \note The call to the function must happen before constructing the first QQuickWindow in the application. The graphics API cannot be changed - afterwards. When used in combination with QQuickRenderControl, this rule is + afterwards. + + \note When used in combination with QQuickRenderControl, this rule is relaxed: it is possible to change the graphics API, but only when all existing QQuickRenderControl and QQuickWindow instances have been destroyed. + To query what graphics API the scene graph is using to render, + QSGRendererInterface::graphicsApi() after the scene graph + \l{QQuickWindow::isSceneGraphInitialized()}{has initialized}, which + typically happens either when the window becomes visible for the first time, or + when QQuickRenderControl::initialize() is called. + + To switch back to the default behavior, where the scene graph chooses a + graphics API based on the platform and other conditions, set \a api to + QSGRendererInterface::Unknown. + \since 5.8 */ -void QQuickWindow::setSceneGraphBackend(QSGRendererInterface::GraphicsApi api) +void QQuickWindow::setGraphicsApi(QSGRendererInterface::GraphicsApi api) { + // Special cases: these are different scenegraph backends. switch (api) { case QSGRendererInterface::Software: setSceneGraphBackend(QStringLiteral("software")); break; + case QSGRendererInterface::OpenVG: + setSceneGraphBackend(QStringLiteral("openvg")); + break; default: break; } + + // Standard case: tell the QRhi-based default adaptation what graphics api + // (QRhi backend) to use. if (QSGRendererInterface::isApiRhiBased(api) || api == QSGRendererInterface::Unknown) QSGRhiSupport::configure(api); } /*! - Requests a Qt Quick scenegraph backend for the specified graphics \a api. - Backends can either be built-in or be installed in form of dynamically - loaded plugins. + Requests a Qt Quick scenegraph \a backend. Backends can either be built-in + or be installed in form of dynamically loaded plugins. \overload @@ -5627,6 +5662,9 @@ void QQuickWindow::setSceneGraphBackend(const QString &backend) subsequent calls to setSceneGraphBackend() until the first QQuickWindow in the application has been constructed. + \note The value only reflects the request in the \c{QT_QUICK_BACKEND} + environment variable after a QQuickWindow has been constructed. + \since 5.9 */ QString QQuickWindow::sceneGraphBackend() @@ -5695,7 +5733,7 @@ QString QQuickWindow::sceneGraphBackend() \since 6.0 - \sa QQuickRenderControl, setRenderTarget(), setSceneGraphBackend() + \sa QQuickRenderControl, setRenderTarget(), setGraphicsApi() */ void QQuickWindow::setGraphicsDevice(const QQuickGraphicsDevice &device) { diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h index fd4fb28cbe..3a908e94f0 100644 --- a/src/quick/items/qquickwindow.h +++ b/src/quick/items/qquickwindow.h @@ -182,7 +182,8 @@ public: QSGRendererInterface *rendererInterface() const; - static void setSceneGraphBackend(QSGRendererInterface::GraphicsApi api); + static void setGraphicsApi(QSGRendererInterface::GraphicsApi api); + static void setSceneGraphBackend(const QString &backend); static QString sceneGraphBackend(); diff --git a/src/quick/scenegraph/qsgrhisupport.cpp b/src/quick/scenegraph/qsgrhisupport.cpp index 4ba0cca65e..5029103cff 100644 --- a/src/quick/scenegraph/qsgrhisupport.cpp +++ b/src/quick/scenegraph/qsgrhisupport.cpp @@ -120,7 +120,7 @@ void QSGRhiSupport::applySettings() m_settingsApplied = true; // This is also done when creating the renderloop but we may be before that - // in case we get here due to a setScenegraphBackend() -> configure() early + // in case we get here due to a setGraphicsApi() -> configure() early // on in main(). Avoid losing info logs since troubleshooting gets // confusing otherwise. QSGRhiSupport::checkEnvQSgInfo(); diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 2da5e21fb8..04c321d0a5 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -140,7 +140,7 @@ void QQuickWidgetPrivate::init(QQmlEngine* e) } if (QSGRhiSupport::instance()->rhiBackend() != QRhi::OpenGLES2) - qWarning("QQuickWidget is only supported on OpenGL. Use QQuickWindow::setSceneGraphBackend() to override the default."); + qWarning("QQuickWidget is only supported on OpenGL. Use QQuickWindow::setGraphicsApi() to override the default."); engine = e; diff --git a/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp b/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp index 17c8f9ba12..5e7ab02537 100644 --- a/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp +++ b/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp @@ -154,7 +154,7 @@ private slots: void tst_QQuickFramebufferObject::initTestCase() { QQmlDataTest::initTestCase(); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); } void tst_QQuickFramebufferObject::testThatStuffWorks_data() diff --git a/tests/auto/quick/qquickrendercontrol/tst_qquickrendercontrol.cpp b/tests/auto/quick/qquickrendercontrol/tst_qquickrendercontrol.cpp index 7e8fcbfcf1..a2217f5427 100644 --- a/tests/auto/quick/qquickrendercontrol/tst_qquickrendercontrol.cpp +++ b/tests/auto/quick/qquickrendercontrol/tst_qquickrendercontrol.cpp @@ -147,7 +147,7 @@ void tst_RenderControl::renderAndReadBackWithRhi() // QQuickRenderControl, etc. instances are destroyed, before creating new // ones. That's why it is possible to have this test run with multiple QRhi // backends. - QQuickWindow::setSceneGraphBackend(api); + QQuickWindow::setGraphicsApi(api); QScopedPointer<QQuickRenderControl> renderControl(new QQuickRenderControl); QScopedPointer<QQuickWindow> quickWindow(new QQuickWindow(renderControl.data())); @@ -316,7 +316,7 @@ void tst_RenderControl::renderAndReadBackWithVulkanNative() if (!vulkanInstance.isValid()) QSKIP("Skipping native Vulkan test due to failing to create a VkInstance"); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi); // We will create our own VkDevice and friends, which will then get used by // Qt Quick as well (instead of creating its own objects), so this is a test diff --git a/tests/auto/quick/qquickshape/tst_qquickshape.cpp b/tests/auto/quick/qquickshape/tst_qquickshape.cpp index 578d8d4e3a..3a26f7e382 100644 --- a/tests/auto/quick/qquickshape/tst_qquickshape.cpp +++ b/tests/auto/quick/qquickshape/tst_qquickshape.cpp @@ -95,7 +95,7 @@ private: tst_QQuickShape::tst_QQuickShape() { // Force the software backend to get reliable rendering results regardless of the hw and drivers. - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Software); const char *uri = "tst_qquickpathitem"; qmlRegisterType<QQuickShape>(uri, 1, 0, "Shape"); diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 91a898d834..c957d2d702 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -3741,7 +3741,7 @@ void tst_qquickwindow::rendererInterfaceWithRenderControl() // QQuickRenderControl, etc. instances are destroyed, before creating new // ones. That's why it is possible to have this test run with multiple QRhi // backends. - QQuickWindow::setSceneGraphBackend(api); + QQuickWindow::setGraphicsApi(api); QScopedPointer<QQuickRenderControl> renderControl(new QQuickRenderControl); QScopedPointer<QQuickWindow> quickWindow(new QQuickWindow(renderControl.data())); @@ -3911,7 +3911,7 @@ void tst_qquickwindow::rendererInterfaceWithRenderControl() // Now that everything is torn down, go back to the default unspecified-api // state, to prevent conflicting with tests that come afterwards. - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Unknown); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Unknown); } QTEST_MAIN(tst_qquickwindow) diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp index b47837179a..3f67006554 100644 --- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp +++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp @@ -152,7 +152,7 @@ private: tst_qquickwidget::tst_qquickwidget() { - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); } void tst_qquickwidget::showHide() |