From 2fd3e28766ede1d3334ab0248fb19b65d2e9e7d9 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Wed, 10 Aug 2016 16:28:44 +0200 Subject: Move tests for QCuboidGeometry into extras Change-Id: I6ffb9e0a743dfad78624b2edcfa2d93d69d685dd Reviewed-by: Sean Harmer --- tests/auto/auto.pro | 3 +- tests/auto/extras/extras.pro | 4 + .../extras/qcuboidgeometry/qcuboidgeometry.pro | 10 + .../extras/qcuboidgeometry/tst_qcuboidgeometry.cpp | 505 +++++++++++++++++++++ .../render/qcuboidgeometry/qcuboidgeometry.pro | 13 - .../render/qcuboidgeometry/tst_qcuboidgeometry.cpp | 505 --------------------- tests/auto/render/render.pro | 1 - 7 files changed, 521 insertions(+), 520 deletions(-) create mode 100644 tests/auto/extras/extras.pro create mode 100644 tests/auto/extras/qcuboidgeometry/qcuboidgeometry.pro create mode 100644 tests/auto/extras/qcuboidgeometry/tst_qcuboidgeometry.cpp delete mode 100644 tests/auto/render/qcuboidgeometry/qcuboidgeometry.pro delete mode 100644 tests/auto/render/qcuboidgeometry/tst_qcuboidgeometry.cpp diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 7d19ad26d..e5745a99e 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -5,6 +5,7 @@ SUBDIRS = \ render \ quick3d \ cmake \ - input + input \ + extras installed_cmake.depends = cmake diff --git a/tests/auto/extras/extras.pro b/tests/auto/extras/extras.pro new file mode 100644 index 000000000..3bba4d37b --- /dev/null +++ b/tests/auto/extras/extras.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS = \ + qcuboidgeometry diff --git a/tests/auto/extras/qcuboidgeometry/qcuboidgeometry.pro b/tests/auto/extras/qcuboidgeometry/qcuboidgeometry.pro new file mode 100644 index 000000000..7208f1c7b --- /dev/null +++ b/tests/auto/extras/qcuboidgeometry/qcuboidgeometry.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +TARGET = tst_qcuboidgeometry + +QT += 3dextras testlib + +CONFIG += testcase + +SOURCES += \ + tst_qcuboidgeometry.cpp diff --git a/tests/auto/extras/qcuboidgeometry/tst_qcuboidgeometry.cpp b/tests/auto/extras/qcuboidgeometry/tst_qcuboidgeometry.cpp new file mode 100644 index 000000000..ddd9eed22 --- /dev/null +++ b/tests/auto/extras/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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +void generateGeometry(Qt3DRender::QGeometry &geometry) +{ + // Get all attributes + const QVector attributes = geometry.attributes(); + + // Get all unique data generators from the buffers referenced by the attributes + QHash 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 +IndexType extractIndexData(Qt3DRender::QAttribute *attribute, int index) +{ + // Get the raw data + const IndexType *typedData = reinterpret_cast(attribute->buffer()->data().constData()); + + // Offset into the data taking stride and offset into account + const IndexType indexValue = *(typedData + index); + return indexValue; +} + +template +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(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("xExtent"); + QTest::addColumn("yExtent"); + QTest::addColumn("zExtent"); + QTest::addColumn("xyMeshResolution"); + QTest::addColumn("yzMeshResolution"); + QTest::addColumn("xzMeshResolution"); + QTest::addColumn("triangleIndex"); + QTest::addColumn>("indices"); + QTest::addColumn>("positions"); + QTest::addColumn>("normals"); + QTest::addColumn>("texCoords"); + QTest::addColumn>("tangents"); + + { + const int triangleIndex = 0; + const auto indices = (QVector() << 0 << 1 << 2); + const auto positions = (QVector() + << 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(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(0.0f, 0.0f) + << QVector2D(0.0f, 1.0f) + << QVector2D(1.0f, 0.0f)); + const auto tangents = (QVector() + << 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() << 6 << 5 << 7); + const auto positions = (QVector() + << 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(-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(1.0f, 0.0f) + << QVector2D(0.0f, 1.0f) + << QVector2D(1.0f, 1.0f)); + const auto tangents = (QVector() + << 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() << 8 << 9 << 10); + const auto positions = (QVector() + << 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(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(0.0f, 0.0f) + << QVector2D(1.0f, 0.0f) + << QVector2D(0.0f, 1.0f)); + const auto tangents = (QVector() + << 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() << 14 << 13 << 15); + const auto positions = (QVector() + << 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(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(0.0f, 1.0f) + << QVector2D(1.0f, 0.0f) + << QVector2D(1.0f, 1.0f)); + const auto tangents = (QVector() + << 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() << 16 << 17 << 18); + const auto positions = (QVector() + << 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(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(0.0f, 0.0f) + << QVector2D(1.0f, 0.0f) + << QVector2D(0.0f, 1.0f)); + const auto tangents = (QVector() + << 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() << 22 << 21 << 23); + const auto positions = (QVector() + << 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(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(0.0f, 1.0f) + << QVector2D(1.0f, 0.0f) + << QVector2D(1.0f, 1.0f)); + const auto tangents = (QVector() + << 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 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, indices); + QFETCH(QVector, positions); + QFETCH(QVector, normals); + QFETCH(QVector, texCoords); + QFETCH(QVector, tangents); + + int i = 0; + for (auto index : indices) { + const auto testIndex = extractIndexData(indexAttribute, 3 * triangleIndex + i); + QCOMPARE(testIndex, indices.at(i)); + + const auto position = extractVertexData(positionAttribute, index); + QCOMPARE(position, positions.at(i)); + + const auto normal = extractVertexData(normalAttribute, index); + QCOMPARE(normal, normals.at(i)); + + const auto texCoord = extractVertexData(texCoordAttribute, index); + QCOMPARE(texCoord, texCoords.at(i)); + + const auto tangent = extractVertexData(tangentAttribute, index); + QCOMPARE(tangent, tangents.at(i)); + + ++i; + } + } +}; + + +QTEST_APPLESS_MAIN(tst_QCuboidGeometry) + +#include "tst_qcuboidgeometry.moc" diff --git a/tests/auto/render/qcuboidgeometry/qcuboidgeometry.pro b/tests/auto/render/qcuboidgeometry/qcuboidgeometry.pro deleted file mode 100644 index 2599b5fe6..000000000 --- a/tests/auto/render/qcuboidgeometry/qcuboidgeometry.pro +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ddd9eed22..000000000 --- a/tests/auto/render/qcuboidgeometry/tst_qcuboidgeometry.cpp +++ /dev/null @@ -1,505 +0,0 @@ -/**************************************************************************** -** -** 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - -void generateGeometry(Qt3DRender::QGeometry &geometry) -{ - // Get all attributes - const QVector attributes = geometry.attributes(); - - // Get all unique data generators from the buffers referenced by the attributes - QHash 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 -IndexType extractIndexData(Qt3DRender::QAttribute *attribute, int index) -{ - // Get the raw data - const IndexType *typedData = reinterpret_cast(attribute->buffer()->data().constData()); - - // Offset into the data taking stride and offset into account - const IndexType indexValue = *(typedData + index); - return indexValue; -} - -template -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(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("xExtent"); - QTest::addColumn("yExtent"); - QTest::addColumn("zExtent"); - QTest::addColumn("xyMeshResolution"); - QTest::addColumn("yzMeshResolution"); - QTest::addColumn("xzMeshResolution"); - QTest::addColumn("triangleIndex"); - QTest::addColumn>("indices"); - QTest::addColumn>("positions"); - QTest::addColumn>("normals"); - QTest::addColumn>("texCoords"); - QTest::addColumn>("tangents"); - - { - const int triangleIndex = 0; - const auto indices = (QVector() << 0 << 1 << 2); - const auto positions = (QVector() - << 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(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(0.0f, 0.0f) - << QVector2D(0.0f, 1.0f) - << QVector2D(1.0f, 0.0f)); - const auto tangents = (QVector() - << 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() << 6 << 5 << 7); - const auto positions = (QVector() - << 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(-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(1.0f, 0.0f) - << QVector2D(0.0f, 1.0f) - << QVector2D(1.0f, 1.0f)); - const auto tangents = (QVector() - << 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() << 8 << 9 << 10); - const auto positions = (QVector() - << 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(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(0.0f, 0.0f) - << QVector2D(1.0f, 0.0f) - << QVector2D(0.0f, 1.0f)); - const auto tangents = (QVector() - << 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() << 14 << 13 << 15); - const auto positions = (QVector() - << 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(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(0.0f, 1.0f) - << QVector2D(1.0f, 0.0f) - << QVector2D(1.0f, 1.0f)); - const auto tangents = (QVector() - << 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() << 16 << 17 << 18); - const auto positions = (QVector() - << 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(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(0.0f, 0.0f) - << QVector2D(1.0f, 0.0f) - << QVector2D(0.0f, 1.0f)); - const auto tangents = (QVector() - << 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() << 22 << 21 << 23); - const auto positions = (QVector() - << 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(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(0.0f, 1.0f) - << QVector2D(1.0f, 0.0f) - << QVector2D(1.0f, 1.0f)); - const auto tangents = (QVector() - << 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 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, indices); - QFETCH(QVector, positions); - QFETCH(QVector, normals); - QFETCH(QVector, texCoords); - QFETCH(QVector, tangents); - - int i = 0; - for (auto index : indices) { - const auto testIndex = extractIndexData(indexAttribute, 3 * triangleIndex + i); - QCOMPARE(testIndex, indices.at(i)); - - const auto position = extractVertexData(positionAttribute, index); - QCOMPARE(position, positions.at(i)); - - const auto normal = extractVertexData(normalAttribute, index); - QCOMPARE(normal, normals.at(i)); - - const auto texCoord = extractVertexData(texCoordAttribute, index); - QCOMPARE(texCoord, texCoords.at(i)); - - const auto tangent = extractVertexData(tangentAttribute, index); - QCOMPARE(tangent, tangents.at(i)); - - ++i; - } - } -}; - - -QTEST_APPLESS_MAIN(tst_QCuboidGeometry) - -#include "tst_qcuboidgeometry.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index 1c1ca4d68..d86e73c96 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -52,7 +52,6 @@ contains(QT_CONFIG, private_tests) { qgraphicsapifilter \ qrendersurfaceselector \ sortpolicy \ - qcuboidgeometry \ sceneloader \ qsceneloader \ qrendertargetoutput \ -- cgit v1.2.3