1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
---|---|
2 | // Copyright (C) 2016 Paul Lemire |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | #include "framegraphvisitor_p.h" |
6 | |
7 | #include "framegraphnode_p.h" |
8 | #include "subtreeenabler_p.h" |
9 | #include <Qt3DRender/private/abstractrenderer_p.h> |
10 | #include <Qt3DRender/private/managers_p.h> |
11 | #include <QThreadPool> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | |
16 | namespace Qt3DRender { |
17 | namespace Render { |
18 | |
19 | using namespace Qt3DCore; |
20 | |
21 | FrameGraphVisitor::FrameGraphVisitor(const FrameGraphManager *manager) |
22 | : m_manager(manager) |
23 | { |
24 | m_leaves.reserve(n: 8); |
25 | } |
26 | |
27 | std::vector<FrameGraphNode *> &&FrameGraphVisitor::traverse(FrameGraphNode *root) |
28 | { |
29 | m_leaves.clear(); |
30 | m_enablersToDisable.clear(); |
31 | |
32 | Q_ASSERT_X(root, Q_FUNC_INFO, "The FrameGraphRoot is null"); |
33 | |
34 | // Kick off the traversal |
35 | Render::FrameGraphNode *node = root; |
36 | if (node == nullptr) |
37 | qCritical() << Q_FUNC_INFO << "FrameGraph is null"; |
38 | visit(node); |
39 | return std::move(m_leaves); |
40 | } |
41 | |
42 | // intended to be called after traverse |
43 | // (returns data that is captured during the traverse) |
44 | std::vector<FrameGraphNode *> &&FrameGraphVisitor::takeEnablersToDisable() |
45 | { |
46 | return std::move(m_enablersToDisable); |
47 | } |
48 | |
49 | void FrameGraphVisitor::visit(Render::FrameGraphNode *node) |
50 | { |
51 | if (node->nodeType() == Render::FrameGraphNode::SubtreeEnabler) { |
52 | if (!node->isEnabled()) |
53 | return; |
54 | if (static_cast<SubtreeEnabler*>(node)->enablement() == QSubtreeEnabler::SingleShot) { |
55 | node->setEnabled(false); |
56 | m_enablersToDisable.push_back(x: node); |
57 | } |
58 | } |
59 | |
60 | // Recurse to children (if we have any), otherwise if this is a leaf node, |
61 | // initiate a rendering from the current camera |
62 | const QList<Qt3DCore::QNodeId> fgChildIds = node->childrenIds(); |
63 | |
64 | for (const Qt3DCore::QNodeId &fgChildId : fgChildIds) |
65 | visit(node: m_manager->lookupNode(id: fgChildId)); |
66 | |
67 | // Leaf node - create a RenderView ready to be populated |
68 | // TODO: Pass in only framegraph config that has changed from previous |
69 | // index RenderViewJob. |
70 | if (fgChildIds.empty()) |
71 | m_leaves.push_back(x: node); |
72 | } |
73 | |
74 | } // namespace Render |
75 | } // namespace Qt3DRender |
76 | |
77 | QT_END_NAMESPACE |
78 |