summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-09-17 12:34:12 +0200
committerPaul Lemire <paul.lemire@kdab.com>2019-09-20 14:25:34 +0200
commitfa3eab91e157bab5b9662660eb31c75fa53141f6 (patch)
tree41c4ca40c2dbd37f78d4b17d9962d9c09e94f18a
parent74ac5ba62fedc3cd44a602e981f72ffc7276cf0f (diff)
Update QRenderStateSet to use direct sync
Change-Id: I33ea330b3b8a4f826ee5debb38306767c62cda07 Reviewed-by: Mike Krus <mike.krus@kdab.com>
-rw-r--r--src/render/framegraph/qrenderstateset.cpp12
-rw-r--r--src/render/framegraph/statesetnode.cpp40
-rw-r--r--src/render/framegraph/statesetnode_p.h4
-rw-r--r--src/render/frontend/qrenderaspect.cpp2
-rw-r--r--tests/auto/render/qrenderstateset/tst_qrenderstateset.cpp26
5 files changed, 25 insertions, 59 deletions
diff --git a/src/render/framegraph/qrenderstateset.cpp b/src/render/framegraph/qrenderstateset.cpp
index 6f70456ab..d558a939e 100644
--- a/src/render/framegraph/qrenderstateset.cpp
+++ b/src/render/framegraph/qrenderstateset.cpp
@@ -194,11 +194,7 @@ void QRenderStateSet::addRenderState(QRenderState *state)
if (!state->parent())
state->setParent(this);
- if (d->m_changeArbiter != nullptr) {
- const auto change = QPropertyNodeAddedChangePtr::create(id(), state);
- change->setPropertyName("renderState");
- d->notifyObservers(change);
- }
+ d->update();
}
}
@@ -210,11 +206,7 @@ void QRenderStateSet::removeRenderState(QRenderState *state)
Q_ASSERT(state);
Q_D(QRenderStateSet);
- if (d->m_changeArbiter != nullptr) {
- const auto change = QPropertyNodeRemovedChangePtr::create(id(), state);
- change->setPropertyName("renderState");
- d->notifyObservers(change);
- }
+ d->update();
d->m_renderStates.removeOne(state);
// Remove bookkeeping connection
d->unregisterDestructionHelper(state);
diff --git a/src/render/framegraph/statesetnode.cpp b/src/render/framegraph/statesetnode.cpp
index 96551684e..32ac5e569 100644
--- a/src/render/framegraph/statesetnode.cpp
+++ b/src/render/framegraph/statesetnode.cpp
@@ -68,40 +68,20 @@ QVector<QNodeId> StateSetNode::renderStates() const
return m_renderStates;
}
-void StateSetNode::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+void StateSetNode::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
{
- FrameGraphNode::initializeFromPeer(change);
- const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QRenderStateSetData>>(change);
- const auto &data = typedChange->data;
- for (const auto &stateId : qAsConst(data.renderStateIds))
- addRenderState(stateId);
-}
+ const QRenderStateSet *node = qobject_cast<const QRenderStateSet *>(frontEnd);
+ if (!node)
+ return;
-void StateSetNode::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
-{
- switch (e->type()) {
- case PropertyValueAdded: {
- const auto change = qSharedPointerCast<QPropertyNodeAddedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("renderState")) {
- addRenderState(change->addedNodeId());
- markDirty(AbstractRenderer::FrameGraphDirty);
- }
- break;
- }
-
- case PropertyValueRemoved: {
- const auto propertyChange = qSharedPointerCast<QPropertyNodeRemovedChange>(e);
- if (propertyChange->propertyName() == QByteArrayLiteral("renderState")) {
- removeRenderState(propertyChange->removedNodeId());
- markDirty(AbstractRenderer::FrameGraphDirty);
- }
- break;
- }
+ FrameGraphNode::syncFromFrontEnd(frontEnd, firstTime);
- default:
- break;
+ auto stateIds = qIdsForNodes(node->renderStates());
+ std::sort(std::begin(stateIds), std::end(stateIds));
+ if (m_renderStates != stateIds) {
+ m_renderStates = stateIds;
+ markDirty(AbstractRenderer::FrameGraphDirty);
}
- FrameGraphNode::sceneChangeEvent(e);
}
void StateSetNode::addRenderState(QNodeId renderStateId)
diff --git a/src/render/framegraph/statesetnode_p.h b/src/render/framegraph/statesetnode_p.h
index d33e118cb..5081f3215 100644
--- a/src/render/framegraph/statesetnode_p.h
+++ b/src/render/framegraph/statesetnode_p.h
@@ -68,13 +68,13 @@ public:
inline bool hasRenderStates() const { return !m_renderStates.empty(); }
QVector<Qt3DCore::QNodeId> renderStates() const;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
+
protected:
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
void addRenderState(Qt3DCore::QNodeId renderStateId);
void removeRenderState(Qt3DCore::QNodeId renderStateId);
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
QVector<Qt3DCore::QNodeId> m_renderStates;
};
diff --git a/src/render/frontend/qrenderaspect.cpp b/src/render/frontend/qrenderaspect.cpp
index ef0593835..93aa5843e 100644
--- a/src/render/frontend/qrenderaspect.cpp
+++ b/src/render/frontend/qrenderaspect.cpp
@@ -303,7 +303,7 @@ void QRenderAspectPrivate::registerBackendTypes()
q->registerBackendType<QLayerFilter, true>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::LayerFilterNode, QLayerFilter> >::create(m_renderer));
q->registerBackendType<QNoDraw, true>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::NoDraw, QNoDraw> >::create(m_renderer));
q->registerBackendType<QRenderPassFilter, true>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::RenderPassFilter, QRenderPassFilter> >::create(m_renderer));
- q->registerBackendType<QRenderStateSet>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::StateSetNode, QRenderStateSet> >::create(m_renderer));
+ q->registerBackendType<QRenderStateSet, true>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::StateSetNode, QRenderStateSet> >::create(m_renderer));
q->registerBackendType<QRenderSurfaceSelector>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::RenderSurfaceSelector, QRenderSurfaceSelector> >::create(m_renderer));
q->registerBackendType<QRenderTargetSelector>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::RenderTargetSelector, QRenderTargetSelector> >::create(m_renderer));
q->registerBackendType<QSortPolicy>(QSharedPointer<Render::FrameGraphNodeFunctor<Render::SortPolicy, QSortPolicy> >::create(m_renderer));
diff --git a/tests/auto/render/qrenderstateset/tst_qrenderstateset.cpp b/tests/auto/render/qrenderstateset/tst_qrenderstateset.cpp
index 6b200d19d..9eb97ce93 100644
--- a/tests/auto/render/qrenderstateset/tst_qrenderstateset.cpp
+++ b/tests/auto/render/qrenderstateset/tst_qrenderstateset.cpp
@@ -140,14 +140,11 @@ private Q_SLOTS:
QCoreApplication::processEvents();
// THEN
- QCOMPARE(arbiter.events.size(), 1);
- Qt3DCore::QPropertyNodeAddedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyNodeAddedChange>();
- QCOMPARE(change->propertyName(), "renderState");
- QCOMPARE(change->subjectId(), stateSet->id());
- QCOMPARE(change->addedNodeId(), state1->id());
- QCOMPARE(change->type(), Qt3DCore::PropertyValueAdded);
+ QCOMPARE(arbiter.events.size(), 0);
+ QCOMPARE(arbiter.dirtyNodes.size(), 1);
+ QVERIFY(arbiter.dirtyNodes.contains(stateSet.data()));
- arbiter.events.clear();
+ arbiter.dirtyNodes.clear();
// WHEN
stateSet->addRenderState(state1);
@@ -155,20 +152,17 @@ private Q_SLOTS:
// THEN
QCOMPARE(arbiter.events.size(), 0);
-
+ QCOMPARE(arbiter.dirtyNodes.size(), 0);
// WHEN
stateSet->removeRenderState(state1);
QCoreApplication::processEvents();
// THEN
- QCOMPARE(arbiter.events.size(), 1);
- Qt3DCore::QPropertyNodeRemovedChangePtr nodeRemovedChange = arbiter.events.first().staticCast<Qt3DCore::QPropertyNodeRemovedChange>();
- QCOMPARE(nodeRemovedChange->propertyName(), "renderState");
- QCOMPARE(nodeRemovedChange->subjectId(), stateSet->id());
- QCOMPARE(nodeRemovedChange->removedNodeId(), state1->id());
- QCOMPARE(nodeRemovedChange->type(), Qt3DCore::PropertyValueRemoved);
-
- arbiter.events.clear();
+ QCOMPARE(arbiter.events.size(), 0);
+ QCOMPARE(arbiter.dirtyNodes.size(), 1);
+ QVERIFY(arbiter.dirtyNodes.contains(stateSet.data()));
+
+ arbiter.dirtyNodes.clear();
}
void checkRenderStateBookkeeping()