1/****************************************************************************
2**
3** Copyright (C) 2014 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#include "framegraphnode_p.h"
41#include <Qt3DRender/private/abstractrenderer_p.h>
42#include <Qt3DRender/private/nodemanagers_p.h>
43#include <Qt3DRender/qframegraphnodecreatedchange.h>
44
45QT_BEGIN_NAMESPACE
46
47namespace Qt3DRender {
48namespace Render {
49
50FrameGraphNode::FrameGraphNode()
51 : BackendNode()
52 , m_nodeType(InvalidNodeType)
53 , m_manager(nullptr)
54{
55}
56
57FrameGraphNode::FrameGraphNode(FrameGraphNodeType nodeType, QBackendNode::Mode mode)
58 : BackendNode(mode)
59 , m_nodeType(nodeType)
60 , m_manager(nullptr)
61{
62}
63
64FrameGraphNode::~FrameGraphNode()
65{
66}
67
68void FrameGraphNode::setFrameGraphManager(FrameGraphManager *manager)
69{
70 if (m_manager != manager)
71 m_manager = manager;
72}
73
74FrameGraphManager *FrameGraphNode::manager() const
75{
76 return m_manager;
77}
78
79void FrameGraphNode::setParentId(Qt3DCore::QNodeId parentId)
80{
81 if (m_parentId != parentId) {
82 // We already had a parent, tell it to abandon us
83 if (!m_parentId.isNull()) {
84 FrameGraphNode *parent = m_manager->lookupNode(id: m_parentId);
85 if (parent != nullptr)
86 parent->m_childrenIds.removeAll(t: peerId());
87 }
88 m_parentId = parentId;
89 FrameGraphNode *parent = m_manager->lookupNode(id: m_parentId);
90 if (parent != nullptr && !parent->m_childrenIds.contains(t: peerId()))
91 parent->m_childrenIds.append(t: peerId());
92 }
93}
94
95Qt3DCore::QNodeId FrameGraphNode::parentId() const
96{
97 return m_parentId;
98}
99
100QVector<Qt3DCore::QNodeId> FrameGraphNode::childrenIds() const
101{
102 return m_childrenIds;
103}
104
105FrameGraphNode *FrameGraphNode::parent() const
106{
107 return m_manager->lookupNode(id: m_parentId);
108}
109
110QVector<FrameGraphNode *> FrameGraphNode::children() const
111{
112 QVector<FrameGraphNode *> children;
113 children.reserve(asize: m_childrenIds.size());
114
115 for (Qt3DCore::QNodeId id : m_childrenIds) {
116 FrameGraphNode *child = m_manager->lookupNode(id);
117 if (child != nullptr)
118 children << child;
119 }
120 return children;
121}
122
123void FrameGraphNode::cleanup()
124{
125 setParentId({});
126 markDirty(changes: AbstractRenderer::FrameGraphDirty);
127}
128
129void FrameGraphNode::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
130{
131 const QFrameGraphNode *node = qobject_cast<const QFrameGraphNode *>(object: frontEnd);
132
133 const auto parentId = Qt3DCore::qIdForNode(node: node->parentFrameGraphNode());
134 if (parentId != m_parentId) {
135 setParentId(parentId);
136 // TO DO: Check if FrameGraphDirty wouldn't be enough here
137 markDirty(changes: AbstractRenderer::AllDirty);
138 }
139
140 if (node->isEnabled() != d_func()->m_enabled) {
141 d_func()->m_enabled = node->isEnabled();
142 markDirty(changes: AbstractRenderer::FrameGraphDirty);
143 }
144
145 if (firstTime)
146 markDirty(changes: AbstractRenderer::FrameGraphDirty);
147}
148
149
150
151} // namespace Render
152} // namespace Qt3DRender
153
154QT_END_NAMESPACE
155

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