| 1 | // Copyright (C) 2015 Paul Lemire |
|---|---|
| 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 "loadgeometryjob_p.h" |
| 5 | #include <Qt3DRender/private/nodemanagers_p.h> |
| 6 | #include <Qt3DRender/private/geometryrenderermanager_p.h> |
| 7 | #include <Qt3DRender/private/job_common_p.h> |
| 8 | #include <Qt3DCore/private/qaspectmanager_p.h> |
| 9 | #include <Qt3DCore/private/vector_helper_p.h> |
| 10 | #include <Qt3DRender/private/qmesh_p.h> |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | namespace Qt3DRender { |
| 15 | |
| 16 | namespace Render { |
| 17 | |
| 18 | class LoadGeometryJobPrivate : public Qt3DCore::QAspectJobPrivate |
| 19 | { |
| 20 | public: |
| 21 | LoadGeometryJobPrivate() {} |
| 22 | ~LoadGeometryJobPrivate() {} |
| 23 | |
| 24 | void postFrame(Qt3DCore::QAspectManager *manager) override; |
| 25 | |
| 26 | QList<std::pair<Qt3DCore::QNodeId, GeometryFunctorResult>> m_updates; |
| 27 | }; |
| 28 | |
| 29 | LoadGeometryJob::LoadGeometryJob(const HGeometryRenderer &handle) |
| 30 | : QAspectJob(*new LoadGeometryJobPrivate) |
| 31 | , m_handle(handle) |
| 32 | , m_nodeManagers(nullptr) |
| 33 | { |
| 34 | SET_JOB_RUN_STAT_TYPE(this, JobTypes::LoadGeometry, 0) |
| 35 | } |
| 36 | |
| 37 | LoadGeometryJob::~LoadGeometryJob() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | void LoadGeometryJob::run() |
| 42 | { |
| 43 | Q_D(LoadGeometryJob); |
| 44 | GeometryRenderer *geometryRenderer = m_nodeManagers->geometryRendererManager()->data(handle: m_handle); |
| 45 | if (geometryRenderer != nullptr) |
| 46 | d->m_updates.push_back(t: { geometryRenderer->peerId(), geometryRenderer->executeFunctor() }); |
| 47 | } |
| 48 | |
| 49 | void LoadGeometryJobPrivate::postFrame(Qt3DCore::QAspectManager *manager) |
| 50 | { |
| 51 | const auto updates = Qt3DCore::moveAndClear(data&: m_updates); |
| 52 | for (const auto &update : updates) { |
| 53 | QGeometryRenderer *gR = static_cast<decltype(gR)>(manager->lookupNode(id: update.first)); |
| 54 | const GeometryFunctorResult &result = update.second; |
| 55 | gR->setGeometry(result.geometry); |
| 56 | |
| 57 | // Set status if gR is a QMesh instance |
| 58 | QMesh *mesh = qobject_cast<QMesh *>(object: gR); |
| 59 | if (mesh) { |
| 60 | QMeshPrivate *dMesh = static_cast<decltype(dMesh)>(Qt3DCore::QNodePrivate::get(q: mesh)); |
| 61 | dMesh->setStatus(result.status); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } // namespace Render |
| 67 | |
| 68 | } // namespace Qt3DRender |
| 69 | |
| 70 | QT_END_NAMESPACE |
| 71 |
