1// Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies).
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 "scene2dplugin.h"
5
6#include <Qt3DRender/qrenderaspect.h>
7#include <Qt3DQuickScene2D/qscene2d.h>
8
9QT_BEGIN_NAMESPACE
10
11namespace Qt3DRender {
12namespace Render {
13
14template <typename Backend>
15class Scene2DBackendNodeMapper : public Qt3DCore::QBackendNodeMapper
16{
17public:
18 explicit Scene2DBackendNodeMapper(Render::AbstractRenderer *renderer,
19 Render::Scene2DNodeManager *manager)
20 : m_manager(manager)
21 , m_renderer(renderer)
22 {
23 }
24
25 Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const final
26 {
27 Backend *backend = m_manager->getOrCreateResource(id);
28 backend->setRenderer(m_renderer);
29 return backend;
30 }
31
32 Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const final
33 {
34 return m_manager->lookupResource(id);
35 }
36
37 void destroy(Qt3DCore::QNodeId id) const final
38 {
39 m_manager->releaseResource(id);
40 }
41
42private:
43 Render::Scene2DNodeManager *m_manager;
44 Render::AbstractRenderer *m_renderer;
45};
46
47Scene2DPlugin::Scene2DPlugin()
48 : m_scene2dNodeManager(new Render::Scene2DNodeManager())
49{
50
51}
52
53Scene2DPlugin::~Scene2DPlugin()
54{
55 delete m_scene2dNodeManager;
56}
57
58bool Scene2DPlugin::registerBackendTypes(QRenderAspect *aspect,
59 AbstractRenderer *renderer)
60{
61 registerBackendType(aspect, obj: Qt3DRender::Quick::QScene2D::staticMetaObject,
62 functor: QSharedPointer<Scene2DBackendNodeMapper<Render::Quick::Scene2D> >
63 ::create(arguments&: renderer, arguments&: m_scene2dNodeManager));
64 return true;
65}
66bool Scene2DPlugin::unregisterBackendTypes(QRenderAspect *aspect)
67{
68 unregisterBackendType(aspect, obj: Qt3DRender::Quick::QScene2D::staticMetaObject);
69 return true;
70}
71
72} // namespace Render
73} // namespace Qt3DRender
74
75QT_END_NAMESPACE
76

source code of qt3d/src/plugins/renderplugins/scene2d/scene2dplugin.cpp