aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickitemrhiintegration
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquickitemrhiintegration')
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/BLACKLIST3
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/CMakeLists.txt46
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/data/test.qml38
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/rhiitem.cpp352
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/rhiitem.h75
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/rhiitem_p.h60
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/testrhiitem.cpp162
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/testrhiitem.h61
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/texture.frag18
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/texture.vert19
-rw-r--r--tests/auto/quick/qquickitemrhiintegration/tst_qquickitemrhiintegration.cpp77
11 files changed, 0 insertions, 911 deletions
diff --git a/tests/auto/quick/qquickitemrhiintegration/BLACKLIST b/tests/auto/quick/qquickitemrhiintegration/BLACKLIST
deleted file mode 100644
index 03e5bc8c1d..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/BLACKLIST
+++ /dev/null
@@ -1,3 +0,0 @@
-# QTBUG-102721
-[rhiItem]
-android
diff --git a/tests/auto/quick/qquickitemrhiintegration/CMakeLists.txt b/tests/auto/quick/qquickitemrhiintegration/CMakeLists.txt
deleted file mode 100644
index 8f918dd753..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/CMakeLists.txt
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-# Collect test data
-file(GLOB_RECURSE test_data_glob
- RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- data/*)
-list(APPEND test_data ${test_data_glob})
-
-qt_internal_add_test(tst_qquickitemrhiintegration
- SOURCES
- tst_qquickitemrhiintegration.cpp
- rhiitem.cpp rhiitem.h rhiitem_p.h
- testrhiitem.cpp testrhiitem.h
- LIBRARIES
- Qt::CorePrivate
- Qt::Gui
- Qt::GuiPrivate
- Qt::QmlPrivate
- Qt::QuickPrivate
- Qt::QuickTestUtilsPrivate
- TESTDATA ${test_data}
-)
-
-qt_internal_extend_target(tst_qquickitemrhiintegration CONDITION ANDROID OR IOS
- DEFINES
- QT_QMLTEST_DATADIR=":/data"
-)
-
-qt_internal_extend_target(tst_qquickitemrhiintegration CONDITION NOT ANDROID AND NOT IOS
- DEFINES
- QT_QMLTEST_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/data"
-)
-
-qt_internal_add_shaders(tst_qquickitemrhiintegration "shaders"
- PREFIX
- "/"
- FILES
- "texture.vert"
- "texture.frag"
-)
-
-qt_add_qml_module(tst_qquickitemrhiintegration
- URI TestQquickitemrhiintegration
- AUTO_RESOURCE_PREFIX
-)
diff --git a/tests/auto/quick/qquickitemrhiintegration/data/test.qml b/tests/auto/quick/qquickitemrhiintegration/data/test.qml
deleted file mode 100644
index 8ffbe0d6ed..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/data/test.qml
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-import QtQuick
-import TestQquickitemrhiintegration
-
-Item {
- width: 640
- height: 480
-
- Text {
- id: apiInfo
- color: "black"
- font.pixelSize: 16
- property int api: GraphicsInfo.api
- text: {
- if (GraphicsInfo.api === GraphicsInfo.OpenGLRhi)
- "OpenGL on QRhi";
- else if (GraphicsInfo.api === GraphicsInfo.Direct3D11Rhi)
- "D3D11 on QRhi";
- else if (GraphicsInfo.api === GraphicsInfo.VulkanRhi)
- "Vulkan on QRhi";
- else if (GraphicsInfo.api === GraphicsInfo.MetalRhi)
- "Metal on QRhi";
- else if (GraphicsInfo.api === GraphicsInfo.Null)
- "Null on QRhi";
- else
- "Unknown API";
- }
- }
-
- TestRhiItem {
- anchors.centerIn: parent
- width: 400
- height: 400
- color: "red"
- }
-}
diff --git a/tests/auto/quick/qquickitemrhiintegration/rhiitem.cpp b/tests/auto/quick/qquickitemrhiintegration/rhiitem.cpp
deleted file mode 100644
index bcc1f2f6a3..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/rhiitem.cpp
+++ /dev/null
@@ -1,352 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "rhiitem_p.h"
-
-RhiItemNode::RhiItemNode(RhiItem *item)
- : m_item(item)
-{
- m_window = m_item->window();
- Q_ASSERT(m_window);
- connect(m_window, &QQuickWindow::beforeRendering, this, &RhiItemNode::render);
- connect(m_window, &QQuickWindow::screenChanged, this, [this]() {
- if (m_window->effectiveDevicePixelRatio() != m_dpr)
- m_item->update();
- });
-}
-
-RhiItemNode::~RhiItemNode()
-{
- delete m_renderer;
- delete m_sgWrapperTexture;
- releaseNativeTexture();
-}
-
-QSGTexture *RhiItemNode::texture() const
-{
- return m_sgWrapperTexture;
-}
-
-void RhiItemNode::createNativeTexture()
-{
- Q_ASSERT(!m_texture);
- Q_ASSERT(!m_pixelSize.isEmpty());
-
- m_texture = m_rhi->newTexture(QRhiTexture::RGBA8, m_pixelSize, 1, QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
- if (!m_texture->create()) {
- qWarning("Failed to create RhiItem texture of size %dx%d", m_pixelSize.width(), m_pixelSize.height());
- delete m_texture;
- m_texture = nullptr;
- }
-}
-
-void RhiItemNode::releaseNativeTexture()
-{
- if (m_texture) {
- m_texture->deleteLater();
- m_texture = nullptr;
- }
-}
-
-void RhiItemNode::sync()
-{
- if (!m_rhi) {
- QSGRendererInterface *rif = m_window->rendererInterface();
- m_rhi = static_cast<QRhi *>(rif->getResource(m_window, QSGRendererInterface::RhiResource));
- if (!m_rhi) {
- qWarning("No QRhi found for window %p, RhiItem will not be functional", m_window);
- return;
- }
- }
-
- QSize newSize(m_item->explicitTextureWidth(), m_item->explicitTextureHeight());
- if (newSize.isEmpty()) {
- m_dpr = m_window->effectiveDevicePixelRatio();
- const int minTexSize = m_rhi->resourceLimit(QRhi::TextureSizeMin);
- newSize = QSize(qMax<int>(minTexSize, m_item->width()),
- qMax<int>(minTexSize, m_item->height())) * m_dpr;
- }
-
- bool needsNew = !m_sgWrapperTexture;
- if (newSize != m_pixelSize) {
- needsNew = true;
- m_pixelSize = newSize;
- }
-
- if (needsNew) {
- if (m_texture && m_sgWrapperTexture) {
- m_texture->setPixelSize(m_pixelSize);
- if (m_texture->create())
- m_sgWrapperTexture->setTextureSize(m_pixelSize);
- else
- qWarning("Failed to recreate RhiItem texture of size %dx%d", m_pixelSize.width(), m_pixelSize.height());
- } else {
- delete m_sgWrapperTexture;
- m_sgWrapperTexture = nullptr;
- releaseNativeTexture();
- createNativeTexture();
- if (m_texture) {
- m_sgWrapperTexture = new QSGPlainTexture;
- m_sgWrapperTexture->setOwnsTexture(false);
- m_sgWrapperTexture->setTexture(m_texture);
- m_sgWrapperTexture->setTextureSize(m_pixelSize);
- m_sgWrapperTexture->setHasAlphaChannel(m_item->alphaBlending());
- setTexture(m_sgWrapperTexture);
- }
- }
- RhiItemPrivate::get(m_item)->effectiveTextureSize = m_pixelSize;
- emit m_item->effectiveTextureSizeChanged();
- if (m_texture)
- m_renderer->initialize(m_rhi, m_texture);
- }
-
- if (m_sgWrapperTexture && m_sgWrapperTexture->hasAlphaChannel() != m_item->alphaBlending()) {
- m_sgWrapperTexture->setHasAlphaChannel(m_item->alphaBlending());
- // hasAlphaChannel is mapped to QSGMaterial::Blending in setTexture() so that has to be called again
- setTexture(m_sgWrapperTexture);
- }
-
- m_renderer->synchronize(m_item);
-}
-
-void RhiItemNode::render()
-{
- // called before Qt Quick starts recording its main render pass
-
- if (!m_rhi || !m_texture || !m_renderer)
- return;
-
- if (!m_renderPending)
- return;
-
- QSGRendererInterface *rif = m_window->rendererInterface();
- QRhiCommandBuffer *cb = nullptr;
- QRhiSwapChain *swapchain = static_cast<QRhiSwapChain *>(
- rif->getResource(m_window, QSGRendererInterface::RhiSwapchainResource));
- cb = swapchain ? swapchain->currentFrameCommandBuffer()
- : static_cast<QRhiCommandBuffer *>(rif->getResource(m_window, QSGRendererInterface::RhiRedirectCommandBuffer));
- if (!cb) {
- qWarning("Neither swapchain nor redirected command buffer are available.");
- return;
- }
-
- m_renderPending = false;
- m_renderer->render(cb);
-
- markDirty(QSGNode::DirtyMaterial);
- emit textureChanged();
-}
-
-void RhiItemNode::scheduleUpdate()
-{
- m_renderPending = true;
- m_window->update(); // ensure getting to beforeRendering() at some point
-}
-
-void RhiItemNode::setMirrorVertically(bool b)
-{
- if (m_rhi->isYUpInFramebuffer())
- b = !b;
-
- setTextureCoordinatesTransform(b ? QSGSimpleTextureNode::MirrorVertically : QSGSimpleTextureNode::NoTransform);
-}
-
-RhiItem::RhiItem(QQuickItem *parent)
- : QQuickItem(*new RhiItemPrivate, parent)
-{
- setFlag(ItemHasContents);
-}
-
-QSGNode *RhiItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *)
-{
- Q_D(RhiItem);
- RhiItemNode *n = static_cast<RhiItemNode *>(node);
-
- // Changing to an empty size should not involve destroying and then later
- // recreating the node, because we do not know how expensive the user's
- // renderer setup is. Rather, keep the node if it already exist, and clamp
- // all accesses to width and height. Hence the unusual !n condition here.
- if (!n && (width() <= 0 || height() <= 0))
- return nullptr;
-
- if (!n) {
- if (!d->node)
- d->node = new RhiItemNode(this);
- n = d->node;
- }
-
- if (!n->hasRenderer()) {
- RhiItemRenderer *r = createRenderer();
- if (r) {
- r->data = n;
- n->setRenderer(r);
- } else {
- qWarning("No RhiItemRenderer was created; the item will not render");
- delete n;
- d->node = nullptr;
- return nullptr;
- }
- }
-
- n->sync();
-
- if (!n->isValid()) {
- delete n;
- d->node = nullptr;
- return nullptr;
- }
-
- n->setMirrorVertically(d->mirrorVertically);
- n->setFiltering(QSGTexture::Linear);
- n->setRect(0, 0, qMax<int>(0, width()), qMax<int>(0, height()));
-
- n->scheduleUpdate();
-
- return n;
-}
-
-void RhiItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
-{
- QQuickItem::geometryChange(newGeometry, oldGeometry);
- if (newGeometry.size() != oldGeometry.size())
- update();
-}
-
-void RhiItem::releaseResources()
-{
- // called on the gui thread if the item is removed from scene
-
- Q_D(RhiItem);
- d->node = nullptr;
-}
-
-void RhiItem::invalidateSceneGraph()
-{
- // called on the render thread when the scenegraph is invalidated
-
- Q_D(RhiItem);
- d->node = nullptr;
-}
-
-bool RhiItem::isTextureProvider() const
-{
- return true;
-}
-
-QSGTextureProvider *RhiItem::textureProvider() const
-{
- if (QQuickItem::isTextureProvider()) // e.g. if Item::layer::enabled == true
- return QQuickItem::textureProvider();
-
- QQuickWindow *w = window();
- if (!w || !w->isSceneGraphInitialized() || QThread::currentThread() != QQuickWindowPrivate::get(w)->context->thread()) {
- qWarning("RhiItem::textureProvider: can only be queried on the rendering thread of an exposed window");
- return nullptr;
- }
-
- Q_D(const RhiItem);
- if (!d->node) // create a node to have a provider, the texture will be null but that's ok
- d->node = new RhiItemNode(const_cast<RhiItem *>(this));
-
- return d->node;
-}
-
-int RhiItem::explicitTextureWidth() const
-{
- Q_D(const RhiItem);
- return d->explicitTextureWidth;
-}
-
-void RhiItem::setExplicitTextureWidth(int w)
-{
- Q_D(RhiItem);
- if (d->explicitTextureWidth == w)
- return;
-
- d->explicitTextureWidth = w;
- emit explicitTextureWidthChanged();
- update();
-}
-
-int RhiItem::explicitTextureHeight() const
-{
- Q_D(const RhiItem);
- return d->explicitTextureHeight;
-}
-
-void RhiItem::setExplicitTextureHeight(int h)
-{
- Q_D(RhiItem);
- if (d->explicitTextureHeight == h)
- return;
-
- d->explicitTextureHeight = h;
- emit explicitTextureHeightChanged();
- update();
-}
-
-QSize RhiItem::effectiveTextureSize() const
-{
- Q_D(const RhiItem);
- return d->effectiveTextureSize;
-}
-
-bool RhiItem::alphaBlending() const
-{
- Q_D(const RhiItem);
- return d->blend;
-}
-
-void RhiItem::setAlphaBlending(bool enable)
-{
- Q_D(RhiItem);
- if (d->blend == enable)
- return;
-
- d->blend = enable;
- emit alphaBlendingChanged();
- update();
-}
-
-bool RhiItem::mirrorVertically() const
-{
- Q_D(const RhiItem);
- return d->mirrorVertically;
-}
-
-void RhiItem::setMirrorVertically(bool enable)
-{
- Q_D(RhiItem);
- if (d->mirrorVertically == enable)
- return;
-
- d->mirrorVertically = enable;
- emit mirrorVerticallyChanged();
- update();
-}
-
-void RhiItemRenderer::update()
-{
- if (data)
- static_cast<RhiItemNode *>(data)->scheduleUpdate();
-}
-
-RhiItemRenderer::~RhiItemRenderer()
-{
-}
-
-void RhiItemRenderer::initialize(QRhi *rhi, QRhiTexture *outputTexture)
-{
- Q_UNUSED(rhi);
- Q_UNUSED(outputTexture);
-}
-
-void RhiItemRenderer::synchronize(RhiItem *item)
-{
- Q_UNUSED(item);
-}
-
-void RhiItemRenderer::render(QRhiCommandBuffer *cb)
-{
- Q_UNUSED(cb);
-}
diff --git a/tests/auto/quick/qquickitemrhiintegration/rhiitem.h b/tests/auto/quick/qquickitemrhiintegration/rhiitem.h
deleted file mode 100644
index 6439bfba4a..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/rhiitem.h
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#ifndef RHIITEM_H
-#define RHIITEM_H
-
-#include <QQuickItem>
-#include <QtGui/private/qrhi_p.h>
-
-class RhiItem;
-class RhiItemPrivate;
-
-class RhiItemRenderer
-{
-public:
- virtual ~RhiItemRenderer();
- virtual void initialize(QRhi *rhi, QRhiTexture *outputTexture);
- virtual void synchronize(RhiItem *item);
- virtual void render(QRhiCommandBuffer *cb);
-
- void update();
-
-private:
- void *data;
- friend class RhiItem;
-};
-
-class RhiItem : public QQuickItem
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(RhiItem)
-
- Q_PROPERTY(int explicitTextureWidth READ explicitTextureWidth WRITE setExplicitTextureWidth NOTIFY explicitTextureWidthChanged)
- Q_PROPERTY(int explicitTextureHeight READ explicitTextureHeight WRITE setExplicitTextureHeight NOTIFY explicitTextureHeightChanged)
- Q_PROPERTY(QSize effectiveTextureSize READ effectiveTextureSize NOTIFY effectiveTextureSizeChanged)
- Q_PROPERTY(bool alphaBlending READ alphaBlending WRITE setAlphaBlending NOTIFY alphaBlendingChanged)
- Q_PROPERTY(bool mirrorVertically READ mirrorVertically WRITE setMirrorVertically NOTIFY mirrorVerticallyChanged)
-
-public:
- RhiItem(QQuickItem *parent = nullptr);
-
- virtual RhiItemRenderer *createRenderer() = 0;
-
- int explicitTextureWidth() const;
- void setExplicitTextureWidth(int w);
- int explicitTextureHeight() const;
- void setExplicitTextureHeight(int h);
-
- QSize effectiveTextureSize() const;
-
- bool alphaBlending() const;
- void setAlphaBlending(bool enable);
-
- bool mirrorVertically() const;
- void setMirrorVertically(bool enable);
-
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
- void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
- void releaseResources() override;
- bool isTextureProvider() const override;
- QSGTextureProvider *textureProvider() const override;
-
-Q_SIGNALS:
- void explicitTextureWidthChanged();
- void explicitTextureHeightChanged();
- void effectiveTextureSizeChanged();
- void alphaBlendingChanged();
- void mirrorVerticallyChanged();
-
-private Q_SLOTS:
- void invalidateSceneGraph();
-};
-
-#endif
diff --git a/tests/auto/quick/qquickitemrhiintegration/rhiitem_p.h b/tests/auto/quick/qquickitemrhiintegration/rhiitem_p.h
deleted file mode 100644
index 5fe2de8de0..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/rhiitem_p.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#ifndef RHIITEM_P_H
-#define RHIITEM_P_H
-
-#include "rhiitem.h"
-#include <QSGSimpleTextureNode>
-#include <QtQuick/private/qquickitem_p.h>
-#include <QtQuick/private/qsgplaintexture_p.h>
-
-class RhiItemNode : public QSGTextureProvider, public QSGSimpleTextureNode
-{
- Q_OBJECT
-
-public:
- RhiItemNode(RhiItem *item);
- ~RhiItemNode();
-
- QSGTexture *texture() const override;
-
- void sync();
- bool isValid() const { return m_rhi && m_texture && m_sgWrapperTexture; }
- void scheduleUpdate();
- bool hasRenderer() const { return m_renderer; }
- void setRenderer(RhiItemRenderer *r) { m_renderer = r; }
- void setMirrorVertically(bool b);
-
-private slots:
- void render();
-
-private:
- void createNativeTexture();
- void releaseNativeTexture();
-
- RhiItem *m_item;
- QQuickWindow *m_window;
- QSize m_pixelSize;
- qreal m_dpr = 0.0f;
- QRhi *m_rhi = nullptr;
- QRhiTexture *m_texture = nullptr;
- QSGPlainTexture *m_sgWrapperTexture = nullptr;
- bool m_renderPending = true;
- RhiItemRenderer *m_renderer = nullptr;
-};
-
-class RhiItemPrivate : public QQuickItemPrivate
-{
- Q_DECLARE_PUBLIC(RhiItem)
-public:
- static RhiItemPrivate *get(RhiItem *item) { return item->d_func(); }
- mutable RhiItemNode *node = nullptr;
- int explicitTextureWidth = 0;
- int explicitTextureHeight = 0;
- bool blend = true;
- bool mirrorVertically = false;
- QSize effectiveTextureSize;
-};
-
-#endif
diff --git a/tests/auto/quick/qquickitemrhiintegration/testrhiitem.cpp b/tests/auto/quick/qquickitemrhiintegration/testrhiitem.cpp
deleted file mode 100644
index 926bb53bcf..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/testrhiitem.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "testrhiitem.h"
-#include <QFile>
-
-static const QSize TEX_SIZE(512, 512);
-
-void TestRenderer::initialize(QRhi *rhi, QRhiTexture *outputTexture)
-{
- m_rhi = rhi;
- m_output = outputTexture;
-
- if (!m_ds) {
- m_ds.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, m_output->pixelSize()));
- m_ds->create();
- } else if (m_ds->pixelSize() != m_output->pixelSize()) {
- m_ds->setPixelSize(m_output->pixelSize());
- m_ds->create();
- }
-
- if (!m_rt) {
- m_rt.reset(m_rhi->newTextureRenderTarget({ { m_output }, m_ds.data() }));
- m_rp.reset(m_rt->newCompatibleRenderPassDescriptor());
- m_rt->setRenderPassDescriptor(m_rp.data());
- m_rt->create();
- }
-
- if (!scene.vbuf)
- initScene();
-
- const QSize outputSize = m_output->pixelSize();
- scene.mvp = m_rhi->clipSpaceCorrMatrix();
- scene.mvp.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f);
- scene.mvp.translate(0, 0, -4);
- if (!scene.resourceUpdates)
- scene.resourceUpdates = m_rhi->nextResourceUpdateBatch();
- scene.resourceUpdates->updateDynamicBuffer(scene.ubuf.data(), 0, 64, scene.mvp.constData());
-}
-
-static QShader getShader(const QString &name)
-{
- QFile f(name);
- if (f.open(QIODevice::ReadOnly))
- return QShader::fromSerialized(f.readAll());
-
- return QShader();
-}
-
-void TestRenderer::updateTexture()
-{
- QImage img(TEX_SIZE, QImage::Format_RGBA8888);
- img.fill(itemData.color);
-
- if (!scene.resourceUpdates)
- scene.resourceUpdates = m_rhi->nextResourceUpdateBatch();
-
- scene.resourceUpdates->uploadTexture(scene.tex.data(), img);
-}
-
-void TestRenderer::initScene()
-{
- static const float tri[] = {
- 0.0f, 0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, 0.0f, 0.0f,
- 0.5f, -0.5f, 1.0f, 0.0f
- };
-
- scene.vbuf.reset(m_rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(tri)));
- scene.vbuf->create();
-
- scene.resourceUpdates = m_rhi->nextResourceUpdateBatch();
- scene.resourceUpdates->uploadStaticBuffer(scene.vbuf.data(), tri);
-
- scene.ubuf.reset(m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 68));
- scene.ubuf->create();
-
- const qint32 flip = m_rhi->isYUpInFramebuffer() ? 1 : 0;
- scene.resourceUpdates->updateDynamicBuffer(scene.ubuf.data(), 64, 4, &flip);
-
- scene.tex.reset(m_rhi->newTexture(QRhiTexture::RGBA8, TEX_SIZE));
- scene.tex->create();
-
- scene.sampler.reset(m_rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
- QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
- scene.sampler->create();
-
- scene.srb.reset(m_rhi->newShaderResourceBindings());
- scene.srb->setBindings({
- QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, scene.ubuf.data()),
- QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, scene.tex.data(), scene.sampler.data())
- });
- scene.srb->create();
-
- scene.ps.reset(m_rhi->newGraphicsPipeline());
- scene.ps->setDepthTest(true);
- scene.ps->setDepthWrite(true);
- scene.ps->setDepthOp(QRhiGraphicsPipeline::Less);
- scene.ps->setCullMode(QRhiGraphicsPipeline::Back);
- scene.ps->setFrontFace(QRhiGraphicsPipeline::CCW);
- QShader vs = getShader(QLatin1String(":/texture.vert.qsb"));
- Q_ASSERT(vs.isValid());
- QShader fs = getShader(QLatin1String(":/texture.frag.qsb"));
- Q_ASSERT(fs.isValid());
- scene.ps->setShaderStages({
- { QRhiShaderStage::Vertex, vs },
- { QRhiShaderStage::Fragment, fs }
- });
- QRhiVertexInputLayout inputLayout;
- inputLayout.setBindings({
- { 4 * sizeof(float) },
- });
- inputLayout.setAttributes({
- { 0, 0, QRhiVertexInputAttribute::Float2, 0 },
- { 0, 1, QRhiVertexInputAttribute::Float2, 2 * sizeof(float) }
- });
- scene.ps->setVertexInputLayout(inputLayout);
- scene.ps->setShaderResourceBindings(scene.srb.data());
- scene.ps->setRenderPassDescriptor(m_rp.data());
- scene.ps->create();
-}
-
-void TestRenderer::synchronize(RhiItem *rhiItem)
-{
- TestRhiItem *item = static_cast<TestRhiItem *>(rhiItem);
- if (item->color() != itemData.color) {
- itemData.color = item->color();
- updateTexture();
- }
-}
-
-void TestRenderer::render(QRhiCommandBuffer *cb)
-{
- QRhiResourceUpdateBatch *rub = scene.resourceUpdates;
- if (rub)
- scene.resourceUpdates = nullptr;
-
- const QColor clearColor = QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f);
- cb->beginPass(m_rt.data(), clearColor, { 1.0f, 0 }, rub);
-
- cb->setGraphicsPipeline(scene.ps.data());
- const QSize outputSize = m_output->pixelSize();
- cb->setViewport(QRhiViewport(0, 0, outputSize.width(), outputSize.height()));
- cb->setShaderResources();
- const QRhiCommandBuffer::VertexInput vbufBindings[] = {
- { scene.vbuf.data(), 0 },
- };
- cb->setVertexInput(0, 1, vbufBindings);
- cb->draw(3);
-
- cb->endPass();
-}
-
-void TestRhiItem::setColor(QColor c)
-{
- if (m_color == c)
- return;
-
- m_color = c;
- emit colorChanged();
- update();
-}
diff --git a/tests/auto/quick/qquickitemrhiintegration/testrhiitem.h b/tests/auto/quick/qquickitemrhiintegration/testrhiitem.h
deleted file mode 100644
index 94a50a6d9b..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/testrhiitem.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#ifndef TESTRHIITEM_H
-#define TESTRHIITEM_H
-
-#include "rhiitem.h"
-
-class TestRenderer : public RhiItemRenderer
-{
-public:
- void initialize(QRhi *rhi, QRhiTexture *outputTexture) override;
- void synchronize(RhiItem *item) override;
- void render(QRhiCommandBuffer *cb) override;
-
-private:
- QRhi *m_rhi = nullptr;
- QRhiTexture *m_output = nullptr;
- QScopedPointer<QRhiRenderBuffer> m_ds;
- QScopedPointer<QRhiTextureRenderTarget> m_rt;
- QScopedPointer<QRhiRenderPassDescriptor> m_rp;
-
- struct {
- QRhiResourceUpdateBatch *resourceUpdates = nullptr;
- QScopedPointer<QRhiBuffer> vbuf;
- QScopedPointer<QRhiBuffer> ubuf;
- QScopedPointer<QRhiShaderResourceBindings> srb;
- QScopedPointer<QRhiGraphicsPipeline> ps;
- QScopedPointer<QRhiSampler> sampler;
- QScopedPointer<QRhiTexture> tex;
- QMatrix4x4 mvp;
- } scene;
-
- struct {
- QColor color;
- } itemData;
-
- void initScene();
- void updateTexture();
-};
-
-class TestRhiItem : public RhiItem
-{
- Q_OBJECT
- QML_NAMED_ELEMENT(TestRhiItem)
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
-
-public:
- RhiItemRenderer *createRenderer() override { return new TestRenderer; }
-
- QColor color() const { return m_color; }
- void setColor(QColor c);
-
-signals:
- void colorChanged();
-
-private:
- QColor m_color;
-};
-
-#endif
diff --git a/tests/auto/quick/qquickitemrhiintegration/texture.frag b/tests/auto/quick/qquickitemrhiintegration/texture.frag
deleted file mode 100644
index a7b8bce0ad..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/texture.frag
+++ /dev/null
@@ -1,18 +0,0 @@
-#version 440
-
-layout(location = 0) in vec2 v_texcoord;
-
-layout(location = 0) out vec4 fragColor;
-
-layout(std140, binding = 0) uniform buf {
- mat4 mvp;
- int flip;
-};
-
-layout(binding = 1) uniform sampler2D tex;
-
-void main()
-{
- vec4 c = texture(tex, v_texcoord);
- fragColor = vec4(c.rgb * c.a, c.a);
-}
diff --git a/tests/auto/quick/qquickitemrhiintegration/texture.vert b/tests/auto/quick/qquickitemrhiintegration/texture.vert
deleted file mode 100644
index bf678d1e9b..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/texture.vert
+++ /dev/null
@@ -1,19 +0,0 @@
-#version 440
-
-layout(location = 0) in vec4 position;
-layout(location = 1) in vec2 texcoord;
-
-layout(location = 0) out vec2 v_texcoord;
-
-layout(std140, binding = 0) uniform buf {
- mat4 mvp;
- int flip;
-};
-
-void main()
-{
- v_texcoord = texcoord;
- if (flip != 0)
- v_texcoord.y = 1.0 - v_texcoord.y;
- gl_Position = mvp * position;
-}
diff --git a/tests/auto/quick/qquickitemrhiintegration/tst_qquickitemrhiintegration.cpp b/tests/auto/quick/qquickitemrhiintegration/tst_qquickitemrhiintegration.cpp
deleted file mode 100644
index 9915c81fc1..0000000000
--- a/tests/auto/quick/qquickitemrhiintegration/tst_qquickitemrhiintegration.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include <qtest.h>
-#include <QtQuickTestUtils/private/qmlutils_p.h>
-
-#include <QtGui/private/qrhi_p.h>
-
-#include <QQuickView>
-#include <QSGRendererInterface>
-#include <private/qsgrhisupport_p.h>
-
-class tst_QQuickItemRhiIntegration : public QQmlDataTest
-{
- Q_OBJECT
-
-public:
- tst_QQuickItemRhiIntegration();
-
-private slots:
- void initTestCase() override;
- void cleanupTestCase();
- void rhiItem();
-};
-
-tst_QQuickItemRhiIntegration::tst_QQuickItemRhiIntegration()
- : QQmlDataTest(QT_QMLTEST_DATADIR)
-{
-}
-
-void tst_QQuickItemRhiIntegration::initTestCase()
-{
- QQmlDataTest::initTestCase();
- qDebug() << "RHI backend:" << QSGRhiSupport::instance()->rhiBackendName();
-}
-
-void tst_QQuickItemRhiIntegration::cleanupTestCase()
-{
-}
-
-void tst_QQuickItemRhiIntegration::rhiItem()
-{
- if (QGuiApplication::platformName() == QLatin1String("offscreen")
- || QGuiApplication::platformName() == QLatin1String("minimal"))
- {
- QSKIP("Skipping on offscreen/minimal");
- }
-
- // Load up a scene that instantiates a TestRhiItem, which in turn
- // renders a triangle with QRhi into a QRhiTexture and then draws
- // a quad textured with it.
-
- QQuickView view;
- view.setSource(testFileUrl(QLatin1String("test.qml")));
- view.setResizeMode(QQuickView::SizeViewToRootObject);
- view.show();
- QVERIFY(QTest::qWaitForWindowExposed(&view));
-
- if (!QSGRendererInterface::isApiRhiBased(view.rendererInterface()->graphicsApi()))
- QSKIP("Scenegraph does not use QRhi, test is pointless");
-
- QImage result = view.grabWindow();
- QVERIFY(!result.isNull());
-
- const int tolerance = 5;
-
- // The result is a red triangle in the center of the view, confirm at least one pixel.
- QRgb a = result.pixel(result.width() / 2, result.height() / 2);
- QRgb b = QColor(Qt::red).rgb();
- QVERIFY(qAbs(qRed(a) - qRed(b)) <= tolerance
- && qAbs(qGreen(a) - qGreen(b)) <= tolerance
- && qAbs(qBlue(a) - qBlue(b)) <= tolerance);
-}
-
-#include "tst_qquickitemrhiintegration.moc"
-
-QTEST_MAIN(tst_QQuickItemRhiIntegration)