diff options
author | Mike Krus <mike.krus@kdab.com> | 2020-08-26 16:24:53 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2020-08-27 10:41:31 +0100 |
commit | 66b06525c57342016ba94c9e081f1c6eadbdb431 (patch) | |
tree | cf5e1d25f3725ff30a0acfaa10dff129695dac87 /src/core/aspect | |
parent | f9920b285767bceb7b771df000742c277ac9da91 (diff) |
Add QCoreSettings class
Adds the ability to disable bounding volume updates from the core
aspect.
Change-Id: I6d8a4c6f8fd880c9fca015cd40eaf7316747a2c6
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/aspect')
-rw-r--r-- | src/core/aspect/aspect.pri | 9 | ||||
-rw-r--r-- | src/core/aspect/coresettings.cpp | 96 | ||||
-rw-r--r-- | src/core/aspect/coresettings_p.h | 93 | ||||
-rw-r--r-- | src/core/aspect/qcoreaspect.cpp | 25 | ||||
-rw-r--r-- | src/core/aspect/qcoreaspect.h | 1 | ||||
-rw-r--r-- | src/core/aspect/qcoreaspect_p.h | 2 | ||||
-rw-r--r-- | src/core/aspect/qcoresettings.cpp | 137 | ||||
-rw-r--r-- | src/core/aspect/qcoresettings.h | 78 | ||||
-rw-r--r-- | src/core/aspect/qcoresettings_p.h | 80 |
9 files changed, 515 insertions, 6 deletions
diff --git a/src/core/aspect/aspect.pri b/src/core/aspect/aspect.pri index b371400b8..b9c4d5099 100644 --- a/src/core/aspect/aspect.pri +++ b/src/core/aspect/aspect.pri @@ -1,8 +1,13 @@ SOURCES += \ - $$PWD/qcoreaspect.cpp + $$PWD/qcoreaspect.cpp \ + $$PWD/qcoresettings.cpp \ + $$PWD/coresettings.cpp HEADERS += \ $$PWD/qcoreaspect.h \ - $$PWD/qcoreaspect_p.h + $$PWD/qcoreaspect_p.h \ + $$PWD/qcoresettings.h \ + $$PWD/qcoresettings_p.h \ + $$PWD/coresettings_p.h INCLUDEPATH += $$PWD diff --git a/src/core/aspect/coresettings.cpp b/src/core/aspect/coresettings.cpp new file mode 100644 index 000000000..1425ef5d9 --- /dev/null +++ b/src/core/aspect/coresettings.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "coresettings_p.h" +#include <Qt3DCore/private/qcoreaspect_p.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3DCore; + +CoreSettings::CoreSettings() + : QBackendNode() +{ +} + +void CoreSettings::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) +{ + Q_UNUSED(firstTime); + + const QCoreSettings *node = qobject_cast<const QCoreSettings *>(frontEnd); + if (!node) + return; + + Q_ASSERT(m_aspect); + auto daspect = QCoreAspectPrivate::get(m_aspect); + daspect->m_boundingVolumesEnabled = node->boundingVolumesEnabled(); +} + +CoreSettingsFunctor::CoreSettingsFunctor(QCoreAspect *aspect) + : m_aspect(aspect) + , m_settings(nullptr) +{ +} + +Qt3DCore::QBackendNode *CoreSettingsFunctor::create(Qt3DCore::QNodeId) const +{ + if (m_settings != nullptr) { + qWarning() << "Core settings already exists"; + return nullptr; + } + + m_settings = new CoreSettings; + m_settings->setAspect(m_aspect); + return m_settings; +} + +Qt3DCore::QBackendNode *CoreSettingsFunctor::get(Qt3DCore::QNodeId id) const +{ + Q_UNUSED(id); + return m_settings; +} + +void CoreSettingsFunctor::destroy(Qt3DCore::QNodeId id) const +{ + Q_UNUSED(id); + delete m_settings; + m_settings = nullptr; +} + +QT_END_NAMESPACE diff --git a/src/core/aspect/coresettings_p.h b/src/core/aspect/coresettings_p.h new file mode 100644 index 000000000..076f37797 --- /dev/null +++ b/src/core/aspect/coresettings_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DCORE_RENDERSETTINGS_H +#define QT3DCORE_RENDERSETTINGS_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/qbackendnode.h> +#include <Qt3DCore/qcoresettings.h> +#include <Qt3DCore/private/qt3dcore_global_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +class QCoreAspect; + +class Q_3DCORE_PRIVATE_EXPORT CoreSettings : public QBackendNode +{ +public: + CoreSettings(); + + void setAspect(QCoreAspect *aspect) { m_aspect = aspect; } + void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; + +private: + QCoreAspect *m_aspect; +}; + +class CoreSettingsFunctor : public Qt3DCore::QBackendNodeMapper +{ +public: + explicit CoreSettingsFunctor(QCoreAspect *aspect); + Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const override; + Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override; + void destroy(Qt3DCore::QNodeId id) const override; + +private: + QCoreAspect *m_aspect; + mutable CoreSettings *m_settings; +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_RENDERSETTINGS_H diff --git a/src/core/aspect/qcoreaspect.cpp b/src/core/aspect/qcoreaspect.cpp index b2924fb72..46e71a224 100644 --- a/src/core/aspect/qcoreaspect.cpp +++ b/src/core/aspect/qcoreaspect.cpp @@ -39,6 +39,8 @@ #include "qcoreaspect.h" #include "qcoreaspect_p.h" +#include <Qt3DCore/qcoresettings.h> +#include <Qt3DCore/private/coresettings_p.h> #include <Qt3DCore/private/qaspectmanager_p.h> #include <Qt3DCore/private/qscene_p.h> #include <Qt3DCore/private/calcboundingvolumejob_p.h> @@ -49,6 +51,7 @@ using namespace Qt3DCore; QCoreAspectPrivate::QCoreAspectPrivate() : Qt3DCore::QAbstractAspectPrivate() + , m_boundingVolumesEnabled(true) { } @@ -58,6 +61,11 @@ QCoreAspectPrivate::~QCoreAspectPrivate() } +QCoreAspectPrivate *QCoreAspectPrivate::get(QCoreAspect *aspect) +{ + return aspect->d_func(); +} + void QCoreAspectPrivate::jobsDone() { @@ -95,9 +103,11 @@ std::vector<QAspectJobPtr> QCoreAspect::jobsToExecute(qint64 time) auto scene = d->m_aspectManager->scene(); auto dirtyBits = scene->dirtyBits(); - if (dirtyBits & QScene::GeometryDirty || - dirtyBits & QScene::BuffersDirty) { - jobs.push_back(d->m_calculateBoundingVolumeJob); + if (d->m_boundingVolumesEnabled) { + if (dirtyBits & QScene::GeometryDirty || + dirtyBits & QScene::BuffersDirty) { + jobs.push_back(d->m_calculateBoundingVolumeJob); + } } return jobs; @@ -114,7 +124,14 @@ void QCoreAspect::onRegistered() Q_D(QCoreAspect); if (d->m_calculateBoundingVolumeJob.isNull()) - d->m_calculateBoundingVolumeJob = CalculateBoundingVolumeJobPtr::create(); + d->m_calculateBoundingVolumeJob = CalculateBoundingVolumeJobPtr::create(this); + + registerBackendType<QCoreSettings>(QSharedPointer<CoreSettingsFunctor>::create(this)); +} + +void QCoreAspect::onUnregistered() +{ + unregisterBackendType<Qt3DCore::QCoreSettings>(); } void QCoreAspect::onEngineStartup() diff --git a/src/core/aspect/qcoreaspect.h b/src/core/aspect/qcoreaspect.h index 3289111d1..0e27346f0 100644 --- a/src/core/aspect/qcoreaspect.h +++ b/src/core/aspect/qcoreaspect.h @@ -64,6 +64,7 @@ private: std::vector<Qt3DCore::QAspectJobPtr> jobsToExecute(qint64 time) override; QVariant executeCommand(const QStringList &args) override; void onRegistered() override; + void onUnregistered() override; void onEngineStartup() override; void frameDone() override; }; diff --git a/src/core/aspect/qcoreaspect_p.h b/src/core/aspect/qcoreaspect_p.h index cda0a140a..1c09bac56 100644 --- a/src/core/aspect/qcoreaspect_p.h +++ b/src/core/aspect/qcoreaspect_p.h @@ -71,12 +71,14 @@ public: ~QCoreAspectPrivate(); Q_DECLARE_PUBLIC(QCoreAspect) + static QCoreAspectPrivate *get(QCoreAspect *aspect); void jobsDone() override; void frameDone() override; bool m_initialized; CalculateBoundingVolumeJobPtr m_calculateBoundingVolumeJob; + bool m_boundingVolumesEnabled; }; } diff --git a/src/core/aspect/qcoresettings.cpp b/src/core/aspect/qcoresettings.cpp new file mode 100644 index 000000000..81415de7e --- /dev/null +++ b/src/core/aspect/qcoresettings.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qcoresettings.h" +#include "qcoresettings_p.h" +#include <Qt3DCore/private/corelogging_p.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3DCore; + +/*! + \class Qt3DCore::QCoreSettings + \brief The QCoreSettings class holds settings related to core data handling process. + \since 6.0 + \inmodule Qt3DCore + \inherits Qt3DCore::QComponent + + The QCoreSettings component should be set as a component of the scene root entity + (although it could be anywhere in the scene graph). There should be a single instance. + + It can be used to control some of Qt 3D's behavior. +*/ + +/*! + \qmltype CoreSettings + \brief The CoreSettings class holds settings related to core data handling process. + \since 6.0 + \inqmlmodule Qt3D.Core + \instantiates Qt3DCore::QCoreSettings + + The CoreSettings component should be set as a component of the scene root entity + (although it could be anywhere in the scene graph). There should be a single instance. + + It can be used to control some of Qt 3D's behavior. +*/ + +namespace Qt3DCore { + +QCoreSettingsPrivate::QCoreSettingsPrivate() + : QComponentPrivate() + , m_boundingVolumesEnabled(true) +{ +} + +QCoreSettingsPrivate *QCoreSettingsPrivate::get(QCoreSettings *q) +{ + return q->d_func(); +} + +/*! + * Constructs a new QCoreSettings with \a parent. + */ +QCoreSettings::QCoreSettings(QNode *parent) + : QComponent(*new QCoreSettingsPrivate(), parent) +{ +} + +/*! + * \internal + */ +QCoreSettings::~QCoreSettings() +{ +} + +/*! +\qmlproperty bool CoreSettings::boundingVolumesEnabled + +Holds whether bounding volumes handling is enabled. This is true by +default. Disabling this allows to reduce the amount of computations +performed each frame. If you are using picking or frustum culling you +should keep this enabled (even when providing explicit bounding volumes +sizes using BoundingVolume). +*/ +/*! +\property QCoreSettings::boundingVolumesEnabled + +Holds whether bounding volumes handling is enabled. This is true by +default. Disabling this allows to reduce the amount of computations +performed each frame. If you are using picking or frustum culling you +should keep this enabled (even when providing explicit bounding volumes +sizes using QBoundingVolume). +*/ +bool QCoreSettings::boundingVolumesEnabled() const +{ + Q_D(const QCoreSettings); + return d->m_boundingVolumesEnabled; +} + +void QCoreSettings::setBoundingVolumesEnabled(bool boundingVolumesEnabled) +{ + Q_D(QCoreSettings); + if (d->m_boundingVolumesEnabled == boundingVolumesEnabled) + return; + d->m_boundingVolumesEnabled = boundingVolumesEnabled; + emit boundingVolumesEnabledChanged(boundingVolumesEnabled); +} + +} // namespace Qt3DCore + +QT_END_NAMESPACE diff --git a/src/core/aspect/qcoresettings.h b/src/core/aspect/qcoresettings.h new file mode 100644 index 000000000..23aeebe15 --- /dev/null +++ b/src/core/aspect/qcoresettings.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DCORE_QCORESETTINGS_H +#define QT3DCORE_QCORESETTINGS_H + +#include <Qt3DCore/qcomponent.h> +#include <Qt3DCore/qt3dcore_global.h> +#include <QtCore/QSharedPointer> + + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +class QCoreSettingsPrivate; + +class Q_3DCORESHARED_EXPORT QCoreSettings : public Qt3DCore::QComponent +{ + Q_OBJECT + Q_PROPERTY(bool boundingVolumesEnabled WRITE setBoundingVolumesEnabled READ boundingVolumesEnabled NOTIFY boundingVolumesEnabledChanged) +public: + explicit QCoreSettings(Qt3DCore::QNode *parent = nullptr); + ~QCoreSettings(); + + bool boundingVolumesEnabled() const; + +public Q_SLOTS: + void setBoundingVolumesEnabled(bool boundingVolumesEnabled); + +Q_SIGNALS: + void boundingVolumesEnabledChanged(bool boundingVolumesEnabled); + +private: + Q_DECLARE_PRIVATE(QCoreSettings) +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QCORESETTINGS_H diff --git a/src/core/aspect/qcoresettings_p.h b/src/core/aspect/qcoresettings_p.h new file mode 100644 index 000000000..25e4a5573 --- /dev/null +++ b/src/core/aspect/qcoresettings_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DCORE_QCORESETTINGS_P_H +#define QT3DCORE_QCORESETTINGS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DCore/qcoresettings.h> +#include <Qt3DCore/qt3dcore_global.h> +#include <Qt3DCore/private/qcomponent_p.h> +#include <QByteArray> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +class Q_3DCORESHARED_EXPORT QCoreSettingsPrivate : public Qt3DCore::QComponentPrivate +{ +public: + Q_DECLARE_PUBLIC(QCoreSettings) + + QCoreSettingsPrivate(); + + static QCoreSettingsPrivate *get(QCoreSettings *q); + + bool m_boundingVolumesEnabled; +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QBUFFER_P_H |