diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/render/blitframebuffer/blitframebuffer.pro | 12 | ||||
-rw-r--r-- | tests/auto/render/blitframebuffer/tst_blitframebuffer.cpp | 196 | ||||
-rw-r--r-- | tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp | 12 | ||||
-rw-r--r-- | tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp | 36 | ||||
-rw-r--r-- | tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp | 36 | ||||
-rw-r--r-- | tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp | 36 | ||||
-rw-r--r-- | tests/auto/render/qblitframebuffer/qblitframebuffer.pro | 11 | ||||
-rw-r--r-- | tests/auto/render/qblitframebuffer/tst_qblitframebuffer.cpp | 338 | ||||
-rw-r--r-- | tests/auto/render/render.pro | 4 | ||||
-rw-r--r-- | tests/manual/blitframebuffer-qml/blitframebuffer-qml.pro | 14 | ||||
-rw-r--r-- | tests/manual/blitframebuffer-qml/blitframebuffer-qml.qrc | 5 | ||||
-rw-r--r-- | tests/manual/blitframebuffer-qml/main.cpp | 72 | ||||
-rw-r--r-- | tests/manual/blitframebuffer-qml/main.qml | 273 | ||||
-rw-r--r-- | tests/manual/manual.pro | 4 |
14 files changed, 1047 insertions, 2 deletions
diff --git a/tests/auto/render/blitframebuffer/blitframebuffer.pro b/tests/auto/render/blitframebuffer/blitframebuffer.pro new file mode 100644 index 000000000..39531ae9a --- /dev/null +++ b/tests/auto/render/blitframebuffer/blitframebuffer.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_blitframebuffer + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_blitframebuffer.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/blitframebuffer/tst_blitframebuffer.cpp b/tests/auto/render/blitframebuffer/tst_blitframebuffer.cpp new file mode 100644 index 000000000..6c70b0e95 --- /dev/null +++ b/tests/auto/render/blitframebuffer/tst_blitframebuffer.cpp @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 <Qt3DRender/qblitframebuffer.h> +#include <Qt3DRender/private/qblitframebuffer_p.h> +#include <Qt3DRender/private/blitframebuffer_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> +#include "qbackendnodetester.h" +#include "testrenderer.h" + +class tst_BlitFramebuffer : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DRender::Render::BlitFramebuffer backendBlitFramebuffer; + + // THEN + QCOMPARE(backendBlitFramebuffer.nodeType(), Qt3DRender::Render::FrameGraphNode::BlitFramebuffer); + QCOMPARE(backendBlitFramebuffer.isEnabled(), false); + QVERIFY(backendBlitFramebuffer.peerId().isNull()); + QVERIFY(backendBlitFramebuffer.sourceRenderTargetId().isNull()); + QVERIFY(backendBlitFramebuffer.destinationRenderTargetId().isNull()); + QCOMPARE(backendBlitFramebuffer.sourceRect(), QRect()); + QCOMPARE(backendBlitFramebuffer.destinationRect(), QRect()); + QCOMPARE(backendBlitFramebuffer.sourceAttachmentPoint(), Qt3DRender::QRenderTargetOutput::Color0); + QCOMPARE(backendBlitFramebuffer.destinationAttachmentPoint(), Qt3DRender::QRenderTargetOutput::Color0); + QCOMPARE(backendBlitFramebuffer.interpolationMethod(), Qt3DRender::QBlitFramebuffer::Linear); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DRender::QRenderTarget sourceTarget; + Qt3DRender::QRenderTarget destinationTarget; + Qt3DRender::QBlitFramebuffer blitFramebuffer; + blitFramebuffer.setSource(&sourceTarget); + blitFramebuffer.setDestination(&destinationTarget); + blitFramebuffer.setSourceRect(QRect(0,0,1,1)); + blitFramebuffer.setDestinationRect(QRect(0,0,1,1)); + blitFramebuffer.setSourceAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); + blitFramebuffer.setDestinationAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); + blitFramebuffer.setInterpolationMethod(Qt3DRender::QBlitFramebuffer::Nearest); + + { + // WHEN + Qt3DRender::Render::BlitFramebuffer backendBlitFramebuffer; + simulateInitialization(&blitFramebuffer, &backendBlitFramebuffer); + + // THEN + QCOMPARE(backendBlitFramebuffer.isEnabled(), true); + QCOMPARE(backendBlitFramebuffer.peerId(), blitFramebuffer.id()); + QCOMPARE(backendBlitFramebuffer.sourceRenderTargetId(), sourceTarget.id()); + QCOMPARE(backendBlitFramebuffer.destinationRenderTargetId(), destinationTarget.id()); + QCOMPARE(backendBlitFramebuffer.sourceRect(), QRect(0,0,1,1)); + QCOMPARE(backendBlitFramebuffer.destinationRect(), QRect(0,0,1,1)); + QCOMPARE(backendBlitFramebuffer.sourceAttachmentPoint(), Qt3DRender::QRenderTargetOutput::Color1); + QCOMPARE(backendBlitFramebuffer.destinationAttachmentPoint(), Qt3DRender::QRenderTargetOutput::Color1); + QCOMPARE(backendBlitFramebuffer.interpolationMethod(), Qt3DRender::QBlitFramebuffer::Nearest); + } + { + // WHEN + Qt3DRender::Render::BlitFramebuffer backendBlitFramebuffer; + blitFramebuffer.setEnabled(false); + simulateInitialization(&blitFramebuffer, &backendBlitFramebuffer); + + // THEN + QCOMPARE(backendBlitFramebuffer.peerId(), blitFramebuffer.id()); + QCOMPARE(backendBlitFramebuffer.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DRender::Render::BlitFramebuffer backendBlitFramebuffer; + TestRenderer renderer; + backendBlitFramebuffer.setRenderer(&renderer); + + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendBlitFramebuffer.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendBlitFramebuffer.isEnabled(), newValue); + } + { + // WHEN + const Qt3DRender::QRenderTarget sourceRenderTarget; + const Qt3DCore::QNodeId newValue = sourceRenderTarget.id(); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("sourceRenderTarget"); + change->setValue(QVariant::fromValue(newValue)); + backendBlitFramebuffer.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendBlitFramebuffer.sourceRenderTargetId(), newValue); + } + { + // WHEN + const Qt3DRender::QRenderTarget destinationRenderTarget; + const Qt3DCore::QNodeId newValue = destinationRenderTarget.id(); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("destinationRenderTarget"); + change->setValue(QVariant::fromValue(newValue)); + backendBlitFramebuffer.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendBlitFramebuffer.destinationRenderTargetId(), newValue); + } + { + // WHEN + const auto newValue = QRect(0,0,1,1); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("sourceRect"); + change->setValue(QVariant::fromValue(newValue)); + backendBlitFramebuffer.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendBlitFramebuffer.sourceRect(), newValue); + } + { + // WHEN + const auto newValue = QRect(0,0,1,1); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("destinationRect"); + change->setValue(QVariant::fromValue(newValue)); + backendBlitFramebuffer.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendBlitFramebuffer.destinationRect(), newValue); + } + { + // WHEN + const auto newValue = Qt3DRender::QRenderTargetOutput::Color1; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("sourceAttachmentPoint"); + change->setValue(QVariant::fromValue(newValue)); + backendBlitFramebuffer.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendBlitFramebuffer.sourceAttachmentPoint(), newValue); + } + { + // WHEN + const auto newValue = Qt3DRender::QRenderTargetOutput::Color1; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("destinationAttachmentPoint"); + change->setValue(QVariant::fromValue(newValue)); + backendBlitFramebuffer.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendBlitFramebuffer.destinationAttachmentPoint(), newValue); + } + } + +}; + +QTEST_MAIN(tst_BlitFramebuffer) + +#include "tst_blitframebuffer.moc" diff --git a/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp b/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp index c6719f3bd..292bcfba3 100644 --- a/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp +++ b/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp @@ -1506,6 +1506,18 @@ private Q_SLOTS: QCOMPARE(computed, expected); } + void drawBuffer() + { + QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); + // Not supported by GL2 + } + + void readBuffer() + { + QSKIP("Initialization failed, OpenGL 2.0 functions not supported"); + // Not supported by GL2 + } + private: QScopedPointer<QWindow> m_window; QOpenGLContext m_glContext; diff --git a/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp b/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp index 86a26cfdf..22fdb36a3 100644 --- a/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp +++ b/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp @@ -2115,6 +2115,42 @@ private Q_SLOTS: QCOMPARE(computed, expected); } + void drawBuffer() + { + if (!m_initializationSuccessful) + QSKIP("Initialization failed, OpenGL 3.2 Core functions not supported"); + + m_func->glGetError(); + + // WHEN + m_glHelper.drawBuffer(GL_FRONT); + const GLint error = m_func->glGetError(); + QVERIFY(error == 0); + + // THEN + GLint p; + m_func->glGetIntegerv(GL_DRAW_BUFFER, &p); + QCOMPARE((GLenum)p, GL_FRONT); + } + + void readBuffer() + { + if (!m_initializationSuccessful) + QSKIP("Initialization failed, OpenGL 3.2 Core functions not supported"); + + m_func->glGetError(); + + // WHEN + m_glHelper.readBuffer(GL_FRONT); + + // THEN + const GLint error = m_func->glGetError(); + QVERIFY(error == 0); + GLint p; + m_func->glGetIntegerv(GL_READ_BUFFER, &p); + QCOMPARE((GLenum)p, GL_FRONT); + } + private: QScopedPointer<QWindow> m_window; QOpenGLContext m_glContext; diff --git a/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp b/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp index 48121ad36..06a3c41cd 100644 --- a/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp +++ b/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp @@ -2215,6 +2215,42 @@ private Q_SLOTS: QCOMPARE(computed, expected); } + void drawBuffer() + { + if (!m_initializationSuccessful) + QSKIP("Initialization failed, OpenGL 3.3 Core functions not supported"); + + m_func->glGetError(); + + // WHEN + m_glHelper.drawBuffer(GL_FRONT); + const GLint error = m_func->glGetError(); + QVERIFY(error == 0); + + // THEN + GLint p; + m_func->glGetIntegerv(GL_DRAW_BUFFER, &p); + QCOMPARE(p, GL_FRONT); + } + + void readBuffer() + { + if (!m_initializationSuccessful) + QSKIP("Initialization failed, OpenGL 3.3 Core functions not supported"); + + m_func->glGetError(); + + // WHEN + m_glHelper.readBuffer(GL_FRONT); + + // THEN + const GLint error = m_func->glGetError(); + QVERIFY(error == 0); + GLint p; + m_func->glGetIntegerv(GL_READ_BUFFER, &p); + QCOMPARE(p, GL_FRONT); + } + private: QScopedPointer<QWindow> m_window; QOpenGLContext m_glContext; diff --git a/tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp b/tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp index 46897ab49..5a96cf116 100644 --- a/tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp +++ b/tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp @@ -2294,6 +2294,42 @@ private Q_SLOTS: QCOMPARE(computed, expected); } + void drawBuffer() + { + if (!m_initializationSuccessful) + QSKIP("Initialization failed, OpenGL 4.3 Core functions not supported"); + + m_func->glGetError(); + + // WHEN + m_glHelper.drawBuffer(GL_FRONT); + const GLint error = m_func->glGetError(); + QVERIFY(error == 0); + + // THEN + GLint p; + m_func->glGetIntegerv(GL_DRAW_BUFFER, &p); + QCOMPARE(p, GL_FRONT); + } + + void readBuffer() + { + if (!m_initializationSuccessful) + QSKIP("Initialization failed, OpenGL 4.3 Core functions not supported"); + + m_func->glGetError(); + + // WHEN + m_glHelper.readBuffer(GL_FRONT); + + // THEN + const GLint error = m_func->glGetError(); + QVERIFY(error == 0); + GLint p; + m_func->glGetIntegerv(GL_READ_BUFFER, &p); + QCOMPARE(p, GL_FRONT); + } + private: QScopedPointer<QWindow> m_window; QOpenGLContext m_glContext; diff --git a/tests/auto/render/qblitframebuffer/qblitframebuffer.pro b/tests/auto/render/qblitframebuffer/qblitframebuffer.pro new file mode 100644 index 000000000..219bad3d2 --- /dev/null +++ b/tests/auto/render/qblitframebuffer/qblitframebuffer.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_qblitframebuffer + +QT += core-private 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_qblitframebuffer.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/render/qblitframebuffer/tst_qblitframebuffer.cpp b/tests/auto/render/qblitframebuffer/tst_qblitframebuffer.cpp new file mode 100644 index 000000000..26ef936f6 --- /dev/null +++ b/tests/auto/render/qblitframebuffer/tst_qblitframebuffer.cpp @@ -0,0 +1,338 @@ +/**************************************************************************** +** +** 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 <Qt3DCore/private/qnode_p.h> +#include <Qt3DCore/private/qscene_p.h> +#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> + +#include <Qt3DRender/QBlitFramebuffer> +#include <Qt3DRender/private/qblitframebuffer_p.h> + +#include "testpostmanarbiter.h" + +class tst_QBlitFrameBuffer: public QObject +{ + Q_OBJECT + +public: + tst_QBlitFrameBuffer() : QObject() + { + qRegisterMetaType<Qt3DRender::QRenderTarget*>(); + } + +private Q_SLOTS: + + void checkCreationData_data() + { + QTest::addColumn<Qt3DRender::QBlitFramebuffer *>("blitFramebuffer"); + + Qt3DRender::QBlitFramebuffer *defaultConstructed = new Qt3DRender::QBlitFramebuffer(); + Qt3DRender::QRenderTarget *sourceRenderTarget = new Qt3DRender::QRenderTarget(); + Qt3DRender::QRenderTarget *destinationRenderTarget = new Qt3DRender::QRenderTarget(); + defaultConstructed->setSource(sourceRenderTarget); + defaultConstructed->setDestination(destinationRenderTarget); + QTest::newRow("defaultConstructed") << defaultConstructed; + } + + void checkInitialState() + { + // GIVEN + Qt3DRender::QBlitFramebuffer blitFramebuffer; + + // THEN + QCOMPARE(blitFramebuffer.source(), nullptr); + QCOMPARE(blitFramebuffer.destination(), nullptr); + QCOMPARE(blitFramebuffer.sourceRect(), QRect()); + QCOMPARE(blitFramebuffer.destinationRect(), QRect()); + QCOMPARE(blitFramebuffer.sourceAttachmentPoint(), Qt3DRender::QRenderTargetOutput::AttachmentPoint::Color0); + QCOMPARE(blitFramebuffer.destinationAttachmentPoint(), Qt3DRender::QRenderTargetOutput::AttachmentPoint::Color0); + QCOMPARE(blitFramebuffer.interpolationMethod(), Qt3DRender::QBlitFramebuffer::Linear); + } + + void checkCreationData() + { + // GIVEN + QFETCH(Qt3DRender::QBlitFramebuffer *, blitFramebuffer); + + // WHEN + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(blitFramebuffer); + QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges(); + + // THEN + QCOMPARE(creationChanges.size(), 1); + + const Qt3DCore::QNodeCreatedChangePtr<Qt3DRender::QBlitFramebufferData> creationChangeData = + qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QBlitFramebufferData>>(creationChanges.first()); + const Qt3DRender::QBlitFramebufferData &cloneData = creationChangeData->data; + + // THEN + QCOMPARE(blitFramebuffer->id(), creationChangeData->subjectId()); + QCOMPARE(blitFramebuffer->isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(blitFramebuffer->metaObject(), creationChangeData->metaObject()); + QCOMPARE(blitFramebuffer->source()->id(), cloneData.m_sourceRenderTargetId); + QCOMPARE(blitFramebuffer->destination()->id(), cloneData.m_destinationRenderTargetId); + QCOMPARE(blitFramebuffer->sourceRect(), cloneData.m_sourceRect); + QCOMPARE(blitFramebuffer->destinationRect(), cloneData.m_destinationRect); + QCOMPARE(blitFramebuffer->sourceAttachmentPoint(), cloneData.m_sourceAttachmentPoint); + QCOMPARE(blitFramebuffer->destinationAttachmentPoint(), cloneData.m_destinationAttachmentPoint); + + + delete blitFramebuffer; + } + + void checkPropertyUpdate() + { + // GIVEN + TestArbiter arbiter; + QScopedPointer<Qt3DRender::QBlitFramebuffer> blitFramebuffer(new Qt3DRender::QBlitFramebuffer()); + arbiter.setArbiterOnNode(blitFramebuffer.data()); + + Qt3DRender::QRenderTarget *sourceRenderTarget = new Qt3DRender::QRenderTarget; + Qt3DRender::QRenderTarget *destinationRenderTarget = new Qt3DRender::QRenderTarget; + + // sourceRenderTarget + // WHEN + blitFramebuffer->setSource(sourceRenderTarget); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "source"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), sourceRenderTarget->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + blitFramebuffer->setSource(sourceRenderTarget); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + blitFramebuffer->setSource(nullptr); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "source"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), Qt3DCore::QNodeId()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // destinationRenderTarget + // WHEN + blitFramebuffer->setDestination(destinationRenderTarget); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "destination"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), destinationRenderTarget->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + blitFramebuffer->setDestination(destinationRenderTarget); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + blitFramebuffer->setDestination(nullptr); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "destination"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), Qt3DCore::QNodeId()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // sourceRect + // WHEN + blitFramebuffer->setSourceRect(QRect(0,0,1,1)); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "sourceRect"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<QRect>(), QRect(0,0,1,1)) ; + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + blitFramebuffer->setSourceRect(QRect(0,0,1,1)); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + blitFramebuffer->setSourceRect(QRect()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "sourceRect"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<QRect>(), QRect()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // destinationRect + blitFramebuffer->setDestinationRect(QRect(0,0,1,1)); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "destinationRect"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<QRect>(), QRect(0,0,1,1)) ; + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + blitFramebuffer->setDestinationRect(QRect(0,0,1,1)); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + blitFramebuffer->setDestinationRect(QRect()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "destinationRect"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<QRect>(), QRect()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // sourceAttachmentPoint + // WHEN + blitFramebuffer->setSourceAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "sourceAttachmentPoint"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<Qt3DRender::QRenderTargetOutput::AttachmentPoint>(), Qt3DRender::QRenderTargetOutput::Color1); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + blitFramebuffer->setSourceAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + blitFramebuffer->setSourceAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color0); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "sourceAttachmentPoint"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<Qt3DRender::QRenderTargetOutput::AttachmentPoint>(), Qt3DRender::QRenderTargetOutput::Color0); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // destinationAttachmentPoint + // WHEN + blitFramebuffer->setDestinationAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "destinationAttachmentPoint"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<Qt3DRender::QRenderTargetOutput::AttachmentPoint>(), Qt3DRender::QRenderTargetOutput::Color1); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + blitFramebuffer->setDestinationAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + blitFramebuffer->setDestinationAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color0); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "destinationAttachmentPoint"); + QCOMPARE(change->subjectId(), blitFramebuffer->id()); + QCOMPARE(change->value().value<Qt3DRender::QRenderTargetOutput::AttachmentPoint>(), Qt3DRender::QRenderTargetOutput::Color0); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } +}; + +QTEST_MAIN(tst_QBlitFrameBuffer) + +#include "tst_qblitframebuffer.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index 7cd5317c7..32a7b35fc 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -107,7 +107,9 @@ qtConfig(private_tests) { joint \ qproximityfilter \ proximityfilter \ - proximityfiltering + proximityfiltering \ + qblitframebuffer \ + blitframebuffer QT_FOR_CONFIG = 3dcore-private qtConfig(qt3d-extras) { diff --git a/tests/manual/blitframebuffer-qml/blitframebuffer-qml.pro b/tests/manual/blitframebuffer-qml/blitframebuffer-qml.pro new file mode 100644 index 000000000..c115cbeaf --- /dev/null +++ b/tests/manual/blitframebuffer-qml/blitframebuffer-qml.pro @@ -0,0 +1,14 @@ +!include( ../manual.pri ) { + error( "Couldn't find the manual.pri file!" ) +} + +QT += 3dcore 3drender 3dinput 3dquick 3dlogic qml quick 3dquickextras + +SOURCES += \ + main.cpp + +OTHER_FILES += \ + main.qml + +RESOURCES += \ + blitframebuffer-qml.qrc diff --git a/tests/manual/blitframebuffer-qml/blitframebuffer-qml.qrc b/tests/manual/blitframebuffer-qml/blitframebuffer-qml.qrc new file mode 100644 index 000000000..5f6483ac3 --- /dev/null +++ b/tests/manual/blitframebuffer-qml/blitframebuffer-qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> diff --git a/tests/manual/blitframebuffer-qml/main.cpp b/tests/manual/blitframebuffer-qml/main.cpp new file mode 100644 index 000000000..3d85df6eb --- /dev/null +++ b/tests/manual/blitframebuffer-qml/main.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <Qt3DQuickExtras/qt3dquickwindow.h> +#include <QGuiApplication> + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + Qt3DExtras::Quick::Qt3DQuickWindow view; + + + QSurfaceFormat format; + format.setVersion(4, 3); + format.setProfile(QSurfaceFormat::CoreProfile); + format.setDepthBufferSize(24); + format.setSamples(1); + format.setStencilBufferSize(8); + view.setFormat(format); + + view.setSource(QUrl("qrc:/main.qml")); + view.show(); + + return app.exec(); +} diff --git a/tests/manual/blitframebuffer-qml/main.qml b/tests/manual/blitframebuffer-qml/main.qml new file mode 100644 index 000000000..4b3c1915b --- /dev/null +++ b/tests/manual/blitframebuffer-qml/main.qml @@ -0,0 +1,273 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 as QQ2 +import Qt3D.Core 2.0 +import Qt3D.Render 2.10 +import Qt3D.Input 2.0 +import Qt3D.Extras 2.0 + +Entity { + id: sceneRoot + + Camera { + id: camera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: 16/9 + nearPlane : 0.1 + farPlane : 1000.0 + position: Qt.vector3d( 0.0, 0.0, -40.0 ) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + } + + RenderTarget { + id: intermediateRenderTarget + attachments : [ + RenderTargetOutput { + objectName : "color" + attachmentPoint : RenderTargetOutput.Color0 + texture : Texture2D { + id : colorAttachment0 + width : 1024 + height : 768 + format : Texture.R32F + generateMipMaps : false + magnificationFilter : Texture.Linear + minificationFilter : Texture.Linear + wrapMode { + x: WrapMode.ClampToEdge + y: WrapMode.ClampToEdge + } + } + }, + RenderTargetOutput { + objectName : "color" + attachmentPoint : RenderTargetOutput.Color1 + texture : Texture2D { + id : colorAttachment1 + width : 1024 + height : 1024 + format : Texture.R32F + generateMipMaps : false + magnificationFilter : Texture.Linear + minificationFilter : Texture.Linear + wrapMode { + x: WrapMode.ClampToEdge + y: WrapMode.ClampToEdge + } + } + } + ] + } + + components: [ + RenderSettings { + activeFrameGraph: RenderSurfaceSelector { + Viewport { + RenderTargetSelector { + target: intermediateRenderTarget + NoDraw {} + } + + RenderTargetSelector { + target: RenderTarget { + id: renderTarget + attachments : [ + RenderTargetOutput { + objectName : "color" + attachmentPoint : RenderTargetOutput.Color0 + texture : Texture2D { + id : colorAttachment + width : 1024 + height : 768 + format : Texture.RGBA32F + generateMipMaps : false + magnificationFilter : Texture.Linear + minificationFilter : Texture.Linear + wrapMode { + x: WrapMode.ClampToEdge + y: WrapMode.ClampToEdge + } + } + }, + RenderTargetOutput { + objectName : "depth" + attachmentPoint : RenderTargetOutput.Depth + texture : Texture2D { + id : depthAttachment + width : 1024 + height : 1024 + format : Texture.D32F + generateMipMaps : false + magnificationFilter : Texture.Linear + minificationFilter : Texture.Linear + wrapMode { + x: WrapMode.ClampToEdge + y: WrapMode.ClampToEdge + } + } + } + ] + } + ClearBuffers { + clearColor: "white" + buffers: ClearBuffers.ColorDepthBuffer + CameraSelector { + camera: camera + } + } + } + + NoDraw{ + + BlitFramebuffer { + source: renderTarget + destination: intermediateRenderTarget + sourceRect: Qt.rect(0,0,1024,768) + destinationRect: Qt.rect(0,0,1024,1024) + sourceAttachmentPoint: RenderTargetOutput.Color0 + destinationAttachmentPoint: RenderTargetOutput.Color0 + interpolationMethod: BlitFramebuffer.Linear + } + + BlitFramebuffer { + source: intermediateRenderTarget + sourceRect: Qt.rect(0,0,1024,1024) + destinationRect: Qt.rect(0,0,512,384) + sourceAttachmentPoint: RenderTargetOutput.Color0 + interpolationMethod: BlitFramebuffer.Linear + } + + BlitFramebuffer { + source: renderTarget + sourceRect: Qt.rect(0,0,1024,768) + destinationRect: Qt.rect(0,384,512,384) + sourceAttachmentPoint: RenderTargetOutput.Color0 + interpolationMethod: BlitFramebuffer.Linear + } + + BlitFramebuffer { + source: renderTarget + sourceRect: Qt.rect(128,200,256,256) + destinationRect: Qt.rect(512,384,512,384) + sourceAttachmentPoint: RenderTargetOutput.Color0 + interpolationMethod: BlitFramebuffer.Linear + } + + BlitFramebuffer { + source: renderTarget + sourceRect: Qt.rect(128,200,256,256) + destinationRect: Qt.rect(512,0,512,384) + sourceAttachmentPoint: RenderTargetOutput.Color0 + interpolationMethod: BlitFramebuffer.Nearest + } + } + } + } + } + ] + + PhongMaterial { + id: material + } + + TorusMesh { + id: torusMesh + radius: 5 + minorRadius: 1 + rings: 100 + slices: 20 + } + + Transform { + id: torusTransform + scale3D: Qt.vector3d(1.5, 1, 0.5) + rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) + } + + Entity { + id: torusEntity + components: [ torusMesh, material, torusTransform ] + } + + SphereMesh { + id: sphereMesh + radius: 3 + } + + Transform { + id: sphereTransform + property real userAngle: 0.0 + matrix: { + var m = Qt.matrix4x4(); + m.rotate(userAngle, Qt.vector3d(0, 1, 0)); + m.translate(Qt.vector3d(20, 0, 0)); + return m; + } + } + + QQ2.NumberAnimation { + target: sphereTransform + property: "userAngle" + duration: 10000 + from: 0 + to: 360 + + loops: QQ2.Animation.Infinite + running: true + } + + Entity { + id: sphereEntity + components: [ sphereMesh, material, sphereTransform ] + } +} diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 8501a41af..2b13bd896 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -54,7 +54,9 @@ SUBDIRS += \ layerfilter-qml \ skinned-mesh \ proximityfilter \ - rendercapture-qml-fbo + rendercapture-qml-fbo \ + blitframebuffer-qml \ + skinned-mesh qtHaveModule(widgets): { SUBDIRS += \ |