| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef TESTRENDERASPECT_H |
| 5 |
#define TESTRENDERASPECT_H |
| 6 |
|
| 7 |
#include <Qt3DRender/qrenderaspect.h> |
| 8 |
#include <Qt3DRender/private/qrenderaspect_p.h> |
| 9 |
#include <Qt3DRender/private/abstractrenderer_p.h> |
| 10 |
#include <Qt3DCore/private/qaspectjobmanager_p.h> |
| 11 |
#include <Qt3DCore/private/qnodevisitor_p.h> |
| 12 |
#include <Qt3DCore/private/qabstractfrontendnodemanager_p.h> |
| 13 |
#include <Qt3DRender/private/qrenderaspect_p.h> |
| 14 |
|
| 15 |
QT_BEGIN_NAMESPACE |
| 16 |
|
| 17 |
namespace Qt3DRender { |
| 18 |
|
| 19 |
class TestAspect : public Qt3DRender::QRenderAspect, public Qt3DCore::QAbstractFrontEndNodeManager |
| 20 |
{ |
| 21 |
public: |
| 22 |
TestAspect(Qt3DCore::QNode *root); |
| 23 |
|
| 24 |
~TestAspect(); |
| 25 |
|
| 26 |
Qt3DRender::Render::NodeManagers *nodeManagers() const; |
| 27 |
|
| 28 |
void onEngineStartup() override; |
| 29 |
void onRegistered() override; |
| 30 |
void onUnregistered() override; |
| 31 |
|
| 32 |
void registerNode(Qt3DCore::QNode *node) { m_frontEndNodes.insert(node->id(), node); } |
| 33 |
void registerTree(Qt3DCore::QEntity *root) { |
| 34 |
using namespace Qt3DCore; |
| 35 |
QNodeVisitor visitor; |
| 36 |
visitor.traverse(root, [](QNode *) {}, [this](QEntity *entity) { |
| 37 |
registerNode(entity); |
| 38 |
const auto &components = entity->components(); |
| 39 |
for (const auto &c : components) |
| 40 |
registerNode(c); |
| 41 |
}); |
| 42 |
} |
| 43 |
Qt3DCore::QNode *lookupNode(Qt3DCore::QNodeId id) const override { return m_frontEndNodes.value(id, nullptr); } |
| 44 |
QList<Qt3DCore::QNode *> lookupNodes(const QList<Qt3DCore::QNodeId> &ids) const override { |
| 45 |
QList<Qt3DCore::QNode *> res; |
| 46 |
for (const auto &id: ids) { |
| 47 |
auto node = m_frontEndNodes.value(id, nullptr); |
| 48 |
if (node) |
| 49 |
res.push_back(node); |
| 50 |
} |
| 51 |
return res; |
| 52 |
} |
| 53 |
|
| 54 |
private: |
| 55 |
QScopedPointer<Qt3DCore::QAspectJobManager> m_jobManager; |
| 56 |
QHash<Qt3DCore::QNodeId, Qt3DCore::QNode *> m_frontEndNodes; |
| 57 |
}; |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
QT_END_NAMESPACE |
| 62 |
|
| 63 |
#endif |