2012-02-14 11:31:11 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-02-14 11:31:11 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-20 05:21:40 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 11:23:05 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-02-14 11:31:11 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <qtest.h>
|
|
|
|
|
|
|
|
#include <QtQuick/qquickitem.h>
|
|
|
|
#include <QtQuick/qquickview.h>
|
2020-02-03 14:02:31 +00:00
|
|
|
#include <qopenglcontext.h>
|
|
|
|
#include <qopenglfunctions.h>
|
2013-08-30 11:18:49 +00:00
|
|
|
#include <QtGui/qscreen.h>
|
2012-02-14 11:31:11 +00:00
|
|
|
#include <private/qsgrendernode_p.h>
|
|
|
|
|
2021-08-06 10:27:35 +00:00
|
|
|
#include <QtQuickTestUtils/private/qmlutils_p.h>
|
2012-02-14 11:31:11 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class tst_rendernode: public QQmlDataTest
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
tst_rendernode();
|
|
|
|
|
2012-03-14 14:42:58 +00:00
|
|
|
QImage runTest(const QString &fileName)
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
2014-01-10 17:08:17 +00:00
|
|
|
QQuickView view(&outerWindow);
|
2013-10-24 18:44:17 +00:00
|
|
|
view.setResizeMode(QQuickView::SizeViewToRootObject);
|
2014-01-10 17:08:17 +00:00
|
|
|
view.setSource(testFileUrl(fileName));
|
|
|
|
view.setVisible(true);
|
2019-07-12 11:17:02 +00:00
|
|
|
return QTest::qWaitForWindowExposed(&view) ? view.grabWindow() : QImage();
|
2012-02-14 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 17:08:17 +00:00
|
|
|
//It is important for platforms that only are able to show fullscreen windows
|
|
|
|
//to have a container for the window that is painted on.
|
|
|
|
QQuickWindow outerWindow;
|
|
|
|
|
2012-02-14 11:31:11 +00:00
|
|
|
private slots:
|
|
|
|
void renderOrder();
|
|
|
|
void messUpState();
|
2014-05-06 12:54:52 +00:00
|
|
|
void matrix();
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool isRunningOnRhi() const;
|
2012-02-14 11:31:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ClearNode : public QSGRenderNode
|
|
|
|
{
|
|
|
|
public:
|
2016-04-20 08:38:30 +00:00
|
|
|
StateFlags changedStates() const override
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
|
|
|
return ColorState;
|
|
|
|
}
|
|
|
|
|
2016-04-20 08:38:30 +00:00
|
|
|
void render(const RenderState *) override
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
|
|
|
// If clip has been set, scissoring will make sure the right area is cleared.
|
2014-06-26 13:08:47 +00:00
|
|
|
QOpenGLContext::currentContext()->functions()->glClearColor(color.redF(), color.greenF(), color.blueF(), 1.0f);
|
|
|
|
QOpenGLContext::currentContext()->functions()->glClear(GL_COLOR_BUFFER_BIT);
|
2012-02-14 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QColor color;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClearItem : public QQuickItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
|
|
|
public:
|
|
|
|
ClearItem() : m_color(Qt::black)
|
|
|
|
{
|
|
|
|
setFlag(ItemHasContents, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor color() const { return m_color; }
|
|
|
|
void setColor(const QColor &color)
|
|
|
|
{
|
|
|
|
if (color == m_color)
|
|
|
|
return;
|
|
|
|
m_color = color;
|
|
|
|
emit colorChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2021-03-25 13:44:04 +00:00
|
|
|
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
|
|
|
ClearNode *node = static_cast<ClearNode *>(oldNode);
|
|
|
|
if (!node)
|
|
|
|
node = new ClearNode;
|
|
|
|
node->color = m_color;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void colorChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QColor m_color;
|
|
|
|
};
|
|
|
|
|
2014-06-26 13:08:47 +00:00
|
|
|
class MessUpNode : public QSGRenderNode, protected QOpenGLFunctions
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-02-21 10:52:59 +00:00
|
|
|
MessUpNode() {}
|
2014-06-26 13:08:47 +00:00
|
|
|
|
2016-04-20 08:38:30 +00:00
|
|
|
StateFlags changedStates() const override
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
|
|
|
return StateFlags(DepthState) | StencilState | ScissorState | ColorState | BlendState
|
2016-04-20 08:38:30 +00:00
|
|
|
| CullState | ViewportState | RenderTargetState;
|
2012-02-14 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
2016-04-20 08:38:30 +00:00
|
|
|
void render(const RenderState *) override
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
2014-06-26 13:08:47 +00:00
|
|
|
if (!initialized) {
|
|
|
|
initializeOpenGLFunctions();
|
|
|
|
initialized = true;
|
|
|
|
}
|
2012-02-14 11:31:11 +00:00
|
|
|
// Don't draw anything, just mess up the state
|
|
|
|
glViewport(10, 10, 10, 10);
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
glDepthMask(true);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_EQUAL);
|
|
|
|
glClearDepthf(1);
|
|
|
|
glClearStencil(42);
|
|
|
|
glClearColor(1.0f, 0.5f, 1.0f, 0.0f);
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glScissor(190, 190, 10, 10);
|
|
|
|
glStencilFunc(GL_EQUAL, 28, 0xff);
|
|
|
|
glBlendFunc(GL_ZERO, GL_ZERO);
|
|
|
|
GLint frontFace;
|
|
|
|
glGetIntegerv(GL_FRONT_FACE, &frontFace);
|
|
|
|
glFrontFace(frontFace == GL_CW ? GL_CCW : GL_CW);
|
|
|
|
glEnable(GL_CULL_FACE);
|
2016-04-20 08:38:30 +00:00
|
|
|
GLuint fbo;
|
|
|
|
glGenFramebuffers(1, &fbo);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
2012-02-14 11:31:11 +00:00
|
|
|
}
|
2014-06-26 13:08:47 +00:00
|
|
|
|
2018-02-21 10:52:59 +00:00
|
|
|
bool initialized = false;
|
2012-02-14 11:31:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MessUpItem : public QQuickItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
MessUpItem()
|
|
|
|
{
|
|
|
|
setFlag(ItemHasContents, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2021-03-25 13:44:04 +00:00
|
|
|
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
|
|
|
MessUpNode *node = static_cast<MessUpNode *>(oldNode);
|
|
|
|
if (!node)
|
|
|
|
node = new MessUpNode;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
tst_rendernode::tst_rendernode()
|
2021-08-06 10:27:35 +00:00
|
|
|
: QQmlDataTest(QT_QMLTEST_DATADIR)
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
|
|
|
qmlRegisterType<ClearItem>("Test", 1, 0, "ClearItem");
|
|
|
|
qmlRegisterType<MessUpItem>("Test", 1, 0, "MessUpItem");
|
2014-01-10 17:08:17 +00:00
|
|
|
outerWindow.showNormal();
|
|
|
|
outerWindow.setGeometry(0,0,400,400);
|
2012-02-14 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 11:18:49 +00:00
|
|
|
static bool fuzzyCompareColor(QRgb x, QRgb y, QByteArray *errorMessage)
|
2012-02-14 11:31:11 +00:00
|
|
|
{
|
2013-08-30 11:18:49 +00:00
|
|
|
enum { fuzz = 4 };
|
|
|
|
if (qAbs(qRed(x) - qRed(y)) >= fuzz || qAbs(qGreen(x) - qGreen(y)) >= fuzz || qAbs(qBlue(x) - qBlue(y)) >= fuzz) {
|
|
|
|
QString s;
|
2019-07-08 11:01:56 +00:00
|
|
|
QDebug(&s).nospace() << Qt::hex << "Color mismatch 0x" << x << " 0x" << y << Qt::dec << " (fuzz=" << fuzz << ").";
|
2013-08-30 11:18:49 +00:00
|
|
|
*errorMessage = s.toLocal8Bit();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline QByteArray msgColorMismatchAt(const QByteArray &colorMsg, int x, int y)
|
|
|
|
{
|
|
|
|
return colorMsg + QByteArrayLiteral(" at ") + QByteArray::number(x) +',' + QByteArray::number(y);
|
2012-02-14 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 18:44:17 +00:00
|
|
|
/* The test draws four rects, each 100x100 and verifies
|
|
|
|
* that a rendernode which calls glClear() is stacked
|
|
|
|
* correctly. The red rectangles come under the white
|
|
|
|
* and are obscured.
|
|
|
|
*/
|
2012-02-14 11:31:11 +00:00
|
|
|
void tst_rendernode::renderOrder()
|
|
|
|
{
|
2013-08-30 11:18:49 +00:00
|
|
|
if (QGuiApplication::primaryScreen()->depth() < 24)
|
|
|
|
QSKIP("This test does not work at display depths < 24");
|
2017-08-30 12:39:28 +00:00
|
|
|
|
|
|
|
if ((QGuiApplication::platformName() == QLatin1String("offscreen"))
|
|
|
|
|| (QGuiApplication::platformName() == QLatin1String("minimal")))
|
2020-03-18 13:24:29 +00:00
|
|
|
QSKIP("Skipping due to grabWindow not functional on offscreen/minimal platforms");
|
2017-08-30 12:39:28 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (isRunningOnRhi())
|
|
|
|
QSKIP("Render nodes not yet supported with QRhi");
|
|
|
|
|
2012-03-14 14:42:58 +00:00
|
|
|
QImage fb = runTest("RenderOrder.qml");
|
2019-07-12 11:17:02 +00:00
|
|
|
QVERIFY(!fb.isNull());
|
2013-10-24 18:44:17 +00:00
|
|
|
|
2016-10-17 12:02:35 +00:00
|
|
|
const qreal scaleFactor = QGuiApplication::primaryScreen()->devicePixelRatio();
|
|
|
|
QCOMPARE(fb.width(), qRound(200 * scaleFactor));
|
|
|
|
QCOMPARE(fb.height(), qRound(200 * scaleFactor));
|
2013-10-24 18:44:17 +00:00
|
|
|
|
2016-10-17 12:02:35 +00:00
|
|
|
QCOMPARE(fb.pixel(50 * scaleFactor, 50 * scaleFactor), qRgb(0xff, 0xff, 0xff));
|
|
|
|
QCOMPARE(fb.pixel(50 * scaleFactor, 150 * scaleFactor), qRgb(0xff, 0xff, 0xff));
|
|
|
|
QCOMPARE(fb.pixel(150 * scaleFactor, 50 * scaleFactor), qRgb(0x00, 0x00, 0xff));
|
2012-02-14 11:31:11 +00:00
|
|
|
|
2013-08-30 11:18:49 +00:00
|
|
|
QByteArray errorMessage;
|
2016-10-17 12:02:35 +00:00
|
|
|
const qreal coordinate = 150 * scaleFactor;
|
|
|
|
QVERIFY2(fuzzyCompareColor(fb.pixel(coordinate, coordinate), qRgb(0x7f, 0x7f, 0xff), &errorMessage),
|
|
|
|
msgColorMismatchAt(errorMessage, coordinate, coordinate).constData());
|
2012-02-14 11:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 18:44:17 +00:00
|
|
|
/* The test uses a number of nested rectangles with clipping
|
|
|
|
* and rotation to verify that using a render node which messes
|
|
|
|
* with the state does not break rendering that comes after it.
|
|
|
|
*/
|
2012-02-14 11:31:11 +00:00
|
|
|
void tst_rendernode::messUpState()
|
|
|
|
{
|
2013-08-30 11:18:49 +00:00
|
|
|
if (QGuiApplication::primaryScreen()->depth() < 24)
|
|
|
|
QSKIP("This test does not work at display depths < 24");
|
2017-08-30 12:39:28 +00:00
|
|
|
|
|
|
|
if ((QGuiApplication::platformName() == QLatin1String("offscreen"))
|
|
|
|
|| (QGuiApplication::platformName() == QLatin1String("minimal")))
|
2020-03-18 13:24:29 +00:00
|
|
|
QSKIP("Skipping due to grabWindow not functional on offscreen/minimal platforms");
|
2017-08-30 12:39:28 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (isRunningOnRhi())
|
|
|
|
QSKIP("Render nodes not yet supported with QRhi");
|
|
|
|
|
2012-03-14 14:42:58 +00:00
|
|
|
QImage fb = runTest("MessUpState.qml");
|
2019-07-12 11:17:02 +00:00
|
|
|
QVERIFY(!fb.isNull());
|
2012-02-14 11:31:11 +00:00
|
|
|
int x1 = 0;
|
|
|
|
int x2 = fb.width() / 2;
|
|
|
|
int x3 = fb.width() - 1;
|
|
|
|
int y1 = 0;
|
|
|
|
int y2 = fb.height() * 3 / 16;
|
|
|
|
int y3 = fb.height() / 2;
|
|
|
|
int y4 = fb.height() * 13 / 16;
|
|
|
|
int y5 = fb.height() - 1;
|
|
|
|
|
|
|
|
QCOMPARE(fb.pixel(x1, y3), qRgb(0xff, 0xff, 0xff));
|
|
|
|
QCOMPARE(fb.pixel(x3, y3), qRgb(0xff, 0xff, 0xff));
|
|
|
|
|
|
|
|
QCOMPARE(fb.pixel(x2, y1), qRgb(0x00, 0x00, 0x00));
|
|
|
|
QCOMPARE(fb.pixel(x2, y2), qRgb(0x00, 0x00, 0x00));
|
2013-08-30 11:18:49 +00:00
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(fuzzyCompareColor(fb.pixel(x2, y3), qRgb(0x7f, 0x00, 0x7f), &errorMessage),
|
|
|
|
msgColorMismatchAt(errorMessage, x2, y3).constData());
|
2012-02-14 11:31:11 +00:00
|
|
|
QCOMPARE(fb.pixel(x2, y4), qRgb(0x00, 0x00, 0x00));
|
|
|
|
QCOMPARE(fb.pixel(x2, y5), qRgb(0x00, 0x00, 0x00));
|
|
|
|
}
|
|
|
|
|
2014-05-06 12:54:52 +00:00
|
|
|
class StateRecordingRenderNode : public QSGRenderNode
|
|
|
|
{
|
|
|
|
public:
|
2016-04-20 08:38:30 +00:00
|
|
|
StateFlags changedStates() const override { return StateFlags(-1); }
|
|
|
|
void render(const RenderState *) override {
|
2014-05-06 12:54:52 +00:00
|
|
|
matrices[name] = *matrix();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QString name;
|
|
|
|
static QHash<QString, QMatrix4x4> matrices;
|
|
|
|
};
|
|
|
|
|
|
|
|
QHash<QString, QMatrix4x4> StateRecordingRenderNode::matrices;
|
|
|
|
|
|
|
|
class StateRecordingRenderNodeItem : public QQuickItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
StateRecordingRenderNodeItem() { setFlag(ItemHasContents, true); }
|
2021-06-04 09:50:03 +00:00
|
|
|
QSGNode *updatePaintNode(QSGNode *r, UpdatePaintNodeData *) override
|
|
|
|
{
|
2014-05-06 12:54:52 +00:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
StateRecordingRenderNode *rn = new StateRecordingRenderNode();
|
|
|
|
rn->name = objectName();
|
|
|
|
return rn;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_rendernode::matrix()
|
|
|
|
{
|
2017-08-30 12:39:28 +00:00
|
|
|
if ((QGuiApplication::platformName() == QLatin1String("offscreen"))
|
|
|
|
|| (QGuiApplication::platformName() == QLatin1String("minimal")))
|
2020-03-18 13:24:29 +00:00
|
|
|
QSKIP("Skipping due to grabWindow not functional on offscreen/minimal platforms");
|
2017-08-30 12:39:28 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (isRunningOnRhi())
|
|
|
|
QSKIP("Render nodes not yet supported with QRhi");
|
|
|
|
|
2014-05-06 12:54:52 +00:00
|
|
|
qmlRegisterType<StateRecordingRenderNodeItem>("RenderNode", 1, 0, "StateRecorder");
|
|
|
|
StateRecordingRenderNode::matrices.clear();
|
2019-07-12 11:17:02 +00:00
|
|
|
QVERIFY(!runTest("matrix.qml").isNull());
|
2014-05-06 12:54:52 +00:00
|
|
|
|
|
|
|
QMatrix4x4 noRotateOffset;
|
|
|
|
noRotateOffset.translate(20, 20);
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("no-clip; no-rotation"));
|
|
|
|
QCOMPARE(result, noRotateOffset);
|
|
|
|
}
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("parent-clip; no-rotation"));
|
|
|
|
QCOMPARE(result, noRotateOffset);
|
|
|
|
}
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("self-clip; no-rotation"));
|
|
|
|
QCOMPARE(result, noRotateOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix4x4 parentRotation;
|
|
|
|
parentRotation.translate(10, 10); // parent at x/y: 10
|
|
|
|
parentRotation.translate(5, 5); // rotate 90 around center (width/height: 10)
|
|
|
|
parentRotation.rotate(90, 0, 0, 1);
|
|
|
|
parentRotation.translate(-5, -5);
|
|
|
|
parentRotation.translate(10, 10); // StateRecorder at: x/y: 10
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("no-clip; parent-rotation"));
|
|
|
|
QCOMPARE(result, parentRotation);
|
|
|
|
}
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("parent-clip; parent-rotation"));
|
|
|
|
QCOMPARE(result, parentRotation);
|
|
|
|
}
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("self-clip; parent-rotation"));
|
|
|
|
QCOMPARE(result, parentRotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix4x4 selfRotation;
|
|
|
|
selfRotation.translate(10, 10); // parent at x/y: 10
|
|
|
|
selfRotation.translate(10, 10); // StateRecorder at: x/y: 10
|
|
|
|
selfRotation.rotate(90, 0, 0, 1); // rotate 90, width/height: 0
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("no-clip; self-rotation"));
|
|
|
|
QCOMPARE(result, selfRotation);
|
|
|
|
}
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("parent-clip; self-rotation"));
|
|
|
|
QCOMPARE(result, selfRotation);
|
|
|
|
}
|
|
|
|
{ QMatrix4x4 result = StateRecordingRenderNode::matrices.value(QStringLiteral("self-clip; self-rotation"));
|
|
|
|
QCOMPARE(result, selfRotation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
bool tst_rendernode::isRunningOnRhi() const
|
|
|
|
{
|
|
|
|
static bool retval = false;
|
|
|
|
static bool decided = false;
|
|
|
|
if (!decided) {
|
|
|
|
decided = true;
|
|
|
|
QQuickView dummy;
|
|
|
|
dummy.show();
|
2019-07-12 11:17:02 +00:00
|
|
|
if (QTest::qWaitForWindowExposed(&dummy)) {
|
|
|
|
QSGRendererInterface::GraphicsApi api = dummy.rendererInterface()->graphicsApi();
|
|
|
|
retval = QSGRendererInterface::isApiRhiBased(api);
|
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
dummy.hide();
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
2012-02-14 11:31:11 +00:00
|
|
|
|
|
|
|
QTEST_MAIN(tst_rendernode)
|
|
|
|
|
|
|
|
#include "tst_rendernode.moc"
|