summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2017-08-18 11:46:05 +0200
committerSean Harmer <sean.harmer@kdab.com>2017-08-18 19:45:45 +0000
commit0ebfeccafe2ae87dbc10da25a34afdccc7e55124 (patch)
treeb23e1eaf86a92dc48847ebeec223cb9d58d7cd9d
parentecffd9a9351bb9a5e6099a17e09c92495c34ccc8 (diff)
Add ProximityFilter backend node
Change-Id: I2e3fa11cae9113106e4a8c77832e3a2a3c27a24a Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/framegraph/framegraph.pri6
-rw-r--r--src/render/framegraph/framegraphnode_p.h3
-rw-r--r--src/render/framegraph/proximityfilter.cpp82
-rw-r--r--src/render/framegraph/proximityfilter_p.h90
-rw-r--r--src/render/frontend/qrenderaspect.cpp3
-rw-r--r--tests/auto/render/proximityfilter/proximityfilter.pro12
-rw-r--r--tests/auto/render/proximityfilter/tst_proximityfilter.cpp133
-rw-r--r--tests/auto/render/render.pro3
8 files changed, 328 insertions, 4 deletions
diff --git a/src/render/framegraph/framegraph.pri b/src/render/framegraph/framegraph.pri
index 42b679efd..8a2569867 100644
--- a/src/render/framegraph/framegraph.pri
+++ b/src/render/framegraph/framegraph.pri
@@ -54,7 +54,8 @@ HEADERS += \
$$PWD/qmemorybarrier_p.h \
$$PWD/memorybarrier_p.h \
$$PWD/qproximityfilter.h \
- $$PWD/qproximityfilter_p.h
+ $$PWD/qproximityfilter_p.h \
+ $$PWD/proximityfilter_p.h
SOURCES += \
$$PWD/cameraselectornode.cpp \
@@ -93,4 +94,5 @@ SOURCES += \
$$PWD/qframegraphnodecreatedchange.cpp \
$$PWD/qmemorybarrier.cpp \
$$PWD/memorybarrier.cpp \
- $$PWD/qproximityfilter.cpp
+ $$PWD/qproximityfilter.cpp \
+ $$PWD/proximityfilter.cpp
diff --git a/src/render/framegraph/framegraphnode_p.h b/src/render/framegraph/framegraphnode_p.h
index 4e768e773..fb8671ab8 100644
--- a/src/render/framegraph/framegraphnode_p.h
+++ b/src/render/framegraph/framegraphnode_p.h
@@ -99,7 +99,8 @@ public:
Surface,
RenderCapture,
BufferCapture,
- MemoryBarrier
+ MemoryBarrier,
+ ProximityFilter
};
FrameGraphNodeType nodeType() const { return m_nodeType; }
diff --git a/src/render/framegraph/proximityfilter.cpp b/src/render/framegraph/proximityfilter.cpp
new file mode 100644
index 000000000..aed19828b
--- /dev/null
+++ b/src/render/framegraph/proximityfilter.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 "proximityfilter_p.h"
+#include <Qt3DRender/private/qproximityfilter_p.h>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+namespace Render {
+
+ProximityFilter::ProximityFilter()
+ : FrameGraphNode(FrameGraphNode::ProximityFilter)
+ , m_distanceThreshold(0.0f)
+{
+}
+
+void ProximityFilter::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+{
+ FrameGraphNode::initializeFromPeer(change);
+ const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QProximityFilterData>>(change);
+ const QProximityFilterData &data = typedChange->data;
+ m_entityId = data.entityId;
+ m_distanceThreshold = data.distanceThreshold;
+}
+
+void ProximityFilter::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+{
+ qCDebug(Render::Framegraph) << Q_FUNC_INFO;
+ if (e->type() == Qt3DCore::PropertyUpdated) {
+ Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
+ if (propertyChange->propertyName() == QByteArrayLiteral("entity"))
+ m_entityId = propertyChange->value().value<Qt3DCore::QNodeId>();
+ else if (propertyChange->propertyName() == QByteArrayLiteral("distanceThreshold"))
+ m_distanceThreshold = propertyChange->value().toFloat();
+ markDirty(AbstractRenderer::AllDirty);
+ }
+ FrameGraphNode::sceneChangeEvent(e);
+}
+
+} // namespace Render
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/framegraph/proximityfilter_p.h b/src/render/framegraph/proximityfilter_p.h
new file mode 100644
index 000000000..cfd6af805
--- /dev/null
+++ b/src/render/framegraph/proximityfilter_p.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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_RENDER_PROXIMITYFILTER_P_H
+#define QT3DRENDER_RENDER_PROXIMITYFILTER_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/framegraphnode_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+namespace Render {
+
+class Q_AUTOTEST_EXPORT ProximityFilter : public FrameGraphNode
+{
+public:
+ ProximityFilter();
+
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE;
+
+ float distanceThreshold() const { return m_distanceThreshold; }
+ Qt3DCore::QNodeId entityId() const { return m_entityId; }
+
+#if defined(QT_BUILD_INTERNAL)
+ // For unit testing
+ void setDistanceThreshold(float distanceThreshold) { m_distanceThreshold = distanceThreshold; }
+ void setEntityId(Qt3DCore::QNodeId entityId) { m_entityId = entityId; }
+#endif
+
+private:
+ void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
+
+ float m_distanceThreshold;
+ Qt3DCore::QNodeId m_entityId;
+};
+
+} // namespace Render
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_RENDER_PROXIMITYFILTER_P_H
diff --git a/src/render/frontend/qrenderaspect.cpp b/src/render/frontend/qrenderaspect.cpp
index 2ce6fc685..1f928f768 100644
--- a/src/render/frontend/qrenderaspect.cpp
+++ b/src/render/frontend/qrenderaspect.cpp
@@ -83,6 +83,7 @@
#include <Qt3DRender/qrendercapture.h>
#include <Qt3DRender/qbuffercapture.h>
#include <Qt3DRender/qmemorybarrier.h>
+#include <Qt3DRender/qproximityfilter.h>
#include <Qt3DRender/qshaderprogrambuilder.h>
#include <Qt3DCore/qarmature.h>
#include <Qt3DCore/qjoint.h>
@@ -143,6 +144,7 @@
#include <Qt3DRender/private/skeleton_p.h>
#include <Qt3DRender/private/joint_p.h>
#include <Qt3DRender/private/loadskeletonjob_p.h>
+#include <Qt3DRender/private/proximityfilter_p.h>
#include <private/qrenderpluginfactory_p.h>
#include <private/qrenderplugin_p.h>
@@ -280,6 +282,7 @@ void QRenderAspectPrivate::registerBackendTypes()
q->registerBackendType<QRenderCapture>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::RenderCapture, QRenderCapture> >::create(m_renderer));
q->registerBackendType<QBufferCapture>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::BufferCapture, QBufferCapture> >::create(m_renderer));
q->registerBackendType<QMemoryBarrier>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::MemoryBarrier, QMemoryBarrier> >::create(m_renderer));
+ q->registerBackendType<QProximityFilter>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::ProximityFilter, QProximityFilter> >::create(m_renderer));
// Picking
q->registerBackendType<QObjectPicker>(QSharedPointer<Render::NodeFunctor<Render::ObjectPicker, Render::ObjectPickerManager> >::create(m_renderer));
diff --git a/tests/auto/render/proximityfilter/proximityfilter.pro b/tests/auto/render/proximityfilter/proximityfilter.pro
new file mode 100644
index 000000000..74599e4f0
--- /dev/null
+++ b/tests/auto/render/proximityfilter/proximityfilter.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+
+TARGET = tst_proximityfilter
+
+QT += 3dcore 3dcore-private 3drender 3drender-private testlib
+
+CONFIG += testcase
+
+SOURCES += tst_proximityfilter.cpp
+
+include(../../core/common/common.pri)
+include(../commons/commons.pri)
diff --git a/tests/auto/render/proximityfilter/tst_proximityfilter.cpp b/tests/auto/render/proximityfilter/tst_proximityfilter.cpp
new file mode 100644
index 000000000..774e2dd1f
--- /dev/null
+++ b/tests/auto/render/proximityfilter/tst_proximityfilter.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Paul Lemire <paul.lemire350@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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 General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** 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-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QTest>
+#include <Qt3DRender/qproximityfilter.h>
+#include <Qt3DRender/private/qproximityfilter_p.h>
+#include <Qt3DRender/private/proximityfilter_p.h>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+#include "qbackendnodetester.h"
+#include "testrenderer.h"
+
+class tst_ProximityFilter : public Qt3DCore::QBackendNodeTester
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+
+ void checkInitialState()
+ {
+ // GIVEN
+ Qt3DRender::Render::ProximityFilter backendProximityFilter;
+
+ // THEN
+ QCOMPARE(backendProximityFilter.isEnabled(), false);
+ QVERIFY(backendProximityFilter.peerId().isNull());
+ QCOMPARE(backendProximityFilter.distanceThreshold(), 0.0f);
+ QCOMPARE(backendProximityFilter.entityId(), Qt3DCore::QNodeId());
+ }
+
+ void checkInitializeFromPeer()
+ {
+ // GIVEN
+ Qt3DRender::QProximityFilter proximityFilter;
+ Qt3DCore::QEntity entity;
+ proximityFilter.setDistanceThreshold(1340.0f);
+ proximityFilter.setEntity(&entity);
+
+ {
+ // WHEN
+ Qt3DRender::Render::ProximityFilter backendProximityFilter;
+ simulateInitialization(&proximityFilter, &backendProximityFilter);
+
+ // THEN
+ QCOMPARE(backendProximityFilter.isEnabled(), true);
+ QCOMPARE(backendProximityFilter.peerId(), proximityFilter.id());
+ QCOMPARE(backendProximityFilter.distanceThreshold(), 1340.f);
+ QCOMPARE(backendProximityFilter.entityId(), entity.id());
+ }
+ {
+ // WHEN
+ Qt3DRender::Render::ProximityFilter backendProximityFilter;
+ proximityFilter.setEnabled(false);
+ simulateInitialization(&proximityFilter, &backendProximityFilter);
+
+ // THEN
+ QCOMPARE(backendProximityFilter.peerId(), proximityFilter.id());
+ QCOMPARE(backendProximityFilter.isEnabled(), false);
+ }
+ }
+
+ void checkSceneChangeEvents()
+ {
+ // GIVEN
+ Qt3DRender::Render::ProximityFilter backendProximityFilter;
+ TestRenderer renderer;
+ backendProximityFilter.setRenderer(&renderer);
+
+ {
+ // WHEN
+ const bool newValue = false;
+ const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
+ change->setPropertyName("enabled");
+ change->setValue(newValue);
+ backendProximityFilter.sceneChangeEvent(change);
+
+ // THEN
+ QCOMPARE(backendProximityFilter.isEnabled(), newValue);
+ }
+ {
+ // WHEN
+ const float newValue = 383.0f;
+ const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
+ change->setPropertyName("distanceThreshold");
+ change->setValue(QVariant::fromValue(newValue));
+ backendProximityFilter.sceneChangeEvent(change);
+
+ // THEN
+ QCOMPARE(backendProximityFilter.distanceThreshold(), newValue);
+ }
+ {
+ // WHEN
+ const Qt3DCore::QNodeId newValue = Qt3DCore::QNodeId::createId();
+ const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId());
+ change->setPropertyName("entity");
+ change->setValue(QVariant::fromValue(newValue));
+ backendProximityFilter.sceneChangeEvent(change);
+
+ // THEN
+ QCOMPARE(backendProximityFilter.entityId(), newValue);
+ }
+ }
+
+};
+
+QTEST_MAIN(tst_ProximityFilter)
+
+#include "tst_proximityfilter.moc"
diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro
index 146c61c01..8e9a5441f 100644
--- a/tests/auto/render/render.pro
+++ b/tests/auto/render/render.pro
@@ -104,7 +104,8 @@ qtConfig(private_tests) {
armature \
skeleton \
joint \
- qproximityfilter
+ qproximityfilter \
+ proximityfilter
QT_FOR_CONFIG = 3dcore-private
qtConfig(qt3d-extras) {