diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2024-03-08 11:45:46 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2024-03-11 10:04:17 +0100 |
commit | 18c2e2512b1256677ec09f8ac469f34ed30ce2f8 (patch) | |
tree | 828be34a15b7240cdd96554df5db21040e659659 /tests/auto/quick/scenegraph/tst_scenegraph.cpp | |
parent | 4aeb72dc8414e55a76d7a8e7421a29ec1aa6cabb (diff) |
Make the QSGTexture native accessor query work on macOS/iOS
Also add an autotest.
Pick-to: 6.7 6.6 6.5
Fixes: QTBUG-108019
Change-Id: Ie809041019b0a1b842791994e42d9d75578eb350
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'tests/auto/quick/scenegraph/tst_scenegraph.cpp')
-rw-r--r-- | tests/auto/quick/scenegraph/tst_scenegraph.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index 02c9d49796..aa275f8bfc 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -96,6 +96,7 @@ private slots: void createTextureFromImage(); void withAdoptedRhi(); void resizeTextureFromImage(); + void textureNativeInterface(); private: QQuickView *createView(const QString &file, QWindow *parent = nullptr, int x = -1, int y = -1, int w = -1, int h = -1); @@ -783,6 +784,59 @@ void tst_SceneGraph::resizeTextureFromImage() TestOffscreenScene::cleanup(); } +void tst_SceneGraph::textureNativeInterface() +{ + if (!isRunningOnRhi()) + QSKIP("Skipping texture native interface tests due to not running with QRhi"); + + // test it offscreen because we want to do QSG stuff here on the main thread + QScopedPointer<TestOffscreenScene> scene(createOffscreenScene(testFileUrl(QLatin1String("renderControl_rect.qml")))); + QVERIFY(scene->renderControl && scene->window && scene->rootItem); + + QImage image(512, 512, QImage::Format_RGBA8888); + + QScopedPointer<QSGTexture> texture(scene->window->createTextureFromImage(image, QQuickWindow::TextureHasAlphaChannel)); + QVERIFY(texture.data()); + + commitTexture(scene->window->rhi(), texture.data()); + +#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) + if (scene->window->graphicsApi() == QSGRendererInterface::Metal) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGMetalTexture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if defined(Q_OS_WIN) + if (scene->window->graphicsApi() == QSGRendererInterface::Direct3D11) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGD3D11Texture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } else if (scene->window->graphicsApi() == QSGRendererInterface::Direct3D12) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGD3D12Texture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if QT_CONFIG(opengl) + if (scene->window->graphicsApi() == QSGRendererInterface::OpenGL) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGOpenGLTexture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeTexture()); + } +#endif + +#if QT_CONFIG(vulkan) + if (scene->window->graphicsApi() == QSGRendererInterface::Vulkan) { + auto texNatIf = texture->nativeInterface<QNativeInterface::QSGVulkanTexture>(); + QVERIFY(texNatIf); + QVERIFY(texNatIf->nativeImage()); + } +#endif +} + bool tst_SceneGraph::isRunningOnRhi() { static bool retval = false; |