| 1 | // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "testaspect.h" |
| 5 | #include <Qt3DCore/private/qnodevisitor_p.h> |
| 6 | #include <Qt3DCore/private/qnode_p.h> |
| 7 | #include <Qt3DCore/private/qaspectmanager_p.h> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | namespace Qt3DRender { |
| 12 | |
| 13 | QList<Qt3DCore::QNode *> getNodesForCreation(Qt3DCore::QNode *root) |
| 14 | { |
| 15 | using namespace Qt3DCore; |
| 16 | |
| 17 | QList<QNode *> nodes; |
| 18 | Qt3DCore::QNodeVisitor visitor; |
| 19 | visitor.traverse(root, [&nodes](QNode *node) { |
| 20 | nodes.append(node); |
| 21 | |
| 22 | // Store the metaobject of the node in the QNode so that we have it available |
| 23 | // to us during destruction in the QNode destructor. This allows us to send |
| 24 | // the QNodeId and the metaobject as typeinfo to the backend aspects so they |
| 25 | // in turn can find the correct QBackendNodeMapper object to handle the destruction |
| 26 | // of the corresponding backend nodes. |
| 27 | QNodePrivate *d = QNodePrivate::get(node); |
| 28 | d->m_typeInfo = const_cast<QMetaObject*>(QNodePrivate::findStaticMetaObject(node->metaObject())); |
| 29 | |
| 30 | // Mark this node as having been handled for creation so that it is picked up |
| 31 | d->m_hasBackendNode = true; |
| 32 | }); |
| 33 | |
| 34 | return nodes; |
| 35 | } |
| 36 | |
| 37 | TestAspect::TestAspect(Qt3DCore::QNode *root) |
| 38 | : Qt3DRender::QRenderAspect() |
| 39 | , m_jobManager(new Qt3DCore::QAspectJobManager()) |
| 40 | { |
| 41 | Qt3DCore::QAbstractAspectPrivate::get(this)->m_jobManager = m_jobManager.data(); |
| 42 | QRenderAspect::onRegistered(); |
| 43 | |
| 44 | const QList<Qt3DCore::QNode *> nodes = getNodesForCreation(root); |
| 45 | |
| 46 | for (Qt3DCore::QNode *node : nodes) |
| 47 | d_func()->createBackendNode({ |
| 48 | node->id(), |
| 49 | Qt3DCore::QNodePrivate::get(node)->m_typeInfo, |
| 50 | Qt3DCore::NodeTreeChange::Added, |
| 51 | node |
| 52 | }); |
| 53 | } |
| 54 | |
| 55 | TestAspect::~TestAspect() |
| 56 | { |
| 57 | QRenderAspect::onUnregistered(); |
| 58 | } |
| 59 | |
| 60 | Render::NodeManagers *TestAspect::nodeManagers() const |
| 61 | { |
| 62 | return d_func()->m_renderer->nodeManagers(); |
| 63 | } |
| 64 | |
| 65 | void TestAspect::onEngineStartup() |
| 66 | { |
| 67 | QRenderAspect::onEngineStartup(); |
| 68 | } |
| 69 | |
| 70 | void TestAspect::onRegistered() |
| 71 | { |
| 72 | QRenderAspect::onRegistered(); |
| 73 | } |
| 74 | |
| 75 | void TestAspect::onUnregistered() |
| 76 | { |
| 77 | QRenderAspect::onUnregistered(); |
| 78 | } |
| 79 | |
| 80 | } // Qt3DRender |
| 81 | |
| 82 | QT_END_NAMESPACE |