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:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40
41#include <QtTest/QTest>
42#include <Qt3DCore/qentity.h>
43
44#include <Qt3DRender/private/nodemanagers_p.h>
45#include <Qt3DRender/private/managers_p.h>
46#include <Qt3DRender/private/entity_p.h>
47
48#include <Qt3DRender/private/framegraphnode_p.h>
49#include <Qt3DRender/private/framegraphvisitor_p.h>
50
51#include <Qt3DRender/qtechniquefilter.h>
52#include <Qt3DRender/qnodraw.h>
53#include <Qt3DRender/qfrustumculling.h>
54#include <Qt3DRender/qviewport.h>
55
56#include "testaspect.h"
57
58namespace {
59
60
61
62} // anonymous
63
64using FGIdType = QPair<Qt3DCore::QNodeId, Qt3DRender::Render::FrameGraphNode::FrameGraphNodeType>;
65using BranchIdsAndTypes = QVector<FGIdType>;
66
67Q_DECLARE_METATYPE(QVector<BranchIdsAndTypes>)
68
69class tst_FrameGraphVisitor : public QObject
70{
71 Q_OBJECT
72private Q_SLOTS:
73
74 void visitFGTree_data()
75 {
76 QTest::addColumn<Qt3DCore::QEntity *>(name: "rootEntity");
77 QTest::addColumn<Qt3DRender::QFrameGraphNode *>(name: "fgRoot");
78 QTest::addColumn<QVector<BranchIdsAndTypes>>(name: "fgNodeIdsPerBranch");
79
80 {
81 Qt3DCore::QEntity *entity = new Qt3DCore::QEntity();
82 Qt3DRender::QTechniqueFilter *techniqueFilter = new Qt3DRender::QTechniqueFilter(entity);
83
84 QTest::newRow(dataTag: "singleNode") << entity
85 << static_cast<Qt3DRender::QFrameGraphNode *>(techniqueFilter)
86 << (QVector<BranchIdsAndTypes>()
87 << (BranchIdsAndTypes() << FGIdType(techniqueFilter->id(), Qt3DRender::Render::FrameGraphNode::TechniqueFilter))
88 );
89 }
90
91 {
92 Qt3DCore::QEntity *entity = new Qt3DCore::QEntity();
93 Qt3DRender::QTechniqueFilter *techniqueFilter = new Qt3DRender::QTechniqueFilter(entity);
94 Qt3DRender::QFrustumCulling *frustumCulling = new Qt3DRender::QFrustumCulling(techniqueFilter);
95 Qt3DRender::QNoDraw *noDraw = new Qt3DRender::QNoDraw(frustumCulling);
96
97 QTest::newRow(dataTag: "singleBranch") << entity
98 << static_cast<Qt3DRender::QFrameGraphNode *>(techniqueFilter)
99 << (QVector<BranchIdsAndTypes>()
100 << (BranchIdsAndTypes()
101 << FGIdType(noDraw->id(), Qt3DRender::Render::FrameGraphNode::NoDraw)
102 << FGIdType(frustumCulling->id(), Qt3DRender::Render::FrameGraphNode::FrustumCulling)
103 << FGIdType(techniqueFilter->id(), Qt3DRender::Render::FrameGraphNode::TechniqueFilter)
104 )
105 );
106 }
107 {
108 Qt3DCore::QEntity *entity = new Qt3DCore::QEntity();
109 Qt3DRender::QTechniqueFilter *techniqueFilter = new Qt3DRender::QTechniqueFilter(entity);
110 Qt3DRender::QFrustumCulling *frustumCulling = new Qt3DRender::QFrustumCulling(techniqueFilter);
111 Qt3DRender::QNoDraw *noDraw = new Qt3DRender::QNoDraw(frustumCulling);
112 Qt3DRender::QViewport *viewPort = new Qt3DRender::QViewport(frustumCulling);
113
114 QTest::newRow(dataTag: "dualBranch") << entity
115 << static_cast<Qt3DRender::QFrameGraphNode *>(techniqueFilter)
116 << (QVector<BranchIdsAndTypes>()
117 << (BranchIdsAndTypes()
118 << FGIdType(noDraw->id(), Qt3DRender::Render::FrameGraphNode::NoDraw)
119 << FGIdType(frustumCulling->id(), Qt3DRender::Render::FrameGraphNode::FrustumCulling)
120 << FGIdType(techniqueFilter->id(), Qt3DRender::Render::FrameGraphNode::TechniqueFilter)
121 )
122 << (BranchIdsAndTypes()
123 << FGIdType(viewPort->id(), Qt3DRender::Render::FrameGraphNode::Viewport)
124 << FGIdType(frustumCulling->id(), Qt3DRender::Render::FrameGraphNode::FrustumCulling)
125 << FGIdType(techniqueFilter->id(), Qt3DRender::Render::FrameGraphNode::TechniqueFilter)
126 )
127 );
128 }
129
130 }
131
132 void visitFGTree()
133 {
134 // GIVEN
135 QFETCH(Qt3DCore::QEntity *, rootEntity);
136 QFETCH(Qt3DRender::QFrameGraphNode *, fgRoot);
137 QFETCH(QVector<BranchIdsAndTypes>, fgNodeIdsPerBranch);
138 QScopedPointer<Qt3DRender::TestAspect> aspect(new Qt3DRender::TestAspect(rootEntity));
139
140 // THEN
141 Qt3DRender::Render::FrameGraphManager *fgManager = aspect->nodeManagers()->frameGraphManager();
142 Qt3DRender::Render::FrameGraphNode *backendFGRoot = fgManager->lookupNode(id: fgRoot->id());
143 QVERIFY(backendFGRoot != nullptr);
144
145
146 // WHEN
147 Qt3DRender::Render::FrameGraphVisitor visitor(fgManager);
148 const QVector<Qt3DRender::Render::FrameGraphNode *> fgNodes = visitor.traverse(root: backendFGRoot);
149
150 // THEN
151 QCOMPARE(fgNodeIdsPerBranch.size(), fgNodes.size());
152
153 for (int i = 0; i < fgNodeIdsPerBranch.size(); ++i) {
154 const BranchIdsAndTypes brandIdsAndTypes = fgNodeIdsPerBranch.at(i);
155
156 Qt3DRender::Render::FrameGraphNode *fgNode = fgNodes.at(i);
157 for (int j = 0; j < brandIdsAndTypes.size(); ++j) {
158 const FGIdType idAndType = brandIdsAndTypes.at(i: j);
159 QVERIFY(fgNode != nullptr);
160 QCOMPARE(fgNode->peerId(), idAndType.first);
161 QCOMPARE(fgNode->nodeType(), idAndType.second);
162 fgNode = fgNode->parent();
163 }
164
165 QVERIFY(fgNode == nullptr);
166 }
167
168 delete rootEntity;
169 }
170};
171
172QTEST_MAIN(tst_FrameGraphVisitor)
173
174#include "tst_framegraphvisitor.moc"
175

source code of qt3d/tests/auto/render/framegraphvisitor/tst_framegraphvisitor.cpp