1// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
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 "qcoreaspect.h"
5#include "qcoreaspect_p.h"
6#include <Qt3DCore/qcoresettings.h>
7#include <Qt3DCore/private/coresettings_p.h>
8#include <Qt3DCore/private/qaspectmanager_p.h>
9#include <Qt3DCore/private/qscene_p.h>
10#include <Qt3DCore/private/calcboundingvolumejob_p.h>
11
12QT_BEGIN_NAMESPACE
13
14namespace Qt3DCore {
15
16QCoreAspectPrivate::QCoreAspectPrivate()
17 : Qt3DCore::QAbstractAspectPrivate()
18 , m_boundingVolumesEnabled(true)
19{
20
21}
22
23QCoreAspectPrivate::~QCoreAspectPrivate()
24{
25
26}
27
28QCoreAspectPrivate *QCoreAspectPrivate::get(QCoreAspect *aspect)
29{
30 return aspect->d_func();
31}
32
33void QCoreAspectPrivate::jobsDone()
34{
35
36}
37
38void QCoreAspectPrivate::frameDone()
39{
40
41}
42
43QCoreAspect::QCoreAspect(QObject *parent)
44 : Qt3DCore::QAbstractAspect(*new QCoreAspectPrivate, parent)
45{
46
47}
48
49QCoreAspect::~QCoreAspect()
50{
51
52}
53
54QAspectJobPtr QCoreAspect::calculateBoundingVolumeJob() const
55{
56 Q_D(const QCoreAspect);
57 return d->m_calculateBoundingVolumeJob;
58}
59
60std::vector<QAspectJobPtr> QCoreAspect::jobsToExecute(qint64 time)
61{
62 Q_D(QCoreAspect);
63 Q_UNUSED(time);
64
65 std::vector<QAspectJobPtr> jobs;
66
67 auto scene = d->m_aspectManager->scene();
68 auto dirtyBits = scene->dirtyBits();
69
70 if (d->m_boundingVolumesEnabled) {
71 if (dirtyBits & QScene::GeometryDirty ||
72 dirtyBits & QScene::BuffersDirty ||
73 dirtyBits & QScene::EntityEnabledDirty) {
74 jobs.push_back(x: d->m_calculateBoundingVolumeJob);
75 }
76 }
77
78 return jobs;
79}
80
81QVariant QCoreAspect::executeCommand(const QStringList &args)
82{
83 Q_UNUSED(args);
84 return {};
85}
86
87void QCoreAspect::onRegistered()
88{
89 Q_D(QCoreAspect);
90
91 if (d->m_calculateBoundingVolumeJob.isNull())
92 d->m_calculateBoundingVolumeJob = CalculateBoundingVolumeJobPtr::create(arguments: this);
93
94 registerBackendType<QCoreSettings>(functor: QSharedPointer<CoreSettingsFunctor>::create(arguments: this));
95}
96
97void QCoreAspect::onUnregistered()
98{
99 unregisterBackendType<Qt3DCore::QCoreSettings>();
100}
101
102void QCoreAspect::onEngineStartup()
103{
104 Q_D(QCoreAspect);
105
106 Q_ASSERT(d->m_calculateBoundingVolumeJob);
107 d->m_calculateBoundingVolumeJob->setRoot(d->m_root);
108}
109
110void QCoreAspect::frameDone()
111{
112 Q_D(QCoreAspect);
113 auto scene = d->m_aspectManager->scene();
114 scene->clearDirtyBits();
115}
116
117} // namespace Qt3DCore
118
119QT_END_NAMESPACE
120
121QT3D_REGISTER_NAMESPACED_ASPECT("core", QT_PREPEND_NAMESPACE(Qt3DCore), QCoreAspect)
122
123#include "moc_qcoreaspect.cpp"
124

source code of qt3d/src/core/aspect/qcoreaspect.cpp