diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2016-08-14 09:23:05 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-08-14 09:41:21 +0100 |
commit | 9a18925b63d47a20d7b74cfd508d7ae71f2d4d7c (patch) | |
tree | 4d0d0538b9475a9104d56ee3d07f4bab7b0e00b4 /tests | |
parent | 9a1c0c96246126d2377bd56ed702f47214e3ee0a (diff) | |
parent | 71eee85093ba807f5bc2add472b359841faa062d (diff) |
Merge branch '5.7' into dev
Change-Id: Id62e225062a030f4864fb7af2ed6f60d6be87460
Diffstat (limited to 'tests')
31 files changed, 1331 insertions, 67 deletions
diff --git a/tests/auto/core/handlemanager/tst_handlemanager.cpp b/tests/auto/core/handlemanager/tst_handlemanager.cpp index a60d3cc57..3198b54a9 100644 --- a/tests/auto/core/handlemanager/tst_handlemanager.cpp +++ b/tests/auto/core/handlemanager/tst_handlemanager.cpp @@ -47,6 +47,7 @@ private slots: void updateChangesValue(); void resetRemovesAllEntries(); void maximumEntries(); + void checkNoCounterOverflow(); }; class SimpleResource @@ -63,61 +64,83 @@ typedef Qt3DCore::QHandle<SimpleResource> Handle; void tst_HandleManager::construction() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; + + // THEN QVERIFY(manager.activeEntries() == 0); } void tst_HandleManager::correctPointer() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; SimpleResource *p1 = (SimpleResource *)0xdeadbeef; + + // WHEN const Handle h = manager.acquire(p1); bool ok = false; SimpleResource *p2 = manager.data(h, &ok); + + // THEN QVERIFY(ok == true); QVERIFY(p1 == p2); } void tst_HandleManager::correctPointers() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; SimpleResource *p[3]; p[0] = (SimpleResource *)0xdeadbeef; p[1] = (SimpleResource *)0x11111111; p[2] = (SimpleResource *)0x22222222; + // WHEN for (int i = 0; i < 3; ++i) { + // WHEN const Handle h = manager.acquire(p[i]); bool ok = false; SimpleResource *q = manager.data(h, &ok); + + // THEN QVERIFY(ok == true); QVERIFY(p[i] == q); } + // THEN QVERIFY(manager.activeEntries() == 3); } void tst_HandleManager::correctConstPointer() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; QSharedPointer<SimpleResource> p1(new SimpleResource); const Handle h = manager.acquire(p1.data()); + // WHEN bool ok = false; const SimpleResource *p2 = manager.constData(h, &ok); + + // THEN QVERIFY(ok == true); QVERIFY(p1.data() == p2); } void tst_HandleManager::nullForRemovedEntry() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; QSharedPointer<SimpleResource> p1(new SimpleResource); const Handle h = manager.acquire(p1.data()); + + // WHEN manager.release(h); + // THEN bool ok = false; SimpleResource *p2 = manager.data(h, &ok); QVERIFY(ok == false); @@ -126,44 +149,67 @@ void tst_HandleManager::nullForRemovedEntry() void tst_HandleManager::validHandleForReplacementEntry() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; QSharedPointer<SimpleResource> p1(new SimpleResource); const Handle h = manager.acquire(p1.data()); + + // THEN QVERIFY(manager.activeEntries() == 1); + + // WHEN manager.release(h); + + // THEN QVERIFY(manager.activeEntries() == 0); + // WHEN QSharedPointer<SimpleResource> p2(new SimpleResource); const Handle h2 = manager.acquire(p2.data()); + + // THEN QVERIFY(h2.isNull() == false); QVERIFY(h2.counter() == 2); QVERIFY(manager.activeEntries() == 1); + // WHEN bool ok = false; SimpleResource *p3 = manager.data(h2, &ok); + + // THEN QVERIFY(ok == true); QVERIFY(p3 == p2); } void tst_HandleManager::updateChangesValue() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; QSharedPointer<SimpleResource> p1(new SimpleResource); const Handle h = manager.acquire(p1.data()); + // WHEN QSharedPointer<SimpleResource> p2(new SimpleResource); manager.update(h, p2.data()); + + // THEN QVERIFY(manager.activeEntries() == 1); + // WHEN bool ok = false; SimpleResource *p3 = manager.data(h, &ok); + + // THEN QVERIFY(ok == true); QVERIFY(p3 == p2); } void tst_HandleManager::resetRemovesAllEntries() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; + + // WHEN for (int i = 0; i < 100; ++i) { SimpleResource *p = (SimpleResource *) 0xdead0000 + i; const Handle h = manager.acquire(p); @@ -174,18 +220,25 @@ void tst_HandleManager::resetRemovesAllEntries() QVERIFY(p == q); } + // THEN QVERIFY(manager.activeEntries() == 100); + // WHEN manager.reset(); + + // THEN QVERIFY(manager.activeEntries() == 0); } void tst_HandleManager::maximumEntries() { + // GIVEN Qt3DCore::QHandleManager<SimpleResource> manager; + // THEN QCOMPARE(Handle::maxIndex(), (uint)((1 << 16) - 1)); + // WHEN for (int i = 0; i < (int)Handle::maxIndex(); ++i) { SimpleResource *p = (SimpleResource *) 0xdead0000 + i; const Handle h = manager.acquire(p); @@ -196,11 +249,58 @@ void tst_HandleManager::maximumEntries() QVERIFY(p == q); } - QVERIFY(manager.activeEntries() == Handle::maxIndex()); + // THEN + QVERIFY(manager.activeEntries() == Handle::maxIndex());\ + + // WHEN manager.reset(); + + // THEN QVERIFY(manager.activeEntries() == 0); } +void tst_HandleManager::checkNoCounterOverflow() +{ + // GIVEN + const int indexBits = 16; + Qt3DCore::QHandleManager<SimpleResource, indexBits> manager; + SimpleResource *p = (SimpleResource *) 0xdead0000; + Qt3DCore::QHandle<SimpleResource, indexBits> h = manager.acquire(p); + + // THEN + QCOMPARE(h.maxCounter(), (quint32)((1 << (32 - indexBits - 2)) - 1)); + QCOMPARE(h.counter(), (quint32)1); + + // WHEN + const quint32 maxIterations = h.maxCounter() - 2; + const quint32 handleIndex = h.index(); + + qDebug() << maxIterations << handleIndex; + + // Acquire and release maxIteration time to increase counter + for (quint32 i = 0; i < maxIterations; ++i) { + // WHEN + manager.release(h); + h = manager.acquire(p); + + // THEN + QCOMPARE(h.index(), handleIndex); + QCOMPARE(h.counter(), i + 2); + } + + // THEN + QCOMPARE(h.counter(), h.maxCounter() - 1); + + // WHEN + manager.release(h); + h = manager.acquire(p); + + // THEN + QCOMPARE(h.counter(), (quint32)1); +} + + + QTEST_APPLESS_MAIN(tst_HandleManager) #include "tst_handlemanager.moc" diff --git a/tests/auto/core/qtransform/tst_qtransform.cpp b/tests/auto/core/qtransform/tst_qtransform.cpp index 0713ec775..ee63255b8 100644 --- a/tests/auto/core/qtransform/tst_qtransform.cpp +++ b/tests/auto/core/qtransform/tst_qtransform.cpp @@ -41,6 +41,23 @@ class tst_QTransform : public QObject Q_OBJECT private Q_SLOTS: + void defaultConstruction() + { + // GIVEN + Qt3DCore::QTransform transform; + + // THEN + QCOMPARE(transform.isShareable(), false); + QCOMPARE(transform.matrix(), QMatrix4x4()); + QCOMPARE(transform.scale(), 1.0f); + QCOMPARE(transform.scale3D(), QVector3D(1.0f, 1.0f, 1.0f)); + QCOMPARE(transform.rotation(), QQuaternion()); + QCOMPARE(transform.rotationX(), 0.0f); + QCOMPARE(transform.rotationY(), 0.0f); + QCOMPARE(transform.rotationZ(), 0.0f); + QCOMPARE(transform.translation(), QVector3D(0.0f, 0.0f, 0.0f)); + } + void checkCloning_data() { QTest::addColumn<Qt3DCore::QTransform *>("transform"); 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" diff --git a/tests/manual/assimp-cpp/main.cpp b/tests/manual/assimp-cpp/main.cpp index 9701cb66a..06e0907be 100644 --- a/tests/manual/assimp-cpp/main.cpp +++ b/tests/manual/assimp-cpp/main.cpp @@ -118,7 +118,7 @@ int main(int ac, char **av) { QApplication app(ac, av); Qt3DExtras::Qt3DWindow view; - view.defaultFramegraph()->setClearColor(Qt::black); + view.defaultFrameGraph()->setClearColor(Qt::black); // Root entity Qt3DCore::QEntity *sceneRoot = new Qt3DCore::QEntity(); diff --git a/tests/manual/bigscene-cpp/main.cpp b/tests/manual/bigscene-cpp/main.cpp index 95b198f58..ebbd499f3 100644 --- a/tests/manual/bigscene-cpp/main.cpp +++ b/tests/manual/bigscene-cpp/main.cpp @@ -77,7 +77,7 @@ int main(int ac, char **av) { QGuiApplication app(ac, av); Qt3DExtras::Qt3DWindow view; - view.defaultFramegraph()->setClearColor(Qt::black); + view.defaultFrameGraph()->setClearColor(Qt::black); QEntity *root = new QEntity(); diff --git a/tests/manual/clip-planes-qml/CappingMaterialEffect.qml b/tests/manual/clip-planes-qml/CappingMaterialEffect.qml index 512e9f920..e503b15e3 100644 --- a/tests/manual/clip-planes-qml/CappingMaterialEffect.qml +++ b/tests/manual/clip-planes-qml/CappingMaterialEffect.qml @@ -70,7 +70,7 @@ Effect { graphicsApiFilter { api: GraphicsApiFilter.OpenGL - profile: GraphicsApiFilter.NoProfile + profile: GraphicsApiFilter.CoreProfile majorVersion: 3 minorVersion: 2 } diff --git a/tests/manual/clip-planes-qml/ClipMaterialEffect.qml b/tests/manual/clip-planes-qml/ClipMaterialEffect.qml index 7132831ed..f6761403f 100644 --- a/tests/manual/clip-planes-qml/ClipMaterialEffect.qml +++ b/tests/manual/clip-planes-qml/ClipMaterialEffect.qml @@ -69,7 +69,7 @@ Effect { graphicsApiFilter { api: GraphicsApiFilter.OpenGL - profile: GraphicsApiFilter.NoProfile + profile: GraphicsApiFilter.CoreProfile majorVersion: 3 minorVersion: 2 } diff --git a/tests/manual/clip-planes-qml/main.qml b/tests/manual/clip-planes-qml/main.qml index 4ab043285..7f449e291 100644 --- a/tests/manual/clip-planes-qml/main.qml +++ b/tests/manual/clip-planes-qml/main.qml @@ -91,7 +91,7 @@ Entity { ClippingPlanes { id: clippingPlanes visualizationLayer: frameGraph.visualizationLayer - capsLayer: frameGraph.contentLayer + capsLayer: frameGraph.capsLayer } // Entity being clipped diff --git a/tests/manual/custom-mesh-cpp/main.cpp b/tests/manual/custom-mesh-cpp/main.cpp index 26fc236be..e51321e65 100644 --- a/tests/manual/custom-mesh-cpp/main.cpp +++ b/tests/manual/custom-mesh-cpp/main.cpp @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); Qt3DExtras::Qt3DWindow view; - view.defaultFramegraph()->setClearColor(QColor::fromRgbF(0.0, 0.5, 1.0, 1.0)); + view.defaultFrameGraph()->setClearColor(QColor::fromRgbF(0.0, 0.5, 1.0, 1.0)); // Root entity Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); diff --git a/tests/manual/custom-mesh-update-data-cpp/main.cpp b/tests/manual/custom-mesh-update-data-cpp/main.cpp index 94c4d6982..7485dbec5 100644 --- a/tests/manual/custom-mesh-update-data-cpp/main.cpp +++ b/tests/manual/custom-mesh-update-data-cpp/main.cpp @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); Qt3DExtras::Qt3DWindow view; - view.defaultFramegraph()->setClearColor(QColor::fromRgbF(0.0, 0.5, 1.0, 1.0)); + view.defaultFrameGraph()->setClearColor(QColor::fromRgbF(0.0, 0.5, 1.0, 1.0)); // Root entity Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); diff --git a/tests/manual/deferred-renderer-cpp/deferredrenderer.cpp b/tests/manual/deferred-renderer-cpp/deferredrenderer.cpp index 5d613fef8..48f8ad3fe 100644 --- a/tests/manual/deferred-renderer-cpp/deferredrenderer.cpp +++ b/tests/manual/deferred-renderer-cpp/deferredrenderer.cpp @@ -64,7 +64,9 @@ DeferredRenderer::DeferredRenderer(Qt3DCore::QNode *parent) , m_geometryPassFilter(new Qt3DRender::QRenderPassFilter(m_clearGBuffer)) , m_finalPassFilter(new Qt3DRender::QRenderPassFilter(m_clearScreenQuad)) , m_sceneCameraSelector(new Qt3DRender::QCameraSelector(m_geometryPassFilter)) + , m_winSize(new Qt3DRender::QParameter(QStringLiteral("winSize"), QSizeF(1024.0f, 768.0f))) , m_gBuffer(new GBuffer(this)) + , m_window(nullptr) { m_clearGBuffer->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer); m_clearScreenQuad->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer); @@ -73,13 +75,7 @@ DeferredRenderer::DeferredRenderer(Qt3DCore::QNode *parent) m_finalPassFilter->addParameter(new Qt3DRender::QParameter(QStringLiteral("position"), m_gBuffer->positionTexture())); m_finalPassFilter->addParameter(new Qt3DRender::QParameter(QStringLiteral("normal"), m_gBuffer->normalTexture())); m_finalPassFilter->addParameter(new Qt3DRender::QParameter(QStringLiteral("color"), m_gBuffer->colorTexture())); - - Qt3DRender::QParameter *winSize = new Qt3DRender::QParameter(QStringLiteral("winSize"), QSize(1024, 768)); - QObject::connect(m_surfaceSelector, &Qt3DRender::QRenderSurfaceSelector::externalRenderTargetSizeChanged, - [=] (const QSize &viewSize) { - winSize->setValue(viewSize); - }); - m_finalPassFilter->addParameter(winSize); + m_finalPassFilter->addParameter(m_winSize); } void DeferredRenderer::setSceneCamera(Qt3DCore::QEntity *camera) @@ -111,5 +107,27 @@ void DeferredRenderer::setScreenQuadLayer(Qt3DRender::QLayer *layer) void DeferredRenderer::setSurface(QWindow *surface) { - m_surfaceSelector->setSurface(surface); + if (surface != m_window) { + + // Disconnect old window's signals + if (m_window != nullptr) { + QObject::disconnect(m_widthChangedConnection); + QObject::disconnect(m_heightChangedConnection); + } + + m_window = surface; + m_surfaceSelector->setSurface(surface); + + if (m_window != nullptr) { + // Store connections + m_widthChangedConnection = QObject::connect(surface, &QWindow::widthChanged, + [this] (int width) { + m_winSize->setValue(QSizeF(float(width), m_winSize->value().toSizeF().height())); + }); + m_heightChangedConnection = QObject::connect(surface, &QWindow::heightChanged, + [this] (int height) { + m_winSize->setValue(QSizeF(m_winSize->value().toSizeF().width(), float(height))); + }); + } + } } diff --git a/tests/manual/deferred-renderer-cpp/deferredrenderer.h b/tests/manual/deferred-renderer-cpp/deferredrenderer.h index 4483afb07..0d22c1e81 100644 --- a/tests/manual/deferred-renderer-cpp/deferredrenderer.h +++ b/tests/manual/deferred-renderer-cpp/deferredrenderer.h @@ -85,7 +85,12 @@ private: Qt3DRender::QRenderPassFilter *m_geometryPassFilter; Qt3DRender::QRenderPassFilter *m_finalPassFilter; Qt3DRender::QCameraSelector *m_sceneCameraSelector; + Qt3DRender::QParameter *m_winSize; GBuffer *m_gBuffer; + QWindow *m_window; + + QMetaObject::Connection m_widthChangedConnection; + QMetaObject::Connection m_heightChangedConnection; }; #endif // DEFERREDRENDERER_H diff --git a/tests/manual/deferred-renderer-cpp/sceneeffect.cpp b/tests/manual/deferred-renderer-cpp/sceneeffect.cpp index 8e0b597ca..570df66c7 100644 --- a/tests/manual/deferred-renderer-cpp/sceneeffect.cpp +++ b/tests/manual/deferred-renderer-cpp/sceneeffect.cpp @@ -65,10 +65,10 @@ SceneEffect::SceneEffect(Qt3DCore::QNode *parent) , m_passCriterion(new Qt3DRender::QFilterKey(this)) { - m_gl3Technique->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile); + m_gl3Technique->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile); m_gl3Technique->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); m_gl3Technique->graphicsApiFilter()->setMajorVersion(3); - m_gl3Technique->graphicsApiFilter()->setMinorVersion(3); + m_gl3Technique->graphicsApiFilter()->setMinorVersion(1); m_gl2Technique->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); m_gl2Technique->graphicsApiFilter()->setMajorVersion(2); diff --git a/tests/manual/deferred-renderer-qml/DeferredRenderer.qml b/tests/manual/deferred-renderer-qml/DeferredRenderer.qml index 9ee2c2345..8e10005a5 100644 --- a/tests/manual/deferred-renderer-qml/DeferredRenderer.qml +++ b/tests/manual/deferred-renderer-qml/DeferredRenderer.qml @@ -61,7 +61,12 @@ Viewport { property alias screenQuadLayer: screenQuadLayerFilter.layers property alias debugLayer: debugLayerFilter.layers + readonly property real windowWidth: surfaceSelector.surface !== null ? surfaceSelector.surface.width: 0 + readonly property real windowHeight: surfaceSelector.surface !== null ? surfaceSelector.surface.height: 0 + RenderSurfaceSelector { + id: surfaceSelector + CameraSelector { id : sceneCameraSelector @@ -104,7 +109,7 @@ Viewport { buffers: ClearBuffers.ColorDepthBuffer RenderPassFilter { matchAny : FilterKey { name : "pass"; value : "final" } - parameters: Parameter { name: "winSize"; value : Qt.size(1024, 768) } + parameters: Parameter { name: "winSize"; value : Qt.size(windowWidth, windowHeight) } } } @@ -116,7 +121,7 @@ Viewport { normalizedRect : Qt.rect(0.5, 0.5, 0.5, 0.5) RenderPassFilter { matchAny : FilterKey { name : "pass"; value : "final" } - parameters: Parameter { name: "winSize"; value : Qt.size(1024 * 0.5, 768 * 0.5) } + parameters: Parameter { name: "winSize"; value : Qt.size(windowWidth * 0.5, windowHeight * 0.5) } } } } diff --git a/tests/manual/deferred-renderer-qml/GBufferDebugger.qml b/tests/manual/deferred-renderer-qml/GBufferDebugger.qml index f7c730cb1..7f148099e 100644 --- a/tests/manual/deferred-renderer-qml/GBufferDebugger.qml +++ b/tests/manual/deferred-renderer-qml/GBufferDebugger.qml @@ -65,46 +65,18 @@ Entity { renderPasses: RenderPass { filterKeys: FilterKey { name: "pass"; value: "final" } shaderProgram: ShaderProgram { - vertexShaderCode: - "#version 110 - - attribute vec4 vertexPosition; - uniform mat4 modelMatrix; - - void main() - { - gl_Position = modelMatrix * vertexPosition; - }" - - fragmentShaderCode: - "#version 110 - - uniform sampler2D color; - uniform sampler2D position; - uniform sampler2D normal; - uniform sampler2D depth; - uniform vec2 winSize; - - void main() - { - vec2 texCoord = (gl_FragCoord.xy + vec2(-winSize.x, 0)) / winSize; - - // Draw 4 quadrants - if (texCoord.x > 0.5) { // Right - if (texCoord.y > 0.5) { // Top - gl_FragColor = vec4(texture2D(normal, vec2(texCoord.x - 0.5, texCoord.y - 0.5) * 2.0).xyz, 1.0); - } else { // Bottom - gl_FragColor = vec4(texture2D(color, vec2(texCoord.x - 0.5, texCoord.y) * 2.0).xyz, 1.0); - } - } else { // Left - if (texCoord.y > 0.5) { // Top - gl_FragColor = texture2D(position, vec2(texCoord.x, texCoord.y - 0.5) * 2.0); - } else { // Bottom - gl_FragColor = vec4(texture2D(depth, texCoord * 2.0).rrr, 1.0); - } - } - gl_FragColor.a = 0.5; - }" + vertexShaderCode: loadSource("qrc:/debug_es2.vert") + fragmentShaderCode: loadSource("qrc:/debug_es2.frag") + } + } + }, + Technique { + graphicsApiFilter {api : GraphicsApiFilter.OpenGL; profile : GraphicsApiFilter.CoreProfile; minorVersion : 2; majorVersion : 3 } + renderPasses: RenderPass { + filterKeys: FilterKey { name: "pass"; value: "final" } + shaderProgram: ShaderProgram { + vertexShaderCode: loadSource("qrc:/debug_gl3.vert") + fragmentShaderCode: loadSource("qrc:/debug_gl3.frag") } } } diff --git a/tests/manual/deferred-renderer-qml/debug_es2.frag b/tests/manual/deferred-renderer-qml/debug_es2.frag new file mode 100644 index 000000000..8438ca916 --- /dev/null +++ b/tests/manual/deferred-renderer-qml/debug_es2.frag @@ -0,0 +1,28 @@ +#version 110 + +uniform sampler2D color; +uniform sampler2D position; +uniform sampler2D normal; +uniform sampler2D depth; +uniform vec2 winSize; + +void main() +{ + vec2 texCoord = (gl_FragCoord.xy + vec2(-winSize.x, 0)) / winSize; + + // Draw 4 quadrants + if (texCoord.x > 0.5) { // Right + if (texCoord.y > 0.5) { // Top + gl_FragColor = vec4(texture2D(normal, vec2(texCoord.x - 0.5, texCoord.y - 0.5) * 2.0).xyz, 1.0); + } else { // Bottom + gl_FragColor = vec4(texture2D(color, vec2(texCoord.x - 0.5, texCoord.y) * 2.0).xyz, 1.0); + } + } else { // Left + if (texCoord.y > 0.5) { // Top + gl_FragColor = texture2D(position, vec2(texCoord.x, texCoord.y - 0.5) * 2.0); + } else { // Bottom + gl_FragColor = vec4(texture2D(depth, texCoord * 2.0).rrr, 1.0); + } + } + gl_FragColor.a = 0.5; +} diff --git a/tests/manual/deferred-renderer-qml/debug_es2.vert b/tests/manual/deferred-renderer-qml/debug_es2.vert new file mode 100644 index 000000000..a907e10ca --- /dev/null +++ b/tests/manual/deferred-renderer-qml/debug_es2.vert @@ -0,0 +1,9 @@ +#version 110 + +attribute vec4 vertexPosition; +uniform mat4 modelMatrix; + +void main() +{ + gl_Position = modelMatrix * vertexPosition; +} diff --git a/tests/manual/deferred-renderer-qml/debug_gl3.frag b/tests/manual/deferred-renderer-qml/debug_gl3.frag new file mode 100644 index 000000000..571174d3b --- /dev/null +++ b/tests/manual/deferred-renderer-qml/debug_gl3.frag @@ -0,0 +1,30 @@ +#version 150 + +uniform sampler2D color; +uniform sampler2D position; +uniform sampler2D normal; +uniform sampler2D depth; +uniform vec2 winSize; + +out vec4 fragColor; + +void main() +{ + vec2 texCoord = (gl_FragCoord.xy + vec2(-winSize.x, 0)) / winSize; + + // Draw 4 quadrants + if (texCoord.x > 0.5) { // Right + if (texCoord.y > 0.5) { // Top + fragColor = vec4(texture(normal, vec2(texCoord.x - 0.5, texCoord.y - 0.5) * 2.0).xyz, 1.0); + } else { // Bottom + fragColor = vec4(texture(color, vec2(texCoord.x - 0.5, texCoord.y) * 2.0).xyz, 1.0); + } + } else { // Left + if (texCoord.y > 0.5) { // Top + fragColor = texture(position, vec2(texCoord.x, texCoord.y - 0.5) * 2.0); + } else { // Bottom + fragColor = vec4(texture(depth, texCoord * 2.0).rrr, 1.0); + } + } + fragColor.a = 0.5; +} diff --git a/tests/manual/deferred-renderer-qml/debug_gl3.vert b/tests/manual/deferred-renderer-qml/debug_gl3.vert new file mode 100644 index 000000000..2ed46a471 --- /dev/null +++ b/tests/manual/deferred-renderer-qml/debug_gl3.vert @@ -0,0 +1,9 @@ +#version 150 + +in vec4 vertexPosition; +uniform mat4 modelMatrix; + +void main() +{ + gl_Position = modelMatrix * vertexPosition; +} diff --git a/tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc b/tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc index 6ee17f42d..a2ca88cf9 100644 --- a/tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc +++ b/tests/manual/deferred-renderer-qml/deferred-renderer-qml.qrc @@ -12,5 +12,9 @@ <file>final_gl3.vert</file> <file>final_es2.frag</file> <file>GBufferDebugger.qml</file> + <file>debug_gl3.vert</file> + <file>debug_gl3.frag</file> + <file>debug_es2.frag</file> + <file>debug_es2.vert</file> </qresource> </RCC> diff --git a/tests/manual/paintedtexture-cpp/main.cpp b/tests/manual/paintedtexture-cpp/main.cpp index d8f5c515c..4651acd65 100644 --- a/tests/manual/paintedtexture-cpp/main.cpp +++ b/tests/manual/paintedtexture-cpp/main.cpp @@ -73,7 +73,7 @@ int main(int argc, char **argv) QApplication app(argc, argv); Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow(); - view->defaultFramegraph()->setClearColor(QColor(QRgb(0x4d4d4f))); + view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f))); QWidget *container = QWidget::createWindowContainer(view); QSize screenSize = view->screen()->size(); container->setMinimumSize(QSize(200, 100)); |