| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: http://www.qt-project.org/legal |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 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 http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #include "testaspect.h" |
| 38 | #include <Qt3DCore/private/qnodevisitor_p.h> |
| 39 | #include <Qt3DCore/private/qnode_p.h> |
| 40 | #include <Qt3DCore/private/qaspectmanager_p.h> |
| 41 | |
| 42 | QT_BEGIN_NAMESPACE |
| 43 | |
| 44 | namespace Qt3DRender { |
| 45 | |
| 46 | QVector<Qt3DCore::QNode *> getNodesForCreation(Qt3DCore::QNode *root) |
| 47 | { |
| 48 | using namespace Qt3DCore; |
| 49 | |
| 50 | QVector<QNode *> nodes; |
| 51 | Qt3DCore::QNodeVisitor visitor; |
| 52 | visitor.traverse(rootNode_: root, fN: [&nodes](QNode *node) { |
| 53 | nodes.append(t: node); |
| 54 | |
| 55 | // Store the metaobject of the node in the QNode so that we have it available |
| 56 | // to us during destruction in the QNode destructor. This allows us to send |
| 57 | // the QNodeId and the metaobject as typeinfo to the backend aspects so they |
| 58 | // in turn can find the correct QBackendNodeMapper object to handle the destruction |
| 59 | // of the corresponding backend nodes. |
| 60 | QNodePrivate *d = QNodePrivate::get(q: node); |
| 61 | d->m_typeInfo = const_cast<QMetaObject*>(QNodePrivate::findStaticMetaObject(metaObject: node->metaObject())); |
| 62 | |
| 63 | // Mark this node as having been handled for creation so that it is picked up |
| 64 | d->m_hasBackendNode = true; |
| 65 | }); |
| 66 | |
| 67 | return nodes; |
| 68 | } |
| 69 | |
| 70 | TestAspect::TestAspect(Qt3DCore::QNode *root) |
| 71 | : Qt3DRender::QRenderAspect(Qt3DRender::QRenderAspect::Synchronous) |
| 72 | , m_jobManager(new Qt3DCore::QAspectJobManager()) |
| 73 | { |
| 74 | Qt3DCore::QAbstractAspectPrivate::get(aspect: this)->m_jobManager = m_jobManager.data(); |
| 75 | QRenderAspect::onRegistered(); |
| 76 | |
| 77 | const QVector<Qt3DCore::QNode *> nodes = getNodesForCreation(root); |
| 78 | |
| 79 | for (Qt3DCore::QNode *node : nodes) |
| 80 | d_func()->createBackendNode(change: { |
| 81 | .id: node->id(), |
| 82 | .metaObj: Qt3DCore::QNodePrivate::get(q: node)->m_typeInfo, |
| 83 | .type: Qt3DCore::NodeTreeChange::Added, |
| 84 | .node: node |
| 85 | }); |
| 86 | } |
| 87 | |
| 88 | TestAspect::~TestAspect() |
| 89 | { |
| 90 | QRenderAspect::onUnregistered(); |
| 91 | } |
| 92 | |
| 93 | Render::NodeManagers *TestAspect::nodeManagers() const |
| 94 | { |
| 95 | return d_func()->m_renderer->nodeManagers(); |
| 96 | } |
| 97 | |
| 98 | void TestAspect::onEngineStartup() |
| 99 | { |
| 100 | QRenderAspect::onEngineStartup(); |
| 101 | } |
| 102 | |
| 103 | void TestAspect::onRegistered() |
| 104 | { |
| 105 | QRenderAspect::onRegistered(); |
| 106 | } |
| 107 | |
| 108 | void TestAspect::onUnregistered() |
| 109 | { |
| 110 | QRenderAspect::onUnregistered(); |
| 111 | } |
| 112 | |
| 113 | } // Qt3DRender |
| 114 | |
| 115 | QT_END_NAMESPACE |
| 116 |
