From 2395b1fa9b9c5f66fd9c3b175d5eb8635cda6582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Wed, 2 Nov 2016 12:04:14 +0200 Subject: Add scene2dplugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4875c1a8c319d03e002d591f406379a636f07d8d Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- src/plugins/renderplugins/renderplugins.pro | 2 + src/plugins/renderplugins/scene2d/main.cpp | 63 ++++++++++++ src/plugins/renderplugins/scene2d/scene2d.pro | 21 ++++ .../renderplugins/scene2d/scene2dplugin.cpp | 111 +++++++++++++++++++++ src/plugins/renderplugins/scene2d/scene2dplugin.h | 92 +++++++++++++++++ .../renderplugins/scene2d/scene2dplugin.json | 3 + src/src.pro | 5 + 7 files changed, 297 insertions(+) create mode 100644 src/plugins/renderplugins/renderplugins.pro create mode 100644 src/plugins/renderplugins/scene2d/main.cpp create mode 100644 src/plugins/renderplugins/scene2d/scene2d.pro create mode 100644 src/plugins/renderplugins/scene2d/scene2dplugin.cpp create mode 100644 src/plugins/renderplugins/scene2d/scene2dplugin.h create mode 100644 src/plugins/renderplugins/scene2d/scene2dplugin.json diff --git a/src/plugins/renderplugins/renderplugins.pro b/src/plugins/renderplugins/renderplugins.pro new file mode 100644 index 000000000..1bc2f6c6c --- /dev/null +++ b/src/plugins/renderplugins/renderplugins.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += scene2d diff --git a/src/plugins/renderplugins/scene2d/main.cpp b/src/plugins/renderplugins/scene2d/main.cpp new file mode 100644 index 000000000..00a3db734 --- /dev/null +++ b/src/plugins/renderplugins/scene2d/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "scene2dplugin.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +class Scene2DPlugin : public Qt3DRender::Render::QRenderPluginFactoryIf +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QRenderPluginFactoryInterface_iid FILE "scene2dplugin.json") + + Qt3DRender::Render::QRenderPlugin *create(const QString &key, + const QStringList ¶mList) Q_DECL_OVERRIDE + { + Q_UNUSED(key) + Q_UNUSED(paramList) + return new Qt3DRender::Render::Scene2DPlugin(); + } +}; + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/renderplugins/scene2d/scene2d.pro b/src/plugins/renderplugins/scene2d/scene2d.pro new file mode 100644 index 000000000..dbf9c3e36 --- /dev/null +++ b/src/plugins/renderplugins/scene2d/scene2d.pro @@ -0,0 +1,21 @@ +TARGET = scene2d +QT += core-private 3dcore 3dcore-private 3drender 3drender-private 3dextras 3dquickrender 3dquickrender-private + +# Qt3D is free of Q_FOREACH - make sure it stays that way: +DEFINES += QT_NO_FOREACH + +HEADERS += \ + scene2dplugin.h +# scene2dnode_p.h + +SOURCES += \ + main.cpp \ + scene2dplugin.cpp +# scene2dnode.cpp + +DISTFILES += \ + scene2dplugin.json + +PLUGIN_TYPE = renderplugins +PLUGIN_CLASS_NAME = Scene2DPlugin +load(qt_plugin) diff --git a/src/plugins/renderplugins/scene2d/scene2dplugin.cpp b/src/plugins/renderplugins/scene2d/scene2dplugin.cpp new file mode 100644 index 000000000..5621858ea --- /dev/null +++ b/src/plugins/renderplugins/scene2d/scene2dplugin.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "scene2dplugin.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +template +class Scene2DBackendNodeMapper : public Qt3DCore::QBackendNodeMapper +{ +public: + explicit Scene2DBackendNodeMapper(Render::AbstractRenderer *renderer, + Render::Scene2DNodeManager *manager) + : m_manager(manager) + , m_renderer(renderer) + { + } + + Qt3DCore::QBackendNode *create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const Q_DECL_FINAL + { + Backend *backend = m_manager->getOrCreateResource(change->subjectId()); + backend->setRenderer(m_renderer); + return backend; + } + + Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const Q_DECL_FINAL + { + return m_manager->lookupResource(id); + } + + void destroy(Qt3DCore::QNodeId id) const Q_DECL_FINAL + { + m_manager->releaseResource(id); + } + +private: + Render::Scene2DNodeManager *m_manager; + Render::AbstractRenderer *m_renderer; +}; + +Scene2DPlugin::Scene2DPlugin() + : m_scene2dNodeManager(new Render::Scene2DNodeManager()) +{ + +} + +Scene2DPlugin::~Scene2DPlugin() +{ + delete m_scene2dNodeManager; +} + +bool Scene2DPlugin::registerBackendTypes(QRenderAspect *aspect, + AbstractRenderer *renderer) +{ + registerBackendType(aspect, Qt3DRender::Quick::QScene2D::staticMetaObject, + QSharedPointer > + ::create(renderer, m_scene2dNodeManager)); + return true; +} +bool Scene2DPlugin::unregisterBackendTypes(QRenderAspect *aspect) +{ + unregisterBackendType(aspect, Qt3DRender::Quick::QScene2D::staticMetaObject); + return true; +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/plugins/renderplugins/scene2d/scene2dplugin.h b/src/plugins/renderplugins/scene2d/scene2dplugin.h new file mode 100644 index 000000000..f19093c7e --- /dev/null +++ b/src/plugins/renderplugins/scene2d/scene2dplugin.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_SCENE2DPLUGIN_H +#define QT3DRENDER_SCENE2DPLUGIN_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +class Scene2DNode; + +class Scene2DNodeManager : public Qt3DCore::QResourceManager< + Render::Quick::Scene2D, + Qt3DCore::QNodeId, + 16, + Qt3DCore::ArrayAllocatingPolicy, + Qt3DCore::ObjectLevelLockingPolicy> +{ +}; + +class Scene2DPlugin : public QRenderPlugin +{ +public: + Scene2DPlugin(); + ~Scene2DPlugin(); + bool registerBackendTypes(QRenderAspect *aspect, AbstractRenderer *renderer) Q_DECL_OVERRIDE; + bool unregisterBackendTypes(QRenderAspect *aspect) Q_DECL_OVERRIDE; +private: + Render::Scene2DNodeManager *m_scene2dNodeManager; +}; + +} // Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_SCENE2DPLUGIN_H diff --git a/src/plugins/renderplugins/scene2d/scene2dplugin.json b/src/plugins/renderplugins/scene2d/scene2dplugin.json new file mode 100644 index 000000000..2eece1046 --- /dev/null +++ b/src/plugins/renderplugins/scene2d/scene2dplugin.json @@ -0,0 +1,3 @@ +{ + "Keys": ["scene2d"] +} diff --git a/src/src.pro b/src/src.pro index 61ceeb5f9..eb41669c8 100644 --- a/src/src.pro +++ b/src/src.pro @@ -66,6 +66,10 @@ src_plugins_sceneparsers.file = $$PWD/plugins/sceneparsers/sceneparsers.pro src_plugins_sceneparsers.target = sub-plugins-sceneparsers src_plugins_sceneparsers.depends = src_render src_extras +src_plugins_render.file = $$PWD/plugins/renderplugins/renderplugins.pro +src_plugins_render.target = sub-plugins-render +src_plugins_render.depends = src_render src_extras src_quick3d_render + SUBDIRS += \ src_core \ src_render \ @@ -83,6 +87,7 @@ SUBDIRS += \ src_quick3d_imports_logic \ src_quick3d_imports_extras \ src_plugins_sceneparsers \ + src_plugins_render \ doc -- cgit v1.2.3