diff options
author | Mike Krus <mike.krus@kdab.com> | 2019-10-03 15:50:42 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2019-10-08 15:27:03 +0100 |
commit | d3507c90e20a8f2b0a78428a3c78888dbe2138d9 (patch) | |
tree | 2e95f525b4f2003bd38fcad3dcf4df58b721815b /src/render/frontend | |
parent | bf437f7da6c57307f93a24162981d4efd989fc53 (diff) |
Update UpdateLevelOfDetailJob to use direct sync
Change-Id: I26ca21fc0f18bc79f3554824869eefc2178e83f8
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/frontend')
-rw-r--r-- | src/render/frontend/qlevelofdetail.cpp | 29 | ||||
-rw-r--r-- | src/render/frontend/qlevelofdetail.h | 1 | ||||
-rw-r--r-- | src/render/frontend/qlevelofdetail_p.h | 2 | ||||
-rw-r--r-- | src/render/frontend/qlevelofdetailswitch.cpp | 65 | ||||
-rw-r--r-- | src/render/frontend/qlevelofdetailswitch.h | 4 | ||||
-rw-r--r-- | src/render/frontend/qlevelofdetailswitch_p.h | 77 | ||||
-rw-r--r-- | src/render/frontend/render-frontend.pri | 1 |
7 files changed, 127 insertions, 52 deletions
diff --git a/src/render/frontend/qlevelofdetail.cpp b/src/render/frontend/qlevelofdetail.cpp index a3596a518..3d0cb9553 100644 --- a/src/render/frontend/qlevelofdetail.cpp +++ b/src/render/frontend/qlevelofdetail.cpp @@ -40,7 +40,6 @@ #include "qlevelofdetail.h" #include "qlevelofdetail_p.h" #include "qcamera.h" -#include <Qt3DCore/qpropertyupdatedchange.h> QT_BEGIN_NAMESPACE @@ -55,6 +54,15 @@ QLevelOfDetailPrivate::QLevelOfDetailPrivate() { } +void QLevelOfDetailPrivate::setCurrentIndex(int currentIndex) +{ + Q_Q(QLevelOfDetail); + if (m_currentIndex != currentIndex) { + m_currentIndex = currentIndex; + emit q->currentIndexChanged(m_currentIndex); + } +} + /*! \class Qt3DRender::QLevelOfDetail \inmodule Qt3DRender @@ -317,20 +325,6 @@ Qt3DCore::QNodeCreatedChangeBasePtr QLevelOfDetail::createNodeCreationChange() c return creationChange; } -/*! \internal */ -void QLevelOfDetail::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) -{ - Q_D(QLevelOfDetail); - Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change); - if (e->type() == Qt3DCore::PropertyUpdated) { - if (e->propertyName() == QByteArrayLiteral("currentIndex")) { - int ndx = e->value().value<int>(); - d->m_currentIndex = ndx; - emit currentIndexChanged(ndx); - } - } -} - QCamera *QLevelOfDetail::camera() const { Q_D(const QLevelOfDetail); @@ -367,10 +361,7 @@ int QLevelOfDetail::currentIndex() const void QLevelOfDetail::setCurrentIndex(int currentIndex) { Q_D(QLevelOfDetail); - if (d->m_currentIndex != currentIndex) { - d->m_currentIndex = currentIndex; - emit currentIndexChanged(d->m_currentIndex); - } + d->setCurrentIndex(currentIndex); } QLevelOfDetail::ThresholdType QLevelOfDetail::thresholdType() const diff --git a/src/render/frontend/qlevelofdetail.h b/src/render/frontend/qlevelofdetail.h index 308a4d3c0..f6c09a287 100644 --- a/src/render/frontend/qlevelofdetail.h +++ b/src/render/frontend/qlevelofdetail.h @@ -97,7 +97,6 @@ Q_SIGNALS: protected: explicit QLevelOfDetail(QLevelOfDetailPrivate &dd, Qt3DCore::QNode *parent = nullptr); Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const override; - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override; private: Q_DECLARE_PRIVATE(QLevelOfDetail) diff --git a/src/render/frontend/qlevelofdetail_p.h b/src/render/frontend/qlevelofdetail_p.h index 7b409e4ca..429128427 100644 --- a/src/render/frontend/qlevelofdetail_p.h +++ b/src/render/frontend/qlevelofdetail_p.h @@ -72,6 +72,8 @@ public: void _q_radiusChanged(float radius); void _q_centerChanged(const QVector3D ¢er); + virtual void setCurrentIndex(int currentIndex); + QCamera *m_camera; int m_currentIndex; QLevelOfDetail::ThresholdType m_thresholdType; diff --git a/src/render/frontend/qlevelofdetailswitch.cpp b/src/render/frontend/qlevelofdetailswitch.cpp index 845fdd5a6..7b888fe98 100644 --- a/src/render/frontend/qlevelofdetailswitch.cpp +++ b/src/render/frontend/qlevelofdetailswitch.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qlevelofdetailswitch.h" +#include "qlevelofdetailswitch_p.h" #include "qlevelofdetail_p.h" #include "qglobal.h" #include <Qt3DCore/QEntity> @@ -47,6 +48,38 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { +QLevelOfDetailSwitchPrivate::QLevelOfDetailSwitchPrivate() + : QLevelOfDetailPrivate() +{ + +} + +void QLevelOfDetailSwitchPrivate::setCurrentIndex(int currentIndex) +{ + Q_Q(QLevelOfDetailSwitch); + + bool changed = m_currentIndex != currentIndex; + QLevelOfDetailPrivate::setCurrentIndex(currentIndex); + + if (!changed) + return; + + int entityIndex = 0; + const auto entities = q->entities(); + for (Qt3DCore::QEntity *entity : entities) { + const auto childNodes = entity->childNodes(); + for (Qt3DCore::QNode *childNode : childNodes) { + Qt3DCore::QEntity *childEntity = qobject_cast<Qt3DCore::QEntity *>(childNode); + if (childEntity) { + childEntity->setEnabled(entityIndex == currentIndex); + entityIndex++; + } + } + + break; // only work on the first entity, LOD should not be shared + } +} + /*! \class Qt3DRender::QLevelOfDetailSwitch \inmodule Qt3DRender @@ -84,9 +117,9 @@ namespace Qt3DRender { Constructs a new QLevelOfDetailSwitch with the specified \a parent. */ QLevelOfDetailSwitch::QLevelOfDetailSwitch(QNode *parent) - : QLevelOfDetail(parent) + : QLevelOfDetail(*new QLevelOfDetailSwitchPrivate(), parent) { - Q_D(QLevelOfDetail); + Q_D(QLevelOfDetailSwitch); d->m_currentIndex = -1; } @@ -101,34 +134,6 @@ QLevelOfDetailSwitch::QLevelOfDetailSwitch(QLevelOfDetailPrivate &dd, QNode *par { } -/*! \internal */ -void QLevelOfDetailSwitch::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) -{ - Q_D(QLevelOfDetail); - Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change); - if (e->type() == Qt3DCore::PropertyUpdated) { - if (e->propertyName() == QByteArrayLiteral("currentIndex")) { - int ndx = e->value().value<int>(); - d->m_currentIndex = ndx; - emit currentIndexChanged(ndx); - - int entityIndex = 0; - const auto entities = this->entities(); - for (Qt3DCore::QEntity *entity : entities) { - const auto childNodes = entity->childNodes(); - for (Qt3DCore::QNode *childNode : childNodes) { - Qt3DCore::QEntity *childEntity = qobject_cast<Qt3DCore::QEntity *>(childNode); - if (childEntity) { - childEntity->setEnabled(entityIndex == ndx); - entityIndex++; - } - } - break; // only work on the first entity, LOD should not be shared - } - } - } -} - } // namespace Qt3DRender QT_END_NAMESPACE diff --git a/src/render/frontend/qlevelofdetailswitch.h b/src/render/frontend/qlevelofdetailswitch.h index 1615d16e6..90f4ee3e2 100644 --- a/src/render/frontend/qlevelofdetailswitch.h +++ b/src/render/frontend/qlevelofdetailswitch.h @@ -45,6 +45,7 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { +class QLevelOfDetailSwitchPrivate; class Q_3DRENDERSHARED_EXPORT QLevelOfDetailSwitch : public QLevelOfDetail { @@ -56,10 +57,9 @@ public: protected: explicit QLevelOfDetailSwitch(QLevelOfDetailPrivate &dd, Qt3DCore::QNode *parent = nullptr); - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override; private: - Q_DECLARE_PRIVATE(QLevelOfDetail) + Q_DECLARE_PRIVATE(QLevelOfDetailSwitch) }; } // namespace Qt3DRender diff --git a/src/render/frontend/qlevelofdetailswitch_p.h b/src/render/frontend/qlevelofdetailswitch_p.h new file mode 100644 index 000000000..51321c986 --- /dev/null +++ b/src/render/frontend/qlevelofdetailswitch_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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 QT3DRENDER_QLEVELOFDETAILSWITCH_P_H +#define QT3DRENDER_QLEVELOFDETAILSWITCH_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 <Qt3DRender/private/qlevelofdetail_p.h> +#include <Qt3DRender/qlevelofdetailswitch.h> + +#include <QVector3D> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class Q_3DRENDERSHARED_PRIVATE_EXPORT QLevelOfDetailSwitchPrivate : public QLevelOfDetailPrivate +{ +public: + QLevelOfDetailSwitchPrivate(); + + Q_DECLARE_PUBLIC(QLevelOfDetailSwitch) + + void setCurrentIndex(int currentIndex) override; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QLEVELOFDETAILSWITCH_P_H diff --git a/src/render/frontend/render-frontend.pri b/src/render/frontend/render-frontend.pri index 1fafcc294..0153e9c97 100644 --- a/src/render/frontend/render-frontend.pri +++ b/src/render/frontend/render-frontend.pri @@ -9,6 +9,7 @@ HEADERS += \ $$PWD/qlevelofdetail.h \ $$PWD/qlevelofdetail_p.h \ $$PWD/qlevelofdetailswitch.h \ + $$PWD/qlevelofdetailswitch_p.h \ $$PWD/qrendertarget.h \ $$PWD/qrendertarget_p.h \ $$PWD/sphere_p.h \ |