| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <QtTest/QTest> |
| 30 | #include <qbackendnodetester.h> |
| 31 | #include <Qt3DRender/QLevelOfDetail> |
| 32 | #include <Qt3DRender/QLevelOfDetailBoundingSphere> |
| 33 | #include <Qt3DRender/private/levelofdetail_p.h> |
| 34 | #include <Qt3DRender/private/qlevelofdetail_p.h> |
| 35 | #include <Qt3DCore/private/qbackendnode_p.h> |
| 36 | #include "testpostmanarbiter.h" |
| 37 | #include "testrenderer.h" |
| 38 | |
| 39 | class tst_LevelOfDetail : public Qt3DCore::QBackendNodeTester |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | private Q_SLOTS: |
| 43 | |
| 44 | void checkPeerPropertyMirroring() |
| 45 | { |
| 46 | // GIVEN |
| 47 | TestRenderer renderer; |
| 48 | Qt3DRender::Render::LevelOfDetail renderLod; |
| 49 | Qt3DRender::QLevelOfDetail lod; |
| 50 | |
| 51 | // WHEN |
| 52 | renderLod.setRenderer(&renderer); |
| 53 | simulateInitializationSync(frontend: &lod, backend: &renderLod); |
| 54 | |
| 55 | // THEN |
| 56 | QCOMPARE(renderLod.peerId(), lod.id()); |
| 57 | QVERIFY(renderLod.camera().isNull() && lod.camera() == nullptr); |
| 58 | QCOMPARE(renderLod.currentIndex(), lod.currentIndex()); |
| 59 | QCOMPARE(renderLod.thresholdType(), lod.thresholdType()); |
| 60 | QCOMPARE(renderLod.thresholds(), lod.thresholds()); |
| 61 | QCOMPARE(renderLod.center(), lod.volumeOverride().center()); |
| 62 | QCOMPARE(renderLod.radius(), lod.volumeOverride().radius()); |
| 63 | } |
| 64 | |
| 65 | void checkInitialAndCleanedUpState() |
| 66 | { |
| 67 | // GIVEN |
| 68 | Qt3DRender::Render::LevelOfDetail renderLod; |
| 69 | TestRenderer renderer; |
| 70 | |
| 71 | // THEN |
| 72 | QCOMPARE(renderLod.camera(), Qt3DCore::QNodeId{}); |
| 73 | QCOMPARE(renderLod.currentIndex(), 0); |
| 74 | QCOMPARE(renderLod.thresholdType(), Qt3DRender::QLevelOfDetail::DistanceToCameraThreshold); |
| 75 | QVERIFY(renderLod.thresholds().empty()); |
| 76 | QCOMPARE(renderLod.radius(), 1.f); |
| 77 | QCOMPARE(renderLod.center(), QVector3D{}); |
| 78 | QVERIFY(renderLod.peerId().isNull()); |
| 79 | |
| 80 | // GIVEN |
| 81 | Qt3DRender::QLevelOfDetail lod; |
| 82 | lod.setThresholdType(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold); |
| 83 | |
| 84 | // WHEN |
| 85 | renderLod.setRenderer(&renderer); |
| 86 | simulateInitializationSync(frontend: &lod, backend: &renderLod); |
| 87 | |
| 88 | // THEN |
| 89 | QCOMPARE(renderLod.thresholdType(), lod.thresholdType()); |
| 90 | } |
| 91 | |
| 92 | void checkPropertyChanges() |
| 93 | { |
| 94 | // GIVEN |
| 95 | TestRenderer renderer; |
| 96 | Qt3DRender::QLevelOfDetail lod; |
| 97 | Qt3DRender::Render::LevelOfDetail renderLod; |
| 98 | renderLod.setRenderer(&renderer); |
| 99 | simulateInitializationSync(frontend: &lod, backend: &renderLod); |
| 100 | |
| 101 | // THEN |
| 102 | QVERIFY(renderLod.thresholdType() != Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold); |
| 103 | QVERIFY(renderLod.camera().isNull()); |
| 104 | |
| 105 | { |
| 106 | // WHEN |
| 107 | lod.setThresholdType(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold); |
| 108 | renderLod.syncFromFrontEnd(frontEnd: &lod, firstTime: false); |
| 109 | |
| 110 | // THEN |
| 111 | QCOMPARE(renderLod.thresholdType(), Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold); |
| 112 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::GeometryDirty); |
| 113 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); } |
| 114 | |
| 115 | { |
| 116 | const QVector<qreal> thresholds = {20.f, 30.f, 40.f}; |
| 117 | |
| 118 | // WHEN |
| 119 | lod.setThresholds(thresholds); |
| 120 | renderLod.syncFromFrontEnd(frontEnd: &lod, firstTime: false); |
| 121 | // THEN |
| 122 | QCOMPARE(renderLod.thresholds(), thresholds); |
| 123 | } |
| 124 | |
| 125 | { |
| 126 | // WHEN |
| 127 | const Qt3DRender::QLevelOfDetailBoundingSphere sphere(QVector3D(1.0f, 2.0f, 3.0f), 1.0f); |
| 128 | // WHEN |
| 129 | lod.setVolumeOverride(sphere); |
| 130 | renderLod.syncFromFrontEnd(frontEnd: &lod, firstTime: false); |
| 131 | |
| 132 | // THEN |
| 133 | QCOMPARE(renderLod.center(), QVector3D(1., 2., 3.)); |
| 134 | } |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | |
| 139 | QTEST_APPLESS_MAIN(tst_LevelOfDetail) |
| 140 | |
| 141 | #include "tst_levelofdetail.moc" |
| 142 | |