diff options
-rw-r--r-- | src/core/aspects/qaspectmanager.cpp | 9 | ||||
-rw-r--r-- | src/core/aspects/qaspectmanager_p.h | 2 | ||||
-rw-r--r-- | src/core/geometry/qattribute.cpp | 13 | ||||
-rw-r--r-- | src/core/geometry/qattribute_p.h | 4 | ||||
-rw-r--r-- | src/core/geometry/qbuffer.cpp | 16 | ||||
-rw-r--r-- | src/core/geometry/qbuffer_p.h | 4 | ||||
-rw-r--r-- | src/core/geometry/qgeometry.cpp | 25 | ||||
-rw-r--r-- | src/core/geometry/qgeometry_p.h | 4 | ||||
-rw-r--r-- | src/core/geometry/qgeometryview.cpp | 8 | ||||
-rw-r--r-- | src/core/geometry/qgeometryview_p.h | 3 | ||||
-rw-r--r-- | src/core/nodes/qentity.cpp | 10 | ||||
-rw-r--r-- | src/core/nodes/qentity_p.h | 2 | ||||
-rw-r--r-- | src/core/nodes/qnode.cpp | 6 | ||||
-rw-r--r-- | src/core/nodes/qnode_p.h | 4 | ||||
-rw-r--r-- | src/core/qscene.cpp | 19 | ||||
-rw-r--r-- | src/core/qscene_p.h | 14 | ||||
-rw-r--r-- | src/core/transforms/qtransform.cpp | 8 | ||||
-rw-r--r-- | src/core/transforms/qtransform_p.h | 3 | ||||
-rw-r--r-- | src/extras/text/qtext2dentity.cpp | 12 | ||||
-rw-r--r-- | src/extras/text/qtext2dentity_p.h | 2 |
20 files changed, 160 insertions, 8 deletions
diff --git a/src/core/aspects/qaspectmanager.cpp b/src/core/aspects/qaspectmanager.cpp index a327ddaf8..266beb8ff 100644 --- a/src/core/aspects/qaspectmanager.cpp +++ b/src/core/aspects/qaspectmanager.cpp @@ -440,6 +440,15 @@ QVector<QNode *> QAspectManager::lookupNodes(const QVector<QNodeId> &ids) const return d->m_scene ? d->m_scene->lookupNodes(ids) : QVector<QNode *>{}; } +QScene *QAspectManager::scene() const +{ + if (!m_root) + return nullptr; + + QNodePrivate *d = QNodePrivate::get(m_root); + return d->m_scene; +} + void QAspectManager::dumpJobsOnNextFrame() { m_dumpJobs = true; diff --git a/src/core/aspects/qaspectmanager_p.h b/src/core/aspects/qaspectmanager_p.h index 9633149f6..b9982ab96 100644 --- a/src/core/aspects/qaspectmanager_p.h +++ b/src/core/aspects/qaspectmanager_p.h @@ -75,6 +75,7 @@ class QAbstractAspect; class QAbstractAspectJobManager; class QAspectEngine; class QServiceLocator; +class QScene; class NodePostConstructorInit; struct NodeTreeChange; #if QT_CONFIG(animation) @@ -118,6 +119,7 @@ public: QNode *lookupNode(QNodeId id) const; QVector<QNode *> lookupNodes(const QVector<QNodeId> &ids) const; + QScene *scene() const; int jobsInLastFrame() const { return m_jobsInLastFrame; } void dumpJobsOnNextFrame(); diff --git a/src/core/geometry/qattribute.cpp b/src/core/geometry/qattribute.cpp index 6be9c0203..d3a564b66 100644 --- a/src/core/geometry/qattribute.cpp +++ b/src/core/geometry/qattribute.cpp @@ -56,9 +56,22 @@ QAttributePrivate::QAttributePrivate() , m_byteOffset(0) , m_divisor(0) , m_attributeType(QAttribute::VertexAttribute) + , m_dirty(false) { } +void QAttributePrivate::update() +{ + if (!m_blockNotifications) + m_dirty = true; + QNodePrivate::update(); +} + +QAttributePrivate *QAttributePrivate::get(QAttribute *q) +{ + return q->d_func(); +} + /*! * \qmltype Attribute * \instantiates Qt3DCore::QAttribute diff --git a/src/core/geometry/qattribute_p.h b/src/core/geometry/qattribute_p.h index 755a62207..228988c96 100644 --- a/src/core/geometry/qattribute_p.h +++ b/src/core/geometry/qattribute_p.h @@ -68,6 +68,9 @@ public: Q_DECLARE_PUBLIC(QAttribute) QAttributePrivate(); + void update() override; + + static QAttributePrivate *get(QAttribute *q); QBuffer *m_buffer; QString m_name; @@ -78,6 +81,7 @@ public: uint m_byteOffset; uint m_divisor; QAttribute::AttributeType m_attributeType; + bool m_dirty; }; } // Qt3DCore diff --git a/src/core/geometry/qbuffer.cpp b/src/core/geometry/qbuffer.cpp index a6a13f52e..9ef380b76 100644 --- a/src/core/geometry/qbuffer.cpp +++ b/src/core/geometry/qbuffer.cpp @@ -51,11 +51,27 @@ QBufferPrivate::QBufferPrivate() : QNodePrivate() , m_usage(QBuffer::StaticDraw) , m_access(QBuffer::Write) + , m_dirty(false) { } +QBufferPrivate *QBufferPrivate::get(QBuffer *q) +{ + return q->d_func(); +} + +void QBufferPrivate::update() +{ + if (!m_blockNotifications) { + m_dirty = true; + markDirty(QScene::BuffersDirty); + } + QNodePrivate::update(); +} + void QBufferPrivate::setData(const QByteArray &data) { + // this is called when date is loaded from backend, should not set dirty flag Q_Q(QBuffer); const bool blocked = q->blockNotifications(true); m_data = data; diff --git a/src/core/geometry/qbuffer_p.h b/src/core/geometry/qbuffer_p.h index 8baffc13e..6d57d7c04 100644 --- a/src/core/geometry/qbuffer_p.h +++ b/src/core/geometry/qbuffer_p.h @@ -68,10 +68,14 @@ public: QBufferPrivate(); + static QBufferPrivate *get(QBuffer *q); + QByteArray m_data; QBuffer::UsageType m_usage; QBuffer::AccessType m_access; + bool m_dirty; + void update() override; void setData(const QByteArray &data); }; diff --git a/src/core/geometry/qgeometry.cpp b/src/core/geometry/qgeometry.cpp index 008ad4b3d..16e204bbc 100644 --- a/src/core/geometry/qgeometry.cpp +++ b/src/core/geometry/qgeometry.cpp @@ -61,17 +61,42 @@ QGeometryPrivate::~QGeometryPrivate() { } +QGeometryPrivate *QGeometryPrivate::get(QGeometry *q) +{ + return q->d_func(); +} + +void QGeometryPrivate::setScene(QScene *scene) +{ + QNodePrivate::setScene(scene); + if (scene) + scene->markDirty(QScene::GeometryDirty); +} + +void QGeometryPrivate::update() +{ + if (!m_blockNotifications) { + m_dirty = true; + markDirty(QScene::GeometryDirty); + } + QNodePrivate::update(); +} + void QGeometryPrivate::setExtent(const QVector3D &minExtent, const QVector3D &maxExtent) { Q_Q(QGeometry); if (m_minExtent != minExtent) { m_minExtent = minExtent; + const auto wasBlocked = q->blockNotifications(true); emit q->minExtentChanged(minExtent); + q->blockNotifications(wasBlocked); } if (m_maxExtent != maxExtent) { m_maxExtent = maxExtent; + const auto wasBlocked = q->blockNotifications(true); emit q->maxExtentChanged(maxExtent); + q->blockNotifications(wasBlocked); } } diff --git a/src/core/geometry/qgeometry_p.h b/src/core/geometry/qgeometry_p.h index 467131fbe..2a05b5b6f 100644 --- a/src/core/geometry/qgeometry_p.h +++ b/src/core/geometry/qgeometry_p.h @@ -69,13 +69,17 @@ public: QGeometryPrivate(); ~QGeometryPrivate(); + void setScene(QScene *scene) override; + void update() override; void setExtent(const QVector3D &minExtent, const QVector3D &maxExtent); + static QGeometryPrivate *get(QGeometry *q); QVector<QAttribute *> m_attributes; QAttribute *m_boundingVolumePositionAttribute; QVector3D m_minExtent; QVector3D m_maxExtent; + bool m_dirty; }; } // namespace Qt3DCore diff --git a/src/core/geometry/qgeometryview.cpp b/src/core/geometry/qgeometryview.cpp index 991bca0de..65e30d982 100644 --- a/src/core/geometry/qgeometryview.cpp +++ b/src/core/geometry/qgeometryview.cpp @@ -57,6 +57,7 @@ QGeometryViewPrivate::QGeometryViewPrivate() , m_primitiveRestart(false) , m_geometry(nullptr) , m_primitiveType(QGeometryView::Triangles) + , m_dirty(false) { } @@ -64,6 +65,13 @@ QGeometryViewPrivate::~QGeometryViewPrivate() { } +void QGeometryViewPrivate::update() +{ + if (!m_blockNotifications) + m_dirty = true; + QNodePrivate::update(); +} + /*! \qmltype GeometryView \instantiates Qt3DCore::QGeometryView diff --git a/src/core/geometry/qgeometryview_p.h b/src/core/geometry/qgeometryview_p.h index ff8ff4880..f806c4d69 100644 --- a/src/core/geometry/qgeometryview_p.h +++ b/src/core/geometry/qgeometryview_p.h @@ -67,6 +67,8 @@ public: QGeometryViewPrivate(); ~QGeometryViewPrivate(); + void update() override; + Q_DECLARE_PUBLIC(QGeometryView) int m_instanceCount; @@ -80,6 +82,7 @@ public: bool m_primitiveRestart; QGeometry *m_geometry; QGeometryView::PrimitiveType m_primitiveType; + bool m_dirty; }; } // namespace Qt3DCore diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp index ac07faaef..0a504b4eb 100644 --- a/src/core/nodes/qentity.cpp +++ b/src/core/nodes/qentity.cpp @@ -128,6 +128,7 @@ namespace Qt3DCore { QEntityPrivate::QEntityPrivate() : QNodePrivate() , m_parentEntityId() + , m_dirty(false) {} /*! \internal */ @@ -136,6 +137,12 @@ QEntityPrivate::~QEntityPrivate() } /*! \internal */ +QEntityPrivate *QEntityPrivate::get(QEntity *q) +{ + return q->d_func(); +} + +/*! \internal */ void QEntityPrivate::removeDestroyedComponent(QComponent *comp) { // comp is actually no longer a QComponent, just a QObject @@ -145,6 +152,7 @@ void QEntityPrivate::removeDestroyedComponent(QComponent *comp) updateComponentRelationShip(comp, ComponentRelationshipChange::Removed); m_components.removeOne(comp); + m_dirty = true; // Remove bookkeeping connection unregisterDestructionHelper(comp); @@ -218,6 +226,7 @@ void QEntity::addComponent(QComponent *comp) QNodePrivate::get(comp)->_q_ensureBackendNodeCreated(); d->m_components.append(comp); + d->m_dirty = true; // Ensures proper bookkeeping d->registerPrivateDestructionHelper(comp, &QEntityPrivate::removeDestroyedComponent); @@ -240,6 +249,7 @@ void QEntity::removeComponent(QComponent *comp) d->updateComponentRelationShip(comp, ComponentRelationshipChange::Removed); d->m_components.removeOne(comp); + d->m_dirty = true; // Remove bookkeeping connection d->unregisterDestructionHelper(comp); diff --git a/src/core/nodes/qentity_p.h b/src/core/nodes/qentity_p.h index d074148c1..57d67bbc4 100644 --- a/src/core/nodes/qentity_p.h +++ b/src/core/nodes/qentity_p.h @@ -68,6 +68,7 @@ public : ~QEntityPrivate(); Q_DECLARE_PUBLIC(QEntity) + static QEntityPrivate *get(QEntity *q); QNodeId parentEntityId() const; void updateComponentRelationShip(QComponent *component, ComponentRelationshipChange::RelationShip change); @@ -89,6 +90,7 @@ public : QComponentVector m_components; mutable QNodeId m_parentEntityId; + bool m_dirty; }; struct QEntityData diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp index 918ce0827..9b643299c 100644 --- a/src/core/nodes/qnode.cpp +++ b/src/core/nodes/qnode.cpp @@ -595,6 +595,12 @@ void QNodePrivate::update() } } +void QNodePrivate::markDirty(QScene::DirtyNodeSet changes) +{ + if (m_scene) + m_scene->markDirty(changes); +} + /*! \internal */ diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h index 907f0062a..269b815e3 100644 --- a/src/core/nodes/qnode_p.h +++ b/src/core/nodes/qnode_p.h @@ -57,6 +57,7 @@ #include <Qt3DCore/private/propertychangehandler_p.h> #include <Qt3DCore/private/qchangearbiter_p.h> +#include <Qt3DCore/private/qscene_p.h> #include <Qt3DCore/private/qt3dcore_global_p.h> #include <QtCore/private/qobject_p.h> #include <QQueue> @@ -87,7 +88,8 @@ public: void insertTree(QNode *treeRoot, int depth = 0); void updatePropertyTrackMode(); - void update(); + virtual void update(); + void markDirty(QScene::DirtyNodeSet changes); Q_DECLARE_PUBLIC(QNode) diff --git a/src/core/qscene.cpp b/src/core/qscene.cpp index 17f89603f..d2a341c15 100644 --- a/src/core/qscene.cpp +++ b/src/core/qscene.cpp @@ -69,6 +69,7 @@ public: mutable QReadWriteLock m_lock; mutable QReadWriteLock m_nodePropertyTrackModeLock; QNode *m_rootNode; + QScene::DirtyNodeSet m_dirtyBits; }; @@ -208,6 +209,24 @@ NodePostConstructorInit *QScene::postConstructorInit() const return d->m_postConstructorInit.get(); } +QScene::DirtyNodeSet QScene::dirtyBits() +{ + Q_D(QScene); + return d->m_dirtyBits; +} + +void QScene::clearDirtyBits() +{ + Q_D(QScene); + d->m_dirtyBits = {}; +} + +void QScene::markDirty(QScene::DirtyNodeSet changes) +{ + Q_D(QScene); + d->m_dirtyBits |= changes; +} + void QScene::setRootNode(QNode *root) { Q_D(QScene); diff --git a/src/core/qscene_p.h b/src/core/qscene_p.h index b2341b159..7b3037180 100644 --- a/src/core/qscene_p.h +++ b/src/core/qscene_p.h @@ -69,6 +69,16 @@ class QChangeArbiter; class Q_3DCORE_PRIVATE_EXPORT QScene { public: + // Changes made to backend nodes are reported to the Renderer + enum DirtyNodeFlag { + TransformDirty = 1 << 0, + GeometryDirty = 1 << 1, + EntityEnabledDirty = 1 << 2, + BuffersDirty = 1 << 3, + AllDirty = 0xffffff + }; + Q_DECLARE_FLAGS(DirtyNodeSet, DirtyNodeFlag) + QScene(QAspectEngine *engine = nullptr); ~QScene(); @@ -103,6 +113,10 @@ public: NodePostConstructorInit* postConstructorInit() const; + void markDirty(DirtyNodeSet changes); + DirtyNodeSet dirtyBits(); + void clearDirtyBits(); + private: Q_DECLARE_PRIVATE(QScene) QScopedPointer<QScenePrivate> d_ptr; diff --git a/src/core/transforms/qtransform.cpp b/src/core/transforms/qtransform.cpp index edbca7280..dedb27b26 100644 --- a/src/core/transforms/qtransform.cpp +++ b/src/core/transforms/qtransform.cpp @@ -243,6 +243,14 @@ void QTransformPrivate::setWorldMatrix(const QMatrix4x4 &worldMatrix) q->blockNotifications(blocked); } +void QTransformPrivate::update() +{ + if (!m_blockNotifications) + m_dirty = true; + markDirty(QScene::TransformDirty); + QNodePrivate::update(); +} + void QTransform::setMatrix(const QMatrix4x4 &m) { Q_D(QTransform); diff --git a/src/core/transforms/qtransform_p.h b/src/core/transforms/qtransform_p.h index 56053309e..81c8489a7 100644 --- a/src/core/transforms/qtransform_p.h +++ b/src/core/transforms/qtransform_p.h @@ -78,7 +78,10 @@ public: QMatrix4x4 m_worldMatrix; + bool m_dirty; + void setWorldMatrix(const QMatrix4x4 &worldMatrix); + void update() override; }; struct QTransformData diff --git a/src/extras/text/qtext2dentity.cpp b/src/extras/text/qtext2dentity.cpp index a159ffab5..ecd8be440 100644 --- a/src/extras/text/qtext2dentity.cpp +++ b/src/extras/text/qtext2dentity.cpp @@ -186,7 +186,7 @@ void QText2DEntityPrivate::setScene(Qt3DCore::QScene *scene) m_glyphCache = entry.glyphCache; ++entry.count; // Update to populate glyphCache if needed - update(); + updateGlyphs(); } } @@ -325,7 +325,7 @@ void QText2DEntityPrivate::clearCurrentGlyphRuns() m_currentGlyphRuns.clear(); } -void QText2DEntityPrivate::update() +void QText2DEntityPrivate::updateGlyphs() { if (m_glyphCache == nullptr) return; @@ -387,7 +387,7 @@ void QText2DEntity::setFont(const QFont &font) emit fontChanged(font); if (!d->m_text.isEmpty()) - d->update(); + d->updateGlyphs(); } } @@ -434,7 +434,7 @@ void QText2DEntity::setText(const QString &text) d->m_text = text; emit textChanged(text); - d->update(); + d->updateGlyphs(); } } @@ -468,7 +468,7 @@ void QText2DEntity::setWidth(float width) if (width != d->m_width) { d->m_width = width; emit widthChanged(width); - d->update(); + d->updateGlyphs(); } } @@ -478,7 +478,7 @@ void QText2DEntity::setHeight(float height) if (height != d->m_height) { d->m_height = height; emit heightChanged(height); - d->update(); + d->updateGlyphs(); } } diff --git a/src/extras/text/qtext2dentity_p.h b/src/extras/text/qtext2dentity_p.h index b98c62ce3..ba907e7f9 100644 --- a/src/extras/text/qtext2dentity_p.h +++ b/src/extras/text/qtext2dentity_p.h @@ -105,7 +105,7 @@ public: void setCurrentGlyphRuns(const QVector<QGlyphRun> &runs); void clearCurrentGlyphRuns(); - void update(); + void updateGlyphs(); struct CacheEntry { |