summaryrefslogtreecommitdiffstats
path: root/tests/auto/render
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2016-08-14 09:23:05 +0100
committerSean Harmer <sean.harmer@kdab.com>2016-08-14 09:41:21 +0100
commit9a18925b63d47a20d7b74cfd508d7ae71f2d4d7c (patch)
tree4d0d0538b9475a9104d56ee3d07f4bab7b0e00b4 /tests/auto/render
parent9a1c0c96246126d2377bd56ed702f47214e3ee0a (diff)
parent71eee85093ba807f5bc2add472b359841faa062d (diff)
Merge branch '5.7' into dev
Diffstat (limited to 'tests/auto/render')
-rw-r--r--tests/auto/render/layerfiltering/tst_layerfiltering.cpp29
-rw-r--r--tests/auto/render/qcuboidgeometry/qcuboidgeometry.pro13
-rw-r--r--tests/auto/render/qcuboidgeometry/tst_qcuboidgeometry.cpp505
-rw-r--r--tests/auto/render/qgraphicsapifilter/qgraphicsapifilter.pro13
-rw-r--r--tests/auto/render/qgraphicsapifilter/tst_qgraphicsapifilter.cpp246
-rw-r--r--tests/auto/render/qrendersurfaceselector/qrendersurfaceselector.pro10
-rw-r--r--tests/auto/render/qrendersurfaceselector/tst_qrendersurfaceselector.cpp107
-rw-r--r--tests/auto/render/render.pro6
-rw-r--r--tests/auto/render/renderviewutils/tst_renderviewutils.cpp32
-rw-r--r--tests/auto/render/sortpolicy/sortpolicy.pro13
-rw-r--r--tests/auto/render/sortpolicy/tst_sortpolicy.cpp105
11 files changed, 1073 insertions, 6 deletions
diff --git a/tests/auto/render/layerfiltering/tst_layerfiltering.cpp b/tests/auto/render/layerfiltering/tst_layerfiltering.cpp
index cf7a507a1..244906c90 100644
--- a/tests/auto/render/layerfiltering/tst_layerfiltering.cpp
+++ b/tests/auto/render/layerfiltering/tst_layerfiltering.cpp
@@ -164,9 +164,9 @@ private Q_SLOTS:
childEntity3->addComponent(layer);
QTest::newRow("LayerWithLayerFilterWithFilter-ShouldSelectAllButRoot") << rootEntity
- << (Qt3DCore::QNodeIdVector() << layer->id())
- << true
- << (Qt3DCore::QNodeIdVector() << childEntity1->id() << childEntity2->id() << childEntity3->id());
+ << (Qt3DCore::QNodeIdVector() << layer->id())
+ << true
+ << (Qt3DCore::QNodeIdVector() << childEntity1->id() << childEntity2->id() << childEntity3->id());
}
{
@@ -202,9 +202,28 @@ private Q_SLOTS:
childEntity3->addComponent(layer);
QTest::newRow("LayerWithLayerFilterWithFilter-ShouldSelectNone") << rootEntity
- << (Qt3DCore::QNodeIdVector() << layer2->id())
+ << (Qt3DCore::QNodeIdVector() << layer2->id())
+ << true
+ << Qt3DCore::QNodeIdVector();
+ }
+
+ {
+ Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
+ Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity);
+ Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity);
+ Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity);
+
+ childEntity1->setEnabled(false);
+
+ Qt3DRender::QLayer *layer = new Qt3DRender::QLayer(rootEntity);
+ childEntity1->addComponent(layer);
+ childEntity2->addComponent(layer);
+ childEntity3->addComponent(layer);
+
+ QTest::newRow("LayerWithEntityDisabled-ShouldSelectOnlyEntityEnabled") << rootEntity
+ << (Qt3DCore::QNodeIdVector() << layer->id())
<< true
- << Qt3DCore::QNodeIdVector();
+ << (Qt3DCore::QNodeIdVector() << childEntity2->id() << childEntity3->id());
}
}
diff --git a/tests/auto/render/qcuboidgeometry/qcuboidgeometry.pro b/tests/auto/render/qcuboidgeometry/qcuboidgeometry.pro
new file mode 100644
index 000000000..2599b5fe6
--- /dev/null
+++ b/tests/auto/render/qcuboidgeometry/qcuboidgeometry.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+
+TARGET = tst_qcuboidgeometry
+
+QT += 3dextras testlib
+
+CONFIG += testcase
+
+SOURCES += \
+ tst_qcuboidgeometry.cpp
+
+include(../../core/common/common.pri)
+include(../commons/commons.pri)
diff --git a/tests/auto/render/qcuboidgeometry/tst_qcuboidgeometry.cpp b/tests/auto/render/qcuboidgeometry/tst_qcuboidgeometry.cpp
new file mode 100644
index 000000000..ddd9eed22
--- /dev/null
+++ b/tests/auto/render/qcuboidgeometry/tst_qcuboidgeometry.cpp
@@ -0,0 +1,505 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** 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.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <QObject>
+#include <Qt3DExtras/qcuboidgeometry.h>
+#include <Qt3DRender/qattribute.h>
+#include <Qt3DRender/qbuffer.h>
+#include <Qt3DRender/qbufferdatagenerator.h>
+#include <QtGui/qopenglcontext.h>
+#include <QtGui/qvector2d.h>
+#include <QtGui/qvector3d.h>
+#include <QtGui/qvector4d.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qsharedpointer.h>
+#include <QSignalSpy>
+
+namespace {
+
+void generateGeometry(Qt3DRender::QGeometry &geometry)
+{
+ // Get all attributes
+ const QVector<Qt3DRender::QAttribute *> attributes = geometry.attributes();
+
+ // Get all unique data generators from the buffers referenced by the attributes
+ QHash<Qt3DRender::QBufferDataGeneratorPtr, Qt3DRender::QBuffer *> dataGenerators;
+ for (const auto attribute : attributes) {
+ const auto dataGenerator = attribute->buffer()->dataGenerator();
+ if (!dataGenerators.contains(dataGenerator))
+ dataGenerators.insert(dataGenerator, attribute->buffer());
+ }
+
+ // Generate data for each buffer
+ const auto end = dataGenerators.end();
+ for (auto it = dataGenerators.begin(); it != end; ++it) {
+ Qt3DRender::QBufferDataGeneratorPtr dataGenerator = it.key();
+ const QByteArray data = (*dataGenerator)();
+
+ Qt3DRender::QBuffer *buffer = it.value();
+ buffer->setData(data);
+ }
+}
+
+template<typename IndexType>
+IndexType extractIndexData(Qt3DRender::QAttribute *attribute, int index)
+{
+ // Get the raw data
+ const IndexType *typedData = reinterpret_cast<const IndexType *>(attribute->buffer()->data().constData());
+
+ // Offset into the data taking stride and offset into account
+ const IndexType indexValue = *(typedData + index);
+ return indexValue;
+}
+
+template<typename VertexType, typename IndexType>
+VertexType extractVertexData(Qt3DRender::QAttribute *attribute, IndexType index)
+{
+ // Get the raw data
+ const char *rawData = attribute->buffer()->data().constData();
+
+ // Offset into the data taking stride and offset into account
+ const char *vertexData = rawData + (index * attribute->byteStride() + attribute->byteOffset());
+
+ // Construct vertex from the typed data
+ VertexType vertex;
+ const Qt3DRender::QAttribute::VertexBaseType type = attribute->vertexBaseType();
+ switch (type)
+ {
+ case Qt3DRender::QAttribute::Float: {
+ const float *typedVertexData = reinterpret_cast<const float *>(vertexData);
+ const int components = attribute->vertexSize();
+ for (int i = 0; i < components; ++i)
+ vertex[i] = typedVertexData[i];
+ break;
+
+ // TODO: Handle other types as needed
+ }
+
+ default:
+ qWarning() << "Unhandled type";
+ Q_UNREACHABLE();
+ break;
+ }
+
+ return vertex;
+}
+
+}
+
+class tst_QCuboidGeometry : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void defaultConstruction()
+ {
+ // WHEN
+ Qt3DExtras::QCuboidGeometry geometry;
+
+ // THEN
+ QCOMPARE(geometry.xExtent(), 1.0f);
+ QCOMPARE(geometry.yExtent(), 1.0f);
+ QCOMPARE(geometry.zExtent(), 1.0f);
+ QCOMPARE(geometry.xyMeshResolution(), QSize(2, 2));
+ QCOMPARE(geometry.yzMeshResolution(), QSize(2, 2));
+ QCOMPARE(geometry.xzMeshResolution(), QSize(2, 2));
+ QVERIFY(geometry.positionAttribute() != nullptr);
+ QCOMPARE(geometry.positionAttribute()->name(), Qt3DRender::QAttribute::defaultPositionAttributeName());
+ QVERIFY(geometry.normalAttribute() != nullptr);
+ QCOMPARE(geometry.normalAttribute()->name(), Qt3DRender::QAttribute::defaultNormalAttributeName());
+ QVERIFY(geometry.texCoordAttribute() != nullptr);
+ QCOMPARE(geometry.texCoordAttribute()->name(), Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName());
+ QVERIFY(geometry.tangentAttribute() != nullptr);
+ QCOMPARE(geometry.tangentAttribute()->name(), Qt3DRender::QAttribute::defaultTangentAttributeName());
+ QVERIFY(geometry.indexAttribute() != nullptr);
+ }
+
+ void properties()
+ {
+ // GIVEN
+ Qt3DExtras::QCuboidGeometry geometry;
+
+ {
+ // WHEN
+ QSignalSpy spy(&geometry, SIGNAL(xExtentChanged(float)));
+ const float newValue = 2.0f;
+ geometry.setXExtent(newValue);
+
+ // THEN
+ QCOMPARE(geometry.xExtent(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ geometry.setXExtent(newValue);
+
+ // THEN
+ QCOMPARE(geometry.xExtent(), newValue);
+ QCOMPARE(spy.count(), 0);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&geometry, SIGNAL(yExtentChanged(float)));
+ const float newValue = 2.0f;
+ geometry.setYExtent(newValue);
+
+ // THEN
+ QCOMPARE(geometry.yExtent(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ geometry.setYExtent(newValue);
+
+ // THEN
+ QCOMPARE(geometry.yExtent(), newValue);
+ QCOMPARE(spy.count(), 0);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&geometry, SIGNAL(zExtentChanged(float)));
+ const float newValue = 2.0f;
+ geometry.setZExtent(newValue);
+
+ // THEN
+ QCOMPARE(geometry.zExtent(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ geometry.setZExtent(newValue);
+
+ // THEN
+ QCOMPARE(geometry.zExtent(), newValue);
+ QCOMPARE(spy.count(), 0);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&geometry, SIGNAL(xyMeshResolutionChanged(QSize)));
+ const auto newValue = QSize(4, 8);
+ geometry.setXYMeshResolution(newValue);
+
+ // THEN
+ QCOMPARE(geometry.xyMeshResolution(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ geometry.setXYMeshResolution(newValue);
+
+ // THEN
+ QCOMPARE(geometry.xyMeshResolution(), newValue);
+ QCOMPARE(spy.count(), 0);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&geometry, SIGNAL(yzMeshResolutionChanged(QSize)));
+ const auto newValue = QSize(4, 8);
+ geometry.setYZMeshResolution(newValue);
+
+ // THEN
+ QCOMPARE(geometry.yzMeshResolution(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ geometry.setYZMeshResolution(newValue);
+
+ // THEN
+ QCOMPARE(geometry.yzMeshResolution(), newValue);
+ QCOMPARE(spy.count(), 0);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&geometry, SIGNAL(xzMeshResolutionChanged(QSize)));
+ const auto newValue = QSize(4, 8);
+ geometry.setXZMeshResolution(newValue);
+
+ // THEN
+ QCOMPARE(geometry.xzMeshResolution(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ geometry.setXZMeshResolution(newValue);
+
+ // THEN
+ QCOMPARE(geometry.xzMeshResolution(), newValue);
+ QCOMPARE(spy.count(), 0);
+ }
+ }
+
+ void generatedGeometryShouldBeConsistent_data()
+ {
+ QTest::addColumn<float>("xExtent");
+ QTest::addColumn<float>("yExtent");
+ QTest::addColumn<float>("zExtent");
+ QTest::addColumn<QSize>("xyMeshResolution");
+ QTest::addColumn<QSize>("yzMeshResolution");
+ QTest::addColumn<QSize>("xzMeshResolution");
+ QTest::addColumn<int>("triangleIndex");
+ QTest::addColumn<QVector<quint16>>("indices");
+ QTest::addColumn<QVector<QVector3D>>("positions");
+ QTest::addColumn<QVector<QVector3D>>("normals");
+ QTest::addColumn<QVector<QVector2D>>("texCoords");
+ QTest::addColumn<QVector<QVector4D>>("tangents");
+
+ {
+ const int triangleIndex = 0;
+ const auto indices = (QVector<quint16>() << 0 << 1 << 2);
+ const auto positions = (QVector<QVector3D>()
+ << QVector3D(0.5f, -0.5f, -0.5f)
+ << QVector3D(0.5f, 0.5f, -0.5f)
+ << QVector3D(0.5f, -0.5f, 0.5f));
+ const auto normals = (QVector<QVector3D>()
+ << QVector3D(1.0f, 0.0f, 0.0f)
+ << QVector3D(1.0f, 0.0f, 0.0f)
+ << QVector3D(1.0f, 0.0f, 0.0f));
+ const auto texCoords = (QVector<QVector2D>()
+ << QVector2D(0.0f, 0.0f)
+ << QVector2D(0.0f, 1.0f)
+ << QVector2D(1.0f, 0.0f));
+ const auto tangents = (QVector<QVector4D>()
+ << QVector4D(0.0f, 0.0f, 1.0f, -1.0f)
+ << QVector4D(0.0f, 0.0f, 1.0f, -1.0f)
+ << QVector4D(0.0f, 0.0f, 1.0f, -1.0f));
+ QTest::newRow("default_positiveX_firstTriangle")
+ << 1.0f << 1.0f << 1.0f
+ << QSize(2,2) << QSize(2,2) << QSize(2,2)
+ << triangleIndex
+ << indices << positions << normals << texCoords << tangents;
+ }
+
+ {
+ const int triangleIndex = 3;
+ const auto indices = (QVector<quint16>() << 6 << 5 << 7);
+ const auto positions = (QVector<QVector3D>()
+ << QVector3D(-0.5f, -0.5f, -0.5f)
+ << QVector3D(-0.5f, 0.5f, 0.5f)
+ << QVector3D(-0.5f, 0.5f, -0.5f));
+ const auto normals = (QVector<QVector3D>()
+ << QVector3D(-1.0f, 0.0f, 0.0f)
+ << QVector3D(-1.0f, 0.0f, 0.0f)
+ << QVector3D(-1.0f, 0.0f, 0.0f));
+ const auto texCoords = (QVector<QVector2D>()
+ << QVector2D(1.0f, 0.0f)
+ << QVector2D(0.0f, 1.0f)
+ << QVector2D(1.0f, 1.0f));
+ const auto tangents = (QVector<QVector4D>()
+ << QVector4D(0.0f, 0.0f, -1.0f, -1.0f)
+ << QVector4D(0.0f, 0.0f, -1.0f, -1.0f)
+ << QVector4D(0.0f, 0.0f, -1.0f, -1.0f));
+ QTest::newRow("default_negativeX_lastTriangle")
+ << 1.0f << 1.0f << 1.0f
+ << QSize(2,2) << QSize(2,2) << QSize(2,2)
+ << triangleIndex
+ << indices << positions << normals << texCoords << tangents;
+ }
+
+ {
+ const int triangleIndex = 4;
+ const auto indices = (QVector<quint16>() << 8 << 9 << 10);
+ const auto positions = (QVector<QVector3D>()
+ << QVector3D(-0.5f, 0.5f, 0.5f)
+ << QVector3D(0.5f, 0.5f, 0.5f)
+ << QVector3D(-0.5f, 0.5f, -0.5f));
+ const auto normals = (QVector<QVector3D>()
+ << QVector3D(0.0f, 1.0f, 0.0f)
+ << QVector3D(0.0f, 1.0f, 0.0f)
+ << QVector3D(0.0f, 1.0f, 0.0f));
+ const auto texCoords = (QVector<QVector2D>()
+ << QVector2D(0.0f, 0.0f)
+ << QVector2D(1.0f, 0.0f)
+ << QVector2D(0.0f, 1.0f));
+ const auto tangents = (QVector<QVector4D>()
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
+ QTest::newRow("default_positiveY_firstTriangle")
+ << 1.0f << 1.0f << 1.0f
+ << QSize(2,2) << QSize(2,2) << QSize(2,2)
+ << triangleIndex
+ << indices << positions << normals << texCoords << tangents;
+ }
+
+ {
+ const int triangleIndex = 7;
+ const auto indices = (QVector<quint16>() << 14 << 13 << 15);
+ const auto positions = (QVector<QVector3D>()
+ << QVector3D(-0.5f, -0.5f, 0.5f)
+ << QVector3D(0.5f, -0.5f, -0.5f)
+ << QVector3D(0.5f, -0.5f, 0.5f));
+ const auto normals = (QVector<QVector3D>()
+ << QVector3D(0.0f, -1.0f, 0.0f)
+ << QVector3D(0.0f, -1.0f, 0.0f)
+ << QVector3D(0.0f, -1.0f, 0.0f));
+ const auto texCoords = (QVector<QVector2D>()
+ << QVector2D(0.0f, 1.0f)
+ << QVector2D(1.0f, 0.0f)
+ << QVector2D(1.0f, 1.0f));
+ const auto tangents = (QVector<QVector4D>()
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
+ QTest::newRow("default_negativeY_lastTriangle")
+ << 1.0f << 1.0f << 1.0f
+ << QSize(2,2) << QSize(2,2) << QSize(2,2)
+ << triangleIndex
+ << indices << positions << normals << texCoords << tangents;
+ }
+
+ {
+ const int triangleIndex = 8;
+ const auto indices = (QVector<quint16>() << 16 << 17 << 18);
+ const auto positions = (QVector<QVector3D>()
+ << QVector3D(-0.5f, -0.5f, 0.5f)
+ << QVector3D(0.5f, -0.5f, 0.5f)
+ << QVector3D(-0.5f, 0.5f, 0.5f));
+ const auto normals = (QVector<QVector3D>()
+ << QVector3D(0.0f, 0.0f, 1.0f)
+ << QVector3D(0.0f, 0.0f, 1.0f)
+ << QVector3D(0.0f, 0.0f, 1.0f));
+ const auto texCoords = (QVector<QVector2D>()
+ << QVector2D(0.0f, 0.0f)
+ << QVector2D(1.0f, 0.0f)
+ << QVector2D(0.0f, 1.0f));
+ const auto tangents = (QVector<QVector4D>()
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
+ << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
+ QTest::newRow("default_positiveZ_firstTriangle")
+ << 1.0f << 1.0f << 1.0f
+ << QSize(2,2) << QSize(2,2) << QSize(2,2)
+ << triangleIndex
+ << indices << positions << normals << texCoords << tangents;
+ }
+
+ {
+ const int triangleIndex = 11;
+ const auto indices = (QVector<quint16>() << 22 << 21 << 23);
+ const auto positions = (QVector<QVector3D>()
+ << QVector3D(0.5f, 0.5f, -0.5f)
+ << QVector3D(-0.5f, -0.5f, -0.5f)
+ << QVector3D(-0.5f, 0.5f, -0.5f));
+ const auto normals = (QVector<QVector3D>()
+ << QVector3D(0.0f, 0.0f, -1.0f)
+ << QVector3D(0.0f, 0.0f, -1.0f)
+ << QVector3D(0.0f, 0.0f, -1.0f));
+ const auto texCoords = (QVector<QVector2D>()
+ << QVector2D(0.0f, 1.0f)
+ << QVector2D(1.0f, 0.0f)
+ << QVector2D(1.0f, 1.0f));
+ const auto tangents = (QVector<QVector4D>()
+ << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f)
+ << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f)
+ << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f));
+ QTest::newRow("default_negativeZ_lastTriangle")
+ << 1.0f << 1.0f << 1.0f
+ << QSize(2,2) << QSize(2,2) << QSize(2,2)
+ << triangleIndex
+ << indices << positions << normals << texCoords << tangents;
+ }
+ }
+
+ void generatedGeometryShouldBeConsistent()
+ {
+ // GIVEN
+ Qt3DExtras::QCuboidGeometry geometry;
+ const QVector<Qt3DRender::QAttribute *> attributes = geometry.attributes();
+ Qt3DRender::QAttribute *positionAttribute = geometry.positionAttribute();
+ Qt3DRender::QAttribute *normalAttribute = geometry.normalAttribute();
+ Qt3DRender::QAttribute *texCoordAttribute = geometry.texCoordAttribute();
+ Qt3DRender::QAttribute *tangentAttribute = geometry.tangentAttribute();
+ Qt3DRender::QAttribute *indexAttribute = geometry.indexAttribute();
+
+ // WHEN
+ QFETCH(float, xExtent);
+ QFETCH(float, yExtent);
+ QFETCH(float, zExtent);
+ QFETCH(QSize, xyMeshResolution);
+ QFETCH(QSize, yzMeshResolution);
+ QFETCH(QSize, xzMeshResolution);
+ geometry.setXExtent(xExtent);
+ geometry.setYExtent(yExtent);
+ geometry.setZExtent(zExtent);
+ geometry.setXYMeshResolution(xyMeshResolution);
+ geometry.setYZMeshResolution(yzMeshResolution);
+ geometry.setXZMeshResolution(xzMeshResolution);
+
+ generateGeometry(geometry);
+
+ // THEN
+
+ // Check buffer of each attribute is valid and actually has some data
+ for (const auto &attribute : attributes) {
+ Qt3DRender::QBuffer *buffer = attribute->buffer();
+ QVERIFY(buffer != nullptr);
+ QVERIFY(buffer->data().size() != 0);
+ }
+
+ // Check some data in the buffers
+
+ // Check specific indices and vertex attributes of triangle under test
+ QFETCH(int, triangleIndex);
+ QFETCH(QVector<quint16>, indices);
+ QFETCH(QVector<QVector3D>, positions);
+ QFETCH(QVector<QVector3D>, normals);
+ QFETCH(QVector<QVector2D>, texCoords);
+ QFETCH(QVector<QVector4D>, tangents);
+
+ int i = 0;
+ for (auto index : indices) {
+ const auto testIndex = extractIndexData<quint16>(indexAttribute, 3 * triangleIndex + i);
+ QCOMPARE(testIndex, indices.at(i));
+
+ const auto position = extractVertexData<QVector3D, quint32>(positionAttribute, index);
+ QCOMPARE(position, positions.at(i));
+
+ const auto normal = extractVertexData<QVector3D, quint32>(normalAttribute, index);
+ QCOMPARE(normal, normals.at(i));
+
+ const auto texCoord = extractVertexData<QVector2D, quint32>(texCoordAttribute, index);
+ QCOMPARE(texCoord, texCoords.at(i));
+
+ const auto tangent = extractVertexData<QVector4D, quint32>(tangentAttribute, index);
+ QCOMPARE(tangent, tangents.at(i));
+
+ ++i;
+ }
+ }
+};
+
+
+QTEST_APPLESS_MAIN(tst_QCuboidGeometry)
+
+#include "tst_qcuboidgeometry.moc"
diff --git a/tests/auto/render/qgraphicsapifilter/qgraphicsapifilter.pro b/tests/auto/render/qgraphicsapifilter/qgraphicsapifilter.pro
new file mode 100644
index 000000000..ce2d9ac12
--- /dev/null
+++ b/tests/auto/render/qgraphicsapifilter/qgraphicsapifilter.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+
+TARGET = tst_qgraphicsapifilter
+
+QT += 3dcore 3dcore-private 3drender 3drender-private testlib
+
+CONFIG += testcase
+
+SOURCES += \
+ tst_qgraphicsapifilter.cpp
+
+include(../../core/common/common.pri)
+include(../commons/commons.pri)
diff --git a/tests/auto/render/qgraphicsapifilter/tst_qgraphicsapifilter.cpp b/tests/auto/render/qgraphicsapifilter/tst_qgraphicsapifilter.cpp
new file mode 100644
index 000000000..7d4a3bfc9
--- /dev/null
+++ b/tests/auto/render/qgraphicsapifilter/tst_qgraphicsapifilter.cpp
@@ -0,0 +1,246 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** 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.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <QObject>
+#include <Qt3DRender/qgraphicsapifilter.h>
+#include <QtGui/qopenglcontext.h>
+#include <QtCore/qsharedpointer.h>
+#include <QSignalSpy>
+
+class tst_QGraphicsApiFilter : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void defaultConstruction()
+ {
+ // WHEN
+ Qt3DRender::QGraphicsApiFilter apiFilter;
+
+ // THEN
+ const auto api = (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL)
+ ? Qt3DRender::QGraphicsApiFilter::OpenGL
+ : Qt3DRender::QGraphicsApiFilter::OpenGLES;
+ QCOMPARE(apiFilter.api(), api);
+ QCOMPARE(apiFilter.profile(), Qt3DRender::QGraphicsApiFilter::NoProfile);
+ QCOMPARE(apiFilter.majorVersion(), 0);
+ QCOMPARE(apiFilter.minorVersion(), 0);
+ QCOMPARE(apiFilter.extensions(), QStringList());
+ QCOMPARE(apiFilter.vendor(), QString());
+ }
+
+ void properties()
+ {
+ // GIVEN
+ Qt3DRender::QGraphicsApiFilter apiFilter;
+
+ {
+ // WHEN
+ QSignalSpy spy(&apiFilter, SIGNAL(apiChanged(Qt3DRender::QGraphicsApiFilter::Api)));
+ apiFilter.setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+
+ // THEN
+ QCOMPARE(apiFilter.api(), Qt3DRender::QGraphicsApiFilter::OpenGL);
+ bool shouldEmitSignal = (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL);
+ QCOMPARE(spy.isEmpty(), !shouldEmitSignal);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&apiFilter, SIGNAL(profileChanged(Qt3DRender::QGraphicsApiFilter::OpenGLProfile)));
+ apiFilter.setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+
+ // THEN
+ QCOMPARE(apiFilter.profile(), Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ QCOMPARE(spy.count(), 1);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&apiFilter, SIGNAL(majorVersionChanged(int)));
+ apiFilter.setMajorVersion(4);
+
+ // THEN
+ QCOMPARE(apiFilter.majorVersion(), 4);
+ QCOMPARE(spy.count(), 1);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&apiFilter, SIGNAL(minorVersionChanged(int)));
+ apiFilter.setMinorVersion(5);
+
+ // THEN
+ QCOMPARE(apiFilter.minorVersion(), 5);
+ QCOMPARE(spy.count(), 1);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&apiFilter, SIGNAL(extensionsChanged(QStringList)));
+ const auto extensions = (QStringList() << QLatin1String("extension1") << QLatin1String("extension2"));
+ apiFilter.setExtensions(extensions);
+
+ // THEN
+ QCOMPARE(apiFilter.extensions(), extensions);
+ QCOMPARE(spy.count(), 1);
+ }
+
+ {
+ // WHEN
+ QSignalSpy spy(&apiFilter, SIGNAL(vendorChanged(QString)));
+ const QLatin1String vendor("Triangles McTriangleFace");
+ apiFilter.setVendor(vendor);
+
+ // THEN
+ QCOMPARE(apiFilter.vendor(), vendor);
+ QCOMPARE(spy.count(), 1);
+ }
+ }
+
+ void shouldDetermineCompatibility_data()
+ {
+ QTest::addColumn<QSharedPointer<Qt3DRender::QGraphicsApiFilter>>("required");
+ QTest::addColumn<QSharedPointer<Qt3DRender::QGraphicsApiFilter>>("actual");
+ QTest::addColumn<bool>("expected");
+
+ auto required = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ required->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ required->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ required->setMajorVersion(4);
+ required->setMinorVersion(5);
+ auto actual = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ actual->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ actual->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ actual->setMajorVersion(4);
+ actual->setMinorVersion(5);
+ bool expected = true;
+ QTest::newRow("exact_match") << required << actual << expected;
+
+ required = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ required->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ required->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ required->setMajorVersion(3);
+ required->setMinorVersion(2);
+ actual = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ actual->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ actual->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ actual->setMajorVersion(4);
+ actual->setMinorVersion(5);
+ expected = true;
+ QTest::newRow("actual_is_higher_version") << required << actual << expected;
+
+ required = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ required->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ required->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ required->setMajorVersion(4);
+ required->setMinorVersion(5);
+ actual = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ actual->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ actual->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ actual->setMajorVersion(3);
+ actual->setMinorVersion(2);
+ expected = false;
+ QTest::newRow("actual_is_lower_version") << required << actual << expected;
+
+ required = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ required->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ required->setProfile(Qt3DRender::QGraphicsApiFilter::CompatibilityProfile);
+ required->setMajorVersion(4);
+ required->setMinorVersion(5);
+ actual = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ actual->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ actual->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ actual->setMajorVersion(4);
+ actual->setMinorVersion(5);
+ expected = false;
+ QTest::newRow("wrong_profile") << required << actual << expected;
+
+ required = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ required->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ required->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ required->setMajorVersion(3);
+ required->setMinorVersion(2);
+ actual = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ actual->setApi(Qt3DRender::QGraphicsApiFilter::OpenGLES);
+ actual->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile);
+ actual->setMajorVersion(3);
+ actual->setMinorVersion(2);
+ expected = false;
+ QTest::newRow("wrong_api") << required << actual << expected;
+
+ required = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ required->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ required->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile);
+ required->setMajorVersion(2);
+ required->setMinorVersion(0);
+ actual = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ actual->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ actual->setProfile(Qt3DRender::QGraphicsApiFilter::CompatibilityProfile);
+ actual->setMajorVersion(3);
+ actual->setMinorVersion(2);
+ expected = true;
+ QTest::newRow("gl_3_2_compatibility_can_use_gl_2_0") << required << actual << expected;
+
+ required = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ required->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ required->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile);
+ required->setMajorVersion(2);
+ required->setMinorVersion(0);
+ actual = QSharedPointer<Qt3DRender::QGraphicsApiFilter>::create();
+ actual->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL);
+ actual->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile);
+ actual->setMajorVersion(3);
+ actual->setMinorVersion(2);
+ expected = false;
+ QTest::newRow("gl_3_2_core_cant_use_gl_2_0") << required << actual << expected;
+ }
+
+ void shouldDetermineCompatibility()
+ {
+ // GIVEN
+ QFETCH(QSharedPointer<Qt3DRender::QGraphicsApiFilter>, required);
+ QFETCH(QSharedPointer<Qt3DRender::QGraphicsApiFilter>, actual);
+ QFETCH(bool, expected);
+
+ // WHEN
+ const auto isCompatible = (*actual == *required);
+
+ // THEN
+ QCOMPARE(isCompatible, expected);
+ }
+
+ // TODO: Add equality test in 5.8 when we can add new api to
+ // test for compatibility and properly use operator == to really
+ // test for equality.
+};
+
+
+QTEST_APPLESS_MAIN(tst_QGraphicsApiFilter)
+
+#include "tst_qgraphicsapifilter.moc"
diff --git a/tests/auto/render/qrendersurfaceselector/qrendersurfaceselector.pro b/tests/auto/render/qrendersurfaceselector/qrendersurfaceselector.pro
new file mode 100644
index 000000000..57626b9ef
--- /dev/null
+++ b/tests/auto/render/qrendersurfaceselector/qrendersurfaceselector.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+
+TARGET = tst_qrendersurfaceselector
+QT += core-private 3dcore 3dcore-private 3drender 3drender-private testlib
+
+CONFIG += testcase
+
+SOURCES += tst_qrendersurfaceselector.cpp
+
+include(../commons/commons.pri)
diff --git a/tests/auto/render/qrendersurfaceselector/tst_qrendersurfaceselector.cpp b/tests/auto/render/qrendersurfaceselector/tst_qrendersurfaceselector.cpp
new file mode 100644
index 000000000..17c7cf40d
--- /dev/null
+++ b/tests/auto/render/qrendersurfaceselector/tst_qrendersurfaceselector.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** 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.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <Qt3DCore/qentity.h>
+
+#include <Qt3DRender/qrendersettings.h>
+#include <Qt3DRender/qrendersurfaceselector.h>
+#include <Qt3DRender/private/qrendersurfaceselector_p.h>
+
+class tst_QRenderSurfaceSelector: public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void shouldFindInstanceInEntityTree_data()
+ {
+ QTest::addColumn<QSharedPointer<Qt3DCore::QEntity>>("root");
+ QTest::addColumn<Qt3DRender::QRenderSurfaceSelector*>("expected");
+
+ auto root = QSharedPointer<Qt3DCore::QEntity>::create();
+ auto settings = new Qt3DRender::QRenderSettings;
+ root->addComponent(settings);
+ auto selector = new Qt3DRender::QRenderSurfaceSelector;
+ settings->setActiveFrameGraph(selector);
+ QTest::newRow("simplest_tree") << root << selector;
+
+ root = QSharedPointer<Qt3DCore::QEntity>::create();
+ settings = new Qt3DRender::QRenderSettings;
+ root->addComponent(settings);
+ settings->setActiveFrameGraph(new Qt3DRender::QFrameGraphNode);
+ selector = nullptr;
+ QTest::newRow("no_selector") << root << selector;
+
+ root = QSharedPointer<Qt3DCore::QEntity>::create();
+ settings = new Qt3DRender::QRenderSettings;
+ root->addComponent(settings);
+ selector = nullptr;
+ QTest::newRow("no_framegraph") << root << selector;
+
+ root = QSharedPointer<Qt3DCore::QEntity>::create();
+ selector = nullptr;
+ QTest::newRow("no_rendersettings") << root << selector;
+
+ root = QSharedPointer<Qt3DCore::QEntity>::create();
+ auto entity = new Qt3DCore::QEntity(root.data());
+ entity = new Qt3DCore::QEntity(entity);
+ settings = new Qt3DRender::QRenderSettings;
+ entity->addComponent(settings);
+ selector = new Qt3DRender::QRenderSurfaceSelector;
+ settings->setActiveFrameGraph(selector);
+ QTest::newRow("in_subentity") << root << selector;
+
+ root = QSharedPointer<Qt3DCore::QEntity>::create();
+ entity = new Qt3DCore::QEntity(root.data());
+ entity = new Qt3DCore::QEntity(entity);
+ settings = new Qt3DRender::QRenderSettings;
+ entity->addComponent(settings);
+ auto node = new Qt3DRender::QFrameGraphNode;
+ settings->setActiveFrameGraph(node);
+ node = new Qt3DRender::QFrameGraphNode(node);
+ selector = new Qt3DRender::QRenderSurfaceSelector(node);
+ QTest::newRow("in_deeper_framegraph") << root << selector;
+ }
+
+ void shouldFindInstanceInEntityTree()
+ {
+ // GIVEN
+ QFETCH(QSharedPointer<Qt3DCore::QEntity>, root);
+
+ // WHEN
+ auto selector = Qt3DRender::QRenderSurfaceSelectorPrivate::find(root.data());
+
+ // THEN
+ QFETCH(Qt3DRender::QRenderSurfaceSelector*, expected);
+ QCOMPARE(selector, expected);
+ }
+};
+
+QTEST_MAIN(tst_QRenderSurfaceSelector)
+
+#include "tst_qrendersurfaceselector.moc"
diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro
index 3c9f4d462..d64a5e4e9 100644
--- a/tests/auto/render/render.pro
+++ b/tests/auto/render/render.pro
@@ -49,5 +49,9 @@ contains(QT_CONFIG, private_tests) {
shadercache \
layerfiltering \
filterentitybycomponent \
- genericlambdajob
+ genericlambdajob \
+ qgraphicsapifilter \
+ qrendersurfaceselector \
+ sortpolicy \
+ qcuboidgeometry
}
diff --git a/tests/auto/render/renderviewutils/tst_renderviewutils.cpp b/tests/auto/render/renderviewutils/tst_renderviewutils.cpp
index 1bda16cba..df68a61d4 100644
--- a/tests/auto/render/renderviewutils/tst_renderviewutils.cpp
+++ b/tests/auto/render/renderviewutils/tst_renderviewutils.cpp
@@ -290,35 +290,45 @@ private:
void tst_RenderViewUtils::topLevelScalarValueNoUniforms()
{
+ // GIVEN
QScopedPointer<ScalarShaderData> shaderData(new ScalarShaderData());
QScopedPointer<Qt3DRender::Render::ShaderDataManager> manager(new Qt3DRender::Render::ShaderDataManager());
+ // WHEN
shaderData->setScalar(883.0f);
initBackendShaderData(shaderData.data(), manager.data());
+ // THEN
Qt3DRender::Render::ShaderData *backendShaderData = manager->lookupResource(shaderData->id());
QVERIFY(backendShaderData != nullptr);
+ // WHEB
Qt3DRender::Render::UniformBlockValueBuilder blockBuilder;
blockBuilder.shaderDataManager = manager.data();
blockBuilder.updatedPropertiesOnly = false;
// build name-value map
blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, QStringLiteral(""));
+
+ // THEN
// activeUniformNamesToValue should be empty as blockBuilder.uniforms is
QVERIFY(blockBuilder.activeUniformNamesToValue.isEmpty());
}
void tst_RenderViewUtils::topLevelScalarValue()
{
+ // GIVEN
QScopedPointer<ScalarShaderData> shaderData(new ScalarShaderData());
QScopedPointer<Qt3DRender::Render::ShaderDataManager> manager(new Qt3DRender::Render::ShaderDataManager());
+ // WHEN
shaderData->setScalar(883.0f);
initBackendShaderData(shaderData.data(), manager.data());
+ // THEN
Qt3DRender::Render::ShaderData *backendShaderData = manager->lookupResource(shaderData->id());
QVERIFY(backendShaderData != nullptr);
+ // WHEN
Qt3DRender::Render::UniformBlockValueBuilder blockBuilder;
blockBuilder.shaderDataManager = manager.data();
blockBuilder.updatedPropertiesOnly = false;
@@ -326,13 +336,16 @@ void tst_RenderViewUtils::topLevelScalarValue()
// build name-value map
blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, QStringLiteral("MyBlock"));
+ // THEN
QVERIFY(blockBuilder.uniforms.count() == 1);
QCOMPARE(blockBuilder.activeUniformNamesToValue.count(), 1);
+ // WHEN
Qt3DRender::Render::UniformBlockValueBuilderHash::const_iterator it = blockBuilder.activeUniformNamesToValue.begin();
const Qt3DRender::Render::UniformBlockValueBuilderHash::const_iterator end = blockBuilder.activeUniformNamesToValue.end();
while (it != end) {
+ // THEN
QVERIFY(blockBuilder.uniforms.contains(Qt3DRender::Render::StringToInt::lookupString(it.key())));
QCOMPARE(it.value(), QVariant(shaderData->scalar()));
++it;
@@ -341,16 +354,20 @@ void tst_RenderViewUtils::topLevelScalarValue()
void tst_RenderViewUtils::topLevelArrayValue()
{
+ // GIVEN
QScopedPointer<ArrayShaderData> shaderData(new ArrayShaderData());
QScopedPointer<Qt3DRender::Render::ShaderDataManager> manager(new Qt3DRender::Render::ShaderDataManager());
+ // WHEN
QVariantList arrayValues = QVariantList() << 454 << 350 << 383 << 427 << 552;
shaderData->setArray(arrayValues);
initBackendShaderData(shaderData.data(), manager.data());
+ // THEN
Qt3DRender::Render::ShaderData *backendShaderData = manager->lookupResource(shaderData->id());
QVERIFY(backendShaderData != nullptr);
+ // WHEN
Qt3DRender::Render::UniformBlockValueBuilder blockBuilder;
blockBuilder.shaderDataManager = manager.data();
blockBuilder.updatedPropertiesOnly = false;
@@ -358,13 +375,16 @@ void tst_RenderViewUtils::topLevelArrayValue()
// build name-value map
blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, QStringLiteral("MyBlock"));
+ // THEN
QVERIFY(blockBuilder.uniforms.count() == 1);
QCOMPARE(blockBuilder.activeUniformNamesToValue.count(), 1);
+ // WHEN
Qt3DRender::Render::UniformBlockValueBuilderHash::const_iterator it = blockBuilder.activeUniformNamesToValue.begin();
const Qt3DRender::Render::UniformBlockValueBuilderHash::const_iterator end = blockBuilder.activeUniformNamesToValue.end();
while (it != end) {
+ // THEN
QVERIFY(blockBuilder.uniforms.contains(Qt3DRender::Render::StringToInt::lookupString(it.key())));
QCOMPARE(it.value(), QVariant(arrayValues));
++it;
@@ -405,15 +425,19 @@ void tst_RenderViewUtils::topLevelStructValue_data()
void tst_RenderViewUtils::topLevelStructValue()
{
+ // GIVEN
QFETCH(StructShaderData *, shaderData);
QFETCH(QString, blockName);
QScopedPointer<Qt3DRender::Render::ShaderDataManager> manager(new Qt3DRender::Render::ShaderDataManager());
+ // WHEN
initBackendShaderData(shaderData, manager.data());
+ // THEN
Qt3DRender::Render::ShaderData *backendShaderData = manager->lookupResource(shaderData->id());
QVERIFY(backendShaderData != nullptr);
+ // WHEN
Qt3DRender::Render::UniformBlockValueBuilder blockBuilder;
blockBuilder.shaderDataManager = manager.data();
blockBuilder.updatedPropertiesOnly = false;
@@ -422,12 +446,15 @@ void tst_RenderViewUtils::topLevelStructValue()
// build name-value map
blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, blockName);
+ // THEN
QCOMPARE(blockBuilder.activeUniformNamesToValue.count(), blockBuilder.uniforms.count());
+ // WHEN
Qt3DRender::Render::UniformBlockValueBuilderHash::const_iterator it = blockBuilder.activeUniformNamesToValue.begin();
const Qt3DRender::Render::UniformBlockValueBuilderHash::const_iterator end = blockBuilder.activeUniformNamesToValue.end();
while (it != end) {
+ // THEN
QVERIFY(blockBuilder.uniforms.contains(Qt3DRender::Render::StringToInt::lookupString(it.key())));
QVERIFY(expectedValues.contains(Qt3DRender::Render::StringToInt::lookupString(it.key())));
QCOMPARE(it.value(), expectedValues.value(Qt3DRender::Render::StringToInt::lookupString(it.key())));
@@ -437,16 +464,20 @@ void tst_RenderViewUtils::topLevelStructValue()
void tst_RenderViewUtils::topLevelDynamicProperties()
{
+ // GIVEN
QScopedPointer<Qt3DRender::QShaderData> shaderData(new Qt3DRender::QShaderData());
QScopedPointer<Qt3DRender::Render::ShaderDataManager> manager(new Qt3DRender::Render::ShaderDataManager());
+ // WHEN
shaderData->setProperty("scalar", 883.0f);
shaderData->setProperty("array", QVariantList() << 454 << 350 << 383 << 427 << 552);
initBackendShaderData(shaderData.data(), manager.data());
+ // THEN
Qt3DRender::Render::ShaderData *backendShaderData = manager->lookupResource(shaderData->id());
QVERIFY(backendShaderData != nullptr);
+ // WHEN
Qt3DRender::Render::UniformBlockValueBuilder blockBuilder;
blockBuilder.shaderDataManager = manager.data();
blockBuilder.updatedPropertiesOnly = false;
@@ -455,6 +486,7 @@ void tst_RenderViewUtils::topLevelDynamicProperties()
// build name-value map
blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, QStringLiteral("MyBlock"));
+ // THEN
QVERIFY(blockBuilder.uniforms.count() == 2);
QCOMPARE(blockBuilder.activeUniformNamesToValue.count(), 2);
diff --git a/tests/auto/render/sortpolicy/sortpolicy.pro b/tests/auto/render/sortpolicy/sortpolicy.pro
new file mode 100644
index 000000000..18b28cff7
--- /dev/null
+++ b/tests/auto/render/sortpolicy/sortpolicy.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+
+TARGET = tst_sortpolicy
+
+QT += 3dcore 3dcore-private 3drender 3drender-private testlib
+
+CONFIG += testcase
+
+SOURCES += \
+ tst_sortpolicy.cpp
+
+include(../../core/common/common.pri)
+include(../commons/commons.pri)
diff --git a/tests/auto/render/sortpolicy/tst_sortpolicy.cpp b/tests/auto/render/sortpolicy/tst_sortpolicy.cpp
new file mode 100644
index 000000000..8cab1a9c4
--- /dev/null
+++ b/tests/auto/render/sortpolicy/tst_sortpolicy.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** 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.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <qbackendnodetester.h>
+#include <Qt3DRender/private/sortpolicy_p.h>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+#include "testrenderer.h"
+
+class tst_SortPolicy : public Qt3DCore::QBackendNodeTester
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void checkInitialState()
+ {
+ // GIVEN
+ TestRenderer renderer;
+ Qt3DRender::Render::SortPolicy backendNode;
+ backendNode.setRenderer(&renderer);
+
+ // THEN
+ QVERIFY(backendNode.peerId().isNull());
+ QVERIFY(backendNode.parentId().isNull());
+ QVERIFY(backendNode.sortTypes().isEmpty());
+ }
+
+ void checkPeerPropertyMirroring()
+ {
+ // GIVEN
+ Qt3DRender::QFrameGraphNode parent;
+ auto parentBackend = new Qt3DRender::Render::FrameGraphNode;
+ simulateInitialization(&parent, parentBackend);
+
+ Qt3DRender::Render::FrameGraphManager manager;
+ manager.appendNode(parent.id(), parentBackend);
+
+ const auto sortTypes = QVector<Qt3DRender::QSortPolicy::SortType>() << Qt3DRender::QSortPolicy::BackToFront
+ << Qt3DRender::QSortPolicy::Material;
+ Qt3DRender::Render::SortPolicy backendNode;
+ backendNode.setFrameGraphManager(&manager);
+ Qt3DRender::QSortPolicy sortPolicy(&parent);
+ sortPolicy.setSortTypes(sortTypes);
+
+ // WHEN
+ simulateInitialization(&sortPolicy, &backendNode);
+
+ // THEN
+ QCOMPARE(backendNode.peerId(), sortPolicy.id());
+ QCOMPARE(backendNode.parentId(), parent.id());
+ QCOMPARE(backendNode.sortTypes(), sortTypes);
+ }
+
+ void checkPropertyChanges()
+ {
+ // GIVEN
+ const auto sortTypes = QVector<Qt3DRender::QSortPolicy::SortType>() << Qt3DRender::QSortPolicy::BackToFront
+ << Qt3DRender::QSortPolicy::Material;
+ TestRenderer renderer;
+ Qt3DRender::Render::SortPolicy backendNode;
+ backendNode.setRenderer(&renderer);
+
+ // WHEN
+ auto sortTypeInts = QVector<int>();
+ std::transform(sortTypes.constBegin(), sortTypes.constEnd(),
+ std::back_inserter(sortTypeInts),
+ [] (Qt3DRender::QSortPolicy::SortType type) -> int { return type; });
+ Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setValue(QVariant::fromValue(sortTypeInts));
+ updateChange->setPropertyName("sortTypes");
+ backendNode.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendNode.sortTypes(), sortTypes);
+ }
+};
+
+
+QTEST_APPLESS_MAIN(tst_SortPolicy)
+
+#include "tst_sortpolicy.moc"