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

source code of qt3d/src/render/framegraph/framegraphvisitor.cpp