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
12QT_BEGIN_NAMESPACE
13
14namespace Qt3DRender {
15
16namespace Render {
17
18class LoadGeometryJobPrivate : public Qt3DCore::QAspectJobPrivate
19{
20public:
21 LoadGeometryJobPrivate() {}
22 ~LoadGeometryJobPrivate() {}
23
24 void postFrame(Qt3DCore::QAspectManager *manager) override;
25
26 QList<std::pair<Qt3DCore::QNodeId, GeometryFunctorResult>> m_updates;
27};
28
29LoadGeometryJob::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
37LoadGeometryJob::~LoadGeometryJob()
38{
39}
40
41void 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
49void 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
70QT_END_NAMESPACE
71

source code of qt3d/src/render/jobs/loadgeometryjob.cpp