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#ifndef QT3DRENDER_RENDER_FRAMEGRAPHNODE_H
5#define QT3DRENDER_RENDER_FRAMEGRAPHNODE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DRender/private/backendnode_p.h>
19#include <Qt3DCore/private/qhandle_p.h>
20#include <Qt3DCore/qnode.h>
21#include <Qt3DRender/qframegraphnode.h>
22#include <Qt3DRender/private/managers_p.h>
23#include <Qt3DRender/private/nodemanagers_p.h>
24#include <qglobal.h>
25#include <QList>
26
27// Windows had the smart idea of using a #define MemoryBarrier
28// https://msdn.microsoft.com/en-us/library/windows/desktop/ms684208(v=vs.85).aspx
29#if defined(Q_OS_WIN) && defined(MemoryBarrier)
30#undef MemoryBarrier
31#endif
32
33QT_BEGIN_NAMESPACE
34
35namespace Qt3DRender {
36
37namespace Render {
38
39class FrameGraphManager;
40
41class Q_3DRENDERSHARED_PRIVATE_EXPORT FrameGraphNode : public BackendNode
42{
43public:
44 FrameGraphNode();
45 virtual ~FrameGraphNode();
46
47 enum FrameGraphNodeType {
48 InvalidNodeType = 0,
49 CameraSelector,
50 LayerFilter,
51 RenderPassFilter,
52 RenderTarget,
53 TechniqueFilter,
54 Viewport,
55 ClearBuffers,
56 SortMethod,
57 SubtreeEnabler,
58 StateSet,
59 NoDraw,
60 FrustumCulling,
61 Lighting,
62 ComputeDispatch,
63 Surface,
64 RenderCapture,
65 BufferCapture,
66 MemoryBarrier,
67 ProximityFilter,
68 BlitFramebuffer,
69 SetFence,
70 WaitFence,
71 NoPicking,
72 DebugOverlay,
73 };
74 FrameGraphNodeType nodeType() const { return m_nodeType; }
75
76 void setFrameGraphManager(FrameGraphManager *manager);
77 FrameGraphManager *manager() const;
78
79 void setParentId(Qt3DCore::QNodeId parentId);
80
81 Qt3DCore::QNodeId parentId() const;
82 QList<Qt3DCore::QNodeId> childrenIds() const;
83
84 FrameGraphNode *parent() const;
85 QList<FrameGraphNode *> children() const;
86
87 void cleanup();
88
89 void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
90
91protected:
92 FrameGraphNode(FrameGraphNodeType nodeType, QBackendNode::Mode mode = QBackendNode::ReadOnly);
93
94private:
95 FrameGraphNodeType m_nodeType;
96 Qt3DCore::QNodeId m_parentId;
97 QList<Qt3DCore::QNodeId> m_childrenIds;
98 FrameGraphManager *m_manager;
99
100 friend class FrameGraphVisitor;
101};
102
103template<typename Backend, typename Frontend>
104class FrameGraphNodeFunctor : public Qt3DCore::QBackendNodeMapper
105{
106public:
107 explicit FrameGraphNodeFunctor(AbstractRenderer *renderer)
108 : m_manager(renderer->nodeManagers()->frameGraphManager())
109 , m_renderer(renderer)
110 {
111 }
112
113 Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const override
114 {
115 return createBackendFrameGraphNode(id);
116 }
117
118 Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override
119 {
120 return m_manager->lookupNode(id);
121 }
122
123 void destroy(Qt3DCore::QNodeId id) const override
124 {
125 m_manager->releaseNode(id);
126 }
127
128protected:
129 Backend *createBackendFrameGraphNode(const Qt3DCore::QNodeId &id) const
130 {
131 if (!m_manager->containsNode(id)) {
132 Backend *backend = new Backend();
133 backend->setFrameGraphManager(m_manager);
134 backend->setRenderer(m_renderer);
135 m_manager->appendNode(id, node: backend);
136 return backend;
137 }
138 return static_cast<Backend *>(m_manager->lookupNode(id));
139 }
140
141private:
142 FrameGraphManager *m_manager;
143 AbstractRenderer *m_renderer;
144};
145
146} // namespace Render
147} // namespace Qt3DRender
148
149QT_END_NAMESPACE
150
151#endif // QT3DRENDER_RENDER_FRAMEGRAPHNODE_H
152

source code of qt3d/src/render/framegraph/framegraphnode_p.h