1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "framegraphnode_p.h"
5#include <Qt3DRender/private/abstractrenderer_p.h>
6#include <Qt3DRender/private/nodemanagers_p.h>
7
8QT_BEGIN_NAMESPACE
9
10namespace Qt3DRender {
11namespace Render {
12
13FrameGraphNode::FrameGraphNode()
14 : BackendNode()
15 , m_nodeType(InvalidNodeType)
16 , m_manager(nullptr)
17{
18}
19
20FrameGraphNode::FrameGraphNode(FrameGraphNodeType nodeType, QBackendNode::Mode mode)
21 : BackendNode(mode)
22 , m_nodeType(nodeType)
23 , m_manager(nullptr)
24{
25}
26
27FrameGraphNode::~FrameGraphNode()
28{
29}
30
31void FrameGraphNode::setFrameGraphManager(FrameGraphManager *manager)
32{
33 if (m_manager != manager)
34 m_manager = manager;
35}
36
37FrameGraphManager *FrameGraphNode::manager() const
38{
39 return m_manager;
40}
41
42void FrameGraphNode::setParentId(Qt3DCore::QNodeId parentId)
43{
44 if (m_parentId != parentId) {
45 // We already had a parent, tell it to abandon us
46 if (!m_parentId.isNull()) {
47 FrameGraphNode *parent = m_manager->lookupNode(id: m_parentId);
48 if (parent != nullptr)
49 parent->m_childrenIds.removeAll(t: peerId());
50 }
51 m_parentId = parentId;
52 FrameGraphNode *parent = m_manager->lookupNode(id: m_parentId);
53 if (parent != nullptr && !parent->m_childrenIds.contains(t: peerId()))
54 parent->m_childrenIds.append(t: peerId());
55 }
56}
57
58Qt3DCore::QNodeId FrameGraphNode::parentId() const
59{
60 return m_parentId;
61}
62
63QList<Qt3DCore::QNodeId> FrameGraphNode::childrenIds() const
64{
65 return m_childrenIds;
66}
67
68FrameGraphNode *FrameGraphNode::parent() const
69{
70 return m_manager->lookupNode(id: m_parentId);
71}
72
73QList<FrameGraphNode *> FrameGraphNode::children() const
74{
75 QList<FrameGraphNode *> children;
76 children.reserve(asize: m_childrenIds.size());
77
78 for (Qt3DCore::QNodeId id : m_childrenIds) {
79 FrameGraphNode *child = m_manager->lookupNode(id);
80 if (child != nullptr)
81 children << child;
82 }
83 return children;
84}
85
86void FrameGraphNode::cleanup()
87{
88 setParentId({});
89 markDirty(changes: AbstractRenderer::FrameGraphDirty);
90}
91
92void FrameGraphNode::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
93{
94 const QFrameGraphNode *node = qobject_cast<const QFrameGraphNode *>(object: frontEnd);
95
96 const auto parentId = Qt3DCore::qIdForNode(node: node->parentFrameGraphNode());
97 if (parentId != m_parentId) {
98 setParentId(parentId);
99 // TO DO: Check if FrameGraphDirty wouldn't be enough here
100 markDirty(changes: AbstractRenderer::AllDirty);
101 }
102
103 if (node->isEnabled() != d_func()->m_enabled) {
104 d_func()->m_enabled = node->isEnabled();
105 markDirty(changes: AbstractRenderer::FrameGraphDirty);
106 }
107
108 if (firstTime)
109 markDirty(changes: AbstractRenderer::FrameGraphDirty);
110}
111
112
113
114} // namespace Render
115} // namespace Qt3DRender
116
117QT_END_NAMESPACE
118

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