summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-09-18 10:57:54 +0200
committerPaul Lemire <paul.lemire@kdab.com>2019-09-24 11:57:47 +0200
commita1e5040d578e55f9fccdfc1347d417508a91bd58 (patch)
treec328381d2595b75207af2d1dcc39807d0a8f2167
parent5815bb74788f9c0f355754d6a56cfa527684ea98 (diff)
Update QCameraLens to use direct sync
Change-Id: I5b1af685c640c218d3720d5339b14dfc913e01c5 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/core/nodes/qnode.cpp3
-rw-r--r--src/render/backend/cameralens.cpp88
-rw-r--r--src/render/backend/cameralens_p.h6
-rw-r--r--src/render/frontend/qcameralens.cpp15
-rw-r--r--src/render/frontend/qcameralens_p.h21
-rw-r--r--src/render/frontend/qrenderaspect.cpp2
6 files changed, 77 insertions, 58 deletions
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp
index 5c37e337e..2cea47372 100644
--- a/src/core/nodes/qnode.cpp
+++ b/src/core/nodes/qnode.cpp
@@ -687,6 +687,9 @@ QNodePrivate *QNodePrivate::get(QNode *q)
return q->d_func();
}
+/*!
+ \internal
+ */
const QNodePrivate *QNodePrivate::get(const QNode *q)
{
return q->d_func();
diff --git a/src/render/backend/cameralens.cpp b/src/render/backend/cameralens.cpp
index f4815a4a9..7a5c1f7e6 100644
--- a/src/render/backend/cameralens.cpp
+++ b/src/render/backend/cameralens.cpp
@@ -41,7 +41,6 @@
#include <Qt3DRender/qcameralens.h>
#include <Qt3DRender/private/nodemanagers_p.h>
#include <Qt3DRender/private/managers_p.h>
-#include <Qt3DRender/private/qcameralens_p.h>
#include <Qt3DRender/private/renderlogging_p.h>
#include <Qt3DRender/private/renderer_p.h>
#include <Qt3DRender/private/entity_p.h>
@@ -119,12 +118,43 @@ Matrix4x4 CameraLens::viewMatrix(const Matrix4x4 &worldTransform)
return Matrix4x4(m);
}
-void CameraLens::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+void CameraLens::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QCameraLensData>>(change);
- const auto &data = typedChange->data;
- m_projection = Matrix4x4(data.projectionMatrix);
- m_exposure = data.exposure;
+ const QCameraLens *node = qobject_cast<const QCameraLens *>(frontEnd);
+ if (!node)
+ return;
+
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+
+ const Matrix4x4 projectionMatrix(node->projectionMatrix());
+ if (projectionMatrix != m_projection) {
+ m_projection = projectionMatrix;
+ markDirty(AbstractRenderer::AllDirty);
+ }
+
+ if (node->exposure() != m_exposure) {
+ m_exposure = node->exposure();
+ markDirty(AbstractRenderer::AllDirty);
+ }
+
+ const QCameraLensPrivate *d = static_cast<const QCameraLensPrivate *>(QNodePrivate::get(node));
+ if (d->m_pendingViewAllCommand != m_pendingViewAllCommand) {
+ m_pendingViewAllCommand = d->m_pendingViewAllCommand;
+
+ if (m_pendingViewAllCommand) {
+ const QVariant v = m_pendingViewAllCommand.data;
+ const QNodeCommand::CommandId commandId = m_pendingViewAllCommand.commandId;
+
+ if (m_pendingViewAllCommand.name == QLatin1String("QueryRootBoundingVolume")) {
+ const QNodeId id = v.value<QNodeId>();
+ computeSceneBoundingVolume({}, id, commandId);
+ } else if (m_pendingViewAllCommand.name == QLatin1String("QueryEntityBoundingVolume")) {
+ const QVector<QNodeId> ids = v.value<QVector<QNodeId>>();
+ if (ids.size() == 2)
+ computeSceneBoundingVolume(ids[0], ids[1], commandId);
+ }
+ }
+ }
}
void CameraLens::computeSceneBoundingVolume(QNodeId entityId,
@@ -152,15 +182,16 @@ void CameraLens::computeSceneBoundingVolume(QNodeId entityId,
void CameraLens::notifySceneBoundingVolume(const Sphere &sphere, QNodeCommand::CommandId commandId)
{
- if (m_pendingViewAllCommand != commandId)
+ if (!m_pendingViewAllCommand || m_pendingViewAllCommand.commandId != commandId)
return;
if (sphere.radius() > 0.f) {
QVector<float> data = { sphere.center().x(), sphere.center().y(), sphere.center().z(),
sphere.radius() };
QVariant v;
v.setValue(data);
- sendCommand(QLatin1String("ViewAll"), v, m_pendingViewAllCommand);
+ sendCommand(QLatin1String("ViewAll"), v, m_pendingViewAllCommand.commandId);
}
+ m_pendingViewAllCommand = {};
}
void CameraLens::setProjection(const Matrix4x4 &projection)
@@ -173,47 +204,6 @@ void CameraLens::setExposure(float exposure)
m_exposure = exposure;
}
-void CameraLens::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
-{
- switch (e->type()) {
- case PropertyUpdated: {
- QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<QPropertyUpdatedChange>(e);
-
- if (propertyChange->propertyName() == QByteArrayLiteral("projectionMatrix")) {
- QMatrix4x4 projectionMatrix = propertyChange->value().value<QMatrix4x4>();
- m_projection = Matrix4x4(projectionMatrix);
- } else if (propertyChange->propertyName() == QByteArrayLiteral("exposure")) {
- setExposure(propertyChange->value().toFloat());
- }
-
- markDirty(AbstractRenderer::AllDirty);
- }
- break;
-
- case CommandRequested: {
- QNodeCommandPtr command = qSharedPointerCast<QNodeCommand>(e);
-
- if (command->name() == QLatin1String("QueryRootBoundingVolume")) {
- m_pendingViewAllCommand = command->commandId();
- QVariant v = command->data();
- QNodeId id = v.value<QNodeId>();
- computeSceneBoundingVolume({}, id, command->commandId());
- } else if (command->name() == QLatin1String("QueryEntityBoundingVolume")) {
- m_pendingViewAllCommand = command->commandId();
- QVariant v = command->data();
- QVector<QNodeId> ids = v.value<QVector<QNodeId>>();
- if (ids.size() == 2)
- computeSceneBoundingVolume(ids[0], ids[1], command->commandId());
- }
- }
- break;
-
- default:
- break;
- }
- BackendNode::sceneChangeEvent(e);
-}
-
bool CameraLens::viewMatrixForCamera(EntityManager* manager, Qt3DCore::QNodeId cameraId,
Matrix4x4 &viewMatrix, Matrix4x4 &projectionMatrix)
{
diff --git a/src/render/backend/cameralens_p.h b/src/render/backend/cameralens_p.h
index 80a1715cf..bd721d5e9 100644
--- a/src/render/backend/cameralens_p.h
+++ b/src/render/backend/cameralens_p.h
@@ -54,6 +54,7 @@
#include <Qt3DRender/private/backendnode_p.h>
#include <Qt3DCore/private/qnodecommand_p.h>
#include <Qt3DCore/private/matrix4x4_p.h>
+#include <Qt3DRender/private/qcameralens_p.h>
#include <QRectF>
QT_BEGIN_NAMESPACE
@@ -96,21 +97,20 @@ public:
void setExposure(float exposure);
inline float exposure() const { return m_exposure; }
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
void notifySceneBoundingVolume(const Sphere &sphere, Qt3DCore::QNodeCommand::CommandId commandId);
static bool viewMatrixForCamera(EntityManager *manager, Qt3DCore::QNodeId cameraId,
Matrix4x4 &viewMatrix, Matrix4x4 &projectionMatrix);
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
void computeSceneBoundingVolume(Qt3DCore::QNodeId entityId,
Qt3DCore::QNodeId cameraId,
Qt3DCore::QNodeCommand::CommandId commandId);
QRenderAspect *m_renderAspect;
- Qt3DCore::QNodeCommand::CommandId m_pendingViewAllCommand;
+ CameraLensCommand m_pendingViewAllCommand;
Matrix4x4 m_projection;
float m_exposure;
};
diff --git a/src/render/frontend/qcameralens.cpp b/src/render/frontend/qcameralens.cpp
index 296421031..cf30b714a 100644
--- a/src/render/frontend/qcameralens.cpp
+++ b/src/render/frontend/qcameralens.cpp
@@ -228,13 +228,17 @@ QCameraLensPrivate::QCameraLensPrivate()
{
}
+
void QCameraLens::viewAll(Qt3DCore::QNodeId cameraId)
{
Q_D(QCameraLens);
if (d->m_projectionType == PerspectiveProjection) {
QVariant v;
v.setValue(cameraId);
- d->m_pendingViewAllCommand = sendCommand(QLatin1String("QueryRootBoundingVolume"), v);
+ d->m_pendingViewAllCommand = {QLatin1String("QueryRootBoundingVolume"),
+ v,
+ id()};
+ d->update();
}
}
@@ -245,7 +249,10 @@ void QCameraLens::viewEntity(Qt3DCore::QNodeId entityId, Qt3DCore::QNodeId camer
QVector<Qt3DCore::QNodeId> ids = {entityId, cameraId};
QVariant v;
v.setValue(ids);
- d->m_pendingViewAllCommand = sendCommand(QLatin1String("QueryEntityBoundingVolume"), v);
+ d->m_pendingViewAllCommand = {QLatin1String("QueryEntityBoundingVolume"),
+ v,
+ id()};
+ d->update();
}
}
@@ -253,7 +260,7 @@ void QCameraLensPrivate::processViewAllCommand(Qt3DCore::QNodeCommand::CommandId
const QVariant &data)
{
Q_Q(QCameraLens);
- if (m_pendingViewAllCommand != commandId)
+ if (!m_pendingViewAllCommand || m_pendingViewAllCommand.commandId != commandId)
return;
QVector<float> boundingVolumeData = data.value< QVector<float> >();
@@ -262,7 +269,7 @@ void QCameraLensPrivate::processViewAllCommand(Qt3DCore::QNodeCommand::CommandId
QVector3D center(boundingVolumeData[0], boundingVolumeData[1], boundingVolumeData[2]);
float radius = boundingVolumeData[3];
Q_EMIT q->viewSphere(center, radius);
- m_pendingViewAllCommand = Qt3DCore::QNodeCommand::CommandId();
+ m_pendingViewAllCommand = {};
}
/*!
diff --git a/src/render/frontend/qcameralens_p.h b/src/render/frontend/qcameralens_p.h
index 111ab6522..01fcac0e5 100644
--- a/src/render/frontend/qcameralens_p.h
+++ b/src/render/frontend/qcameralens_p.h
@@ -65,6 +65,25 @@ QT_BEGIN_NAMESPACE
namespace Qt3DRender {
+struct CameraLensCommand
+{
+ QString name;
+ QVariant data;
+ Qt3DCore::QNodeCommand::CommandId commandId;
+
+ inline operator bool() const { return !name.isEmpty(); }
+};
+
+inline bool operator ==(const CameraLensCommand &a, const CameraLensCommand &b) noexcept
+{
+ return a.name == b.name && a.data == b.data && a.commandId == b.commandId;
+}
+
+inline bool operator !=(const CameraLensCommand &a, const CameraLensCommand &b) noexcept
+{
+ return !(a == b);
+}
+
class Q_3DRENDERSHARED_PRIVATE_EXPORT QCameraLensPrivate : public Qt3DCore::QComponentPrivate
{
public:
@@ -106,7 +125,7 @@ public:
float m_exposure;
- Qt3DCore::QNodeCommand::CommandId m_pendingViewAllCommand;
+ CameraLensCommand m_pendingViewAllCommand;
void processViewAllCommand(Qt3DCore::QNodeCommand::CommandId commandId, const QVariant &data);
private:
diff --git a/src/render/frontend/qrenderaspect.cpp b/src/render/frontend/qrenderaspect.cpp
index 67bcb6c02..08a85368f 100644
--- a/src/render/frontend/qrenderaspect.cpp
+++ b/src/render/frontend/qrenderaspect.cpp
@@ -255,7 +255,7 @@ void QRenderAspectPrivate::registerBackendTypes()
q->registerBackendType<Qt3DCore::QEntity, true>(QSharedPointer<Render::RenderEntityFunctor>::create(m_renderer, m_nodeManagers));
q->registerBackendType<Qt3DCore::QTransform, true>(QSharedPointer<Render::NodeFunctor<Render::Transform, Render::TransformManager> >::create(m_renderer));
- q->registerBackendType<Qt3DRender::QCameraLens>(QSharedPointer<Render::CameraLensFunctor>::create(m_renderer, q));
+ q->registerBackendType<Qt3DRender::QCameraLens, true>(QSharedPointer<Render::CameraLensFunctor>::create(m_renderer, q));
q->registerBackendType<QLayer>(QSharedPointer<Render::NodeFunctor<Render::Layer, Render::LayerManager> >::create(m_renderer));
q->registerBackendType<QLevelOfDetail>(QSharedPointer<Render::NodeFunctor<Render::LevelOfDetail, Render::LevelOfDetailManager> >::create(m_renderer));
q->registerBackendType<QLevelOfDetailSwitch>(QSharedPointer<Render::NodeFunctor<Render::LevelOfDetail, Render::LevelOfDetailManager> >::create(m_renderer));