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_NODEFUNCTOR_P_H |
5 | #define QT3DRENDER_RENDER_NODEFUNCTOR_P_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 <Qt3DCore/qnode.h> |
19 | #include <Qt3DRender/private/backendnode_p.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | namespace Qt3DRender { |
24 | |
25 | namespace Render { |
26 | |
27 | class AbstractRenderer; |
28 | |
29 | template<class Backend, class Manager> |
30 | class NodeFunctor : public Qt3DCore::QBackendNodeMapper |
31 | { |
32 | public: |
33 | explicit NodeFunctor(AbstractRenderer *renderer) |
34 | : m_manager(renderer->nodeManagers()->manager<Backend, Manager>()) |
35 | , m_renderer(renderer) |
36 | { |
37 | } |
38 | |
39 | Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const final |
40 | { |
41 | Backend *backend = m_manager->getOrCreateResource(id); |
42 | backend->setRenderer(m_renderer); |
43 | return backend; |
44 | } |
45 | |
46 | Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const final |
47 | { |
48 | return m_manager->lookupResource(id); |
49 | } |
50 | |
51 | void destroy(Qt3DCore::QNodeId id) const final |
52 | { |
53 | m_manager->releaseResource(id); |
54 | } |
55 | |
56 | private: |
57 | Manager *m_manager; |
58 | AbstractRenderer *m_renderer; |
59 | }; |
60 | |
61 | } // namespace Render |
62 | |
63 | } // namespace Qt3DRender |
64 | |
65 | QT_END_NAMESPACE |
66 | |
67 | #endif // QT3DRENDER_RENDER_NODEFUNCTOR_P_H |
68 | |