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#ifndef QT3DRENDER_RENDER_FRAMEGRAPHNODE_H
41#define QT3DRENDER_RENDER_FRAMEGRAPHNODE_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of other Qt classes. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <Qt3DRender/private/backendnode_p.h>
55#include <Qt3DCore/private/qhandle_p.h>
56#include <Qt3DCore/qnode.h>
57#include <Qt3DRender/qframegraphnode.h>
58#include <Qt3DRender/private/managers_p.h>
59#include <Qt3DRender/private/nodemanagers_p.h>
60#include <qglobal.h>
61#include <QVector>
62
63// Windows had the smart idea of using a #define MemoryBarrier
64// https://msdn.microsoft.com/en-us/library/windows/desktop/ms684208(v=vs.85).aspx
65#if defined(Q_OS_WIN) && defined(MemoryBarrier)
66#undef MemoryBarrier
67#endif
68
69QT_BEGIN_NAMESPACE
70
71namespace Qt3DRender {
72
73namespace Render {
74
75class FrameGraphManager;
76
77class Q_AUTOTEST_EXPORT FrameGraphNode : public BackendNode
78{
79public:
80 FrameGraphNode();
81 virtual ~FrameGraphNode();
82
83 enum FrameGraphNodeType {
84 InvalidNodeType = 0,
85 CameraSelector,
86 LayerFilter,
87 RenderPassFilter,
88 RenderTarget,
89 TechniqueFilter,
90 Viewport,
91 ClearBuffers,
92 SortMethod,
93 SubtreeSelector,
94 StateSet,
95 NoDraw,
96 FrustumCulling,
97 Lighting,
98 ComputeDispatch,
99 Surface,
100 RenderCapture,
101 BufferCapture,
102 MemoryBarrier,
103 ProximityFilter,
104 BlitFramebuffer,
105 SetFence,
106 WaitFence,
107 NoPicking
108 };
109 FrameGraphNodeType nodeType() const { return m_nodeType; }
110
111 void setFrameGraphManager(FrameGraphManager *manager);
112 FrameGraphManager *manager() const;
113
114 void setParentId(Qt3DCore::QNodeId parentId);
115
116 Qt3DCore::QNodeId parentId() const;
117 QVector<Qt3DCore::QNodeId> childrenIds() const;
118
119 FrameGraphNode *parent() const;
120 QVector<FrameGraphNode *> children() const;
121
122 void cleanup();
123
124 void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
125
126protected:
127 FrameGraphNode(FrameGraphNodeType nodeType, QBackendNode::Mode mode = QBackendNode::ReadOnly);
128 void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) override;
129
130private:
131 FrameGraphNodeType m_nodeType;
132 Qt3DCore::QNodeId m_parentId;
133 QVector<Qt3DCore::QNodeId> m_childrenIds;
134 FrameGraphManager *m_manager;
135
136 friend class FrameGraphVisitor;
137};
138
139template<typename Backend, typename Frontend>
140class FrameGraphNodeFunctor : public Qt3DCore::QBackendNodeMapper
141{
142public:
143 explicit FrameGraphNodeFunctor(AbstractRenderer *renderer)
144 : m_manager(renderer->nodeManagers()->frameGraphManager())
145 , m_renderer(renderer)
146 {
147 }
148
149 Qt3DCore::QBackendNode *create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const override
150 {
151 return createBackendFrameGraphNode(change);
152 }
153
154 Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override
155 {
156 return m_manager->lookupNode(id);
157 }
158
159 void destroy(Qt3DCore::QNodeId id) const override
160 {
161 m_manager->releaseNode(id);
162 }
163
164protected:
165 Backend *createBackendFrameGraphNode(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const
166 {
167 if (!m_manager->containsNode(change->subjectId())) {
168 Backend *backend = new Backend();
169 backend->setFrameGraphManager(m_manager);
170 backend->setRenderer(m_renderer);
171 m_manager->appendNode(change->subjectId(), backend);
172 return backend;
173 }
174 return static_cast<Backend *>(m_manager->lookupNode(change->subjectId()));
175 }
176
177private:
178 FrameGraphManager *m_manager;
179 AbstractRenderer *m_renderer;
180};
181
182} // namespace Render
183} // namespace Qt3DRender
184
185QT_END_NAMESPACE
186
187#endif // QT3DRENDER_RENDER_FRAMEGRAPHNODE_H
188