diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2014-09-29 17:19:36 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2014-10-03 21:18:41 +0200 |
commit | 7b26f6a1746419161a8f875e341b3e31220f4141 (patch) | |
tree | f784e568015e1f7f199abb388b97fefdb158c84e /src | |
parent | c16689bb1ccf31416df7b8c69fe032898cf87dec (diff) |
QNode refactoring
Move almost everything to private classes.
Assimp loading restored.
All examples working.
QNode hierachy is now handled through QObject::setParent, addChild,
removeChild are part of the private api.
Note: commented QChangeArbiter unit tests as they can no longer work with this
patch and will restore them when QChangeArbiter will have been made private.
Task-number: QTBUG-41470
Task-number: QTBUG-41523
Change-Id: I4430974b3aa7f3744c38714b451b122e0cb4d0c9
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
188 files changed, 1493 insertions, 1460 deletions
diff --git a/src/bulletphysics/qabstractcollider.cpp b/src/bulletphysics/qabstractcollider.cpp index 88371827d..7f1343f03 100644 --- a/src/bulletphysics/qabstractcollider.cpp +++ b/src/bulletphysics/qabstractcollider.cpp @@ -53,6 +53,13 @@ QAbstractColliderPrivate::QAbstractColliderPrivate(QAbstractCollider *qq) { } +void QAbstractColliderPrivate::copy(const QNodePrivate *ref) +{ + QComponentPrivate::copy(ref); + const QAbstractColliderPrivate *other = static_cast<const QAbstractColliderPrivate *>(ref); + m_collisionBehavior = other->m_collisionBehavior; +} + QAbstractCollider::QAbstractCollider(QNode *parent) : Qt3D::QComponent(*new QAbstractColliderPrivate(this), parent) { @@ -63,14 +70,6 @@ QAbstractCollider::QAbstractCollider(QAbstractColliderPrivate &dd, Qt3D::QNode * { } -void QAbstractCollider::copy(const QNode *ref) -{ - Q_D(QAbstractCollider); - QComponent::copy(ref); - const QAbstractCollider *other = qobject_cast<const QAbstractCollider *>(ref); - if (other != Q_NULLPTR) - d->m_collisionBehavior = other->collisionBehavior(); -} void QAbstractCollider::setCollisionBehavior(CollisionBehavior collisionBehavior) { diff --git a/src/bulletphysics/qabstractcollider.h b/src/bulletphysics/qabstractcollider.h index 9855a51cf..5d89f451d 100644 --- a/src/bulletphysics/qabstractcollider.h +++ b/src/bulletphysics/qabstractcollider.h @@ -62,8 +62,6 @@ class QT3DBULLETPHYSICSSHARED_EXPORT QAbstractCollider : public Qt3D::QComponent public: explicit QAbstractCollider(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - enum CollisionBehavior { SolidColliderBehavior = 0, NonSolidColliderBehavior @@ -76,8 +74,10 @@ Q_SIGNALS: void collisionBehaviorChanged(); protected: - Q_DECLARE_PRIVATE(QAbstractCollider) QAbstractCollider(QAbstractColliderPrivate &dd, Qt3D::QNode *parent = 0); + +private: + Q_DECLARE_PRIVATE(QAbstractCollider) }; } // namespace BulletPhysics diff --git a/src/bulletphysics/qabstractcollider_p.h b/src/bulletphysics/qabstractcollider_p.h index 1d519c3c9..2db46943d 100644 --- a/src/bulletphysics/qabstractcollider_p.h +++ b/src/bulletphysics/qabstractcollider_p.h @@ -57,6 +57,8 @@ class QAbstractColliderPrivate : public Qt3D::QComponentPrivate public: QAbstractColliderPrivate(QAbstractCollider *qq); + virtual void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QAbstractCollider) QAbstractCollider::CollisionBehavior m_collisionBehavior; diff --git a/src/bulletphysics/qboxcollider.cpp b/src/bulletphysics/qboxcollider.cpp index 1686c8c16..471059b58 100644 --- a/src/bulletphysics/qboxcollider.cpp +++ b/src/bulletphysics/qboxcollider.cpp @@ -54,6 +54,13 @@ QBoxColliderPrivate::QBoxColliderPrivate(QBoxCollider *qq) { } +void QBoxColliderPrivate::copy(const QNodePrivate *ref) +{ + QAbstractColliderPrivate::copy(ref); + const QBoxColliderPrivate *other = static_cast<const QBoxColliderPrivate *>(ref); + m_center = other->m_center; + m_halfExtents = other->m_halfExtents; +} QBoxCollider::QBoxCollider(Qt3D::QNode *parent) : QAbstractCollider(*new QBoxColliderPrivate(this), parent) @@ -65,23 +72,10 @@ QBoxCollider::QBoxCollider(QBoxColliderPrivate &dd, QNode *parent) { } -void QBoxCollider::copy(const QNode *ref) -{ - Q_D(QBoxCollider); - QAbstractCollider::copy(ref); - const QBoxCollider *other = qobject_cast<const QBoxCollider *>(ref); - if (other != Q_NULLPTR) { - const QBoxColliderPrivate *d_other = other->d_func(); - d->m_center = d_other->m_center; - d->m_halfExtents = d_other->m_halfExtents; - } -} - -QBoxCollider *QBoxCollider::doClone(bool isClone) const +QBoxCollider *QBoxCollider::doClone() const { QBoxCollider *clone = new QBoxCollider(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/bulletphysics/qboxcollider.h b/src/bulletphysics/qboxcollider.h index de5373170..8e00475b1 100644 --- a/src/bulletphysics/qboxcollider.h +++ b/src/bulletphysics/qboxcollider.h @@ -64,8 +64,6 @@ class QBoxCollider : public Qt3D::BulletPhysics::QAbstractCollider public: explicit QBoxCollider(Qt3D::QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setCenter(const QVector3D ¢er); QVector3D center() const; @@ -77,9 +75,11 @@ Q_SIGNALS: void halfExtentsChanged(); protected: - Q_DECLARE_PRIVATE(QBoxCollider) QBoxCollider(QBoxColliderPrivate &dd, QNode *parent = 0); - QBoxCollider *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QBoxCollider) + QBoxCollider *doClone() const Q_DECL_OVERRIDE; }; } // namespace BulletPhysics diff --git a/src/bulletphysics/qboxcollider_p.h b/src/bulletphysics/qboxcollider_p.h index d40d7e4c2..bee8535d9 100644 --- a/src/bulletphysics/qboxcollider_p.h +++ b/src/bulletphysics/qboxcollider_p.h @@ -58,6 +58,8 @@ class QBoxColliderPrivate : public QAbstractColliderPrivate public: QBoxColliderPrivate(QBoxCollider *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QBoxCollider) QVector3D m_center; diff --git a/src/bulletphysics/qrigidbody.cpp b/src/bulletphysics/qrigidbody.cpp index 5039acc10..bd6198af4 100644 --- a/src/bulletphysics/qrigidbody.cpp +++ b/src/bulletphysics/qrigidbody.cpp @@ -65,23 +65,18 @@ QRigidBody::QRigidBody(QRigidBodyPrivate &dd, Qt3D::QNode *parent) { } -void QRigidBody::copy(const QNode *ref) +void QRigidBodyPrivate::copy(const QNodePrivate *ref) { - Q_D(QRigidBody); - QComponent::copy(ref); - const QRigidBody *other = qobject_cast<const QRigidBody *>(ref); - if (other != Q_NULLPTR) { - const QRigidBodyPrivate *d_other = other->d_func(); - d->m_mass = d_other->m_mass; - d->m_centerOfMass = d_other->m_centerOfMass; - } + QRigidBodyPrivate::copy(ref); + const QRigidBodyPrivate *other = static_cast<const QRigidBodyPrivate *>(ref); + m_mass = other->m_mass; + m_centerOfMass = other->m_centerOfMass; } -QRigidBody *QRigidBody::doClone(bool isClone) const +QRigidBody *QRigidBody::doClone() const { QRigidBody *clone = new QRigidBody(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/bulletphysics/qrigidbody.h b/src/bulletphysics/qrigidbody.h index 7b1aa35e8..2ab23b661 100644 --- a/src/bulletphysics/qrigidbody.h +++ b/src/bulletphysics/qrigidbody.h @@ -67,8 +67,6 @@ class QT3DBULLETPHYSICSSHARED_EXPORT QRigidBody : public Qt3D::QComponent public: explicit QRigidBody(Qt3D::QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setMass(float mass); float mass() const; @@ -80,9 +78,11 @@ Q_SIGNALS: void centerOfMassChanged(); protected: - Q_DECLARE_PRIVATE(QRigidBody) QRigidBody(QRigidBodyPrivate &dd, Qt3D::QNode *parent = 0); - QRigidBody *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QRigidBody) + QRigidBody *doClone() const Q_DECL_OVERRIDE; }; } // namespace BulletPhysics diff --git a/src/bulletphysics/qrigidbody_p.h b/src/bulletphysics/qrigidbody_p.h index e56545b2f..e99b59705 100644 --- a/src/bulletphysics/qrigidbody_p.h +++ b/src/bulletphysics/qrigidbody_p.h @@ -55,6 +55,8 @@ class QRigidBodyPrivate : public Qt3D::QComponentPrivate public: explicit QRigidBodyPrivate(QRigidBody *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QRigidBody) float m_mass; diff --git a/src/bulletphysics/qspherecollider.cpp b/src/bulletphysics/qspherecollider.cpp index 4d02cd834..d484090e3 100644 --- a/src/bulletphysics/qspherecollider.cpp +++ b/src/bulletphysics/qspherecollider.cpp @@ -65,23 +65,18 @@ QSphereCollider::QSphereCollider(QSphereColliderPrivate &dd, QNode *parent) { } -void QSphereCollider::copy(const QNode *ref) +void QSphereColliderPrivate::copy(const QNodePrivate *ref) { - Q_D(QSphereCollider); - QAbstractCollider::copy(ref); - const QSphereCollider *other = qobject_cast<const QSphereCollider *>(ref); - if (other != Q_NULLPTR) { - const QSphereColliderPrivate *d_other = other->d_func(); - d->m_center = d_other->m_center; - d->m_radius = d_other->m_radius; - } + QAbstractColliderPrivate::copy(ref); + const QSphereColliderPrivate *other = static_cast<const QSphereColliderPrivate *>(ref); + m_center = other->m_center; + m_radius = other->m_radius; } -QSphereCollider *QSphereCollider::doClone(bool isClone) const +QSphereCollider *QSphereCollider::doClone() const { QSphereCollider *clone = new QSphereCollider(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/bulletphysics/qspherecollider.h b/src/bulletphysics/qspherecollider.h index ff3d78dd6..0d195848a 100644 --- a/src/bulletphysics/qspherecollider.h +++ b/src/bulletphysics/qspherecollider.h @@ -64,8 +64,6 @@ class QT3DBULLETPHYSICSSHARED_EXPORT QSphereCollider : public Qt3D::BulletPhysic public: explicit QSphereCollider(Qt3D::QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setCenter(const QVector3D ¢er); QVector3D center() const; @@ -77,9 +75,11 @@ Q_SIGNALS: void radiusChanged(); protected: - Q_DECLARE_PRIVATE(QSphereCollider) QSphereCollider(QSphereColliderPrivate &dd, QNode *parent = 0); - QSphereCollider *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QSphereCollider) + QSphereCollider *doClone() const Q_DECL_OVERRIDE; }; } // namespace BulletPhysics diff --git a/src/bulletphysics/qspherecollider_p.h b/src/bulletphysics/qspherecollider_p.h index 3dc30206a..0846aa71a 100644 --- a/src/bulletphysics/qspherecollider_p.h +++ b/src/bulletphysics/qspherecollider_p.h @@ -57,6 +57,8 @@ class QSphereColliderPrivate : public QAbstractColliderPrivate public: QSphereColliderPrivate(QSphereCollider *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QSphereCollider) QVector3D m_center; diff --git a/src/core/aspects/qaspectengine.cpp b/src/core/aspects/qaspectengine.cpp index 5b88037ee..f22492e95 100644 --- a/src/core/aspects/qaspectengine.cpp +++ b/src/core/aspects/qaspectengine.cpp @@ -52,6 +52,7 @@ #include <private/qpostman_p.h> #include "qscene.h" #include <private/qaspectengine_p.h> +#include <private/qnode_p.h> #include "qentity.h" #include "qcomponent.h" @@ -92,15 +93,18 @@ QAspectEngine::QAspectEngine(QAspectEnginePrivate &dd, QObject *parent) void QAspectEngine::initNodeTree(QNode *node) const { Q_D(const QAspectEngine); - node->setScene(d->m_scene); + node->d_func()->setScene(d->m_scene); d->m_scene->addObservable(node); QEntity *entity = qobject_cast<QEntity *>(node); if (entity != Q_NULLPTR) Q_FOREACH (QComponent *comp, entity->components()) d->m_scene->addEntityForComponent(comp->uuid(), entity->uuid()); - Q_FOREACH (QNode *c, node->children()) - initNodeTree(c); + Q_FOREACH (QObject *c, node->children()) { + QNode *childNode = qobject_cast<QNode *>(c); + if (childNode != Q_NULLPTR) + initNodeTree(childNode); + } } void QAspectEngine::initialize() diff --git a/src/core/core-components/qabstracteffect.cpp b/src/core/core-components/qabstracteffect.cpp index 0c722cc1e..5de20afd6 100644 --- a/src/core/core-components/qabstracteffect.cpp +++ b/src/core/core-components/qabstracteffect.cpp @@ -93,14 +93,14 @@ void QAbstractEffect::addTechnique(QAbstractTechnique *t) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, tit gets destroyed as well - if (!t->parent() || t->parent() == this) - QNode::addChild(t); + if (!t->parent()) + t->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, this)); e->setPropertyName(QByteArrayLiteral("technique")); e->setValue(QVariant::fromValue(t)); - notifyObservers(e); + d->notifyObservers(e); } } } @@ -117,7 +117,7 @@ void QAbstractEffect::removeTechnique(QAbstractTechnique *t) QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, this)); e->setPropertyName(QByteArrayLiteral("technique")); e->setValue(QVariant::fromValue(t->uuid())); - notifyObservers(e); + d->notifyObservers(e); } d->m_techniques.removeOne(t); } diff --git a/src/core/core-components/qabstractmaterial.cpp b/src/core/core-components/qabstractmaterial.cpp index 7ef03ba0b..b5c3aa5f4 100644 --- a/src/core/core-components/qabstractmaterial.cpp +++ b/src/core/core-components/qabstractmaterial.cpp @@ -92,7 +92,7 @@ void QAbstractMaterial::setEffect(QAbstractEffect *effect) QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("effect")); change->setValue(QVariant::fromValue(d->m_effect)); - notifyObservers(change); + d->notifyObservers(change); } d->m_effect = effect; @@ -102,14 +102,14 @@ void QAbstractMaterial::setEffect(QAbstractEffect *effect) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!effect->parent() || effect->parent() == this) - QNode::addChild(effect); + if (!effect->parent()) + effect->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("effect")); change->setValue(QVariant::fromValue(effect)); - notifyObservers(change); + d->notifyObservers(change); } } } diff --git a/src/core/core-components/qabstractmesh.cpp b/src/core/core-components/qabstractmesh.cpp index edb59c0b2..7cf960cb0 100644 --- a/src/core/core-components/qabstractmesh.cpp +++ b/src/core/core-components/qabstractmesh.cpp @@ -66,6 +66,14 @@ QAbstractMeshPrivate::QAbstractMeshPrivate(QAbstractMesh *qq) { } +void QAbstractMeshPrivate::copy(const QNodePrivate *ref) +{ + QNodePrivate::copy(ref); + const QAbstractMeshPrivate *abstractMesh = static_cast<const QAbstractMeshPrivate *>(ref); + m_uuid = abstractMesh->m_uuid; + m_dirty = abstractMesh->m_dirty; +} + QAbstractMesh::QAbstractMesh(QNode *parent) : QComponent(*new QAbstractMeshPrivate(this), parent) @@ -92,7 +100,7 @@ void QAbstractMesh::setDirty(bool dirty) QScenePropertyChangePtr change(new QScenePropertyChange(ComponentUpdated, this)); change->setPropertyName(QByteArrayLiteral("meshFunctor")); change->setValue(QVariant::fromValue(meshFunctor())); - notifyObservers(change); + d->notifyObservers(change); // TO DO see if we can clear the d->m_dirty on request. // This would allow to send a single notification for classes that have several property changes occur // over a single given frame or maybe that's the job of the QChangeArbiter diff --git a/src/core/core-components/qabstractmesh.h b/src/core/core-components/qabstractmesh.h index 68f160789..3a6725ccd 100644 --- a/src/core/core-components/qabstractmesh.h +++ b/src/core/core-components/qabstractmesh.h @@ -43,6 +43,7 @@ #define QT3D_QABSTRACTMESH_H #include <Qt3DCore/qcomponent.h> +#include <QSharedPointer> #include <QUuid> QT_BEGIN_NAMESPACE @@ -76,12 +77,11 @@ public: virtual QAbstractMeshFunctorPtr meshFunctor() const = 0; -Q_SIGNALS: - void sourceChanged(); - protected: - Q_DECLARE_PRIVATE(QAbstractMesh) QAbstractMesh(QAbstractMeshPrivate &dd, QNode *parent = 0); + +private: + Q_DECLARE_PRIVATE(QAbstractMesh) }; } // Qt3D diff --git a/src/core/core-components/qabstractmesh_p.h b/src/core/core-components/qabstractmesh_p.h index caf3249f2..3ef172bee 100644 --- a/src/core/core-components/qabstractmesh_p.h +++ b/src/core/core-components/qabstractmesh_p.h @@ -60,9 +60,11 @@ class QT3DCORESHARED_EXPORT QAbstractMeshPrivate : public QComponentPrivate public: QAbstractMeshPrivate(QAbstractMesh *qq); + virtual void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QAbstractMesh) - const QUuid m_uuid; + QUuid m_uuid; bool m_dirty; }; diff --git a/src/core/core-components/qabstractrenderpass.cpp b/src/core/core-components/qabstractrenderpass.cpp index 6b4c81f87..6484f1701 100644 --- a/src/core/core-components/qabstractrenderpass.cpp +++ b/src/core/core-components/qabstractrenderpass.cpp @@ -93,7 +93,7 @@ void QAbstractRenderPass::setShaderProgram(QAbstractShader *shaderProgram) QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, this)); e->setPropertyName(QByteArrayLiteral("shaderProgram")); e->setValue(QVariant::fromValue(d->m_shader->uuid())); - notifyObservers(e); + d->notifyObservers(e); } d->m_shader = shaderProgram; @@ -103,14 +103,14 @@ void QAbstractRenderPass::setShaderProgram(QAbstractShader *shaderProgram) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!shaderProgram->parent() || shaderProgram->parent() == this) - QNode::addChild(shaderProgram); + if (!shaderProgram->parent()) + shaderProgram->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, this)); e->setPropertyName(QByteArrayLiteral("shaderProgram")); e->setValue(QVariant::fromValue(shaderProgram->uuid())); - notifyObservers(e); + d->notifyObservers(e); } } } diff --git a/src/core/core-components/qabstractrenderpass_p.h b/src/core/core-components/qabstractrenderpass_p.h index ffc1f75b4..13045de0f 100644 --- a/src/core/core-components/qabstractrenderpass_p.h +++ b/src/core/core-components/qabstractrenderpass_p.h @@ -43,12 +43,12 @@ #define QT3D_QABSTRACTRENDERPASS_P_H #include <private/qnode_p.h> +#include <Qt3DCore/qabstractrenderpass.h> QT_BEGIN_NAMESPACE namespace Qt3D { -class QAbstractRenderPass; class QAbstractShader; class QT3DCORESHARED_EXPORT QAbstractRenderPassPrivate : public QNodePrivate diff --git a/src/core/core-components/qabstracttechnique.cpp b/src/core/core-components/qabstracttechnique.cpp index 12bc2e7a0..d9c9f04b1 100644 --- a/src/core/core-components/qabstracttechnique.cpp +++ b/src/core/core-components/qabstracttechnique.cpp @@ -98,14 +98,14 @@ void QAbstractTechnique::addPass(QAbstractRenderPass *pass) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!pass->parent() || pass->parent() == this) - QNode::addChild(pass); + if (!pass->parent()) + pass->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, this)); e->setPropertyName(QByteArrayLiteral("pass")); e->setValue(QVariant::fromValue(pass)); - notifyObservers(e); + d->notifyObservers(e); } } } @@ -122,7 +122,7 @@ void QAbstractTechnique::removePass(QAbstractRenderPass *pass) QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, this)); e->setPropertyName(QByteArrayLiteral("pass")); e->setValue(QVariant::fromValue(pass->uuid())); - notifyObservers(e); + d->notifyObservers(e); } d->m_renderPasses.removeOne(pass); } diff --git a/src/core/core-components/qcameralens.cpp b/src/core/core-components/qcameralens.cpp index 154ae13b5..aa06ee27d 100644 --- a/src/core/core-components/qcameralens.cpp +++ b/src/core/core-components/qcameralens.cpp @@ -47,16 +47,16 @@ QT_BEGIN_NAMESPACE namespace Qt3D { QCameraLensPrivate::QCameraLensPrivate(QCameraLens *qq) - : QComponentPrivate(qq) - , m_projectionType(QCameraLens::OrthogonalProjection) - , m_nearPlane(0.1f) - , m_farPlane(1024.0f) - , m_fieldOfView(25.0f) - , m_aspectRatio(1.0f) - , m_left(-0.5f) - , m_right(0.5f) - , m_bottom(-0.5f) - , m_top(0.5f) + : QComponentPrivate(qq) + , m_projectionType(QCameraLens::OrthogonalProjection) + , m_nearPlane(0.1f) + , m_farPlane(1024.0f) + , m_fieldOfView(25.0f) + , m_aspectRatio(1.0f) + , m_left(-0.5f) + , m_right(0.5f) + , m_bottom(-0.5f) + , m_top(0.5f) { } @@ -68,23 +68,20 @@ QCameraLens::QCameraLens(QNode *parent) d->updateProjectionMatrix(); } -void QCameraLens::copy(const QNode *ref) +void QCameraLensPrivate::copy(const QNodePrivate *ref) { - Q_D(QCameraLens); - QComponent::copy(ref); - const QCameraLens *lens = qobject_cast<const QCameraLens *>(ref); - if (lens != Q_NULLPTR) { - d->m_projectionType = lens->projectionType(); - d->m_nearPlane = lens->nearPlane(); - d->m_farPlane = lens->farPlane(); - d->m_fieldOfView = lens->fieldOfView(); - d->m_aspectRatio = lens->aspectRatio(); - d->m_left = lens->left(); - d->m_right = lens->right(); - d->m_bottom = lens->bottom(); - d->m_top = lens->top(); - d->updateProjectionMatrix(); - } + QComponentPrivate::copy(ref); + const QCameraLensPrivate *lens = static_cast<const QCameraLensPrivate *>(ref); + m_projectionType = lens->m_projectionType; + m_nearPlane = lens->m_nearPlane; + m_farPlane = lens->m_farPlane; + m_fieldOfView = lens->m_fieldOfView; + m_aspectRatio = lens->m_aspectRatio; + m_left = lens->m_left; + m_right = lens->m_right; + m_bottom = lens->m_bottom; + m_top = lens->m_top; + m_projectionMatrix = lens->m_projectionMatrix; } QCameraLens::QCameraLens(QCameraLensPrivate &dd, QNode *parent) @@ -94,11 +91,10 @@ QCameraLens::QCameraLens(QCameraLensPrivate &dd, QNode *parent) d->updateOrthogonalProjection(); } -QCameraLens *QCameraLens::doClone(bool isClone) const +QCameraLens *QCameraLens::doClone() const { QCameraLens *clone = new QCameraLens(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -119,8 +115,8 @@ QCameraLens::ProjectionType QCameraLens::projectionType() const } void QCameraLens::setOrthographicProjection( float left, float right, - float bottom, float top, - float nearPlane, float farPlane ) + float bottom, float top, + float nearPlane, float farPlane ) { Q_D(QCameraLens); d->m_left = left; @@ -134,7 +130,7 @@ void QCameraLens::setOrthographicProjection( float left, float right, } void QCameraLens::setPerspectiveProjection( float fieldOfView, float aspectRatio, - float nearPlane, float farPlane ) + float nearPlane, float farPlane ) { Q_D(QCameraLens); d->m_fieldOfView = fieldOfView; diff --git a/src/core/core-components/qcameralens.h b/src/core/core-components/qcameralens.h index 25399c49f..f6a5e4f4c 100644 --- a/src/core/core-components/qcameralens.h +++ b/src/core/core-components/qcameralens.h @@ -74,8 +74,6 @@ class QT3DCORESHARED_EXPORT QCameraLens : public QComponent public: explicit QCameraLens(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - enum ProjectionType { OrthogonalProjection, PerspectiveProjection @@ -131,9 +129,11 @@ Q_SIGNALS: void projectionMatrixChanged(); protected: - Q_DECLARE_PRIVATE(QCameraLens) QCameraLens(QCameraLensPrivate &dd, QNode *parent = 0); - QCameraLens *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QCameraLens) + QCameraLens *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/core/core-components/qcameralens_p.h b/src/core/core-components/qcameralens_p.h index 9a3fa6f42..c92279445 100644 --- a/src/core/core-components/qcameralens_p.h +++ b/src/core/core-components/qcameralens_p.h @@ -58,6 +58,8 @@ class QT3DCORESHARED_EXPORT QCameraLensPrivate : public QComponentPrivate public: QCameraLensPrivate(QCameraLens *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + inline void updateProjectionMatrix() { switch (m_projectionType) { @@ -78,7 +80,7 @@ public: QScenePropertyChangePtr propertyChange(new QScenePropertyChange(ComponentUpdated, q)); propertyChange->setPropertyName(QByteArrayLiteral("projectionMatrix")); propertyChange->setValue(QVariant::fromValue(m_projectionMatrix)); - q->notifyObservers(propertyChange); + QNodePrivate::notifyObservers(propertyChange); } } diff --git a/src/core/nodes/nodevisitor.cpp b/src/core/nodes/nodevisitor.cpp index ac25fc488..f830b6bb4 100644 --- a/src/core/nodes/nodevisitor.cpp +++ b/src/core/nodes/nodevisitor.cpp @@ -62,9 +62,7 @@ void NodeVisitor::traverse(QNode *rootNode) m_path = NodeList() << rootNode; m_matrixStack.clear(); - QEntity* rootEntity = rootNode->asEntity(); - -// m_matrixStack.append(rootEntity ? rootEntity->matrix() : QMatrix4x4()); + QEntity* rootEntity = qobject_cast<QEntity *>(rootNode); if (rootEntity) visitEntity(rootEntity); @@ -110,15 +108,17 @@ void NodeVisitor::visitEntity(QEntity *nd) void NodeVisitor::traverseChildren() { - foreach (QNode* n, currentNode()->children()) { - outerVisitNode(n); + foreach (QObject *n, currentNode()->children()) { + QNode *node = qobject_cast<QNode *>(n); + if (node != Q_NULLPTR) + outerVisitNode(node); } // of children iteration } void NodeVisitor::outerVisitNode(QNode *n) { m_path.append(n); - QEntity* e = n->asEntity(); + QEntity* e = qobject_cast<QEntity *>(n); if (e) { visitEntity(e); m_path.pop_back(); diff --git a/src/core/nodes/qcomponent.cpp b/src/core/nodes/qcomponent.cpp index 562466549..27aa1da37 100644 --- a/src/core/nodes/qcomponent.cpp +++ b/src/core/nodes/qcomponent.cpp @@ -48,7 +48,6 @@ namespace Qt3D { QComponentPrivate::QComponentPrivate(QComponent *qq) : QNodePrivate(qq) - , m_enabled(true) { } @@ -62,21 +61,6 @@ QComponent::QComponent(QComponentPrivate &dd, QNode *parent) { } -void QComponent::setEnabled(bool enabled) -{ - Q_D(QComponent); - if (d->m_enabled != enabled) { - d->m_enabled = enabled; - emit enabledChanged(); - } -} - -bool QComponent::isEnabled() const -{ - Q_D(const QComponent); - return d->m_enabled; -} - } // namespace Qt3D QT_END_NAMESPACE diff --git a/src/core/nodes/qcomponent.h b/src/core/nodes/qcomponent.h index c76dbc6c1..81089d46c 100644 --- a/src/core/nodes/qcomponent.h +++ b/src/core/nodes/qcomponent.h @@ -55,20 +55,13 @@ class QT3DCORESHARED_EXPORT QComponent : public QNode { Q_OBJECT - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - public: explicit QComponent(QNode *parent = 0); - void setEnabled(bool enabled); - bool isEnabled() const; - -Q_SIGNALS: - void enabledChanged(); - protected: - Q_DECLARE_PRIVATE(QComponent) QComponent(QComponentPrivate &dd, QNode *parent = 0); +private: + Q_DECLARE_PRIVATE(QComponent) }; } // namespace Qt3D diff --git a/src/core/nodes/qcomponent_p.h b/src/core/nodes/qcomponent_p.h index da27f6b7d..83c755138 100644 --- a/src/core/nodes/qcomponent_p.h +++ b/src/core/nodes/qcomponent_p.h @@ -55,8 +55,6 @@ public: explicit QComponentPrivate(QComponent *qq); Q_DECLARE_PUBLIC(QComponent) - - bool m_enabled; }; } diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp index 4314bdd6a..5d0144677 100644 --- a/src/core/nodes/qentity.cpp +++ b/src/core/nodes/qentity.cpp @@ -42,6 +42,7 @@ #include "qentity.h" #include "qentity_p.h" #include "qcomponent.h" +#include "qcomponent_p.h" #include "qabstracttransform.h" #include "qmatrixtransform.h" @@ -77,28 +78,24 @@ QEntity::QEntity(QEntityPrivate &dd, QNode *parent) { } -QEntity *QEntity::doClone(bool isClone) const +QEntity *QEntity::doClone() const { Q_D(const QEntity); QEntity *clone = new QEntity(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); Q_FOREACH (QComponent *c, d->m_components) { - QNode *ccclone = c->clone(isClone); + QNode *ccclone = QNodePrivate::get(c)->clone(); clone->addComponent(qobject_cast<QComponent *>(ccclone)); } return clone; } -void QEntity::copy(const QNode *ref) +void QEntityPrivate::copy(const QNodePrivate *ref) { - Q_D(QEntity); - QNode::copy(ref); - const QEntity *entity = qobject_cast<const QEntity *>(ref); - if (entity != Q_NULLPTR) { - d->m_enabled = entity->d_func()->m_enabled; - d->m_visible = entity->d_func()->m_visible; - } + QNodePrivate::copy(ref); + const QEntityPrivate *entity = static_cast<const QEntityPrivate *>(ref); + m_enabled = entity->m_enabled; + m_visible = entity->m_visible; } QList<QComponent *> QEntity::components() const @@ -116,36 +113,34 @@ void QEntity::addComponent(QComponent *comp) d->m_components.append(comp); // We only set the Entity as the Component's parent when it has no parent // This will be the case mostly on C++ but rarely in QML - if (!comp->parent() || comp->parent() == this) - addChild(comp); + if (!comp->parent()) + comp->setParent(this); - if (!isClone() && !comp->isClone() && d->m_scene != Q_NULLPTR) + if (d->m_scene != Q_NULLPTR) d->m_scene->addEntityForComponent(comp->uuid(), d->m_uuid); - if (!isClone() && !comp->isClone() && d->m_changeArbiter != Q_NULLPTR) { + if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr propertyChange(new QScenePropertyChange(ComponentAdded, this)); propertyChange->setPropertyName(QByteArrayLiteral("component")); - propertyChange->setValue(QVariant::fromValue(QNodePtr(comp->clone()))); - notifyObservers(propertyChange); + propertyChange->setValue(QVariant::fromValue(QNodePtr(QNodePrivate::get(comp)->clone(), &QNodePrivate::nodePtrDeleter))); + d->notifyObservers(propertyChange); } } -// As in most cases Components are children of the Entity -// They shouldn't therefore also be called in the removeAllChildren of QNode -// How to handle QML inline declaration however ? void QEntity::removeComponent(QComponent *comp) { Q_CHECK_PTR(comp); qCDebug(Nodes) << Q_FUNC_INFO << comp; Q_D(QEntity); - if (!isClone() && !comp->isClone() && d->m_changeArbiter != Q_NULLPTR) { + + if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr propertyChange(new QScenePropertyChange(ComponentRemoved, this)); - propertyChange->setValue(QVariant::fromValue(QNodePtr(comp->clone()))); + propertyChange->setValue(QVariant::fromValue(QNodePtr(QNodePrivate::get(comp)->clone(), &QNodePrivate::nodePtrDeleter))); propertyChange->setPropertyName(QByteArrayLiteral("component")); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } - if (!isClone() && !comp->isClone() && d->m_scene != Q_NULLPTR) + if (d->m_scene != Q_NULLPTR) d->m_scene->removeEntityForComponent(comp->uuid(), d->m_uuid); d->m_components.removeOne(comp); @@ -158,25 +153,10 @@ void QEntity::removeAllComponents() removeComponent(comp); } -bool QEntity::isEnabled() const -{ - Q_D(const QEntity); - return d->m_enabled; -} - -void QEntity::setEnabled(bool on) -{ - Q_D(QEntity); - if (d->m_enabled != on) { - d->m_enabled = on; - emit enabledChanged(); - } -} - QEntity *QEntity::parentEntity() { QNode *parentNode = QNode::parentNode(); - QEntity *parentEntity = qobject_cast<QEntity*>(parentNode); + QEntity *parentEntity = qobject_cast<QEntity *>(parentNode); while (parentEntity == Q_NULLPTR && parentNode != Q_NULLPTR) { parentNode = parentNode->parentNode(); @@ -185,11 +165,6 @@ QEntity *QEntity::parentEntity() return parentEntity; } -QEntity *QEntity::asEntity() -{ - return this; -} - } // namespace Qt3D QT_END_NAMESPACE diff --git a/src/core/nodes/qentity.h b/src/core/nodes/qentity.h index d937f98f6..1242e2d36 100644 --- a/src/core/nodes/qentity.h +++ b/src/core/nodes/qentity.h @@ -60,93 +60,24 @@ class QT3DCORESHARED_EXPORT QEntity : public QNode { Q_OBJECT - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - public: explicit QEntity(QNode *parent = 0); virtual ~QEntity(); ComponentList components() const; - virtual void copy(const QNode *ref) Q_DECL_OVERRIDE; - - template <class T> - QList<T*> componentsOfType() const - { - QList<T*> result; - Q_FOREACH (QComponent* comp, components()) { - T* i = qobject_cast<T*>(comp); - if (i) - result.append(i); - } - - return result; - } - - template <class T> - static T* findComponentInTree(QNode* root) - { - if (!root) - return Q_NULLPTR; - - if (root->asEntity()) { - Q_FOREACH (QComponent* comp, root->asEntity()->components()) { - T* i = qobject_cast<T*>(comp); - if (i) - return i; - } // of component iteration - } // of is-entity - - Q_FOREACH (QNode* child, root->children()) { - T* i = findComponentInTree<T>(child); - if (i) - return i; - } // of child nodes iteration - - return Q_NULLPTR; - } - - template <class T> - static T* findEntityInTree(QNode* root) - { - if (!root) - return Q_NULLPTR; - - if (root->asEntity()) { - Q_FOREACH (QNode* child, root->children()) { - if (!qobject_cast<QEntity*>(child)) - continue; - T* i = qobject_cast<T*>(child); - if (i) - return i; - } // of child iteration - } // of is-entity - - Q_FOREACH (QNode* child, root->children()) { - T* i = findEntityInTree<T>(child); - if (i) - return i; - } // of child nodes iteration - - return Q_NULLPTR; - } void addComponent(QComponent *comp); void removeComponent(QComponent *comp); void removeAllComponents(); - bool isEnabled() const; - void setEnabled(bool on); - QEntity *parentEntity(); - QEntity *asEntity() Q_DECL_OVERRIDE; - -Q_SIGNALS: - void enabledChanged(); protected: - Q_DECLARE_PRIVATE(QEntity) QEntity(QEntityPrivate &dd, QNode *parent = 0); - QEntity *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QEntity) + QEntity *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/core/nodes/qentity_p.h b/src/core/nodes/qentity_p.h index e883aa93c..20e51d251 100644 --- a/src/core/nodes/qentity_p.h +++ b/src/core/nodes/qentity_p.h @@ -57,6 +57,8 @@ public : Q_DECLARE_PUBLIC(QEntity) + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + ComponentList m_components; bool m_visible; diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp index 2d2271432..d54adc72c 100644 --- a/src/core/nodes/qnode.cpp +++ b/src/core/nodes/qnode.cpp @@ -47,6 +47,7 @@ #include <Qt3DCore/qaspectengine.h> #include <Qt3DCore/qsceneinterface.h> #include <QEvent> +#include <QChildEvent> #include <QMetaObject> #include <QMetaProperty> #include "corelogging.h" @@ -56,223 +57,153 @@ QT_BEGIN_NAMESPACE namespace Qt3D { +QHash<QUuid, QNode *> QNodePrivate::m_clonesLookupTable = QHash<QUuid, QNode *>(); + QNodePrivate::QNodePrivate(QNode *qq) : QObjectPrivate() , m_changeArbiter(Q_NULLPTR) , m_scene(Q_NULLPTR) , m_uuid(QUuid::createUuid()) - , m_isClone(false) { q_ptr = qq; } -QNode::QNode(QNode *parent) - : QObject(*new QNodePrivate(this), parent) -{ -} - -QNode::QNode(QNodePrivate &dd, QNode *parent) - : QObject(dd, parent) -{ -} - -QNode::~QNode() -{ - // TO DO should unregister itself from the QChangeArbiter - removeAllChildren(); -} - -void QNode::dump() +void QNodePrivate::copy(const QNodePrivate *ref) { - const QMetaObject *meta = metaObject(); - QStringList result; - for (int i = 0; i < meta->propertyCount(); ++i) { - const QMetaProperty metaProperty = meta->property(i); - const QVariant value = property(metaProperty.name()); - result += QString(QStringLiteral("%1 %2 = %3;")) - .arg(QString::fromLatin1(metaProperty.typeName())) - .arg(QString::fromLatin1(metaProperty.name())) - .arg(value.toString()); - } - - qCDebug(Nodes) << result.join(QStringLiteral("\n")); - - foreach (QObject *child, children()) { - QNode *node = qobject_cast<QNode *>(child); - if (!node) - continue; - node->dump(); + if (ref != Q_NULLPTR) { + m_uuid = ref->m_uuid; } } -const QUuid QNode::uuid() const +// Called by QEvent::childAdded +void QNodePrivate::addChild(QNode *childNode) { - Q_D(const QNode); - return d->m_uuid; -} -NodeList QNode::children() const -{ - Q_D(const QNode); - return d->m_children; -} - -void QNode::addChild(QNode *childNode) -{ Q_ASSERT(childNode); - Q_D(QNode); - if (childNode == this) - return ; - if (d->m_children.contains(childNode)) + if (childNode == q_ptr) return ; - d->m_children.append(childNode); - childNode->setParent(this); - childNode->setScene(scene()); + // Set the scene + childNode->d_func()->setScene(m_scene); - if (!isClone() && !childNode->isClone() && d->m_scene != Q_NULLPTR) - d->m_scene->addObservable(childNode); + // addObservable set the QChangeArbiter + if (m_scene != Q_NULLPTR) + m_scene->addObservable(childNode); - if (!isClone() && !childNode->isClone() && d->m_changeArbiter != Q_NULLPTR) { - QScenePropertyChangePtr e(new QScenePropertyChange(NodeCreated, this)); + // We notify only if we have a QChangeArbiter + if (m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr e(new QScenePropertyChange(NodeCreated, qobject_cast<QNode *>(q_ptr))); e->setPropertyName(QByteArrayLiteral("node")); // We need to clone the parent of the childNode we send QNode *parentClone = clone(); QNode *childClone = Q_NULLPTR; - Q_FOREACH (QNode *clone, parentClone->children()) { - if (clone->uuid() == childNode->uuid()) { + Q_FOREACH (QObject *c, parentClone->children()) { + QNode *clone = qobject_cast<QNode *>(c); + if (clone != Q_NULLPTR && clone->uuid() == childNode->uuid()) { childClone = clone; break; } } - e->setValue(QVariant::fromValue(QNodePtr(childClone))); + e->setValue(QVariant::fromValue(QNodePtr(childClone, &QNodePrivate::nodePtrDeleter))); notifyObservers(e); - childNode->registerObserver(d->m_changeArbiter); } } -void QNode::removeChild(QNode *childNode) +// Called by QEvent::childRemoved +void QNodePrivate::removeChild(QNode *childNode) { Q_ASSERT(childNode); - if (childNode->parent() != this) + if (childNode->parent() != q_ptr) qCWarning(Nodes) << Q_FUNC_INFO << "not a child of " << this; - Q_D(QNode); - - if (!isClone() && !childNode->isClone() && d->m_scene != Q_NULLPTR) - d->m_scene->removeObservable(childNode); - // Notify only if child isn't a clone - if (!isClone() && !childNode->isClone() && d->m_changeArbiter != Q_NULLPTR) { - QScenePropertyChangePtr e(new QScenePropertyChange(NodeAboutToBeDeleted, this)); + if (m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr e(new QScenePropertyChange(NodeAboutToBeDeleted, qobject_cast<QNode *>(q_ptr))); e->setPropertyName(QByteArrayLiteral("node")); // We need to clone the parent of the childNode we send QNode *parentClone = clone(); QNode *childClone = Q_NULLPTR; - Q_FOREACH (QNode *clone, parentClone->children()) { - if (clone->uuid() == childNode->uuid()) { + Q_FOREACH (QObject *c, parentClone->children()) { + QNode *clone = qobject_cast<QNode *>(c); + if (clone != Q_NULLPTR && clone->uuid() == childNode->uuid()) { childClone = clone; break; } } - e->setValue(QVariant::fromValue(QNodePtr(childClone))); + e->setValue(QVariant::fromValue(QNodePtr(childClone, &QNodePrivate::nodePtrDeleter))); notifyObservers(e); - childNode->unregisterObserver(d->m_changeArbiter); } - d->m_children.removeOne(childNode); - if (!childNode->isClone()) - childNode->setParent(Q_NULLPTR); - childNode->setScene(Q_NULLPTR); + if (m_scene != Q_NULLPTR) + m_scene->removeObservable(childNode); + childNode->d_func()->setScene(Q_NULLPTR); } // In most cases isClone is true so that the clone isn't handled like // a real node. If there is a need for a real clone, set isClone to false // eg When a subtree built in the backend needs to be cloned // in the main thread to be added to the scene graph -QNode *QNode::clone(bool isClone) +QNode *QNodePrivate::clone() { - Q_D(QNode); static int clearLock = 0; - clearLock++; - if (d->m_scene == Q_NULLPTR) - return Q_NULLPTR; - - QNode *clonedNode = d->m_scene->lookupClone(uuid()); + // We keep a reference of clones for the current subtree + // In order to preserve relationships when multiple entities + // reference the same component + QNode *clonedNode = QNodePrivate::m_clonesLookupTable.value(m_uuid); if (clonedNode == Q_NULLPTR) { - clonedNode = doClone(isClone); + clonedNode = qobject_cast<QNode *>(q_ptr)->doClone(); // doClone, returns new instance with content copied // and relationships added - d->m_scene->addCloneLookup(clonedNode); + QNodePrivate::m_clonesLookupTable.insert(clonedNode->uuid(), clonedNode); } - Q_FOREACH (QNode *c, children()) { - QNode *cclone = c->clone(isClone); - clonedNode->addChild(cclone); + Q_FOREACH (QObject *c, q_ptr->children()) { + QNode *childNode = qobject_cast<QNode *>(c); + if (childNode != Q_NULLPTR) { + QNode *cclone = childNode->d_func()->clone(); + if (cclone != Q_NULLPTR) + cclone->setParent(clonedNode); + } } if (--clearLock == 0) - d->m_scene->clearCloneLookup(); - return clonedNode; -} + QNodePrivate::m_clonesLookupTable.clear(); -void QNode::copy(const QNode *ref) -{ - Q_D(QNode); - d->m_uuid = ref->uuid(); - d->m_changeArbiter = ref->d_func()->m_changeArbiter; - d->m_scene = ref->d_func()->m_scene; - setObjectName(ref->objectName()); -} - -bool QNode::isClone() const -{ - Q_D(const QNode); - return d->m_isClone; -} - -void QNode::removeAllChildren() -{ - Q_FOREACH (QObject *child, children()) - if (qobject_cast<QNode *>(child)) - removeChild(qobject_cast<QNode *>(child)); -} - -QEntity *QNode::asEntity() -{ - return Q_NULLPTR; + return clonedNode; } -QNode *QNode::parentNode() const +void QNodePrivate::removeAllChildren() { - return qobject_cast<QNode*>(parent()); + Q_FOREACH (QObject *child, q_ptr->children()) { + QNode *childNode = qobject_cast<QNode *>(child); + if (childNode != Q_NULLPTR) + removeChild(childNode); + } } // Called in the QAspectThread context -void QNode::registerObserver(QObserverInterface *observer) +void QNodePrivate::registerObserver(QObserverInterface *observer) { Q_CHECK_PTR(observer); // For now we only care about the QChangeArbiter observing us QChangeArbiter *changeArbiter = dynamic_cast<QChangeArbiter *>(observer); if (changeArbiter) { - Q_D(QNode); - QWriteLocker locker(&d->m_observerLock); - d->m_changeArbiter = changeArbiter; + QWriteLocker locker(&m_observerLock); + m_changeArbiter = changeArbiter; } } -void QNode::unregisterObserver(QObserverInterface *observer) +void QNodePrivate::unregisterObserver(QObserverInterface *observer) { Q_CHECK_PTR(observer); // For now we only care about the QChangeArbiter observing us - Q_D(QNode); QChangeArbiter *changeArbiter = dynamic_cast<QChangeArbiter *>(observer); - if (changeArbiter == d->m_changeArbiter) { - QWriteLocker locker(&d->m_observerLock); - d->m_changeArbiter = Q_NULLPTR; + if (changeArbiter == m_changeArbiter) { + QWriteLocker locker(&m_observerLock); + m_changeArbiter = Q_NULLPTR; } } @@ -281,36 +212,33 @@ void QNode::sceneChangeEvent(const QSceneChangePtr &) qWarning() << Q_FUNC_INFO << "sceneChangeEvent should have been subclassed"; } -void QNode::setScene(QSceneInterface *scene) +void QNodePrivate::setScene(QSceneInterface *scene) { - Q_D(QNode); - if (d->m_scene != scene) - d->m_scene = scene; + if (m_scene != scene) + m_scene = scene; } -QSceneInterface *QNode::scene() const +QSceneInterface *QNodePrivate::scene() const { - Q_D(const QNode); - return d->m_scene; + return m_scene; } -void QNode::notifyPropertyChange(const QByteArray &name, const QVariant &value) +void QNodePrivate::notifyPropertyChange(const QByteArray &name, const QVariant &value) { // TODO: Review change types. Is there any need to distinguish between NodeUpdated, ComponentUpdated? // They're both just property changes - QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, this)); + QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, qobject_cast<QNode *>(q_ptr))); e->setPropertyName(name); e->setValue(value); notifyObservers(e); } // Called by the main thread -void QNode::notifyObservers(const QSceneChangePtr &change) +void QNodePrivate::notifyObservers(const QSceneChangePtr &change) { Q_CHECK_PTR(change); - Q_D(QNode); - QReadLocker locker(&d->m_observerLock); - QChangeArbiter *changeArbiter = d->m_changeArbiter; + QReadLocker locker(&m_observerLock); + QChangeArbiter *changeArbiter = m_changeArbiter; locker.unlock(); // There is a deadlock issue as sceneChangeEventWithLock locks the QChangeArbiter's mutex // while d->m_observerLock is locked by the locker right above. @@ -321,6 +249,108 @@ void QNode::notifyObservers(const QSceneChangePtr &change) changeArbiter->sceneChangeEventWithLock(change); } +// Inserts this tree into the main Scene tree. +// Needed when SceneLoaders provide a cloned tree from the backend +// and need to insert it in the main scene tree +// QNode *root; +// QNode *subtree; +// QNodePrivate::get(root)->insertTree(subtree); + +void QNodePrivate::insertTree(QNode *treeRoot, int depth) +{ + if (m_scene != Q_NULLPTR) { + treeRoot->d_func()->setScene(m_scene); + m_scene->addObservable(treeRoot); + } + + Q_FOREACH (QObject *c, treeRoot->children()) { + QNode *n = Q_NULLPTR; + if ((n = qobject_cast<QNode *>(c)) != Q_NULLPTR) + insertTree(n, depth + 1); + } + + if (depth == 0) + treeRoot->setParent(q_ptr); +} + +QNodePrivate *QNodePrivate::get(QNode *q) +{ + return q->d_func(); +} + +void QNodePrivate::nodePtrDeleter(QNode *q) +{ + QObject *p = q->parent(); + if (p == Q_NULLPTR) + p = q; + p->deleteLater(); +} + +QNode::QNode(QNode *parent) + : QObject(*new QNodePrivate(this), parent) +{ + // We rely on QEvent::childAdded to be triggered on the parent + // So we don't actually need to invoke a method or anything + // to add ourselve with the parent +} + +QNode::QNode(QNodePrivate &dd, QNode *parent) + : QObject(dd, parent) +{ +} + +void QNode::copy(const QNode *ref) +{ + if (ref != Q_NULLPTR) + d_func()->copy(QNodePrivate::get(const_cast<QNode *>(ref))); +} + +QNode::~QNode() +{ +} + +const QUuid QNode::uuid() const +{ + Q_D(const QNode); + return d->m_uuid; +} + +QNode *QNode::parentNode() const +{ + return qobject_cast<QNode*>(parent()); +} + +bool QNode::event(QEvent *e) +{ + Q_D(QNode); + + switch (e->type()) { + + case QEvent::ChildAdded: { + QNode *childNode = qobject_cast<QNode *>(static_cast<QChildEvent *>(e)->child()); + if (childNode != Q_NULLPTR) { + d->addChild(childNode); + } + break; + } + + case QEvent::ChildRemoved: { + QNode *childNode = qobject_cast<QNode *>(static_cast<QChildEvent *>(e)->child()); + if (childNode != Q_NULLPTR) { + d->removeChild(childNode); + } + break; + } + + default: + break; + + } // switch + + return QObject::event(e); +} + } // namespace Qt3D + QT_END_NAMESPACE diff --git a/src/core/nodes/qnode.h b/src/core/nodes/qnode.h index 8d80e0d35..239f3cef0 100644 --- a/src/core/nodes/qnode.h +++ b/src/core/nodes/qnode.h @@ -44,11 +44,8 @@ #include <QObject> #include <Qt3DCore/qt3dcore_global.h> -#include <Qt3DCore/qobservableinterface.h> -#include <Qt3DCore/qchangearbiter.h> - -#include <QReadWriteLock> #include <QUuid> +#include <Qt3DCore/qscenechange.h> QT_BEGIN_NAMESPACE @@ -63,48 +60,29 @@ class QSceneInterface; typedef QList<QNode *> NodeList; typedef QSharedPointer<QNode> QNodePtr; -class QT3DCORESHARED_EXPORT QNode : public QObject, public QObservableInterface +class QT3DCORESHARED_EXPORT QNode : public QObject { Q_OBJECT - public: explicit QNode(QNode *parent = 0); ~QNode(); - void dump(); - const QUuid uuid() const; - - NodeList children() const; - void addChild(QNode *childNode); - void removeChild(QNode *childNode); - - QNode *clone(bool isClone = true); - virtual void copy(const QNode *ref); - - bool isClone() const; - - void removeAllChildren(); - - virtual QEntity* asEntity(); - QNode *parentNode() const; - void registerObserver(QObserverInterface *observer) Q_DECL_OVERRIDE; - void unregisterObserver(QObserverInterface *observer) Q_DECL_OVERRIDE; - - virtual void sceneChangeEvent(const QSceneChangePtr &change); - - void setScene(QSceneInterface *scene); - QSceneInterface *scene() const; - protected: - void notifyPropertyChange(const QByteArray &name, const QVariant &value); - virtual void notifyObservers(const QSceneChangePtr &change); - virtual QNode *doClone(bool isClone = true) const = 0; + QNode(QNodePrivate &dd, QNode *parent = 0); + virtual void copy(const QNode *ref); + virtual void sceneChangeEvent(const QSceneChangePtr &change); + bool event(QEvent *e) Q_DECL_OVERRIDE; +private: Q_DECLARE_PRIVATE(QNode) - QNode(QNodePrivate &dd, QNode *parent = 0); + virtual QNode *doClone() const = 0; + + friend class QAspectEngine; + friend class QPostman; + friend class QScene; }; } // namespace Qt3D diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h index f6c7749e3..8bebd7bd6 100644 --- a/src/core/nodes/qnode_p.h +++ b/src/core/nodes/qnode_p.h @@ -42,9 +42,12 @@ #ifndef QT3D_QNODE_P_H #define QT3D_QNODE_P_H -#include <Qt3DCore/qt3dcore_global.h> #include <private/qobject_p.h> +#include <QReadWriteLock> +#include <Qt3DCore/qt3dcore_global.h> #include <Qt3DCore/qnode.h> +#include <Qt3DCore/qobservableinterface.h> +#include <Qt3DCore/qchangearbiter.h> QT_BEGIN_NAMESPACE @@ -53,14 +56,29 @@ namespace Qt3D { class QNode; class QAspectEngine; -class QT3DCORESHARED_EXPORT QNodePrivate : public QObjectPrivate +class QT3DCORESHARED_EXPORT QNodePrivate : public QObjectPrivate, public QObservableInterface { public: QNodePrivate(QNode *qq); - Q_DECLARE_PUBLIC(QNode) + // Clone should only be made in the main thread + QNode *clone(); + + virtual void copy(const QNodePrivate *ref); + + + void setScene(QSceneInterface *scene); + QSceneInterface *scene() const; + + void registerObserver(QObserverInterface *observer) Q_DECL_OVERRIDE; + void unregisterObserver(QObserverInterface *observer) Q_DECL_OVERRIDE; - NodeList m_children; + void notifyPropertyChange(const QByteArray &name, const QVariant &value); + virtual void notifyObservers(const QSceneChangePtr &change); + + void insertTree(QNode *treeRoot, int depth = 0); + + Q_DECLARE_PUBLIC(QNode) // For now this just protects access to the m_changeArbiter. // Later on we may decide to extend support for multiple observers. @@ -68,7 +86,16 @@ public: QChangeArbiter *m_changeArbiter; QSceneInterface *m_scene; mutable QUuid m_uuid; - bool m_isClone; + + static QNodePrivate *get(QNode *q); + static void nodePtrDeleter(QNode *q); + +private: + void addChild(QNode *childNode); + void removeChild(QNode *childNode); + void removeAllChildren(); + + static QHash<QUuid, QNode *> m_clonesLookupTable; }; } // namespace Qt3D diff --git a/src/core/qpostman.cpp b/src/core/qpostman.cpp index 9a2272baf..027a372a3 100644 --- a/src/core/qpostman.cpp +++ b/src/core/qpostman.cpp @@ -45,6 +45,7 @@ #include <Qt3DCore/qbackendscenepropertychange.h> #include <Qt3DCore/qscene.h> #include <Qt3DCore/qnode.h> +#include <Qt3DCore/private/qnode_p.h> QT_BEGIN_NAMESPACE diff --git a/src/core/qscene.cpp b/src/core/qscene.cpp index 4715cb961..458633135 100644 --- a/src/core/qscene.cpp +++ b/src/core/qscene.cpp @@ -44,6 +44,8 @@ #include <QReadLocker> #include <Qt3DCore/qnode.h> #include <Qt3DCore/qchangearbiter.h> +#include <Qt3DCore/qobservableinterface.h> +#include <Qt3DCore/private/qnode_p.h> QT_BEGIN_NAMESPACE @@ -94,7 +96,7 @@ void QScene::addObservable(QNode *observable) QWriteLocker lock(&d->m_lock); d->m_nodeLookupTable.insert(observable->uuid(), observable); if (d->m_arbiter != Q_NULLPTR) - observable->registerObserver(d->m_arbiter); + observable->d_func()->registerObserver(d->m_arbiter); } } @@ -125,7 +127,7 @@ void QScene::removeObservable(QNode *observable) d->m_observablesLookupTable.remove(nodeUuid); d->m_nodeLookupTable.remove(nodeUuid); if (d->m_arbiter != Q_NULLPTR) - observable->unregisterObserver(d->m_arbiter); + observable->d_func()->unregisterObserver(d->m_arbiter); } } @@ -179,24 +181,6 @@ void QScene::removeEntityForComponent(const QUuid &componentUuid, const QUuid &e d->m_componentToEntities.remove(componentUuid, entityUuid); } -QNode *QScene::lookupClone(const QUuid &id) const -{ - Q_D(const QScene); - return d->m_clonesLookupTable.value(id); -} - -void QScene::addCloneLookup(QNode *clone) -{ - Q_D(QScene); - d->m_clonesLookupTable.insert(clone->uuid(), clone); -} - -void QScene::clearCloneLookup() -{ - Q_D(QScene); - d->m_clonesLookupTable.clear(); -} - } // Qt3D QT_END_NAMESPACE diff --git a/src/core/qscene.h b/src/core/qscene.h index fd4c1977c..e3b1296c7 100644 --- a/src/core/qscene.h +++ b/src/core/qscene.h @@ -62,8 +62,10 @@ public: void removeObservable(QObservableInterface *observable, const QUuid &uuid) Q_DECL_OVERRIDE; void removeObservable(QNode *observable) Q_DECL_OVERRIDE; QObservableList lookupObservables(const QUuid &uuid) const Q_DECL_OVERRIDE; + QNode *lookupNode(const QUuid &uuid) const Q_DECL_OVERRIDE; QUuid nodeIdFromObservable(QObservableInterface *observable) const Q_DECL_OVERRIDE; + void setArbiter(QChangeArbiter *arbiter) Q_DECL_OVERRIDE; // Component -> Entities @@ -71,11 +73,6 @@ public: void addEntityForComponent(const QUuid &componentUuid, const QUuid &entityUuid) Q_DECL_OVERRIDE; void removeEntityForComponent(const QUuid &componentUuid, const QUuid &entityUuid) Q_DECL_OVERRIDE; - // QNode -> QNode *children - QNode *lookupClone(const QUuid &id) const Q_DECL_OVERRIDE; - void addCloneLookup(QNode *clone) Q_DECL_OVERRIDE; - void clearCloneLookup() Q_DECL_OVERRIDE; - private: Q_DECLARE_PRIVATE(QScene) QScenePrivate *d_ptr; diff --git a/src/core/qsceneinterface.h b/src/core/qsceneinterface.h index ea5b8e729..2a1f2dd3f 100644 --- a/src/core/qsceneinterface.h +++ b/src/core/qsceneinterface.h @@ -74,10 +74,6 @@ public: virtual QList<QUuid> entitiesForComponent(const QUuid &componentUuid) const = 0; virtual void addEntityForComponent(const QUuid &componentUuid, const QUuid &entityUuid) = 0; virtual void removeEntityForComponent(const QUuid &componentUuid, const QUuid &entityUuid) = 0; - - virtual QNode *lookupClone(const QUuid &id) const = 0; - virtual void addCloneLookup(QNode *clone) = 0; - virtual void clearCloneLookup() = 0; }; } // Qt3D diff --git a/src/core/transforms/qabstracttransform.h b/src/core/transforms/qabstracttransform.h index de5e16ed2..c0a2bd593 100644 --- a/src/core/transforms/qabstracttransform.h +++ b/src/core/transforms/qabstracttransform.h @@ -65,9 +65,12 @@ public: virtual QMatrix4x4 transformMatrix() const = 0; Q_SIGNALS: void transformMatrixChanged(); + protected: - Q_DECLARE_PRIVATE(QAbstractTransform) QAbstractTransform(QAbstractTransformPrivate &dd, QNode *parent = 0); + +private: + Q_DECLARE_PRIVATE(QAbstractTransform) }; } // namespace Qt3D diff --git a/src/core/transforms/qabstracttransform_p.h b/src/core/transforms/qabstracttransform_p.h index d296ef233..0f44dc823 100644 --- a/src/core/transforms/qabstracttransform_p.h +++ b/src/core/transforms/qabstracttransform_p.h @@ -44,6 +44,7 @@ #include <private/qnode_p.h> #include <Qt3DCore/qt3dcore_global.h> +#include <Qt3DCore/qabstracttransform.h> QT_BEGIN_NAMESPACE diff --git a/src/core/transforms/qlookattransform.cpp b/src/core/transforms/qlookattransform.cpp index ebd3298ac..b80d52ae3 100644 --- a/src/core/transforms/qlookattransform.cpp +++ b/src/core/transforms/qlookattransform.cpp @@ -57,18 +57,15 @@ QLookAtTransform::QLookAtTransform(QNode *parent) { } -void QLookAtTransform::copy(const QNode *ref) +void QLookAtTransformPrivate::copy(const QNodePrivate *ref) { - Q_D(QLookAtTransform); - QAbstractTransform::copy(ref); - const QLookAtTransform *transform = qobject_cast<const QLookAtTransform *>(ref); - if (transform != Q_NULLPTR) { - d->m_matrix = transformMatrix(); - d->m_position = position(); - d->m_upVector = upVector(); - d->m_viewCenter = viewCenter(); - d->m_viewVector = viewVector(); - } + QAbstractTransformPrivate::copy(ref); + const QLookAtTransformPrivate *transform = static_cast<const QLookAtTransformPrivate *>(ref); + m_matrix = transform->m_matrix; + m_position = transform->m_position; + m_upVector = transform->m_upVector; + m_viewCenter = transform->m_viewCenter; + m_viewVector = transform->m_viewVector; } QLookAtTransform::QLookAtTransform(QLookAtTransformPrivate &dd, QNode *parent) @@ -76,11 +73,11 @@ QLookAtTransform::QLookAtTransform(QLookAtTransformPrivate &dd, QNode *parent) { } -QLookAtTransform *QLookAtTransform::doClone(bool isClone) const +QLookAtTransform *QLookAtTransform::doClone() const { + Q_D(const QLookAtTransform); QLookAtTransform *clone = new QLookAtTransform(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d); return clone; } diff --git a/src/core/transforms/qlookattransform.h b/src/core/transforms/qlookattransform.h index 2707a1498..be04784cc 100644 --- a/src/core/transforms/qlookattransform.h +++ b/src/core/transforms/qlookattransform.h @@ -64,7 +64,6 @@ class QT3DCORESHARED_EXPORT QLookAtTransform : public Qt3D::QAbstractTransform public: explicit QLookAtTransform(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; QMatrix4x4 transformMatrix() const Q_DECL_OVERRIDE; void setPosition(const QVector3D &position); @@ -88,7 +87,7 @@ Q_SIGNALS: protected: Q_DECLARE_PRIVATE(QLookAtTransform) QLookAtTransform(QLookAtTransformPrivate &dd, QNode *parent = 0); - QLookAtTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QLookAtTransform *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/core/transforms/qlookattransform_p.h b/src/core/transforms/qlookattransform_p.h index e5f480ba0..f377afabc 100644 --- a/src/core/transforms/qlookattransform_p.h +++ b/src/core/transforms/qlookattransform_p.h @@ -54,6 +54,9 @@ public : QLookAtTransformPrivate(QLookAtTransform *qq); Q_DECLARE_PUBLIC(QLookAtTransform) + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + mutable QMatrix4x4 m_matrix; QVector3D m_position; QVector3D m_upVector; diff --git a/src/core/transforms/qmatrixtransform.cpp b/src/core/transforms/qmatrixtransform.cpp index 024f03ee9..313dcf551 100644 --- a/src/core/transforms/qmatrixtransform.cpp +++ b/src/core/transforms/qmatrixtransform.cpp @@ -56,11 +56,17 @@ QMatrixTransform::QMatrixTransform(QMatrixTransformPrivate &dd, QNode *parent) { } -QMatrixTransform *QMatrixTransform::doClone(bool isClone) const +void QMatrixTransformPrivate::copy(const QNodePrivate *ref) +{ + QAbstractTransformPrivate::copy(ref); + const QMatrixTransformPrivate *matrix = static_cast<const QMatrixTransformPrivate *>(ref); + m_matrix = matrix->m_matrix; +} + +QMatrixTransform *QMatrixTransform::doClone() const { QMatrixTransform *clone = new QMatrixTransform(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -97,16 +103,6 @@ QMatrix4x4 QMatrixTransform::transformMatrix() const return matrix(); } -void QMatrixTransform::copy(const QNode *ref) -{ - Q_D(QMatrixTransform); - QAbstractTransform::copy(ref); - const QMatrixTransform *matrix = qobject_cast<const QMatrixTransform *>(ref); - if (ref != Q_NULLPTR) { - d->m_matrix = matrix->matrix(); - } -} - } // namespace Qt3D QT_END_NAMESPACE diff --git a/src/core/transforms/qmatrixtransform.h b/src/core/transforms/qmatrixtransform.h index e8fba4aef..e0063c70c 100644 --- a/src/core/transforms/qmatrixtransform.h +++ b/src/core/transforms/qmatrixtransform.h @@ -61,8 +61,6 @@ public: explicit QMatrixTransform(QNode *parent = 0); QMatrixTransform(const QMatrix4x4& m, QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - QMatrix4x4 matrix() const; void setMatrix(const QMatrix4x4 &matrix); @@ -74,7 +72,7 @@ Q_SIGNALS: protected: Q_DECLARE_PRIVATE(QMatrixTransform) QMatrixTransform(QMatrixTransformPrivate &dd, QNode *parent = 0); - QMatrixTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QMatrixTransform *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/core/transforms/qmatrixtransform_p.h b/src/core/transforms/qmatrixtransform_p.h index 7be1e972a..fc0ad3a96 100644 --- a/src/core/transforms/qmatrixtransform_p.h +++ b/src/core/transforms/qmatrixtransform_p.h @@ -55,6 +55,8 @@ class QMatrixTransformPrivate : public QAbstractTransformPrivate public: QMatrixTransformPrivate(QMatrixTransform *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QMatrixTransform) QMatrix4x4 m_matrix; }; diff --git a/src/core/transforms/qrotatetransform.cpp b/src/core/transforms/qrotatetransform.cpp index 8adb620fb..b7a939729 100644 --- a/src/core/transforms/qrotatetransform.cpp +++ b/src/core/transforms/qrotatetransform.cpp @@ -60,20 +60,17 @@ QRotateTransformPrivate::QRotateTransformPrivate(QRotateTransform *qq) { } -QRotateTransform::QRotateTransform(QNode *parent) - : QAbstractTransform(*new QRotateTransformPrivate(this), parent) +void QRotateTransformPrivate::copy(const QNodePrivate *ref) { + QAbstractTransformPrivate::copy(ref); + const QRotateTransformPrivate *transform = static_cast<const QRotateTransformPrivate *>(ref); + m_axis = transform->m_axis; + m_angleDeg = transform->m_angleDeg; } -void QRotateTransform::copy(const QNode *ref) +QRotateTransform::QRotateTransform(QNode *parent) + : QAbstractTransform(*new QRotateTransformPrivate(this), parent) { - Q_D(QRotateTransform); - QAbstractTransform::copy(ref); - const QRotateTransform *transform = qobject_cast<const QRotateTransform *>(ref); - if (ref != Q_NULLPTR) { - d->m_axis = transform->axis(); - d->m_angleDeg = transform->angleDeg(); - } } QRotateTransform::QRotateTransform(QRotateTransformPrivate &dd, QNode *parent) @@ -81,11 +78,10 @@ QRotateTransform::QRotateTransform(QRotateTransformPrivate &dd, QNode *parent) { } -QRotateTransform *QRotateTransform::doClone(bool isClone) const +QRotateTransform *QRotateTransform::doClone() const { QRotateTransform *clone = new QRotateTransform(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/core/transforms/qrotatetransform.h b/src/core/transforms/qrotatetransform.h index 1c6bea033..4416c5c24 100644 --- a/src/core/transforms/qrotatetransform.h +++ b/src/core/transforms/qrotatetransform.h @@ -63,8 +63,6 @@ class QT3DCORESHARED_EXPORT QRotateTransform : public QAbstractTransform public: explicit QRotateTransform(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - float angleDeg() const; float angleRad() const; QVector3D axis() const; @@ -80,9 +78,11 @@ Q_SIGNALS: void angleChanged(); protected: - Q_DECLARE_PRIVATE(QRotateTransform) QRotateTransform(QRotateTransformPrivate &dd, QNode *parent = 0); - QRotateTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QRotateTransform) + QRotateTransform *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/core/transforms/qrotatetransform_p.h b/src/core/transforms/qrotatetransform_p.h index e4e2cf9df..765fb5ba0 100644 --- a/src/core/transforms/qrotatetransform_p.h +++ b/src/core/transforms/qrotatetransform_p.h @@ -57,6 +57,8 @@ public: Q_DECLARE_PUBLIC(QRotateTransform) + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + float m_angleDeg; QVector3D m_axis; }; diff --git a/src/core/transforms/qscaletransform.cpp b/src/core/transforms/qscaletransform.cpp index 60d711db6..a2cb02358 100644 --- a/src/core/transforms/qscaletransform.cpp +++ b/src/core/transforms/qscaletransform.cpp @@ -53,19 +53,16 @@ QScaleTransformPrivate::QScaleTransformPrivate(QScaleTransform *qq) { } -QScaleTransform::QScaleTransform(QNode *parent) : - QAbstractTransform(*new QScaleTransformPrivate(this), parent) +void QScaleTransformPrivate::copy(const QNodePrivate *ref) { + QAbstractTransformPrivate::copy(ref); + const QScaleTransformPrivate *transform = static_cast<const QScaleTransformPrivate *>(ref); + m_scale3D = transform->m_scale3D; } -void QScaleTransform::copy(const QNode *ref) +QScaleTransform::QScaleTransform(QNode *parent) : + QAbstractTransform(*new QScaleTransformPrivate(this), parent) { - Q_D(QScaleTransform); - QAbstractTransform::copy(ref); - const QScaleTransform *transform = qobject_cast<const QScaleTransform *>(ref); - if (ref != Q_NULLPTR) { - d->m_scale3D = transform->scale3D(); - } } QScaleTransform::QScaleTransform(QScaleTransformPrivate &dd, QNode *parent) @@ -73,11 +70,10 @@ QScaleTransform::QScaleTransform(QScaleTransformPrivate &dd, QNode *parent) { } -QScaleTransform *QScaleTransform::doClone(bool isClone) const +QScaleTransform *QScaleTransform::doClone() const { QScaleTransform *clone = new QScaleTransform(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/core/transforms/qscaletransform.h b/src/core/transforms/qscaletransform.h index 2b6cfd96e..7bd2ccb9b 100644 --- a/src/core/transforms/qscaletransform.h +++ b/src/core/transforms/qscaletransform.h @@ -59,8 +59,6 @@ class QT3DCORESHARED_EXPORT QScaleTransform : public QAbstractTransform public: explicit QScaleTransform(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - QVector3D scale3D() const; void setScale3D(const QVector3D &scale3D); @@ -74,9 +72,11 @@ Q_SIGNALS: void scaleChanged(); protected: - Q_DECLARE_PRIVATE(QScaleTransform) QScaleTransform(QScaleTransformPrivate &dd, QNode *parent = 0); - QScaleTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QScaleTransform) + QScaleTransform *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/core/transforms/qscaletransform_p.h b/src/core/transforms/qscaletransform_p.h index c631b6b54..63f6afa62 100644 --- a/src/core/transforms/qscaletransform_p.h +++ b/src/core/transforms/qscaletransform_p.h @@ -54,6 +54,8 @@ class QScaleTransformPrivate : public QAbstractTransformPrivate public: QScaleTransformPrivate(QScaleTransform *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QScaleTransform) QVector3D m_scale3D; }; diff --git a/src/core/transforms/qtransform.cpp b/src/core/transforms/qtransform.cpp index be83559e0..92b9390ea 100644 --- a/src/core/transforms/qtransform.cpp +++ b/src/core/transforms/qtransform.cpp @@ -41,6 +41,7 @@ #include "qtransform.h" #include "qtransform_p.h" +#include "qabstracttransform_p.h" #include <Qt3DCore/qscenepropertychange.h> #include <qmatrixtransform.h> @@ -57,6 +58,13 @@ QTransformPrivate::QTransformPrivate(QTransform *qq) { } +void QTransformPrivate::copy(const QNodePrivate *ref) +{ + QComponentPrivate::copy(ref); + const QTransformPrivate *transform = static_cast<const QTransformPrivate *>(ref); + m_matrix = transform->m_matrix; +} + QTransform::QTransform(QNode *parent) : Qt3D::QComponent(*new QTransformPrivate(this), parent) { @@ -81,28 +89,18 @@ QTransform::QTransform(QAbstractTransform *transform, QNode *parent) appendTransform(transform); } -void QTransform::copy(const QNode *ref) -{ - Q_D(QTransform); - QComponent::copy(ref); - const QTransform *transform = qobject_cast<const QTransform *>(ref); - if (transform != Q_NULLPTR) { - d->m_matrix = transform->matrix(); - emit matrixChanged(); - } -} - QTransform::QTransform(QTransformPrivate &dd, QNode *parent) : QComponent(dd, parent) { } -QTransform *QTransform::doClone(bool isClone) const +QTransform *QTransform::doClone() const { Q_D(const QTransform); QTransform *clone = new QTransform(); + clone->d_func()->copy(d_func()); Q_FOREACH (QAbstractTransform *t, d->m_transforms) - clone->appendTransform(qobject_cast<QAbstractTransform *>(t->clone())); + clone->appendTransform(qobject_cast<QAbstractTransform *>(QNodePrivate::get(t)->clone())); return clone; } @@ -115,7 +113,7 @@ void QTransform::setTransformsDirty() QScenePropertyChangePtr e(new QScenePropertyChange(ComponentUpdated, this)); e->setPropertyName(QByteArrayLiteral("matrix")); e->setValue(matrix()); - notifyObservers(e); + d->notifyObservers(e); } } emit matrixChanged(); diff --git a/src/core/transforms/qtransform.h b/src/core/transforms/qtransform.h index 8cf18a4da..ea58e15d0 100644 --- a/src/core/transforms/qtransform.h +++ b/src/core/transforms/qtransform.h @@ -64,8 +64,6 @@ public: QTransform(QList<QAbstractTransform *> transforms, QNode *parent = 0); QTransform(QAbstractTransform *transform, QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - QMatrix4x4 matrix() const; void setMatrix(const QMatrix4x4 &m); @@ -96,10 +94,11 @@ Q_SIGNALS: protected: QMatrix4x4 applyTransforms() const; QList<QAbstractTransform *> transformList() const; + QTransform(QTransformPrivate &dd, QNode *parent = 0); +private: Q_DECLARE_PRIVATE(QTransform) - QTransform(QTransformPrivate &dd, QNode *parent = 0); - QTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QTransform *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/core/transforms/qtransform_p.h b/src/core/transforms/qtransform_p.h index ebd490fe0..f8b03dfb1 100644 --- a/src/core/transforms/qtransform_p.h +++ b/src/core/transforms/qtransform_p.h @@ -56,6 +56,8 @@ class QTransformPrivate : public QComponentPrivate public: QTransformPrivate(QTransform *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QTransform) mutable QAtomicInt m_transformsDirty; diff --git a/src/core/transforms/qtranslatetransform.cpp b/src/core/transforms/qtranslatetransform.cpp index 0440fa690..0697fad89 100644 --- a/src/core/transforms/qtranslatetransform.cpp +++ b/src/core/transforms/qtranslatetransform.cpp @@ -57,14 +57,11 @@ QTranslateTransform::QTranslateTransform(QNode *parent) { } -void QTranslateTransform::copy(const QNode *ref) +void QTranslateTransformPrivate::copy(const QNodePrivate *ref) { - Q_D(QTranslateTransform); - QAbstractTransform::copy(ref); - const QTranslateTransform *transform = qobject_cast<const QTranslateTransform *>(ref); - if (transform != Q_NULLPTR) { - d->m_translation = transform->translation(); - } + QAbstractTransformPrivate::copy(ref); + const QTranslateTransformPrivate *transform = static_cast<const QTranslateTransformPrivate *>(ref); + m_translation = transform->m_translation; } @@ -73,11 +70,10 @@ QTranslateTransform::QTranslateTransform(QTranslateTransformPrivate &dd, QNode * { } -QTranslateTransform *QTranslateTransform::doClone(bool isClone) const +QTranslateTransform *QTranslateTransform::doClone() const { QTranslateTransform *clone = new QTranslateTransform(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/core/transforms/qtranslatetransform.h b/src/core/transforms/qtranslatetransform.h index 6994a05b1..e64ba3c15 100644 --- a/src/core/transforms/qtranslatetransform.h +++ b/src/core/transforms/qtranslatetransform.h @@ -65,8 +65,6 @@ class QT3DCORESHARED_EXPORT QTranslateTransform : public QAbstractTransform public: explicit QTranslateTransform(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - float dx() const; float dy() const; float dz() const; @@ -86,9 +84,11 @@ Q_SIGNALS: void translateChanged(); protected: - Q_DECLARE_PRIVATE(QTranslateTransform) QTranslateTransform(QTranslateTransformPrivate &dd, QNode *parent = 0); - QTranslateTransform *doClone(bool isClone) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QTranslateTransform) + QTranslateTransform *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/core/transforms/qtranslatetransform_p.h b/src/core/transforms/qtranslatetransform_p.h index 4c942c644..18a8d3d7e 100644 --- a/src/core/transforms/qtranslatetransform_p.h +++ b/src/core/transforms/qtranslatetransform_p.h @@ -55,6 +55,8 @@ public: QTranslateTransformPrivate(QTranslateTransform *qq); Q_DECLARE_PUBLIC(QTranslateTransform) + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + QVector3D m_translation; }; diff --git a/src/plugins/sceneparsers/assimp/assimpparser.cpp b/src/plugins/sceneparsers/assimp/assimpparser.cpp index ebfad8c7d..9e5a067a5 100644 --- a/src/plugins/sceneparsers/assimp/assimpparser.cpp +++ b/src/plugins/sceneparsers/assimp/assimpparser.cpp @@ -191,7 +191,7 @@ public : private: QMeshDataPtr m_meshData; - AssimpMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + AssimpMesh *doClone() const Q_DECL_OVERRIDE; class AssimpMeshFunctor : public QAbstractMeshFunctor { @@ -208,8 +208,8 @@ private: * Initialized a new instance of AssimpParser. */ AssimpParser::AssimpParser() : AbstractSceneParser(), - m_scene(Q_NULLPTR), - m_sceneParsed(false) + m_sceneParsed(false), + m_scene(Q_NULLPTR) { Assimp::DefaultLogger::create("AssimpLog.txt", Assimp::Logger::VERBOSE); Assimp::DefaultLogger::kill(); @@ -338,8 +338,9 @@ QEntity *AssimpParser::node(aiNode *node) // this-> is necessary here otherwise // it conflicts with the variable node QEntity *child = this->node(node->mChildren[i]); + // Are we sure each child are unique ??? if (child != Q_NULLPTR) - entityNode->addChild(child); + child->setParent(entityNode); } // Add Transformations @@ -350,7 +351,7 @@ QEntity *AssimpParser::node(aiNode *node) // Add Camera if (m_scene->m_cameras.contains(node)) - entityNode->addChild(m_scene->m_cameras.value(node)); + m_scene->m_cameras.value(node)->setParent(entityNode); // TO DO : Add lights .... @@ -830,11 +831,10 @@ void AssimpMesh::setData(QMeshDataPtr data) QAbstractMesh::setDirty(this); } -AssimpMesh *AssimpMesh::doClone(bool isClone) const +AssimpMesh *AssimpMesh::doClone() const { AssimpMesh *clone = new AssimpMesh(); clone->copy(this); - clone->d_func()->m_isClone = isClone; return clone; } diff --git a/src/quick3d/quick3d/items/quick3dnode.cpp b/src/quick3d/quick3d/items/quick3dnode.cpp index 1facd36a3..ed8032a08 100644 --- a/src/quick3d/quick3d/items/quick3dnode.cpp +++ b/src/quick3d/quick3d/items/quick3dnode.cpp @@ -113,7 +113,7 @@ void Quick3DNode::appendChild(QQmlListProperty<Qt3D::QNode> *list, Qt3D::QNode * Qt3D::QNode *Quick3DNode::childAt(QQmlListProperty<Qt3D::QNode> *list, int index) { Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - return self->parentNode()->children().at(index); + return qobject_cast<QNode *>(self->parentNode()->children().at(index)); } int Quick3DNode::childCount(QQmlListProperty<Qt3D::QNode> *list) @@ -125,31 +125,24 @@ int Quick3DNode::childCount(QQmlListProperty<Qt3D::QNode> *list) void Quick3DNode::clearChildren(QQmlListProperty<Qt3D::QNode> *list) { Quick3DNode *self = static_cast<Quick3DNode *>(list->object); - Q_FOREACH (QNode *const child, self->parentNode()->children()) + Q_FOREACH (QObject *const child, self->parentNode()->children()) self->childRemoved(0, child); } void Quick3DNode::childAppended(int, QObject *obj) { QNode *parentNode = this->parentNode(); - QNode *node = qobject_cast<Qt3D::QNode *>(obj); if (obj->parent() == parentNode) obj->setParent(0); - if (node && parentNode) { - // Set parent is set in appendChild - parentNode->addChild(node); - } // Set after otherwise addChild might not work obj->setParent(parentNode); } void Quick3DNode::childRemoved(int, QObject *obj) { - QNode *parentNode = this->parentNode(); QNode *node = qobject_cast<Qt3D::QNode *>(obj); - if (node && parentNode) { - parentNode->removeChild(node); - } + if (node) + node->setParent(Q_NULLPTR); } } // Quick diff --git a/src/quick3d/quick3drenderer/items/quick3dparameter.cpp b/src/quick3d/quick3drenderer/items/quick3dparameter.cpp index 336d067f3..70583d25f 100644 --- a/src/quick3d/quick3drenderer/items/quick3dparameter.cpp +++ b/src/quick3d/quick3drenderer/items/quick3dparameter.cpp @@ -94,12 +94,13 @@ Quick3DParameter::Quick3DParameter(Quick3DParameterPrivate &dd, QNode *parent) { } -Quick3DParameter *Quick3DParameter::doClone(bool isClone) const +Quick3DParameter *Quick3DParameter::doClone() const { - return new Quick3DParameter(); + Quick3DParameter *clone = new Quick3DParameter(); + clone->d_func()->copy(d_func()); + return clone; } - } // Quick } // Render diff --git a/src/quick3d/quick3drenderer/items/quick3dparameter.h b/src/quick3d/quick3drenderer/items/quick3dparameter.h index 9fcb77f6a..403fcefbc 100644 --- a/src/quick3d/quick3drenderer/items/quick3dparameter.h +++ b/src/quick3d/quick3drenderer/items/quick3dparameter.h @@ -66,7 +66,7 @@ private: protected: Quick3DParameter(Quick3DParameterPrivate &dd, QNode *parent = 0); - Quick3DParameter *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + Quick3DParameter *doClone() const Q_DECL_OVERRIDE; }; } // Quick diff --git a/src/render/backend/attachmentpack_p.h b/src/render/backend/attachmentpack_p.h index ecae12ddb..25ee8e30c 100644 --- a/src/render/backend/attachmentpack_p.h +++ b/src/render/backend/attachmentpack_p.h @@ -42,7 +42,8 @@ #ifndef QT3D_RENDER_ATTACHMENTPACK_P_H #define QT3D_RENDER_ATTACHMENTPACK_P_H -#include <Qt3DRenderer/QRenderAttachment> +#include <Qt3DRenderer/qrenderattachment.h> +#include <QVector> QT_BEGIN_NAMESPACE diff --git a/src/render/backend/rendercameralens.cpp b/src/render/backend/rendercameralens.cpp index a169a6c5a..c116c63a0 100644 --- a/src/render/backend/rendercameralens.cpp +++ b/src/render/backend/rendercameralens.cpp @@ -49,6 +49,7 @@ #include <Qt3DCore/qaspectmanager.h> #include <Qt3DCore/qscenepropertychange.h> #include <Qt3DRenderer/private/renderer_p.h> +#include <Qt3DCore/qchangearbiter.h> #include <QOpenGLContext> diff --git a/src/render/backend/renderer_p.h b/src/render/backend/renderer_p.h index 7f1581a5b..ad5f5f93d 100644 --- a/src/render/backend/renderer_p.h +++ b/src/render/backend/renderer_p.h @@ -60,6 +60,7 @@ #include <QWaitCondition> #include <QAtomicInt> #include <QScopedPointer> +#include <QThreadStorage> QT_BEGIN_NAMESPACE diff --git a/src/render/backend/renderscenebuilder.cpp b/src/render/backend/renderscenebuilder.cpp index e0a5d5ad4..4df476cf2 100644 --- a/src/render/backend/renderscenebuilder.cpp +++ b/src/render/backend/renderscenebuilder.cpp @@ -108,6 +108,7 @@ namespace Render { RenderSceneBuilder::RenderSceneBuilder(Renderer *renderer) : Qt3D::NodeVisitor() , m_renderer(renderer) + , m_frameGraphRoot(Q_NULLPTR) { } @@ -122,7 +123,7 @@ void RenderSceneBuilder::initializeFrameGraph() // References that the FrameGraphItem may be usings have been inserted // Into the scenegraph // Retrieve and set Renderer FrameGraph - QFrameGraph *fg = QEntity::findComponentInTree<QFrameGraph>(m_renderer->sceneGraphRoot()); + QFrameGraph *fg = m_frameGraphRoot; Q_ASSERT_X(fg, Q_FUNC_INFO, "No FrameGraph component found. The FrameGraph defines the renderer configuration. Cannot continue"); // m_frameGraphEntityNode = m_renderer->renderNodesManager()->lookupHandle(fg->parentNode()->asEntity()->uuid()); // createFrameGraph(fg); @@ -191,12 +192,13 @@ void RenderSceneBuilder::createRenderElement(QNode *frontend) RenderEntity *rEntity = createRenderNode(entity); if (parentEntity) rEntity->setParentHandle(m_renderer->renderNodesManager()->lookupHandle(parentEntity->uuid())); + if (m_rootNodeHandle.isNull()) m_rootNodeHandle = rEntity->handle(); } else if (qobject_cast<QTransform *>(frontend)) { createRenderElementHelper<QTransform, RenderTransform, TransformManager>(frontend, - m_renderer->transformManager()); + m_renderer->transformManager()); } else if (qobject_cast<QAbstractMesh *>(frontend)) { createRenderElementHelper<QAbstractMesh, RenderMesh, MeshManager>(frontend, @@ -236,7 +238,7 @@ void RenderSceneBuilder::createRenderElement(QNode *frontend) } else if (qobject_cast<QAbstractSceneLoader *>(frontend)) { createRenderElementHelper<QAbstractSceneLoader, RenderScene, SceneManager>(frontend, - m_renderer->sceneManager()); + m_renderer->sceneManager()); } else if (qobject_cast<QTexture *>(frontend)) { createRenderElementHelper<QTexture, RenderTexture, TextureManager>(frontend, @@ -309,6 +311,31 @@ void RenderSceneBuilder::releaseRenderElement(QNode *frontend) m_renderer->sortCriterionManager()->releaseResource(frontend->uuid()); } +void RenderSceneBuilder::insertNodeTree(QNode *nd) +{ + if (nd != Q_NULLPTR) { + createRenderElement(nd); + Q_FOREACH (QObject *c, nd->children()) { + QNode *n = qobject_cast<QNode *>(c); + if (n != Q_NULLPTR) + createRenderElement(n); + } + } +} + +void RenderSceneBuilder::releaseNodeTree(QNode *nd) +{ + if (nd != Q_NULLPTR) { + Q_FOREACH (QObject *c, nd->children()) { + QNode *n = qobject_cast<QNode *>(c); + if (n != Q_NULLPTR) { + releaseRenderElement(n); + } + } + releaseRenderElement(nd); + } +} + RenderEntity* RenderSceneBuilder::createRenderNode(QEntity *entity) { HRenderNode renderNodeHandle; @@ -318,12 +345,30 @@ RenderEntity* RenderSceneBuilder::createRenderNode(QEntity *entity) rEntity->setRenderer(m_renderer); rEntity->setPeer(entity); - QList<QTransform *> transforms = entity->componentsOfType<QTransform>(); - QList<QMaterial *> materials = entity->componentsOfType<QMaterial>(); - QList<QAbstractMesh *> meshes = entity->componentsOfType<QAbstractMesh>(); - QList<QCameraLens *> lenses = entity->componentsOfType<QCameraLens>(); - QList<QLayer *> layers = entity->componentsOfType<QLayer>(); - QList<QAbstractLight *> lights = entity->componentsOfType<QAbstractLight>(); + QList<QTransform *> transforms; + QList<QMaterial *> materials; + QList<QAbstractMesh *> meshes; + QList<QCameraLens *> lenses; + QList<QLayer *> layers; + QList<QAbstractLight *> lights; + + Q_FOREACH (QComponent *c, entity->components()) { + // TO DO: switch based on typeId + if (qobject_cast<QTransform *>(c)) + transforms << qobject_cast<QTransform *>(c); + else if (qobject_cast<QMaterial *>(c)) + materials << qobject_cast<QMaterial *>(c); + else if (qobject_cast<QAbstractMesh *>(c)) + meshes << qobject_cast<QAbstractMesh *>(c); + else if (qobject_cast<QCameraLens *>(c)) + lenses << qobject_cast<QCameraLens *>(c); + else if (qobject_cast<QLayer *>(c)) + layers << qobject_cast<QLayer *>(c); + else if (qobject_cast<QAbstractLight *>(c)) + lights << qobject_cast<QAbstractLight *>(c); + else if (qobject_cast<QFrameGraph *>(c)) + m_frameGraphRoot = qobject_cast<QFrameGraph *>(c); + } // Retrieve Transform from Entity if (!transforms.isEmpty()) { diff --git a/src/render/backend/renderscenebuilder_p.h b/src/render/backend/renderscenebuilder_p.h index 22da59b5b..7dec3f6ad 100644 --- a/src/render/backend/renderscenebuilder_p.h +++ b/src/render/backend/renderscenebuilder_p.h @@ -79,6 +79,9 @@ public: void createRenderElement(QNode *frontend); void releaseRenderElement(QNode *frontend); + void insertNodeTree(QNode *nd); + void releaseNodeTree(QNode *nd); + protected: void visitNode(QNode *nd) Q_DECL_OVERRIDE; diff --git a/src/render/backend/rendersceneobserver.cpp b/src/render/backend/rendersceneobserver.cpp index d001ec72a..1a23e2643 100644 --- a/src/render/backend/rendersceneobserver.cpp +++ b/src/render/backend/rendersceneobserver.cpp @@ -65,7 +65,7 @@ void RenderSceneObserver::sceneNodeAdded(QSceneChangePtr &e) if (m_renderer) { QScenePropertyChangePtr propertyChange = e.staticCast<QScenePropertyChange>(); QNode *n = propertyChange->value().value<QNodePtr>().data(); - m_renderer->renderSceneBuilder()->createRenderElement(n); + m_renderer->renderSceneBuilder()->insertNodeTree(n); } } @@ -74,7 +74,7 @@ void RenderSceneObserver::sceneNodeRemoved(QSceneChangePtr &e) if (m_renderer) { QScenePropertyChangePtr propertyChange = e.staticCast<QScenePropertyChange>(); QNode *n = propertyChange->value().value<QNodePtr>().data(); - m_renderer->renderSceneBuilder()->releaseRenderElement(n); + m_renderer->renderSceneBuilder()->releaseNodeTree(n); } } diff --git a/src/render/backend/rendershader_p.h b/src/render/backend/rendershader_p.h index 3ede14d49..69e51a1ae 100644 --- a/src/render/backend/rendershader_p.h +++ b/src/render/backend/rendershader_p.h @@ -49,6 +49,7 @@ #include <Qt3DRenderer/qparameter.h> #include <Qt3DRenderer/private/quniformvalue_p.h> #include <Qt3DRenderer/private/shadervariables_p.h> +#include <Qt3DCore/qobserverinterface.h> QT_BEGIN_NAMESPACE diff --git a/src/render/backend/rendertexture_p.h b/src/render/backend/rendertexture_p.h index fece88708..3cc803502 100644 --- a/src/render/backend/rendertexture_p.h +++ b/src/render/backend/rendertexture_p.h @@ -46,6 +46,7 @@ #include <Qt3DRenderer/qtexture.h> #include <Qt3DRenderer/texturedata.h> +#include <Qt3DCore/qobserverinterface.h> QT_BEGIN_NAMESPACE diff --git a/src/render/frontend/framegraph-components/qcameraselector.cpp b/src/render/frontend/framegraph-components/qcameraselector.cpp index 3097e7fac..36429956f 100644 --- a/src/render/frontend/framegraph-components/qcameraselector.cpp +++ b/src/render/frontend/framegraph-components/qcameraselector.cpp @@ -42,6 +42,7 @@ #include "qcameraselector.h" #include "qcameraselector_p.h" #include <Qt3DCore/qentity.h> +#include <Qt3DCore/private/qentity_p.h> #include <Qt3DCore/qscenepropertychange.h> QT_BEGIN_NAMESPACE @@ -53,19 +54,18 @@ QCameraSelector::QCameraSelector(QCameraSelectorPrivate &dd, QNode *parent) { } -QCameraSelector *QCameraSelector::doClone(bool isClone) const +QCameraSelector *QCameraSelector::doClone() const { Q_D(const QCameraSelector); QCameraSelector *cameraSelector = new QCameraSelector(); - cameraSelector->copy(this); - cameraSelector->d_func()->m_isClone = isClone; + cameraSelector->d_func()->copy(d_func()); Q_FOREACH (QFrameGraphItem *fgChild, d->m_fgChildren) - cameraSelector->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(fgChild->clone(isClone))); + cameraSelector->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(QNodePrivate::get(fgChild)->clone())); if (d->m_camera != Q_NULLPTR) - cameraSelector->setCamera(qobject_cast<QEntity *>(d->m_camera->clone(isClone))); + cameraSelector->setCamera(qobject_cast<QEntity *>(QNodePrivate::get(d->m_camera)->clone())); return cameraSelector; } @@ -90,13 +90,13 @@ void QCameraSelector::setCamera(QEntity *camera) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!camera->parent() || camera->parent() == this) - QNode::addChild(camera); + if (!camera->parent()) + camera->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("camera")); propertyChange->setValue(QVariant::fromValue(d->m_camera->uuid())); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } diff --git a/src/render/frontend/framegraph-components/qcameraselector.h b/src/render/frontend/framegraph-components/qcameraselector.h index 1b26816a9..cc20c0831 100644 --- a/src/render/frontend/framegraph-components/qcameraselector.h +++ b/src/render/frontend/framegraph-components/qcameraselector.h @@ -69,7 +69,7 @@ Q_SIGNALS: protected: Q_DECLARE_PRIVATE(QCameraSelector) QCameraSelector(QCameraSelectorPrivate &dd, QNode *parent = 0); - QCameraSelector *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QCameraSelector *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/render/frontend/framegraph-components/qclearbuffer.cpp b/src/render/frontend/framegraph-components/qclearbuffer.cpp index 6e9ad4383..77370d53c 100644 --- a/src/render/frontend/framegraph-components/qclearbuffer.cpp +++ b/src/render/frontend/framegraph-components/qclearbuffer.cpp @@ -53,6 +53,13 @@ QClearBufferPrivate::QClearBufferPrivate(QClearBuffer *qq) { } +void QClearBufferPrivate::copy(const QNodePrivate *ref) +{ + QFrameGraphItemPrivate::copy(ref); + const QClearBufferPrivate *b = static_cast<const QClearBufferPrivate *>(ref); + m_buffersType = b->m_buffersType; +} + QClearBuffer::QClearBuffer(QNode *parent) : QFrameGraphItem(*new QClearBufferPrivate(this), parent) { @@ -63,14 +70,6 @@ QClearBuffer::QClearBuffer(QClearBufferPrivate &dd, QNode *parent) { } -void QClearBuffer::copy(const QNode *ref) -{ - Q_D(QClearBuffer); - QFrameGraphItem::copy(ref); - const QClearBuffer *b = qobject_cast<const QClearBuffer *>(ref); - if (b != Q_NULLPTR) - d->m_buffersType = b->buffers(); -} QClearBuffer::BufferType QClearBuffer::buffers() const { @@ -79,11 +78,15 @@ QClearBuffer::BufferType QClearBuffer::buffers() const } -QClearBuffer *QClearBuffer::doClone(bool isClone) const +QClearBuffer *QClearBuffer::doClone() const { + Q_D(const QClearBuffer); QClearBuffer *clone = new QClearBuffer(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); + + Q_FOREACH (QFrameGraphItem *fgChild, d->m_fgChildren) + clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(QNodePrivate::get(fgChild)->clone())); + return clone; } @@ -98,7 +101,7 @@ void QClearBuffer::setBuffers(QClearBuffer::BufferType buffers) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("buffers")); propertyChange->setValue(buffers); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } diff --git a/src/render/frontend/framegraph-components/qclearbuffer.h b/src/render/frontend/framegraph-components/qclearbuffer.h index 492880917..8fdf9c926 100644 --- a/src/render/frontend/framegraph-components/qclearbuffer.h +++ b/src/render/frontend/framegraph-components/qclearbuffer.h @@ -69,8 +69,6 @@ public: AllBuffers = 0xFFFFFFFF }; - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setBuffers(BufferType buffers); BufferType buffers() const; @@ -78,9 +76,11 @@ Q_SIGNALS: void buffersChanged(); protected: - Q_DECLARE_PRIVATE(QClearBuffer) QClearBuffer(QClearBufferPrivate &dd, QNode *parent = 0); - QClearBuffer *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QClearBuffer) + QClearBuffer *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/framegraph-components/qclearbuffer_p.h b/src/render/frontend/framegraph-components/qclearbuffer_p.h index 90d4e8be4..eb6a064c1 100644 --- a/src/render/frontend/framegraph-components/qclearbuffer_p.h +++ b/src/render/frontend/framegraph-components/qclearbuffer_p.h @@ -53,6 +53,9 @@ class QClearBufferPrivate : public QFrameGraphItemPrivate { public: QClearBufferPrivate(QClearBuffer *qq); + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QClearBuffer) QClearBuffer::BufferType m_buffersType; }; diff --git a/src/render/frontend/framegraph-components/qframegraph.cpp b/src/render/frontend/framegraph-components/qframegraph.cpp index 090577906..0e6f9ac9b 100644 --- a/src/render/frontend/framegraph-components/qframegraph.cpp +++ b/src/render/frontend/framegraph-components/qframegraph.cpp @@ -43,6 +43,7 @@ #include "qframegraph_p.h" #include <Qt3DCore/qentity.h> #include <Qt3DRenderer/qframegraphitem.h> +#include <Qt3DRenderer/private/qframegraphitem_p.h> QT_BEGIN_NAMESPACE @@ -79,14 +80,13 @@ QFrameGraph::QFrameGraph(QFrameGraphPrivate &dd, QNode *parent) { } -QFrameGraph *QFrameGraph::doClone(bool isClone) const +QFrameGraph *QFrameGraph::doClone() const { Q_D(const QFrameGraph); QFrameGraph *frameGraph = new QFrameGraph(); - frameGraph->copy(this); - frameGraph->d_func()->m_isClone = isClone; + frameGraph->d_func()->copy(d_func()); - frameGraph->setActiveFrameGraph(qobject_cast<QFrameGraphItem *>(d->m_activeFrameGraph->clone(isClone))); + frameGraph->setActiveFrameGraph(qobject_cast<QFrameGraphItem *>(QNodePrivate::get(d->m_activeFrameGraph)->clone())); return frameGraph; } @@ -110,8 +110,8 @@ void QFrameGraph::setActiveFrameGraph(QFrameGraphItem *activeFrameGraph) d->m_activeFrameGraph = activeFrameGraph; emit activeFrameGraphChanged(); - if (!activeFrameGraph->parent() || activeFrameGraph->parent() == this) - QNode::addChild(activeFrameGraph); + if (!activeFrameGraph->parent()) + activeFrameGraph->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { // TO DO : Add QChangeArbiterNotification diff --git a/src/render/frontend/framegraph-components/qframegraph.h b/src/render/frontend/framegraph-components/qframegraph.h index 6a4706c47..df7c3938e 100644 --- a/src/render/frontend/framegraph-components/qframegraph.h +++ b/src/render/frontend/framegraph-components/qframegraph.h @@ -70,9 +70,11 @@ Q_SIGNALS: void activeFrameGraphChanged(); protected: - Q_DECLARE_PRIVATE(QFrameGraph) QFrameGraph(QFrameGraphPrivate &dd, QNode *parent = 0); - QFrameGraph *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QFrameGraph) + QFrameGraph *doClone() const Q_DECL_OVERRIDE; }; } //Qt3D diff --git a/src/render/frontend/framegraph-components/qframegraphitem.cpp b/src/render/frontend/framegraph-components/qframegraphitem.cpp index be5fb7d1c..684772c4b 100644 --- a/src/render/frontend/framegraph-components/qframegraphitem.cpp +++ b/src/render/frontend/framegraph-components/qframegraphitem.cpp @@ -64,6 +64,11 @@ QFrameGraphItemPrivate::QFrameGraphItemPrivate(QFrameGraphItem *qq) { } +void QFrameGraphItemPrivate::copy(const QNodePrivate *ref) +{ + QNodePrivate::copy(ref); +} + QFrameGraphItem::QFrameGraphItem(QNode *parent) : QNode(*new QFrameGraphItemPrivate(this), parent) { @@ -74,26 +79,12 @@ QFrameGraphItem::QFrameGraphItem(QFrameGraphItemPrivate &dd, QNode *parent) { } -void QFrameGraphItem::setEnabled(bool enabled) -{ - Q_D(QFrameGraphItem); - if (d->m_enabled != enabled) { - d->m_enabled = enabled; - emit enabledChanged(); - } -} - -bool QFrameGraphItem::isEnabled() const -{ - Q_D(const QFrameGraphItem); - return d->m_enabled; -} - void QFrameGraphItem::appendFrameGraphItem(QFrameGraphItem *item) { Q_D(QFrameGraphItem); if (!d->m_fgChildren.contains(item)) { - QNode::addChild(item); + if (!item->parent()) + item->setParent(this); d->m_fgChildren.append(item); } } @@ -103,7 +94,6 @@ void QFrameGraphItem::removeFrameGraphItem(QFrameGraphItem *item) Q_D(QFrameGraphItem); if (!d->m_fgChildren.contains(item)) { d->m_fgChildren.removeOne(item); - QNode::removeChild(item); } } diff --git a/src/render/frontend/framegraph-components/qframegraphitem.h b/src/render/frontend/framegraph-components/qframegraphitem.h index ba8b5a604..857914649 100644 --- a/src/render/frontend/framegraph-components/qframegraphitem.h +++ b/src/render/frontend/framegraph-components/qframegraphitem.h @@ -58,19 +58,15 @@ class QT3DRENDERERSHARED_EXPORT QFrameGraphItem : public QNode public: explicit QFrameGraphItem(QNode *parent = 0); - void setEnabled(bool enabled); - bool isEnabled() const; - void appendFrameGraphItem(QFrameGraphItem *item); void removeFrameGraphItem(QFrameGraphItem *item); QList<QFrameGraphItem *> frameGraphChildren() const; -Q_SIGNALS: - void enabledChanged(); - protected: - Q_DECLARE_PRIVATE(QFrameGraphItem) QFrameGraphItem(QFrameGraphItemPrivate &dd, QNode *parent = 0); + +private: + Q_DECLARE_PRIVATE(QFrameGraphItem) }; } // Qt3D diff --git a/src/render/frontend/framegraph-components/qframegraphitem_p.h b/src/render/frontend/framegraph-components/qframegraphitem_p.h index c889eba7d..3dbae8a16 100644 --- a/src/render/frontend/framegraph-components/qframegraphitem_p.h +++ b/src/render/frontend/framegraph-components/qframegraphitem_p.h @@ -57,6 +57,8 @@ class QFrameGraphItemPrivate : public QNodePrivate public: QFrameGraphItemPrivate(QFrameGraphItem *qq); + virtual void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QFrameGraphItem) bool m_enabled; QList<QFrameGraphItem *> m_fgChildren; diff --git a/src/render/frontend/framegraph-components/qlayerfilter.cpp b/src/render/frontend/framegraph-components/qlayerfilter.cpp index 2117980a2..e9a7f9621 100644 --- a/src/render/frontend/framegraph-components/qlayerfilter.cpp +++ b/src/render/frontend/framegraph-components/qlayerfilter.cpp @@ -52,37 +52,32 @@ QLayerFilterPrivate::QLayerFilterPrivate(QLayerFilter *qq) { } -QLayerFilter::QLayerFilter(QNode *parent) - : QFrameGraphItem(*new QLayerFilterPrivate(this), parent) +void QLayerFilterPrivate::copy(const QNodePrivate *ref) { + QFrameGraphItemPrivate::copy(ref); + const QLayerFilterPrivate *layer = static_cast<const QLayerFilterPrivate *>(ref); + m_layers = layer->m_layers; } -void QLayerFilter::copy(const QNode *ref) +QLayerFilter::QLayerFilter(QNode *parent) + : QFrameGraphItem(*new QLayerFilterPrivate(this), parent) { - Q_D(QLayerFilter); - QFrameGraphItem::copy(ref); - const QLayerFilter *layer = qobject_cast<const QLayerFilter *>(ref); - if (layer != Q_NULLPTR) { - d->m_layers = layer->layers(); - } } - QLayerFilter::QLayerFilter(QLayerFilterPrivate &dd, QNode *parent) : QFrameGraphItem(dd, parent) { } -QLayerFilter *QLayerFilter::doClone(bool isClone) const +QLayerFilter *QLayerFilter::doClone() const { Q_D(const QLayerFilter); QLayerFilter *filter = new QLayerFilter(); - filter->copy(this); - filter->d_func()->m_isClone = isClone; + filter->d_func()->copy(d_func()); Q_FOREACH (QFrameGraphItem *fgChild, d->m_fgChildren) - filter->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(fgChild->clone(isClone))); + filter->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(QNodePrivate::get(fgChild)->clone())); return filter; } @@ -98,7 +93,7 @@ void QLayerFilter::setLayers(const QStringList &layers) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("layers")); propertyChange->setValue(QVariant::fromValue(d->m_layers)); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } diff --git a/src/render/frontend/framegraph-components/qlayerfilter.h b/src/render/frontend/framegraph-components/qlayerfilter.h index ed6b74e61..983fc305a 100644 --- a/src/render/frontend/framegraph-components/qlayerfilter.h +++ b/src/render/frontend/framegraph-components/qlayerfilter.h @@ -43,6 +43,7 @@ #define QT3D_QLAYERFILTER_H #include <Qt3DRenderer/qframegraphitem.h> +#include <QStringList> QT_BEGIN_NAMESPACE @@ -57,8 +58,6 @@ class QT3DRENDERERSHARED_EXPORT QLayerFilter : public QFrameGraphItem public: explicit QLayerFilter(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setLayers(const QStringList &layers); QStringList layers() const; @@ -66,9 +65,11 @@ Q_SIGNALS: void layersChanged(); protected: - Q_DECLARE_PRIVATE(QLayerFilter) QLayerFilter(QLayerFilterPrivate &dd, QNode *parent = 0); - QLayerFilter *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QLayerFilter) + QLayerFilter *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/framegraph-components/qlayerfilter_p.h b/src/render/frontend/framegraph-components/qlayerfilter_p.h index 32405fff6..56f3a988e 100644 --- a/src/render/frontend/framegraph-components/qlayerfilter_p.h +++ b/src/render/frontend/framegraph-components/qlayerfilter_p.h @@ -56,6 +56,8 @@ class QT3DRENDERERSHARED_EXPORT QLayerFilterPrivate : public QFrameGraphItemPriv public: explicit QLayerFilterPrivate(QLayerFilter *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QLayerFilter) QStringList m_layers; }; diff --git a/src/render/frontend/framegraph-components/qrenderpassfilter.cpp b/src/render/frontend/framegraph-components/qrenderpassfilter.cpp index 14f260e05..37df2cf69 100644 --- a/src/render/frontend/framegraph-components/qrenderpassfilter.cpp +++ b/src/render/frontend/framegraph-components/qrenderpassfilter.cpp @@ -43,6 +43,7 @@ #include "qrenderpassfilter_p.h" #include "qcriterion.h" +#include "qcriterion_p.h" #include <Qt3DCore/qscenepropertychange.h> QT_BEGIN_NAMESPACE @@ -58,18 +59,17 @@ QRenderPassFilter::QRenderPassFilter(QRenderPassFilterPrivate &dd, QNode *parent { } -QRenderPassFilter *QRenderPassFilter::doClone(bool isClone) const +QRenderPassFilter *QRenderPassFilter::doClone() const { Q_D(const QRenderPassFilter); QRenderPassFilter *clone = new QRenderPassFilter(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); Q_FOREACH (QFrameGraphItem *fgChild, d->m_fgChildren) - clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(fgChild->clone(isClone))); + clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(QNodePrivate::get(fgChild)->clone())); Q_FOREACH (QCriterion *c, d->m_criteriaList) - clone->addCriterion(qobject_cast<QCriterion *>(c->clone(isClone))); + clone->addCriterion(qobject_cast<QCriterion *>(QNodePrivate::get(c)->clone())); return clone; } @@ -90,14 +90,14 @@ void QRenderPassFilter::addCriterion(QCriterion *criterion) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!criterion->parent() || criterion->parent() == this) - QNode::addChild(criterion); + if (!criterion->parent()) + criterion->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeAdded, this)); propertyChange->setPropertyName(QByteArrayLiteral("renderPassCriterion")); propertyChange->setValue(QVariant::fromValue(criterion)); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -109,7 +109,7 @@ void QRenderPassFilter::removeCriterion(QCriterion *criterion) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeRemoved, this)); propertyChange->setPropertyName(QByteArrayLiteral("renderPassCriterion")); propertyChange->setValue(QVariant::fromValue(criterion)); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } d->m_criteriaList.removeOne(criterion); } diff --git a/src/render/frontend/framegraph-components/qrenderpassfilter.h b/src/render/frontend/framegraph-components/qrenderpassfilter.h index cca5d71cf..e7e663368 100644 --- a/src/render/frontend/framegraph-components/qrenderpassfilter.h +++ b/src/render/frontend/framegraph-components/qrenderpassfilter.h @@ -66,9 +66,11 @@ public: void removeCriterion(QCriterion *criterion); protected: - Q_DECLARE_PRIVATE(QRenderPassFilter) QRenderPassFilter(QRenderPassFilterPrivate &dd, QNode *parent = 0); - QRenderPassFilter *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QRenderPassFilter) + QRenderPassFilter *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/render/frontend/framegraph-components/qrendertargetselector.cpp b/src/render/frontend/framegraph-components/qrendertargetselector.cpp index c3f5a21aa..89cf7d126 100644 --- a/src/render/frontend/framegraph-components/qrendertargetselector.cpp +++ b/src/render/frontend/framegraph-components/qrendertargetselector.cpp @@ -43,6 +43,7 @@ #include "qrendertargetselector_p.h" #include <Qt3DRenderer/qrendertarget.h> #include <Qt3DCore/qscenepropertychange.h> +#include <Qt3DRenderer/private/qrenderpass_p.h> QT_BEGIN_NAMESPACE @@ -67,14 +68,14 @@ void QRenderTargetSelector::setTarget(QRenderTarget *target) emit targetChanged(); // For inline declaration cases - if (!target->parent() || target->parent() == this) - QNode::addChild(target); + if (!target->parent()) + target->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("target")); propertyChange->setValue(QVariant::fromValue(target->uuid())); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -90,19 +91,18 @@ QRenderTargetSelector::QRenderTargetSelector(QRenderTargetSelectorPrivate &dd, Q { } -QRenderTargetSelector *QRenderTargetSelector::doClone(bool isClone) const +QRenderTargetSelector *QRenderTargetSelector::doClone() const { Q_D(const QRenderTargetSelector); QRenderTargetSelector *clone = new QRenderTargetSelector(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); Q_FOREACH (QFrameGraphItem *fgChild, d->m_fgChildren) - clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(fgChild->clone(isClone))); + clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(QNodePrivate::get(fgChild)->clone())); if (d->m_target != Q_NULLPTR) - clone->setTarget(qobject_cast<QRenderTarget *>(d->m_target->clone(clone))); + clone->setTarget(qobject_cast<QRenderTarget *>(QNodePrivate::get(d->m_target)->clone())); return clone; } diff --git a/src/render/frontend/framegraph-components/qrendertargetselector.h b/src/render/frontend/framegraph-components/qrendertargetselector.h index 308e09807..5205e19e6 100644 --- a/src/render/frontend/framegraph-components/qrendertargetselector.h +++ b/src/render/frontend/framegraph-components/qrendertargetselector.h @@ -67,9 +67,11 @@ Q_SIGNALS: void targetChanged(); protected: - Q_DECLARE_PRIVATE(QRenderTargetSelector) QRenderTargetSelector(QRenderTargetSelectorPrivate &dd, QNode *parent = 0); - QRenderTargetSelector *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QRenderTargetSelector) + QRenderTargetSelector *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/framegraph-components/qsortcriterion.cpp b/src/render/frontend/framegraph-components/qsortcriterion.cpp index f219e5d97..5584839c4 100644 --- a/src/render/frontend/framegraph-components/qsortcriterion.cpp +++ b/src/render/frontend/framegraph-components/qsortcriterion.cpp @@ -53,18 +53,16 @@ QSortCriterionPrivate::QSortCriterionPrivate(QSortCriterion *qq) { } -QSortCriterion::QSortCriterion(QNode *parent) - : QNode(*new QSortCriterionPrivate(this), parent) +void QSortCriterionPrivate::copy(const QNodePrivate *ref) { + QNodePrivate::copy(ref); + const QSortCriterionPrivate *s = static_cast<const QSortCriterionPrivate *>(ref); + m_sort = s->m_sort; } -void QSortCriterion::copy(const QNode *ref) +QSortCriterion::QSortCriterion(QNode *parent) + : QNode(*new QSortCriterionPrivate(this), parent) { - Q_D(QSortCriterion); - QNode::copy(ref); - const QSortCriterion *s = qobject_cast<const QSortCriterion *>(ref); - if (s != Q_NULLPTR) - d->m_sort = s->sort(); } QSortCriterion::SortType QSortCriterion::sort() const @@ -82,7 +80,7 @@ void QSortCriterion::setSort(QSortCriterion::SortType &sort) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("sort")); propertyChange->setValue(d->m_sort); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } d->m_sort = sort; @@ -92,7 +90,7 @@ void QSortCriterion::setSort(QSortCriterion::SortType &sort) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("sort")); propertyChange->setValue(d->m_sort); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -102,11 +100,10 @@ QSortCriterion::QSortCriterion(QSortCriterionPrivate &dd, QNode *parent) { } -QSortCriterion *QSortCriterion::doClone(bool isClone) const +QSortCriterion *QSortCriterion::doClone() const { QSortCriterion *clone = new QSortCriterion(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/framegraph-components/qsortcriterion.h b/src/render/frontend/framegraph-components/qsortcriterion.h index 39cac29b7..130980c89 100644 --- a/src/render/frontend/framegraph-components/qsortcriterion.h +++ b/src/render/frontend/framegraph-components/qsortcriterion.h @@ -65,8 +65,6 @@ public: Material = (1 << 2) }; - void copy(const QNode *ref) Q_DECL_OVERRIDE; - SortType sort() const; void setSort(SortType &sort); @@ -74,10 +72,11 @@ Q_SIGNALS: void sortChanged(); protected: - Q_DECLARE_PRIVATE(QSortCriterion) QSortCriterion(QSortCriterionPrivate &dd, QNode *parent = 0); - QSortCriterion *doClone(bool isClone = true) const Q_DECL_OVERRIDE; +private: + QSortCriterion *doClone() const Q_DECL_OVERRIDE; + Q_DECLARE_PRIVATE(QSortCriterion) }; } // Qt3D diff --git a/src/render/frontend/framegraph-components/qsortcriterion_p.h b/src/render/frontend/framegraph-components/qsortcriterion_p.h index bde637488..1ba2e9271 100644 --- a/src/render/frontend/framegraph-components/qsortcriterion_p.h +++ b/src/render/frontend/framegraph-components/qsortcriterion_p.h @@ -54,6 +54,8 @@ class QSortCriterionPrivate : public QNodePrivate public: QSortCriterionPrivate(QSortCriterion *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QSortCriterion) QSortCriterion::SortType m_sort; }; diff --git a/src/render/frontend/framegraph-components/qsortmethod.cpp b/src/render/frontend/framegraph-components/qsortmethod.cpp index 39671af84..f71b09f68 100644 --- a/src/render/frontend/framegraph-components/qsortmethod.cpp +++ b/src/render/frontend/framegraph-components/qsortmethod.cpp @@ -41,6 +41,7 @@ #include "qsortmethod.h" #include "qsortmethod_p.h" +#include "qsortcriterion_p.h" #include <Qt3DCore/qscenepropertychange.h> #include <Qt3DRenderer/qsortcriterion.h> @@ -63,16 +64,15 @@ QSortMethod::QSortMethod(QSortMethodPrivate &dd, QNode *parent) { } -QSortMethod *QSortMethod::doClone(bool isClone) const +QSortMethod *QSortMethod::doClone() const { Q_D(const QSortMethod); QSortMethod *clone = new QSortMethod(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); Q_FOREACH (QSortCriterion *c, d->m_criteria) - clone->addCriterion(qobject_cast<QSortCriterion *>(c->clone(isClone))); + clone->addCriterion(qobject_cast<QSortCriterion *>(QNodePrivate::get(c)->clone())); return clone; } @@ -83,14 +83,14 @@ void QSortMethod::addCriterion(QSortCriterion *criterion) if (!d->m_criteria.contains(criterion)) { d->m_criteria.append(criterion); - if (!criterion->parent() || criterion->parent() == this) - QNode::addChild(criterion); + if (!criterion->parent()) + criterion->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeAdded, this)); propertyChange->setPropertyName(QByteArrayLiteral("sortCriterion")); propertyChange->setValue(QVariant::fromValue(criterion)); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -102,7 +102,7 @@ void QSortMethod::removeCriterion(QSortCriterion *criterion) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeRemoved, this)); propertyChange->setPropertyName(QByteArrayLiteral("sortCriterion")); propertyChange->setValue(QVariant::fromValue(criterion)); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } d->m_criteria.removeOne(criterion); } diff --git a/src/render/frontend/framegraph-components/qsortmethod.h b/src/render/frontend/framegraph-components/qsortmethod.h index 5830aae9b..b971e5572 100644 --- a/src/render/frontend/framegraph-components/qsortmethod.h +++ b/src/render/frontend/framegraph-components/qsortmethod.h @@ -63,9 +63,11 @@ public: QList<QSortCriterion *> criteria() const; protected: - Q_DECLARE_PRIVATE(QSortMethod) QSortMethod(QSortMethodPrivate &dd, QNode *parent = 0); - QSortMethod *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QSortMethod) + QSortMethod *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/framegraph-components/qtechniquefilter.cpp b/src/render/frontend/framegraph-components/qtechniquefilter.cpp index 48ee5daa9..b65d8a879 100644 --- a/src/render/frontend/framegraph-components/qtechniquefilter.cpp +++ b/src/render/frontend/framegraph-components/qtechniquefilter.cpp @@ -42,7 +42,7 @@ #include "qtechniquefilter.h" #include "qtechniquefilter_p.h" - +#include "qcriterion_p.h" #include <Qt3DRenderer/qcriterion.h> #include <Qt3DCore/qscenepropertychange.h> @@ -65,18 +65,17 @@ QTechniqueFilter::QTechniqueFilter(QTechniqueFilterPrivate &dd, QNode *parent) { } -QTechniqueFilter *QTechniqueFilter::doClone(bool isClone) const +QTechniqueFilter *QTechniqueFilter::doClone() const { Q_D(const QTechniqueFilter); QTechniqueFilter *clone = new QTechniqueFilter(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); Q_FOREACH (QFrameGraphItem *fgChild, d->m_fgChildren) - clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(fgChild->clone(isClone))); + clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(QNodePrivate::get(fgChild)->clone())); Q_FOREACH (QCriterion *crit, d->m_criteriaList) - clone->addCriterion(qobject_cast<QCriterion *>(crit->clone(isClone))); + clone->addCriterion(qobject_cast<QCriterion *>(QNodePrivate::get(crit)->clone())); return clone; } @@ -96,14 +95,14 @@ void QTechniqueFilter::addCriterion(QCriterion *criterion) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!criterion->parent() || criterion->parent() == this) - QNode::addChild(criterion); + if (!criterion->parent()) + criterion->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeAdded, this)); propertyChange->setPropertyName(QByteArrayLiteral("techniqueCriterion")); propertyChange->setValue(QVariant::fromValue(criterion)); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } @@ -114,7 +113,7 @@ void QTechniqueFilter::removeCriterion(QCriterion *criterion) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeRemoved, this)); propertyChange->setPropertyName(QByteArrayLiteral("techniqueCriterion")); propertyChange->setValue(QVariant::fromValue(criterion->uuid())); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } d->m_criteriaList.removeOne(criterion); } diff --git a/src/render/frontend/framegraph-components/qtechniquefilter.h b/src/render/frontend/framegraph-components/qtechniquefilter.h index 9d7319709..37e7e96ed 100644 --- a/src/render/frontend/framegraph-components/qtechniquefilter.h +++ b/src/render/frontend/framegraph-components/qtechniquefilter.h @@ -63,9 +63,11 @@ public: void removeCriterion(QCriterion *criterion); protected: - Q_DECLARE_PRIVATE(QTechniqueFilter) QTechniqueFilter(QTechniqueFilterPrivate &dd, QNode *parent = 0); - QTechniqueFilter *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QTechniqueFilter) + QTechniqueFilter *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/render/frontend/framegraph-components/qviewport.cpp b/src/render/frontend/framegraph-components/qviewport.cpp index a2d9bd972..79f8403c3 100644 --- a/src/render/frontend/framegraph-components/qviewport.cpp +++ b/src/render/frontend/framegraph-components/qviewport.cpp @@ -53,19 +53,16 @@ QViewportPrivate::QViewportPrivate(QViewport *qq) : { } -QViewport::QViewport(QNode *parent) - : QFrameGraphItem(*new QViewportPrivate(this), parent) +void QViewportPrivate::copy(const QNodePrivate *ref) { + QFrameGraphItemPrivate::copy(ref); + const QViewportPrivate *viewport = static_cast<const QViewportPrivate *>(ref); + m_rect = viewport->m_rect; } -void QViewport::copy(const QNode *ref) +QViewport::QViewport(QNode *parent) + : QFrameGraphItem(*new QViewportPrivate(this), parent) { - Q_D(QViewport); - QFrameGraphItem::copy(ref); - const QViewport *viewport = qobject_cast<const QViewport *>(ref); - if (viewport != Q_NULLPTR) { - d->m_rect = viewport->rect(); - } } QViewport::QViewport(QViewportPrivate &dd, QNode *parent) @@ -73,16 +70,15 @@ QViewport::QViewport(QViewportPrivate &dd, QNode *parent) { } -QViewport *QViewport::doClone(bool isClone) const +QViewport *QViewport::doClone() const { Q_D(const QViewport); QViewport *clone = new QViewport(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); Q_FOREACH (QFrameGraphItem *fgChild, d->m_fgChildren) - clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(fgChild->clone(isClone))); + clone->appendFrameGraphItem(qobject_cast<QFrameGraphItem *>(QNodePrivate::get(fgChild)->clone())); return clone; } @@ -103,7 +99,7 @@ void QViewport::setRect(const QRectF &rect) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("rect")); propertyChange->setValue(QVariant::fromValue(d->m_rect)); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -124,7 +120,7 @@ void QViewport::setClearColor(const QColor &color) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("clearColor")); propertyChange->setValue(QVariant::fromValue(d->m_clearColor)); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } diff --git a/src/render/frontend/framegraph-components/qviewport.h b/src/render/frontend/framegraph-components/qviewport.h index c1041f3ca..4b8499eea 100644 --- a/src/render/frontend/framegraph-components/qviewport.h +++ b/src/render/frontend/framegraph-components/qviewport.h @@ -61,8 +61,6 @@ class QT3DRENDERERSHARED_EXPORT QViewport : public QFrameGraphItem public: explicit QViewport(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - QRectF rect() const; void setRect(const QRectF& rect); @@ -74,9 +72,11 @@ Q_SIGNALS: void clearColorChanged(); protected: - Q_DECLARE_PRIVATE(QViewport) QViewport(QViewportPrivate &dd, QNode *parent = 0); - QViewport *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QViewport) + QViewport *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/framegraph-components/qviewport_p.h b/src/render/frontend/framegraph-components/qviewport_p.h index e178c4f20..6281acaf3 100644 --- a/src/render/frontend/framegraph-components/qviewport_p.h +++ b/src/render/frontend/framegraph-components/qviewport_p.h @@ -55,6 +55,8 @@ class QViewportPrivate : public QFrameGraphItemPrivate public : QViewportPrivate(QViewport *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QViewport) QRectF m_rect; QColor m_clearColor; diff --git a/src/render/frontend/qabstractlight.cpp b/src/render/frontend/qabstractlight.cpp index e9bc5a37d..b74732851 100644 --- a/src/render/frontend/qabstractlight.cpp +++ b/src/render/frontend/qabstractlight.cpp @@ -61,6 +61,14 @@ QAbstractLightPrivate::QAbstractLightPrivate(QAbstractLight *qq) , m_intensity(1.0f) {} +void QAbstractLightPrivate::copy(const QNodePrivate *ref) +{ + QComponentPrivate::copy(ref); + const QAbstractLightPrivate *light = static_cast<const QAbstractLightPrivate *>(ref); + m_color = light->m_color; + m_intensity = light->m_intensity; +} + /*! * Constructs a new QAbstractLight with the given \a parent. */ @@ -69,16 +77,6 @@ QAbstractLight::QAbstractLight(Qt3D::QNode *parent) : { } -void QAbstractLight::copy(const QNode *ref) -{ - Q_D(QAbstractLight); - QComponent::copy(ref); - const QAbstractLight *light = qobject_cast<const QAbstractLight *>(ref); - if (ref != Q_NULLPTR) { - d->m_color = light->color(); - d->m_intensity = light->intensity(); - } -} QAbstractLight::QAbstractLight(QAbstractLightPrivate &dd, QNode *parent) : QComponent(dd, parent) diff --git a/src/render/frontend/qabstractlight.h b/src/render/frontend/qabstractlight.h index 3148e8fea..79c6b85d3 100644 --- a/src/render/frontend/qabstractlight.h +++ b/src/render/frontend/qabstractlight.h @@ -65,8 +65,6 @@ public : explicit QAbstractLight(QNode *parent = 0); - virtual void copy(const QNode *ref) Q_DECL_OVERRIDE; - QColor color() const; void setColor(const QColor &color); diff --git a/src/render/frontend/qabstractlight_p.h b/src/render/frontend/qabstractlight_p.h index 98d2837eb..2ef739db9 100644 --- a/src/render/frontend/qabstractlight_p.h +++ b/src/render/frontend/qabstractlight_p.h @@ -56,6 +56,8 @@ class QT3DRENDERERSHARED_EXPORT QAbstractLightPrivate : public QComponentPrivate public: QAbstractLightPrivate(QAbstractLight *qq); + virtual void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QAbstractLight) QColor m_color; float m_intensity; diff --git a/src/render/frontend/qabstractsceneloader.cpp b/src/render/frontend/qabstractsceneloader.cpp index f7bb8eec2..1fe0d0384 100644 --- a/src/render/frontend/qabstractsceneloader.cpp +++ b/src/render/frontend/qabstractsceneloader.cpp @@ -68,13 +68,10 @@ QAbstractSceneLoader::QAbstractSceneLoader(QNode *parent) { } -void QAbstractSceneLoader::copy(const QNode *ref) +void QAbstractSceneLoaderPrivate::copy(const QNodePrivate *ref) { - Q_D(QAbstractSceneLoader); - const QAbstractSceneLoader *s = qobject_cast<const QAbstractSceneLoader *>(ref); - if (s != Q_NULLPTR) { - d->m_source = s->source(); - } + const QAbstractSceneLoaderPrivate *s = static_cast<const QAbstractSceneLoaderPrivate *>(ref); + m_source = s->m_source; } QString QAbstractSceneLoader::source() const @@ -92,7 +89,7 @@ void QAbstractSceneLoader::setSource(QString arg) QScenePropertyChangePtr change(new QScenePropertyChange(ComponentUpdated, this)); change->setPropertyName(QByteArrayLiteral("source")); change->setValue(d->m_source); - notifyObservers(change); + d->notifyObservers(change); } } diff --git a/src/render/frontend/qabstractsceneloader.h b/src/render/frontend/qabstractsceneloader.h index 4dd06a6f6..8e22d1c2c 100644 --- a/src/render/frontend/qabstractsceneloader.h +++ b/src/render/frontend/qabstractsceneloader.h @@ -43,6 +43,7 @@ #define QT3D_QABSTRACTSCENELOADER_H #include <Qt3DCore/qcomponent.h> +#include <Qt3DCore/qscenechange.h> #include <Qt3DRenderer/qt3drenderer_global.h> QT_BEGIN_NAMESPACE @@ -68,8 +69,6 @@ public: Error }; - void copy(const QNode *ref) Q_DECL_OVERRIDE; - QString source() const; void setSource(QString arg); diff --git a/src/render/frontend/qabstractsceneloader_p.h b/src/render/frontend/qabstractsceneloader_p.h index 96d2dc7e8..edca8f116 100644 --- a/src/render/frontend/qabstractsceneloader_p.h +++ b/src/render/frontend/qabstractsceneloader_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QT3D_QABSTRACTSCENE_P_H -#define QT3D_QABSTRACTSCENE_P_H +#ifndef QT3D_QABSTRACTSCENELOADER_P_H +#define QT3D_QABSTRACTSCENELOADER_P_H #include <private/qcomponent_p.h> #include <Qt3DRenderer/qt3drenderer_global.h> @@ -60,6 +60,8 @@ class QT3DRENDERERSHARED_EXPORT QAbstractSceneLoaderPrivate : public QComponentP public: QAbstractSceneLoaderPrivate(QAbstractSceneLoader *qq); + virtual void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QAbstractSceneLoader) QString m_source; diff --git a/src/render/frontend/qalphatest.cpp b/src/render/frontend/qalphatest.cpp index b8e02f359..89094bc68 100644 --- a/src/render/frontend/qalphatest.cpp +++ b/src/render/frontend/qalphatest.cpp @@ -41,6 +41,7 @@ ****************************************************************************/ #include "qalphatest.h" +#include "qrenderstate_p.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -48,16 +49,18 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QAlphaTestPrivate : public QNodePrivate +class QAlphaTestPrivate : public QRenderStatePrivate { public: QAlphaTestPrivate(QAlphaTest *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) , m_func(QAlphaTest::Never) , m_clamp(0.0f) { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QAlphaTest) QAlphaTest::AlphaFunc m_func; float m_clamp; @@ -68,15 +71,12 @@ QAlphaTest::QAlphaTest(QNode *parent) { } -void QAlphaTest::copy(const QNode *ref) +void QAlphaTestPrivate::copy(const QNodePrivate *ref) { - QRenderState::copy(ref); - Q_D(QAlphaTest); - const QAlphaTest *refState = qobject_cast<const QAlphaTest *>(ref); - if (refState != Q_NULLPTR) { - d->m_func = refState->func(); - d->m_clamp = refState->clamp(); - } + QRenderStatePrivate::copy(ref); + const QAlphaTestPrivate *refState = static_cast<const QAlphaTestPrivate *>(ref); + m_func = refState->m_func; + m_clamp = refState->m_clamp; } QAlphaTest::AlphaFunc QAlphaTest::func() const @@ -95,7 +95,7 @@ void QAlphaTest::setFunc(QAlphaTest::AlphaFunc func) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("func")); propertyChange->setValue(d->m_func); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -116,16 +116,15 @@ void QAlphaTest::setClamp(float clamp) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("clamp")); propertyChange->setValue(d->m_clamp); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QAlphaTest::doClone(bool isClone) const +QNode *QAlphaTest::doClone() const { QAlphaTest *clone = new QAlphaTest(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qalphatest.h b/src/render/frontend/qalphatest.h index 206893b89..4234b66e0 100644 --- a/src/render/frontend/qalphatest.h +++ b/src/render/frontend/qalphatest.h @@ -72,8 +72,6 @@ public: explicit QAlphaTest(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - AlphaFunc func() const; void setFunc(AlphaFunc func); @@ -86,7 +84,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QAlphaTest) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qblendequation.cpp b/src/render/frontend/qblendequation.cpp index 898366d62..0c00cde69 100644 --- a/src/render/frontend/qblendequation.cpp +++ b/src/render/frontend/qblendequation.cpp @@ -40,6 +40,7 @@ ** ****************************************************************************/ +#include "qrenderstate_p.h" #include "qblendequation.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -48,31 +49,30 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QBlendEquationPrivate : public QNodePrivate +class QBlendEquationPrivate : public QRenderStatePrivate { public: QBlendEquationPrivate(QBlendEquation *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QBlendEquation) QBlendEquation::BlendMode m_mode; }; -QBlendEquation::QBlendEquation(QNode *parent) - : QRenderState(*new QBlendEquationPrivate(this), parent) +void QBlendEquationPrivate::copy(const QNodePrivate *ref) { + QRenderStatePrivate::copy(ref); + const QBlendEquationPrivate *refState = reinterpret_cast<const QBlendEquationPrivate *>(ref); + m_mode = refState->m_mode; } -void QBlendEquation::copy(const QNode *ref) +QBlendEquation::QBlendEquation(QNode *parent) + : QRenderState(*new QBlendEquationPrivate(this), parent) { - Q_D(QBlendEquation); - QRenderState::copy(ref); - const QBlendEquation *refState = qobject_cast<const QBlendEquation *>(ref); - if (refState != Q_NULLPTR) { - d->m_mode = refState->mode(); - } } QBlendEquation::BlendMode QBlendEquation::mode() const @@ -91,16 +91,15 @@ void QBlendEquation::setMode(QBlendEquation::BlendMode mode) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("mode")); propertyChange->setValue(d->m_mode); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QBlendEquation::doClone(bool isClone) const +QNode *QBlendEquation::doClone() const { QBlendEquation *clone = new QBlendEquation(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qblendequation.h b/src/render/frontend/qblendequation.h index c73d351c7..f60e50c5f 100644 --- a/src/render/frontend/qblendequation.h +++ b/src/render/frontend/qblendequation.h @@ -69,8 +69,6 @@ public: explicit QBlendEquation(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - BlendMode mode() const; void setMode(BlendMode mode); @@ -79,7 +77,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QBlendEquation) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qblendstate.cpp b/src/render/frontend/qblendstate.cpp index a69397d54..ada1eac95 100644 --- a/src/render/frontend/qblendstate.cpp +++ b/src/render/frontend/qblendstate.cpp @@ -41,6 +41,7 @@ ****************************************************************************/ #include "qblendstate.h" +#include "qrenderstate_p.h" #include <Qt3DCore/qscenepropertychange.h> #include <private/qnode_p.h> @@ -48,11 +49,11 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QBlendStatePrivate : public QNodePrivate +class QBlendStatePrivate : public QRenderStatePrivate { public: QBlendStatePrivate(QBlendState *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) , m_srcRGB(QBlendState::Zero) , m_srcAlpha(QBlendState::Zero) , m_dstRGB(QBlendState::Zero) @@ -60,6 +61,8 @@ public: { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QBlendState) QBlendState::Blending m_srcRGB; @@ -73,17 +76,14 @@ QBlendState::QBlendState(QNode *parent) { } -void QBlendState::copy(const QNode *ref) +void QBlendStatePrivate::copy(const QNodePrivate *ref) { - QRenderState::copy(ref); - Q_D(QBlendState); - const QBlendState *refState = qobject_cast<const QBlendState *>(ref); - if (refState != Q_NULLPTR) { - d->m_srcRGB = refState->srcRGB(); - d->m_srcAlpha = refState->srcAlpha(); - d->m_dstAlpha = refState->dstAlpha(); - d->m_dstRGB = refState->dstRGB(); - } + QRenderStatePrivate::copy(ref); + const QBlendStatePrivate *refState = static_cast<const QBlendStatePrivate *>(ref); + m_srcRGB = refState->m_srcRGB; + m_srcAlpha = refState->m_srcAlpha; + m_dstAlpha = refState->m_dstAlpha; + m_dstRGB = refState->m_dstRGB; } QBlendState::Blending QBlendState::srcRGB() const @@ -102,7 +102,7 @@ void QBlendState::setSrcRGB(QBlendState::Blending srcRGB) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("srcRGB")); propertyChange->setValue(d->m_srcRGB); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -123,7 +123,7 @@ void QBlendState::setDstRGB(QBlendState::Blending dstRGB) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("dstRGB")); propertyChange->setValue(d->m_dstRGB); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -144,7 +144,7 @@ void QBlendState::setSrcAlpha(QBlendState::Blending srcAlpha) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("srcAlpha")); propertyChange->setValue(d->m_srcAlpha); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -165,16 +165,15 @@ void QBlendState::setDstAlpha(QBlendState::Blending dstAlpha) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("dstAlpha")); propertyChange->setValue(d->m_dstAlpha); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QBlendState::doClone(bool isClone) const +QNode *QBlendState::doClone() const { QBlendState *clone = new QBlendState(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qblendstate.h b/src/render/frontend/qblendstate.h index 1920f557f..73295d37e 100644 --- a/src/render/frontend/qblendstate.h +++ b/src/render/frontend/qblendstate.h @@ -87,8 +87,6 @@ public: explicit QBlendState(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - Blending srcRGB() const; void setSrcRGB(Blending srcRGB); @@ -109,7 +107,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QBlendState) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qcriterion.cpp b/src/render/frontend/qcriterion.cpp index 97f814877..171ebb5f4 100644 --- a/src/render/frontend/qcriterion.cpp +++ b/src/render/frontend/qcriterion.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qcriterion.h" +#include "qcriterion_p.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -47,40 +48,30 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QCriterionPrivate : public QNodePrivate + +QCriterionPrivate::QCriterionPrivate(QCriterion *qq) + : QNodePrivate(qq) { -public: - QCriterionPrivate(QCriterion *qq) - : QNodePrivate(qq) - { - } +} - Q_DECLARE_PUBLIC(QCriterion) - QString m_name; - QVariant m_value; -}; +void QCriterionPrivate::copy(const QNodePrivate *ref) +{ + QNodePrivate::copy(ref); + const QCriterionPrivate *criterion = static_cast<const QCriterionPrivate *>(ref); + m_name = criterion->m_name; + m_value = criterion->m_value; +} QCriterion::QCriterion(QNode *parent) : QNode(*new QCriterionPrivate(this), parent) { } -void QCriterion::copy(const QNode *ref) -{ - Q_D(QCriterion); - QNode::copy(ref); - const QCriterion *criterion = qobject_cast<const QCriterion *>(ref); - if (criterion != Q_NULLPTR) { - d->m_name = criterion->name(); - d->m_value = criterion->value(); - } -} -QCriterion *QCriterion::doClone(bool isClone) const +QCriterion *QCriterion::doClone() const { QCriterion *clone = new QCriterion(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -93,7 +84,7 @@ void QCriterion::setValue(const QVariant &value) QScenePropertyChangePtr change(new QScenePropertyChange(ComponentUpdated, this)); change->setPropertyName(QByteArrayLiteral("criterionValue")); change->setValue(value); - notifyObservers(change); + d->notifyObservers(change); } } @@ -106,7 +97,7 @@ void QCriterion::setName(const QString &name) QScenePropertyChangePtr change(new QScenePropertyChange(ComponentUpdated, this)); change->setPropertyName(QByteArrayLiteral("criterionName")); change->setValue(QVariant(name)); - notifyObservers(change); + d->notifyObservers(change); } } diff --git a/src/render/frontend/qcriterion.h b/src/render/frontend/qcriterion.h index a6a57e321..c0d9e0585 100644 --- a/src/render/frontend/qcriterion.h +++ b/src/render/frontend/qcriterion.h @@ -60,8 +60,6 @@ class QT3DRENDERERSHARED_EXPORT QCriterion : public QNode public: explicit QCriterion(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setValue(const QVariant &value); void setName(const QString &customType); @@ -74,7 +72,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QCriterion) - QCriterion *doClone(bool isClone) const Q_DECL_OVERRIDE; + QCriterion *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qcriterion_p.h b/src/render/frontend/qcriterion_p.h new file mode 100644 index 000000000..e756984a2 --- /dev/null +++ b/src/render/frontend/qcriterion_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QCRITERION_P_H +#define QT3D_QCRITERION_P_H + +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DRenderer/qcriterion.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QCriterionPrivate : public QNodePrivate +{ +public: + QCriterionPrivate(QCriterion *qq); + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + + Q_DECLARE_PUBLIC(QCriterion) + QString m_name; + QVariant m_value; +}; + +} // Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_QCRITERION_P_H diff --git a/src/render/frontend/qcuboidmesh.cpp b/src/render/frontend/qcuboidmesh.cpp index 28ba881ee..ea58fd9c0 100644 --- a/src/render/frontend/qcuboidmesh.cpp +++ b/src/render/frontend/qcuboidmesh.cpp @@ -62,25 +62,22 @@ QCuboidMeshPrivate::QCuboidMeshPrivate(QCuboidMesh *qq) { } -QCuboidMesh::QCuboidMesh(QNode *parent) - : QAbstractShapeMesh(*new QCuboidMeshPrivate(this), parent) +void QCuboidMeshPrivate::copy(const QNodePrivate *ref) { - setDirty(true); + QAbstractShapeMeshPrivate::copy(ref); + const QCuboidMeshPrivate *mesh = static_cast<const QCuboidMeshPrivate *>(ref); + m_xExtent = mesh->m_xExtent; + m_yExtent = mesh->m_yExtent; + m_zExtent = mesh->m_zExtent; + m_yzFaceResolution = mesh->m_yzFaceResolution; + m_xzFaceResolution = mesh->m_xzFaceResolution; + m_xyFaceResolution = mesh->m_xyFaceResolution; } -void QCuboidMesh::copy(const QNode *ref) +QCuboidMesh::QCuboidMesh(QNode *parent) + : QAbstractShapeMesh(*new QCuboidMeshPrivate(this), parent) { - Q_D(QCuboidMesh); - QAbstractShapeMesh::copy(ref); - const QCuboidMesh *mesh = qobject_cast<const QCuboidMesh *>(ref); - if (mesh != Q_NULLPTR) { - d->m_xExtent = mesh->xExtent(); - d->m_yExtent = mesh->yExtent(); - d->m_zExtent = mesh->zExtent(); - d->m_yzFaceResolution = mesh->yzMeshResolution(); - d->m_xzFaceResolution = mesh->xzMeshResolution(); - d->m_xyFaceResolution = mesh->xyMeshResolution(); - } + setDirty(true); } QCuboidMesh::QCuboidMesh(QCuboidMeshPrivate &dd, QNode *parent) @@ -89,11 +86,10 @@ QCuboidMesh::QCuboidMesh(QCuboidMeshPrivate &dd, QNode *parent) setDirty(true); } -QCuboidMesh *QCuboidMesh::doClone(bool isClone) const +QCuboidMesh *QCuboidMesh::doClone() const { QCuboidMesh *clone = new QCuboidMesh(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qcuboidmesh.h b/src/render/frontend/qcuboidmesh.h index f8069bddd..8b8087dd6 100644 --- a/src/render/frontend/qcuboidmesh.h +++ b/src/render/frontend/qcuboidmesh.h @@ -65,8 +65,6 @@ class QT3DRENDERERSHARED_EXPORT QCuboidMesh : public Qt3D::QAbstractShapeMesh public: explicit QCuboidMesh(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setXExtent(float xExtent); float xExtent() const; @@ -98,7 +96,9 @@ Q_SIGNALS: protected: QCuboidMesh(QCuboidMeshPrivate &dd, QNode *parent = 0); - QCuboidMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + QCuboidMesh *doClone() const Q_DECL_OVERRIDE; Q_DECLARE_PRIVATE(QCuboidMesh) }; diff --git a/src/render/frontend/qcuboidmesh_p.h b/src/render/frontend/qcuboidmesh_p.h index 02b5eff81..9abd26ec6 100644 --- a/src/render/frontend/qcuboidmesh_p.h +++ b/src/render/frontend/qcuboidmesh_p.h @@ -57,6 +57,8 @@ class QCuboidMeshPrivate : QAbstractShapeMeshPrivate public: QCuboidMeshPrivate(QCuboidMesh *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QCuboidMesh) // Dimensions diff --git a/src/render/frontend/qcullface.cpp b/src/render/frontend/qcullface.cpp index 02ccb4935..4c7251ad8 100644 --- a/src/render/frontend/qcullface.cpp +++ b/src/render/frontend/qcullface.cpp @@ -42,21 +42,24 @@ #include "qcullface.h" #include <private/qnode_p.h> +#include "qrenderstate_p.h" #include <Qt3DCore/qscenepropertychange.h> QT_BEGIN_NAMESPACE namespace Qt3D { -class QCullFacePrivate : public QNodePrivate +class QCullFacePrivate : public QRenderStatePrivate { public: QCullFacePrivate(QCullFace *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) , m_mode(QCullFace::Back) { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QCullFace) QCullFace::CullingMode m_mode; }; @@ -66,14 +69,11 @@ QCullFace::QCullFace(QNode *parent) { } -void QCullFace::copy(const QNode *ref) +void QCullFacePrivate::copy(const QNodePrivate *ref) { - QRenderState::copy(ref); - Q_D(QCullFace); - const QCullFace *refState = qobject_cast<const QCullFace *>(ref); - if (refState != Q_NULLPTR) { - d->m_mode = refState->mode(); - } + QRenderStatePrivate::copy(ref); + const QCullFacePrivate *refState = static_cast<const QCullFacePrivate *>(ref); + m_mode = refState->m_mode; } QCullFace::CullingMode QCullFace::mode() const @@ -92,16 +92,15 @@ void QCullFace::setMode(QCullFace::CullingMode mode) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("mode")); propertyChange->setValue(d->m_mode); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QCullFace::doClone(bool isClone) const +QNode *QCullFace::doClone() const { QCullFace *clone = new QCullFace(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qcullface.h b/src/render/frontend/qcullface.h index c8671fafb..b814d2687 100644 --- a/src/render/frontend/qcullface.h +++ b/src/render/frontend/qcullface.h @@ -69,8 +69,6 @@ public: explicit QCullFace(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - CullingMode mode() const; void setMode(CullingMode mode); @@ -79,7 +77,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QCullFace) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qcylindermesh.cpp b/src/render/frontend/qcylindermesh.cpp index d354cee3e..cd6eb7b69 100644 --- a/src/render/frontend/qcylindermesh.cpp +++ b/src/render/frontend/qcylindermesh.cpp @@ -80,6 +80,8 @@ class QCylinderMeshPrivate : public QAbstractShapeMeshPrivate , m_length(1.0) {} + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QCylinderMesh) int m_rings; int m_slices; @@ -87,24 +89,22 @@ class QCylinderMeshPrivate : public QAbstractShapeMeshPrivate float m_length; }; +void QCylinderMeshPrivate::copy(const QNodePrivate *ref) +{ + QAbstractShapeMeshPrivate::copy(ref); + const QCylinderMeshPrivate *mesh = static_cast<const QCylinderMeshPrivate *>(ref); + m_rings = mesh->m_rings; + m_slices = mesh->m_slices; + m_radius = mesh->m_radius; + m_length = mesh->m_length; +} + QCylinderMesh::QCylinderMesh(QNode *parent) : QAbstractShapeMesh(*new QCylinderMeshPrivate(this), parent) { setDirty(true); } -void QCylinderMesh::copy(const QNode *ref) -{ - Q_D(QCylinderMesh); - QAbstractShapeMesh::copy(ref); - const QCylinderMesh *mesh = qobject_cast<const QCylinderMesh *>(ref); - if (mesh != Q_NULLPTR) { - d->m_rings = mesh->rings(); - d->m_slices = mesh->slices(); - d->m_radius = mesh->radius(); - d->m_length = mesh->length(); - } -} void QCylinderMesh::setRings(int rings) { @@ -334,9 +334,11 @@ QAbstractMeshFunctorPtr QCylinderMesh::meshFunctor() const return QAbstractMeshFunctorPtr(new CylinderMeshFunctor(d->m_rings, d->m_slices, d->m_radius, d->m_length)); } -QCylinderMesh *QCylinderMesh::doClone(bool isClone) const +QCylinderMesh *QCylinderMesh::doClone() const { - return new QCylinderMesh(); + QCylinderMesh *clone = new QCylinderMesh(); + clone->d_func()->copy(d_func()); + return clone; } CylinderMeshFunctor::CylinderMeshFunctor(int rings, int slices, float radius, float length) diff --git a/src/render/frontend/qcylindermesh.h b/src/render/frontend/qcylindermesh.h index 584803504..590191cdb 100644 --- a/src/render/frontend/qcylindermesh.h +++ b/src/render/frontend/qcylindermesh.h @@ -62,8 +62,6 @@ class QT3DRENDERERSHARED_EXPORT QCylinderMesh : public Qt3D::QAbstractShapeMesh public: explicit QCylinderMesh(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setRings(int rings); void setSlices(int slices); void setRadius(float radius); @@ -84,7 +82,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QCylinderMesh) - QCylinderMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QCylinderMesh *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qdepthmask.cpp b/src/render/frontend/qdepthmask.cpp index 923a10b9f..fcc86ee5c 100644 --- a/src/render/frontend/qdepthmask.cpp +++ b/src/render/frontend/qdepthmask.cpp @@ -41,6 +41,7 @@ ****************************************************************************/ #include "qdepthmask.h" +#include "qrenderstate_p.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -48,15 +49,17 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QDepthMaskPrivate : public QNodePrivate +class QDepthMaskPrivate : public QRenderStatePrivate { public: QDepthMaskPrivate(QDepthMask *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) , m_mask(false) { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QDepthMask) bool m_mask; }; @@ -66,14 +69,11 @@ QDepthMask::QDepthMask(QNode *parent) { } -void QDepthMask::copy(const QNode *ref) +void QDepthMaskPrivate::copy(const QNodePrivate *ref) { - QRenderState::copy(ref); - Q_D(QDepthMask); - const QDepthMask *refState = qobject_cast<const QDepthMask *>(ref); - if (refState != Q_NULLPTR) { - d->m_mask = refState->mask(); - } + QRenderStatePrivate::copy(ref); + const QDepthMaskPrivate *refState = static_cast<const QDepthMaskPrivate *>(ref); + m_mask = refState->m_mask; } bool QDepthMask::mask() const @@ -92,16 +92,15 @@ void QDepthMask::setMask(bool mask) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("mask")); propertyChange->setValue(d->m_mask); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QDepthMask::doClone(bool isClone) const +QNode *QDepthMask::doClone() const { QDepthMask *clone = new QDepthMask(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qdepthmask.h b/src/render/frontend/qdepthmask.h index 34ea52a99..10aa2e4d6 100644 --- a/src/render/frontend/qdepthmask.h +++ b/src/render/frontend/qdepthmask.h @@ -58,8 +58,6 @@ class QT3DRENDERERSHARED_EXPORT QDepthMask : public QRenderState public: explicit QDepthMask(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - bool mask() const; void setMask(bool mask); @@ -68,7 +66,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QDepthMask) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qdepthtest.cpp b/src/render/frontend/qdepthtest.cpp index bfebb14b0..6d5da1808 100644 --- a/src/render/frontend/qdepthtest.cpp +++ b/src/render/frontend/qdepthtest.cpp @@ -41,6 +41,7 @@ ****************************************************************************/ #include "qdepthtest.h" +#include "qrenderstate_p.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -48,32 +49,33 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QDepthTestPrivate : QNodePrivate +class QDepthTest; + +class QDepthTestPrivate : public QRenderStatePrivate { public : QDepthTestPrivate(QDepthTest *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) , m_func(QDepthTest::Never) { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QDepthTest) QDepthTest::DepthFunc m_func; }; -QDepthTest::QDepthTest(QNode *parent) - : QRenderState(*new QDepthTestPrivate(this), parent) +void QDepthTestPrivate::copy(const QNodePrivate *ref) { + QRenderStatePrivate::copy(ref); + const QDepthTestPrivate *refState = static_cast<const QDepthTestPrivate *>(ref); + m_func = refState->m_func; } -void QDepthTest::copy(const QNode *ref) +QDepthTest::QDepthTest(QNode *parent) + : QRenderState(*new QDepthTestPrivate(this), parent) { - QRenderState::copy(ref); - Q_D(QDepthTest); - const QDepthTest *refState = qobject_cast<const QDepthTest *>(ref); - if (refState != Q_NULLPTR) { - d->m_func = refState->func(); - } } QDepthTest::DepthFunc QDepthTest::func() const @@ -92,16 +94,15 @@ void QDepthTest::setFunc(QDepthTest::DepthFunc func) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("func")); propertyChange->setValue(d->m_func); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QDepthTest::doClone(bool isClone) const +QNode *QDepthTest::doClone() const { QDepthTest *clone = new QDepthTest(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qdepthtest.h b/src/render/frontend/qdepthtest.h index 7fa9785aa..95b96922c 100644 --- a/src/render/frontend/qdepthtest.h +++ b/src/render/frontend/qdepthtest.h @@ -71,8 +71,6 @@ public: explicit QDepthTest(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - DepthFunc func() const; void setFunc(DepthFunc func); @@ -81,7 +79,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QDepthTest) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qdirectionallight.cpp b/src/render/frontend/qdirectionallight.cpp index 346bb3e07..426a25db4 100644 --- a/src/render/frontend/qdirectionallight.cpp +++ b/src/render/frontend/qdirectionallight.cpp @@ -71,19 +71,16 @@ QDirectionalLightPrivate::QDirectionalLightPrivate(QDirectionalLight *qq) { } -QDirectionalLight::QDirectionalLight(QNode *parent) - : QAbstractLight(*new QDirectionalLightPrivate(this), parent) +void QDirectionalLightPrivate::copy(const QNodePrivate *ref) { + QAbstractLightPrivate::copy(ref); + const QDirectionalLightPrivate *light = static_cast<const QDirectionalLightPrivate *>(ref); + m_direction = light->m_direction; } -void QDirectionalLight::copy(const QNode *ref) +QDirectionalLight::QDirectionalLight(QNode *parent) + : QAbstractLight(*new QDirectionalLightPrivate(this), parent) { - Q_D(QDirectionalLight); - QAbstractLight::copy(ref); - const QDirectionalLight *light = qobject_cast<const QDirectionalLight *>(ref); - if (ref != Q_NULLPTR) { - d->m_direction = light->direction(); - } } QDirectionalLight::QDirectionalLight(QDirectionalLightPrivate &dd, QNode *parent) @@ -91,11 +88,10 @@ QDirectionalLight::QDirectionalLight(QDirectionalLightPrivate &dd, QNode *parent { } -QDirectionalLight *QDirectionalLight::doClone(bool isClone) const +QDirectionalLight *QDirectionalLight::doClone() const { QDirectionalLight *clone = new QDirectionalLight(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -108,7 +104,7 @@ void QDirectionalLight::setDirection(const QVector3D &direction) QScenePropertyChangePtr change(new QScenePropertyChange(ComponentAdded, this)); change->setPropertyName(QByteArrayLiteral("direction")); change->setValue(d->m_direction); - notifyObservers(change); + d->notifyObservers(change); } } diff --git a/src/render/frontend/qdirectionallight.h b/src/render/frontend/qdirectionallight.h index fd3e0db4b..30cc66fe2 100644 --- a/src/render/frontend/qdirectionallight.h +++ b/src/render/frontend/qdirectionallight.h @@ -58,8 +58,6 @@ class QT3DRENDERERSHARED_EXPORT QDirectionalLight : public QAbstractLight public: explicit QDirectionalLight(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setDirection(const QVector3D &direction); QVector3D direction() const; @@ -71,9 +69,11 @@ Q_SIGNALS: void directionChanged(); protected: - Q_DECLARE_PRIVATE(QDirectionalLight) QDirectionalLight(QDirectionalLightPrivate &dd, QNode *parent = 0); - QDirectionalLight *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QDirectionalLight) + QDirectionalLight *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qdirectionallight_p.h b/src/render/frontend/qdirectionallight_p.h index 802d0241c..285adb45d 100644 --- a/src/render/frontend/qdirectionallight_p.h +++ b/src/render/frontend/qdirectionallight_p.h @@ -55,6 +55,8 @@ class QT3DRENDERERSHARED_EXPORT QDirectionalLightPrivate : QAbstractLightPrivate public: QDirectionalLightPrivate(QDirectionalLight *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QDirectionalLight) QVector3D m_direction; }; diff --git a/src/render/frontend/qdithering.cpp b/src/render/frontend/qdithering.cpp index 17f211cfc..d08e7c18f 100644 --- a/src/render/frontend/qdithering.cpp +++ b/src/render/frontend/qdithering.cpp @@ -41,6 +41,7 @@ ****************************************************************************/ #include "qdithering.h" +#include "qrenderstate_p.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -48,11 +49,11 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QDitheringPrivate : public QNodePrivate +class QDitheringPrivate : public QRenderStatePrivate { public: QDitheringPrivate(QDithering *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) {} Q_DECLARE_PUBLIC(QDithering) @@ -63,11 +64,10 @@ QDithering::QDithering(QNode *parent) { } -QNode *QDithering::doClone(bool isClone) const +QNode *QDithering::doClone() const { QDithering *clone = new QDithering(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qdithering.h b/src/render/frontend/qdithering.h index b9ec18c83..8bd5a158a 100644 --- a/src/render/frontend/qdithering.h +++ b/src/render/frontend/qdithering.h @@ -59,7 +59,7 @@ public: private: Q_DECLARE_PRIVATE(QDithering) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qeffect.cpp b/src/render/frontend/qeffect.cpp index ad2fe21dd..b31d86942 100644 --- a/src/render/frontend/qeffect.cpp +++ b/src/render/frontend/qeffect.cpp @@ -59,9 +59,9 @@ QEffect::QEffect(QNode *parent) { } -void QEffect::copy(const QNode *ref) +void QEffectPrivate::copy(const QNodePrivate *ref) { - QAbstractEffect::copy(ref); + QAbstractEffectPrivate::copy(ref); } QEffect::QEffect(QEffectPrivate &dd, QNode *parent) @@ -69,19 +69,18 @@ QEffect::QEffect(QEffectPrivate &dd, QNode *parent) { } -QEffect *QEffect::doClone(bool isClone) const +QEffect *QEffect::doClone() const { Q_D(const QEffect); QEffect *effect = new QEffect(); - effect->copy(this); - effect->d_func()->m_isClone = isClone; + effect->d_func()->copy(d_func()); Q_FOREACH (QParameter *p, d->m_parameters) - effect->addParameter(qobject_cast<QParameter *>(p->clone(isClone))); + effect->addParameter(qobject_cast<QParameter *>(QNodePrivate::get(p)->clone())); Q_FOREACH (QAbstractTechnique *t, d->m_techniques) - effect->addTechnique(qobject_cast<QAbstractTechnique *>(t->clone(isClone))); + effect->addTechnique(qobject_cast<QAbstractTechnique *>(QNodePrivate::get(t)->clone())); return effect; } @@ -96,14 +95,14 @@ void QEffect::addParameter(QParameter *parameter) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!parameter->parent() || parameter->parent() == this) - addChild(parameter); + if (!parameter->parent()) + parameter->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("parameter")); - change->setValue(QVariant::fromValue(parameter->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(parameter)->clone())); + d->notifyObservers(change); } } } @@ -115,8 +114,8 @@ void QEffect::removeParameter(QParameter *parameter) if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("parameter")); - change->setValue(QVariant::fromValue(parameter->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(parameter)->clone())); + d->notifyObservers(change); } d->m_parameters.removeOne(parameter); } diff --git a/src/render/frontend/qeffect.h b/src/render/frontend/qeffect.h index 01285eabf..37b843e99 100644 --- a/src/render/frontend/qeffect.h +++ b/src/render/frontend/qeffect.h @@ -60,16 +60,16 @@ class QT3DRENDERERSHARED_EXPORT QEffect public: explicit QEffect(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void addParameter(QParameter *parameter); void removeParameter(QParameter *parameter); QList<QParameter *> parameters() const; protected: - Q_DECLARE_PRIVATE(QEffect) QEffect(QEffectPrivate &dd, QNode *parent = 0); - QEffect *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QEffect) + QEffect *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qeffect_p.h b/src/render/frontend/qeffect_p.h index 270cb6ec4..8e383141f 100644 --- a/src/render/frontend/qeffect_p.h +++ b/src/render/frontend/qeffect_p.h @@ -56,8 +56,11 @@ class QT3DRENDERERSHARED_EXPORT QEffectPrivate : public QAbstractEffectPrivate { public : QEffectPrivate(QEffect *qq); - QList<QParameter *> m_parameters; + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QEffect) + QList<QParameter *> m_parameters; }; } // Qt3D diff --git a/src/render/frontend/qfrontface.cpp b/src/render/frontend/qfrontface.cpp index bd82b7874..f56e9c99c 100644 --- a/src/render/frontend/qfrontface.cpp +++ b/src/render/frontend/qfrontface.cpp @@ -41,6 +41,7 @@ ****************************************************************************/ #include "qfrontface.h" +#include "qrenderstate_p.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -48,15 +49,17 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QFrontFacePrivate : public QNodePrivate +class QFrontFacePrivate : public QRenderStatePrivate { public: QFrontFacePrivate(QFrontFace *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) , m_direction(QFrontFace::ClockWise) { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QFrontFace) QFrontFace::FaceDir m_direction; }; @@ -66,14 +69,11 @@ QFrontFace::QFrontFace(QNode *parent) { } -void QFrontFace::copy(const QNode *ref) +void QFrontFacePrivate::copy(const QNodePrivate *ref) { - QRenderState::copy(ref); - Q_D(QFrontFace); - const QFrontFace *refState = qobject_cast<const QFrontFace *>(ref); - if (refState != Q_NULLPTR) { - d->m_direction = refState->direction(); - } + QRenderStatePrivate::copy(ref); + const QFrontFacePrivate *refState = static_cast<const QFrontFacePrivate *>(ref); + m_direction = refState->m_direction; } QFrontFace::FaceDir QFrontFace::direction() const @@ -92,16 +92,15 @@ void QFrontFace::setDirection(QFrontFace::FaceDir direction) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("direction")); propertyChange->setValue(d->m_direction); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QFrontFace::doClone(bool isClone) const +QNode *QFrontFace::doClone() const { QFrontFace *clone = new QFrontFace(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qfrontface.h b/src/render/frontend/qfrontface.h index 6e63fd97f..8acb8b28d 100644 --- a/src/render/frontend/qfrontface.h +++ b/src/render/frontend/qfrontface.h @@ -66,8 +66,6 @@ public: explicit QFrontFace(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - FaceDir direction() const; void setDirection(FaceDir direction); @@ -76,7 +74,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QFrontFace) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qlayer.cpp b/src/render/frontend/qlayer.cpp index 215fd4689..79dbfca97 100644 --- a/src/render/frontend/qlayer.cpp +++ b/src/render/frontend/qlayer.cpp @@ -51,31 +51,28 @@ QLayerPrivate::QLayerPrivate(QLayer *qq) { } -QLayer::QLayer(QNode *parent) - : QComponent(*new QLayerPrivate(this), parent) +void QLayerPrivate::copy(const QNodePrivate *ref) { + QComponentPrivate::copy(ref); + const QLayerPrivate *layer = static_cast<const QLayerPrivate *>(ref); + m_name = layer->m_name; } -void QLayer::copy(const QNode *ref) +QLayer::QLayer(QNode *parent) + : QComponent(*new QLayerPrivate(this), parent) { - Q_D(QLayer); - QComponent::copy(ref); - const QLayer *layer = qobject_cast<const QLayer *>(ref); - if (layer != Q_NULLPTR) { - d->m_name = layer->name(); - } } + QLayer::QLayer(QLayerPrivate &dd, QNode *parent) : QComponent(dd, parent) { } -QLayer *QLayer::doClone(bool isClone) const +QLayer *QLayer::doClone() const { QLayer *clone = new QLayer(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qlayer.h b/src/render/frontend/qlayer.h index 3e996afc7..5523c0c85 100644 --- a/src/render/frontend/qlayer.h +++ b/src/render/frontend/qlayer.h @@ -58,8 +58,6 @@ class QT3DRENDERERSHARED_EXPORT QLayer : public QComponent public: explicit QLayer(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - QString name() const; void setName(const QString &name); @@ -67,9 +65,11 @@ Q_SIGNALS: void nameChanged(); protected: - Q_DECLARE_PRIVATE(QLayer) QLayer(QLayerPrivate &dd, QNode *parent = 0); - QLayer *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QLayer) + QLayer *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qlayer_p.h b/src/render/frontend/qlayer_p.h index 23117bdac..e4863b7d2 100644 --- a/src/render/frontend/qlayer_p.h +++ b/src/render/frontend/qlayer_p.h @@ -54,6 +54,9 @@ class QT3DRENDERERSHARED_EXPORT QLayerPrivate : QComponentPrivate { public: QLayerPrivate(QLayer *qq); + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QLayer) QString m_name; }; diff --git a/src/render/frontend/qmaterial.cpp b/src/render/frontend/qmaterial.cpp index ba1102052..c44bd77b8 100644 --- a/src/render/frontend/qmaterial.cpp +++ b/src/render/frontend/qmaterial.cpp @@ -56,24 +56,28 @@ QMaterialPrivate::QMaterialPrivate(QMaterial *qq) { } +void QMaterialPrivate::copy(const QNodePrivate *ref) +{ + QAbstractMaterialPrivate::copy(ref); +} + QMaterial::QMaterial(QMaterialPrivate &dd, QNode *parent) : QAbstractMaterial(dd, parent) { } -QMaterial *QMaterial::doClone(bool isClone) const +QMaterial *QMaterial::doClone() const { Q_D(const QMaterial); QMaterial *mat = new QMaterial(); - mat->copy(this); - mat->d_func()->m_isClone = isClone; + mat->d_func()->copy(d_func()); Q_FOREACH (QParameter *p, d->m_parameters) - mat->addParameter(qobject_cast<QParameter *>(p->clone(isClone))); + mat->addParameter(qobject_cast<QParameter *>(QNodePrivate::get(p)->clone())); if (d->m_effect != Q_NULLPTR) - mat->setEffect(qobject_cast<QAbstractEffect *>(d->m_effect->clone(isClone))); + mat->setEffect(qobject_cast<QAbstractEffect *>(QNodePrivate::get(d->m_effect)->clone())); return mat; } @@ -83,10 +87,6 @@ QMaterial::QMaterial(QNode *parent) { } -void QMaterial::copy(const QNode *ref) -{ - QAbstractMaterial::copy(ref); -} void QMaterial::setEffect(QAbstractEffect *effect) { @@ -105,14 +105,14 @@ void QMaterial::addParameter(QParameter *parameter) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!parameter->parent() || parameter->parent() == this) - QNode::addChild(parameter); + if (!parameter->parent()) + parameter->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("parameter")); - change->setValue(QVariant::fromValue(parameter->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(parameter)->clone())); + d->notifyObservers(change); } } } @@ -123,8 +123,8 @@ void QMaterial::removeParameter(QParameter *parameter) if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("parameter")); - change->setValue(QVariant::fromValue(parameter->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(parameter)->clone())); + d->notifyObservers(change); } d->m_parameters.removeOne(parameter); } diff --git a/src/render/frontend/qmaterial.h b/src/render/frontend/qmaterial.h index e15fe3430..08bc47fc8 100644 --- a/src/render/frontend/qmaterial.h +++ b/src/render/frontend/qmaterial.h @@ -66,8 +66,6 @@ class QT3DRENDERERSHARED_EXPORT QMaterial : public QAbstractMaterial public: explicit QMaterial(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setEffect(QAbstractEffect *effect) Q_DECL_OVERRIDE; void addParameter(QParameter *parameter); @@ -79,9 +77,11 @@ public: void setTextureParameter(QString name, QTexture* tex); protected: - Q_DECLARE_PRIVATE(QMaterial) QMaterial(QMaterialPrivate &dd, QNode *parent = 0); - QMaterial *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QMaterial) + QMaterial *doClone() const Q_DECL_OVERRIDE; }; } diff --git a/src/render/frontend/qmaterial_p.h b/src/render/frontend/qmaterial_p.h index 0d33ba397..a7e68bef9 100644 --- a/src/render/frontend/qmaterial_p.h +++ b/src/render/frontend/qmaterial_p.h @@ -54,9 +54,11 @@ class QT3DRENDERERSHARED_EXPORT QMaterialPrivate : public QAbstractMaterialPriva public: QMaterialPrivate(QMaterial *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + + Q_DECLARE_PUBLIC(QMaterial) QList<QParameter *> m_parameters; TextureDict m_textures; - Q_DECLARE_PUBLIC(QMaterial) }; } // Qt3D diff --git a/src/render/frontend/qmesh.cpp b/src/render/frontend/qmesh.cpp index ccd77a61d..50101f369 100644 --- a/src/render/frontend/qmesh.cpp +++ b/src/render/frontend/qmesh.cpp @@ -71,19 +71,16 @@ QMeshPrivate::QMeshPrivate(QMesh *qq) : QAbstractMeshPrivate(qq) {} -QMesh::QMesh(QNode *parent) - : QAbstractMesh(*new QMeshPrivate(this), parent) +void QMeshPrivate::copy(const QNodePrivate *ref) { + QAbstractMeshPrivate::copy(ref); + const QMeshPrivate *mesh = static_cast<const QMeshPrivate *>(ref); + m_source = mesh->m_source; } -void QMesh::copy(const QNode *ref) +QMesh::QMesh(QNode *parent) + : QAbstractMesh(*new QMeshPrivate(this), parent) { - Q_D(QMesh); - QAbstractMesh::copy(ref); - const QMesh *mesh = qobject_cast<const QMesh *>(ref); - if (mesh != Q_NULLPTR) { - d->m_source = mesh->source(); - } } QMesh::QMesh(QMeshPrivate &dd, QNode *parent) @@ -91,11 +88,10 @@ QMesh::QMesh(QMeshPrivate &dd, QNode *parent) { } -QMesh *QMesh::doClone(bool isClone) const +QMesh *QMesh::doClone() const { QMesh *clone = new QMesh(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qmesh.h b/src/render/frontend/qmesh.h index 5544098fc..fe6044d01 100644 --- a/src/render/frontend/qmesh.h +++ b/src/render/frontend/qmesh.h @@ -66,8 +66,6 @@ class QT3DRENDERERSHARED_EXPORT QMesh : public QAbstractMesh public: explicit QMesh(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setSource(const QString &source); QString source() const; @@ -77,9 +75,11 @@ Q_SIGNALS: void sourceChanged(); protected: - Q_DECLARE_PRIVATE(QMesh) QMesh(QMeshPrivate &dd, QNode *parent = 0); - QMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QMesh) + QMesh *doClone() const Q_DECL_OVERRIDE; }; } diff --git a/src/render/frontend/qmesh_p.h b/src/render/frontend/qmesh_p.h index ee9a08177..77102b0ad 100644 --- a/src/render/frontend/qmesh_p.h +++ b/src/render/frontend/qmesh_p.h @@ -57,9 +57,10 @@ class QT3DRENDERERSHARED_EXPORT QMeshPrivate : public QAbstractMeshPrivate public: QMeshPrivate(QMesh *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QMesh) - QMeshDataPtr m_data; QString m_source; }; diff --git a/src/render/frontend/qparameter.cpp b/src/render/frontend/qparameter.cpp index 2b4a23017..ab609cbc3 100644 --- a/src/render/frontend/qparameter.cpp +++ b/src/render/frontend/qparameter.cpp @@ -61,17 +61,24 @@ void QParameterPrivate::setValue(const QVariant &v) m_value = v; } +void QParameterPrivate::copy(const QNodePrivate *ref) +{ + QNodePrivate::copy(ref); + const QParameterPrivate *param = static_cast<const QParameterPrivate *>(ref); + m_name = param->m_name; + m_value = param->m_value; + m_isTexture = param->m_isTexture; +} + QParameter::QParameter(QParameterPrivate &dd, QNode *parent) : QNode(dd, parent) - { } -QParameter *QParameter::doClone(bool isClone) const +QParameter *QParameter::doClone() const { QParameter *clone = new QParameter(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -96,17 +103,6 @@ QParameter::QParameter(const QString &name, QTexture *texture, QNode *parent) setValue(QVariant::fromValue(texture)); } -void QParameter::copy(const QNode *ref) -{ - Q_D(QParameter); - QNode::copy(ref); - const QParameter *param = qobject_cast<const QParameter *>(ref); - if (param != Q_NULLPTR) { - d->m_name = param->name(); - d->m_value = param->value(); - d->m_isTexture = param->isTextureType(); - } -} void QParameter::setName(const QString &name) { @@ -132,13 +128,13 @@ void QParameter::setValue(const QVariant &dv) // In case texture are declared inline QTexture *txt = dv.value<QTexture *>(); - if ((d->m_isTexture = (txt != Q_NULLPTR)) && (!txt->parent() || txt->parent() == this)) - QNode::addChild(txt); + if ((d->m_isTexture = (txt != Q_NULLPTR)) && !txt->parent()) + txt->setParent(this); QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(d->m_name.toUtf8()); change->setValue(d->m_value); - notifyObservers(change); + d->notifyObservers(change); } } diff --git a/src/render/frontend/qparameter.h b/src/render/frontend/qparameter.h index 75ca0db9e..cbda5c76a 100644 --- a/src/render/frontend/qparameter.h +++ b/src/render/frontend/qparameter.h @@ -42,6 +42,7 @@ #ifndef QT3D_QPARAMETER_H #define QT3D_QPARAMETER_H +#include <QVariant> #include <Qt3DCore/qnode.h> #include <Qt3DRenderer/qt3drenderer_global.h> @@ -63,8 +64,6 @@ public: QParameter(const QString& name, const QVariant& value, QNode* parent = 0); QParameter(const QString &name, QTexture *texture, QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setName(const QString &name); QString name() const; @@ -82,9 +81,11 @@ Q_SIGNALS: void nameChanged(); protected: - Q_DECLARE_PRIVATE(QParameter) QParameter(QParameterPrivate &dd, QNode *parent = 0); - QParameter *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QParameter) + QParameter *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qparameter_p.h b/src/render/frontend/qparameter_p.h index c32f9018a..e9f917939 100644 --- a/src/render/frontend/qparameter_p.h +++ b/src/render/frontend/qparameter_p.h @@ -59,6 +59,7 @@ public: Q_DECLARE_PUBLIC(QParameter) virtual void setValue(const QVariant &v); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; QString m_name; QVariant m_value; diff --git a/src/render/frontend/qparametermapper.cpp b/src/render/frontend/qparametermapper.cpp index 209078254..141ce6428 100644 --- a/src/render/frontend/qparametermapper.cpp +++ b/src/render/frontend/qparametermapper.cpp @@ -52,6 +52,15 @@ QParameterMapperPrivate::QParameterMapperPrivate(QParameterMapper *qq) { } +void QParameterMapperPrivate::copy(const QNodePrivate *ref) +{ + QNodePrivate::copy(ref); + const QParameterMapperPrivate *mapper = static_cast<const QParameterMapperPrivate *>(ref); + m_parameterName = mapper->m_parameterName; + m_shaderVariableName = mapper->m_shaderVariableName; + m_bindingType = mapper->m_bindingType; +} + QParameterMapper::QParameterMapper(QNode *parent) : QNode(*new QParameterMapperPrivate(this), parent) { @@ -62,11 +71,10 @@ QParameterMapper::QParameterMapper(QParameterMapperPrivate &dd, QNode *parent) { } -QNode *QParameterMapper::doClone(bool isClone) const +QNode *QParameterMapper::doClone() const { QParameterMapper *clone = new QParameterMapper(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -79,18 +87,6 @@ QParameterMapper::QParameterMapper(const QString ¶meterName, const QString & d->m_bindingType = bindingType; } -void QParameterMapper::copy(const QNode *ref) -{ - Q_D(QParameterMapper); - QNode::copy(ref); - const QParameterMapper *mapper = qobject_cast<const QParameterMapper *>(ref); - if (mapper != Q_NULLPTR) { - d->m_parameterName = mapper->parameterName(); - d->m_shaderVariableName = mapper->shaderVariableName(); - d->m_bindingType = mapper->bindingType(); - } -} - void QParameterMapper::setParameterName(const QString &name) { Q_D(QParameterMapper); diff --git a/src/render/frontend/qparametermapper.h b/src/render/frontend/qparametermapper.h index cae9a24f5..fd78ea3a1 100644 --- a/src/render/frontend/qparametermapper.h +++ b/src/render/frontend/qparametermapper.h @@ -70,8 +70,6 @@ public: explicit QParameterMapper(QNode *parent = 0); QParameterMapper(const QString ¶meterName, const QString &shaderParameterName, QParameterMapper::Binding bindingType, QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setParameterName(const QString &name); void setShaderVariableName(const QString &name); void setBindingType(Binding type); @@ -87,8 +85,10 @@ Q_SIGNALS: protected: QParameterMapper(QParameterMapperPrivate &dd, QNode *parent = 0); - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: Q_DECLARE_PRIVATE(QParameterMapper) + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qparametermapper_p.h b/src/render/frontend/qparametermapper_p.h index 2d7d5a43c..b75155ba2 100644 --- a/src/render/frontend/qparametermapper_p.h +++ b/src/render/frontend/qparametermapper_p.h @@ -54,6 +54,8 @@ class QParameterMapperPrivate : public QNodePrivate public: QParameterMapperPrivate(QParameterMapper *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QParameterMapper) QString m_parameterName; diff --git a/src/render/frontend/qplanemesh.cpp b/src/render/frontend/qplanemesh.cpp index ee1e86e60..4803ecc53 100644 --- a/src/render/frontend/qplanemesh.cpp +++ b/src/render/frontend/qplanemesh.cpp @@ -65,16 +65,13 @@ QPlaneMesh::QPlaneMesh(QNode *parent) setDirty(true); } -void QPlaneMesh::copy(const QNode *ref) +void QPlaneMeshPrivate::copy(const QNodePrivate *ref) { - Q_D(QPlaneMesh); - QAbstractShapeMesh::copy(ref); - const QPlaneMesh *mesh = qobject_cast<const QPlaneMesh *>(ref); - if (mesh != Q_NULLPTR) { - d->m_width = mesh->width(); - d->m_height = mesh->height(); - d->m_meshResolution = mesh->meshResolution(); - } + QAbstractShapeMeshPrivate::copy(ref); + const QPlaneMeshPrivate *mesh = static_cast<const QPlaneMeshPrivate *>(ref); + m_width = mesh->m_width; + m_height = mesh->m_height; + m_meshResolution = mesh->m_meshResolution; } QPlaneMesh::QPlaneMesh(QPlaneMeshPrivate &dd, QNode *parent) @@ -84,11 +81,10 @@ QPlaneMesh::QPlaneMesh(QPlaneMeshPrivate &dd, QNode *parent) } -QPlaneMesh *QPlaneMesh::doClone(bool isClone) const +QPlaneMesh *QPlaneMesh::doClone() const { QPlaneMesh *clone = new QPlaneMesh(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qplanemesh.h b/src/render/frontend/qplanemesh.h index c2f9dca7b..2eca40feb 100644 --- a/src/render/frontend/qplanemesh.h +++ b/src/render/frontend/qplanemesh.h @@ -62,8 +62,6 @@ class QT3DRENDERERSHARED_EXPORT QPlaneMesh : public Qt3D::QAbstractShapeMesh public: explicit QPlaneMesh(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setWidth(float width); float width() const; @@ -82,8 +80,10 @@ Q_SIGNALS: protected: QPlaneMesh(QPlaneMeshPrivate &dd, QNode *parent = 0); - QPlaneMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: Q_DECLARE_PRIVATE(QPlaneMesh) + QPlaneMesh *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/render/frontend/qplanemesh_p.h b/src/render/frontend/qplanemesh_p.h index 90bceef55..9c72da9a7 100644 --- a/src/render/frontend/qplanemesh_p.h +++ b/src/render/frontend/qplanemesh_p.h @@ -57,6 +57,8 @@ class QPlaneMeshPrivate : public QAbstractShapeMeshPrivate public: QPlaneMeshPrivate(QPlaneMesh *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QPlaneMesh) float m_width; diff --git a/src/render/frontend/qpointlight.cpp b/src/render/frontend/qpointlight.cpp index a9db0381a..34d07ecbc 100644 --- a/src/render/frontend/qpointlight.cpp +++ b/src/render/frontend/qpointlight.cpp @@ -84,11 +84,10 @@ QPointLight::QPointLight(QPointLightPrivate &dd, QNode *parent) { } -QPointLight *QPointLight::doClone(bool isClone) const +QPointLight *QPointLight::doClone() const { QPointLight *clone = new QPointLight(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qpointlight.h b/src/render/frontend/qpointlight.h index 12ab4d51c..3fbb0fa2c 100644 --- a/src/render/frontend/qpointlight.h +++ b/src/render/frontend/qpointlight.h @@ -63,7 +63,7 @@ public: protected: Q_DECLARE_PRIVATE(QPointLight) QPointLight(QPointLightPrivate &dd, QNode *parent); - QPointLight *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QPointLight *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qrenderattachment.cpp b/src/render/frontend/qrenderattachment.cpp index 44828ca2d..f75bbc321 100644 --- a/src/render/frontend/qrenderattachment.cpp +++ b/src/render/frontend/qrenderattachment.cpp @@ -57,6 +57,13 @@ QRenderAttachmentPrivate::QRenderAttachmentPrivate(QRenderAttachment *qq) { } +void QRenderAttachmentPrivate::copy(const QNodePrivate *ref) +{ + QNodePrivate::copy(ref); + const QRenderAttachmentPrivate *rA = static_cast<const QRenderAttachmentPrivate *>(ref); + m_type = rA->m_type; +} + QRenderAttachment::QRenderAttachment(QNode *parent) : QNode(*new QRenderAttachmentPrivate(this), parent) { @@ -67,17 +74,6 @@ QRenderAttachment::QRenderAttachment(QRenderAttachmentPrivate &dd, QNode *parent { } -void QRenderAttachment::copy(const QNode *ref) -{ - QNode::copy(ref); - const QRenderAttachment *rA = qobject_cast<const QRenderAttachment *>(ref); - if (rA != Q_NULLPTR) { - setType(rA->type()); - // TO DO: Send a clone once Texture is a QNode subclass - setTexture(rA->texture()); - } -} - void QRenderAttachment::setType(QRenderAttachment::RenderAttachmentType type) { Q_D(QRenderAttachment); @@ -88,7 +84,7 @@ void QRenderAttachment::setType(QRenderAttachment::RenderAttachmentType type) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("type")); change->setValue(type); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -107,15 +103,15 @@ void QRenderAttachment::setTexture(QTexture *texture) emit textureChanged(); // Handle inline declaration - if (!texture->parent() || texture->parent() == this) - QNode::addChild(texture); + if (!texture->parent()) + texture->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("texture")); // TO DO: Send a clone once Texture is a QNode subclass change->setValue(QVariant::fromValue(texture)); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -136,7 +132,7 @@ void QRenderAttachment::setMipLevel(int level) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("mipLevel")); change->setValue(level); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -157,7 +153,7 @@ void QRenderAttachment::setLayer(int layer) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("layer")); change->setValue(layer); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -178,7 +174,7 @@ void QRenderAttachment::setFace(QRenderAttachment::CubeMapFace face) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("face")); change->setValue(face); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -199,7 +195,7 @@ void QRenderAttachment::setName(const QString &name) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("name")); change->setValue(name); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -210,11 +206,12 @@ QString QRenderAttachment::name() const return d->m_name; } -QNode *QRenderAttachment::doClone(bool isClone) const +QNode *QRenderAttachment::doClone() const { - QRenderAttachment *clone = new QRenderAttachment(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + Q_D(const QRenderAttachment); + QRenderAttachment *clone = new QRenderAttachment();; + clone->d_func()->copy(d_func()); + clone->setTexture(qobject_cast<QTexture *>(QNodePrivate::get(d->m_texture)->clone())); return clone; } diff --git a/src/render/frontend/qrenderattachment.h b/src/render/frontend/qrenderattachment.h index 03cab0ef6..0c63ece5e 100644 --- a/src/render/frontend/qrenderattachment.h +++ b/src/render/frontend/qrenderattachment.h @@ -97,7 +97,6 @@ public: }; explicit QRenderAttachment(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; void setType(RenderAttachmentType type); RenderAttachmentType type() const; @@ -126,9 +125,11 @@ Q_SIGNALS: void nameChanged(); protected: - Q_DECLARE_PRIVATE(QRenderAttachment) QRenderAttachment(QRenderAttachmentPrivate &dd, QNode *parent = 0); - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QRenderAttachment) + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qrenderattachment_p.h b/src/render/frontend/qrenderattachment_p.h index aefe09772..9b58c067c 100644 --- a/src/render/frontend/qrenderattachment_p.h +++ b/src/render/frontend/qrenderattachment_p.h @@ -55,6 +55,9 @@ class QRenderAttachmentPrivate : public QNodePrivate { public: QRenderAttachmentPrivate(QRenderAttachment *qq); + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QRenderAttachment) QTexture *m_texture; diff --git a/src/render/frontend/qrenderpass.cpp b/src/render/frontend/qrenderpass.cpp index 8c805992c..99a7b53c3 100644 --- a/src/render/frontend/qrenderpass.cpp +++ b/src/render/frontend/qrenderpass.cpp @@ -47,6 +47,9 @@ #include "qparametermapper.h" #include "qscenepropertychange.h" #include "qrenderstate.h" +#include "qcriterion_p.h" +#include "qparametermapper_p.h" +#include "private/qnode_p.h" QT_BEGIN_NAMESPACE @@ -67,21 +70,20 @@ QRenderPass::QRenderPass(QRenderPassPrivate &dd, QNode *parent) { } -QRenderPass *QRenderPass::doClone(bool isClone) const +QRenderPass *QRenderPass::doClone() const { Q_D(const QRenderPass); QRenderPass *pass = new QRenderPass(); - pass->copy(this); - pass->d_func()->m_isClone = isClone; + pass->d_func()->copy(d_func()); Q_FOREACH (QCriterion *crit, d->m_criteriaList) - pass->addCriterion(qobject_cast<QCriterion *>(crit->clone(isClone))); + pass->addCriterion(qobject_cast<QCriterion *>(QNodePrivate::get(crit)->clone())); Q_FOREACH (QParameterMapper *binding, d->m_bindings) - pass->addBinding(qobject_cast<QParameterMapper *>(binding->clone(isClone))); + pass->addBinding(qobject_cast<QParameterMapper *>(QNodePrivate::get(binding)->clone())); Q_FOREACH (QRenderState *renderState, d->m_renderStates) - pass->addRenderState(qobject_cast<QRenderState *>(renderState->clone(isClone))); - pass->d_func()->m_shader = qobject_cast<QShaderProgram *>(d->m_shader->clone(isClone)); + pass->addRenderState(qobject_cast<QRenderState *>(QNodePrivate::get(renderState)->clone())); + pass->d_func()->m_shader = qobject_cast<QShaderProgram *>(QNodePrivate::get(d->m_shader)->clone()); return pass; } @@ -108,14 +110,14 @@ void QRenderPass::addCriterion(QCriterion *criterion) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!criterion->parent() || criterion->parent() == this) - QNode::addChild(criterion); + if (!criterion->parent()) + criterion->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("criterion")); - change->setValue(QVariant::fromValue(criterion->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(qobject_cast<QCriterion *>(QNodePrivate::get(criterion)->clone()))); + d->notifyObservers(change); } } } @@ -127,7 +129,7 @@ void QRenderPass::removeCriterion(QCriterion *criterion) QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("criterion")); change->setValue(QVariant::fromValue(criterion->uuid())); - notifyObservers(change); + d->notifyObservers(change); } d->m_criteriaList.removeOne(criterion); } @@ -151,14 +153,14 @@ void QRenderPass::addBinding(QParameterMapper *binding) if (!d->m_bindings.contains(binding)) { d->m_bindings.append(binding); - if (!binding->parent() || binding->parent() == this) - QNode::addChild(binding); + if (!binding->parent()) + binding->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("binding")); - change->setValue(QVariant::fromValue(binding->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(binding)->clone())); + d->notifyObservers(change); } } } @@ -170,7 +172,7 @@ void QRenderPass::removeBinding(QParameterMapper *binding) QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("binding")); change->setValue(QVariant::fromValue(binding->uuid())); - notifyObservers(change); + d->notifyObservers(change); } d->m_bindings.removeOne(binding); } @@ -188,14 +190,14 @@ void QRenderPass::addRenderState(QRenderState *state) if (!d->m_renderStates.contains(state)) { d->m_renderStates.append(state); - if (!state->parent() || state->parent() == this) - QNode::addChild(state); + if (!state->parent()) + state->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("renderState")); - change->setValue(QVariant::fromValue(state->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(state)->clone())); + d->notifyObservers(change); } } } @@ -207,7 +209,7 @@ void QRenderPass::removeRenderState(QRenderState *state) QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("renderState")); change->setValue(QVariant::fromValue(state->uuid())); - notifyObservers(change); + d->notifyObservers(change); } d->m_renderStates.removeOne(state); } diff --git a/src/render/frontend/qrenderpass.h b/src/render/frontend/qrenderpass.h index 896aafb20..5077ab469 100644 --- a/src/render/frontend/qrenderpass.h +++ b/src/render/frontend/qrenderpass.h @@ -94,9 +94,11 @@ public: QList<QRenderState *> renderStates() const; protected: - Q_DECLARE_PRIVATE(QRenderPass) QRenderPass(QRenderPassPrivate &dd, QNode *parent = 0); - QRenderPass *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QRenderPass) + QRenderPass *doClone() const Q_DECL_OVERRIDE; }; } diff --git a/src/render/frontend/qrenderpass_p.h b/src/render/frontend/qrenderpass_p.h index 28a8f6653..58951661d 100644 --- a/src/render/frontend/qrenderpass_p.h +++ b/src/render/frontend/qrenderpass_p.h @@ -44,16 +44,17 @@ #define QT3D_QRENDERPASS_P_H #include <private/qabstractrenderpass_p.h> +#include <Qt3DRenderer/qrenderpass.h> #include <Qt3DRenderer/qt3drenderer_global.h> QT_BEGIN_NAMESPACE namespace Qt3D { -class QRenderPass; class QParameter; class QParameterMapper; class QRenderState; +class QCriterion; typedef QList<QParameter*> ParameterList; namespace Render diff --git a/src/render/frontend/qrenderstate.cpp b/src/render/frontend/qrenderstate.cpp index 2c0be478c..c6ca132f4 100644 --- a/src/render/frontend/qrenderstate.cpp +++ b/src/render/frontend/qrenderstate.cpp @@ -41,17 +41,23 @@ ****************************************************************************/ #include "qrenderstate.h" +#include "qrenderstate_p.h" QT_BEGIN_NAMESPACE namespace Qt3D { +QRenderStatePrivate::QRenderStatePrivate(QRenderState *qq) + : QNodePrivate(qq) +{ +} + QRenderState::QRenderState(QNode *parent) - : QNode(parent) + : QNode(*new QRenderStatePrivate(this), parent) { } -QRenderState::QRenderState(QNodePrivate &dd, QNode *parent) +QRenderState::QRenderState(QRenderStatePrivate &dd, QNode *parent) : QNode(dd, parent) { } diff --git a/src/render/frontend/qrenderstate.h b/src/render/frontend/qrenderstate.h index f6081ed21..aebf65403 100644 --- a/src/render/frontend/qrenderstate.h +++ b/src/render/frontend/qrenderstate.h @@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE namespace Qt3D { +class QRenderStatePrivate; + class QT3DRENDERERSHARED_EXPORT QRenderState : public QNode { Q_OBJECT @@ -57,7 +59,10 @@ public: explicit QRenderState(QNode *parent = 0); protected: - QRenderState(QNodePrivate &dd, QNode *parent = 0); + QRenderState(QRenderStatePrivate &dd, QNode *parent = 0); + +private: + Q_DECLARE_PRIVATE(QRenderState) }; } // Qt3D diff --git a/src/render/frontend/qrenderstate_p.h b/src/render/frontend/qrenderstate_p.h new file mode 100644 index 000000000..18f2b782a --- /dev/null +++ b/src/render/frontend/qrenderstate_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QRENDERSTATE_P_H +#define QT3D_QRENDERSTATE_P_H + +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QRenderStatePrivate : public QNodePrivate +{ +public: + + QRenderStatePrivate(QRenderState *qq); + Q_DECLARE_PUBLIC(QRenderState) +}; + +} + +QT_END_NAMESPACE + +#endif // QT3D_QRENDERSTATE_P_H diff --git a/src/render/frontend/qrendertarget.cpp b/src/render/frontend/qrendertarget.cpp index a211743e2..604335405 100644 --- a/src/render/frontend/qrendertarget.cpp +++ b/src/render/frontend/qrendertarget.cpp @@ -53,6 +53,11 @@ QRenderTargetPrivate::QRenderTargetPrivate(QRenderTarget *qq) { } +void QRenderTargetPrivate::copy(const QNodePrivate *ref) +{ + QNodePrivate::copy(ref); +} + QRenderTarget::QRenderTarget(QNode *parent) : QComponent(*new QRenderTargetPrivate(this), parent) { @@ -63,25 +68,20 @@ QRenderTarget::QRenderTarget(QRenderTargetPrivate &dd, QNode *parent) { } -void QRenderTarget::copy(const QNode *ref) -{ - QNode::copy(ref); -} - void QRenderTarget::addAttachment(QRenderAttachment *attachment) { Q_D(QRenderTarget); if (!d->m_attachments.contains(attachment)) { d->m_attachments.append(attachment); - if (!attachment->parent() || attachment->parent() == this) - addChild(attachment); + if (!attachment->parent()) + attachment->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("attachment")); - change->setValue(QVariant::fromValue(attachment->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(attachment)->clone())); + d->notifyObservers(change); } } } @@ -93,8 +93,8 @@ void QRenderTarget::removeAttachment(QRenderAttachment *attachment) if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("attachment")); - change->setValue(QVariant::fromValue(attachment->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(attachment)->clone())); + d->notifyObservers(change); } d->m_attachments.removeOne(attachment); } @@ -105,16 +105,15 @@ QList<QRenderAttachment *> QRenderTarget::attachments() const return d->m_attachments; } -QRenderTarget *QRenderTarget::doClone(bool isClone) const +QRenderTarget *QRenderTarget::doClone() const { Q_D(const QRenderTarget); QRenderTarget *clone = new QRenderTarget(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); Q_FOREACH (QRenderAttachment *attachment, d->m_attachments) - clone->addAttachment(qobject_cast<QRenderAttachment *>(attachment->clone(isClone))); + clone->addAttachment(qobject_cast<QRenderAttachment *>(QNodePrivate::get(attachment)->clone())); return clone; } diff --git a/src/render/frontend/qrendertarget.h b/src/render/frontend/qrendertarget.h index 766f5eedb..095f9b732 100644 --- a/src/render/frontend/qrendertarget.h +++ b/src/render/frontend/qrendertarget.h @@ -58,16 +58,16 @@ class QT3DRENDERERSHARED_EXPORT QRenderTarget : public QComponent public: explicit QRenderTarget(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void addAttachment(QRenderAttachment *attachment); void removeAttachment(QRenderAttachment *attachment); QList<QRenderAttachment *> attachments() const; protected: - Q_DECLARE_PRIVATE(QRenderTarget) QRenderTarget(QRenderTargetPrivate &dd, QNode *parent = 0); - QRenderTarget *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QRenderTarget) + QRenderTarget *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qrendertarget_p.h b/src/render/frontend/qrendertarget_p.h index 3c740fe97..433c38467 100644 --- a/src/render/frontend/qrendertarget_p.h +++ b/src/render/frontend/qrendertarget_p.h @@ -55,6 +55,9 @@ class QRenderTargetPrivate : public QComponentPrivate { public: QRenderTargetPrivate(QRenderTarget *qq); + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QRenderTarget) QList<QRenderAttachment *> m_attachments; }; diff --git a/src/render/frontend/qsceneloader.cpp b/src/render/frontend/qsceneloader.cpp index ecc2c397f..ea9eb708f 100644 --- a/src/render/frontend/qsceneloader.cpp +++ b/src/render/frontend/qsceneloader.cpp @@ -64,21 +64,16 @@ void QSceneLoader::sceneChangeEvent(const QSceneChangePtr &change) if (e->type() == ComponentUpdated) { if (e->propertyName() == QByteArrayLiteral("scene")) { QEntity *scene = e->value().value<QEntity *>(); + // TO DO: We should send a QNodePtr so that it is release automatically if (scene != Q_NULLPTR && d->m_scene != Q_NULLPTR) { QList<QUuid> entities = d->m_scene->entitiesForComponent(d->m_uuid); - if (entities.size() > 1) + if (entities.size() > 1) // TO DO: QComponent shareable property qCWarning(Render::Frontend) << "It is strongly discouraged to share SceneLoader component between entities"; Q_FOREACH (const QUuid &id, entities) { QEntity *parentEntity = qobject_cast<QEntity *>(d->m_scene->lookupNode(id)); if (parentEntity != Q_NULLPTR) { - scene->dumpObjectTree(); - - qDebug() << "BUILDING SUBTREE DEEP CLONE"; - QEntity *cloneScene = qobject_cast<QEntity *>(scene->clone(false)); - cloneScene->dumpObjectTree(); - // TO DO : Make that work - qDebug() << "<<<<<<<<<<<<<<<<< " << QThread::currentThread() << parentEntity->thread() << scene->thread() << cloneScene->thread(); -// parentEntity->addChild(cloneScene); + QEntity *cloneScene = qobject_cast<QEntity *>(QNodePrivate::get(scene)->clone()); + QNodePrivate::get(parentEntity)->insertTree(cloneScene); } } } @@ -89,11 +84,10 @@ void QSceneLoader::sceneChangeEvent(const QSceneChangePtr &change) } } -QNode *QSceneLoader::doClone(bool isClone) const +QNode *QSceneLoader::doClone() const { QSceneLoader *clone = new QSceneLoader(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qsceneloader.h b/src/render/frontend/qsceneloader.h index 9dae1c359..fa2181a83 100644 --- a/src/render/frontend/qsceneloader.h +++ b/src/render/frontend/qsceneloader.h @@ -56,7 +56,7 @@ public: void sceneChangeEvent(const QSceneChangePtr &change) Q_DECL_OVERRIDE; protected: - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qscissortest.cpp b/src/render/frontend/qscissortest.cpp index 89d07e33b..8babfe1c6 100644 --- a/src/render/frontend/qscissortest.cpp +++ b/src/render/frontend/qscissortest.cpp @@ -41,6 +41,7 @@ ****************************************************************************/ #include "qscissortest.h" +#include "qrenderstate_p.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -49,11 +50,11 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QScissorTestPrivate : public QNodePrivate +class QScissorTestPrivate : public QRenderStatePrivate { public: QScissorTestPrivate(QScissorTest *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) , m_left(0) , m_bottom(0) , m_width(0) @@ -61,6 +62,8 @@ public: { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QScissorTest) int m_left; int m_bottom; @@ -73,17 +76,14 @@ QScissorTest::QScissorTest(QNode *parent) { } -void QScissorTest::copy(const QNode *ref) +void QScissorTestPrivate::copy(const QNodePrivate *ref) { - QRenderState::copy(ref); - Q_D(QScissorTest); - const QScissorTest *refState = qobject_cast<const QScissorTest *>(ref); - if (refState != Q_NULLPTR) { - d->m_left = refState->left(); - d->m_bottom = refState->bottom(); - d->m_width = refState->width(); - d->m_height = refState->height(); - } + QRenderStatePrivate::copy(ref); + const QScissorTestPrivate *refState = static_cast<const QScissorTestPrivate *>(ref); + m_left = refState->m_left; + m_bottom = refState->m_bottom; + m_width = refState->m_width; + m_height = refState->m_height; } int QScissorTest::left() const @@ -102,7 +102,7 @@ void QScissorTest::setLeft(int left) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("left")); propertyChange->setValue(d->m_left); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -123,7 +123,7 @@ void QScissorTest::setBottom(int bottom) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("bottom")); propertyChange->setValue(d->m_bottom); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -144,7 +144,7 @@ void QScissorTest::setWidth(int width) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("width")); propertyChange->setValue(d->m_width); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -165,16 +165,15 @@ void QScissorTest::setHeight(int height) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("height")); propertyChange->setValue(d->m_height); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QScissorTest::doClone(bool isClone) const +QNode *QScissorTest::doClone() const { QScissorTest *clone = new QScissorTest(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qscissortest.h b/src/render/frontend/qscissortest.h index b22e79aba..7e43ae8cc 100644 --- a/src/render/frontend/qscissortest.h +++ b/src/render/frontend/qscissortest.h @@ -62,8 +62,6 @@ class QT3DRENDERERSHARED_EXPORT QScissorTest : public QRenderState public: explicit QScissorTest(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - int left() const; void setLeft(int left); @@ -84,7 +82,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QScissorTest) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qshaderprogram.cpp b/src/render/frontend/qshaderprogram.cpp index 4c39b64aa..048c31e4f 100644 --- a/src/render/frontend/qshaderprogram.cpp +++ b/src/render/frontend/qshaderprogram.cpp @@ -54,31 +54,28 @@ QShaderProgramPrivate::QShaderProgramPrivate(QShaderProgram *qq) { } -QShaderProgram::QShaderProgram(QNode *parent) - : QAbstractShader(*new QShaderProgramPrivate(this), parent) +void QShaderProgramPrivate::copy(const QNodePrivate *ref) { + QAbstractShaderPrivate::copy(ref); + const QShaderProgramPrivate *prog = static_cast<const QShaderProgramPrivate *>(ref); + m_vertexSourceFile = prog->m_vertexSourceFile; + m_tessControlSourceFile = prog->m_tessControlSourceFile; + m_tessEvalSourceFile = prog->m_tessEvalSourceFile; + m_geometrySourceFile = prog->m_geometrySourceFile; + m_fragmentSourceFile = prog->m_fragmentSourceFile; + m_computeSourceFile = prog->m_computeSourceFile; + + m_vertexShaderCode = prog->m_vertexShaderCode; + m_tessControlShaderCode = prog->m_tessControlShaderCode; + m_tessEvalShaderCode = prog->m_tessEvalShaderCode; + m_geometryShaderCode = prog->m_geometryShaderCode; + m_fragmentShaderCode = prog->m_fragmentShaderCode; + m_computeShaderCode = prog->m_computeShaderCode; } -void QShaderProgram::copy(const QNode *ref) +QShaderProgram::QShaderProgram(QNode *parent) + : QAbstractShader(*new QShaderProgramPrivate(this), parent) { - Q_D(QShaderProgram); - QAbstractShader::copy(ref); - const QShaderProgram *prog = qobject_cast<const QShaderProgram *>(ref); - if (prog != Q_NULLPTR) { - d->m_vertexSourceFile = prog->d_func()->m_vertexSourceFile; - d->m_tessControlSourceFile = prog->d_func()->m_tessControlSourceFile; - d->m_tessEvalSourceFile = prog->d_func()->m_tessEvalSourceFile; - d->m_geometrySourceFile = prog->d_func()->m_geometrySourceFile; - d->m_fragmentSourceFile = prog->d_func()->m_fragmentSourceFile; - d->m_computeSourceFile = prog->d_func()->m_computeSourceFile; - - d->m_vertexShaderCode = prog->d_func()->m_vertexShaderCode; - d->m_tessControlShaderCode = prog->d_func()->m_tessControlShaderCode; - d->m_tessEvalShaderCode = prog->d_func()->m_tessEvalShaderCode; - d->m_geometryShaderCode = prog->d_func()->m_geometryShaderCode; - d->m_fragmentShaderCode = prog->d_func()->m_fragmentShaderCode; - d->m_computeShaderCode = prog->d_func()->m_computeShaderCode; - } } QShaderProgram::QShaderProgram(QShaderProgramPrivate &dd, QNode *parent) @@ -86,11 +83,10 @@ QShaderProgram::QShaderProgram(QShaderProgramPrivate &dd, QNode *parent) { } -QShaderProgram *QShaderProgram::doClone(bool isClone) const +QShaderProgram *QShaderProgram::doClone() const { QShaderProgram *clone = new QShaderProgram(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -99,8 +95,8 @@ void QShaderProgram::setVertexShaderSourceFile(const QString& vertexShaderSource Q_D(QShaderProgram); if (vertexShaderSourceFile != d->m_vertexSourceFile) { d->m_vertexSourceFile = vertexShaderSourceFile; - notifyPropertyChange(QByteArrayLiteral("vertexSourceFile"), - vertexShaderSourceFile); + d->notifyPropertyChange(QByteArrayLiteral("vertexSourceFile"), + vertexShaderSourceFile); emit vertexShaderSourceFileChanged(); } } @@ -116,8 +112,8 @@ void QShaderProgram::setTessellationControlShaderSourceFile(const QString &tesse Q_D(QShaderProgram); if (tessellationControlShaderSourceFile != d->m_tessControlSourceFile) { d->m_tessControlSourceFile = tessellationControlShaderSourceFile; - notifyPropertyChange(QByteArrayLiteral("tessellationControlShaderSourceFile"), - tessellationControlShaderSourceFile); + d->notifyPropertyChange(QByteArrayLiteral("tessellationControlShaderSourceFile"), + tessellationControlShaderSourceFile); emit tessellationControlShaderSourceFileChanged(); } } @@ -133,8 +129,8 @@ void QShaderProgram::setTessellationEvaluationShaderSourceFile(const QString &te Q_D(QShaderProgram); if (tessellationEvaluationShaderSourceFile != d->m_tessEvalSourceFile) { d->m_tessEvalSourceFile = tessellationEvaluationShaderSourceFile; - notifyPropertyChange(QByteArrayLiteral("tessellationEvaluationShaderSourceFile"), - tessellationEvaluationShaderSourceFile); + d->notifyPropertyChange(QByteArrayLiteral("tessellationEvaluationShaderSourceFile"), + tessellationEvaluationShaderSourceFile); emit tessellationEvaluationShaderSourceFileChanged(); } } @@ -150,8 +146,8 @@ void QShaderProgram::setGeometryShaderSourceFile(const QString &geometryShaderSo Q_D(QShaderProgram); if (geometryShaderSourceFile != d->m_geometrySourceFile) { d->m_geometrySourceFile = geometryShaderSourceFile; - notifyPropertyChange(QByteArrayLiteral("geometryShaderSourceFile"), - geometryShaderSourceFile); + d->notifyPropertyChange(QByteArrayLiteral("geometryShaderSourceFile"), + geometryShaderSourceFile); emit geometryShaderSourceFileChanged(); } } @@ -167,8 +163,8 @@ void QShaderProgram::setFragmentShaderSourceFile(const QString& fragmentShaderSo Q_D(QShaderProgram); if (fragmentShaderSourceFile != d->m_fragmentSourceFile) { d->m_fragmentSourceFile = fragmentShaderSourceFile; - notifyPropertyChange(QByteArrayLiteral("fragmentSourceFile"), - fragmentShaderSourceFile); + d->notifyPropertyChange(QByteArrayLiteral("fragmentSourceFile"), + fragmentShaderSourceFile); emit fragmentShaderSourceFileChanged(); } } @@ -184,8 +180,8 @@ void QShaderProgram::setComputeShaderSourceFile(const QString &computeShaderSour Q_D(QShaderProgram); if (computeShaderSourceFile != d->m_computeSourceFile) { d->m_computeSourceFile = computeShaderSourceFile; - notifyPropertyChange(QByteArrayLiteral("computeShaderSourceFile"), - computeShaderSourceFile); + d->notifyPropertyChange(QByteArrayLiteral("computeShaderSourceFile"), + computeShaderSourceFile); emit computeShaderSourceFileChanged(); } } @@ -251,8 +247,8 @@ void QShaderProgram::setVertexShaderCode(const QByteArray &vertexShaderCode) Q_D(QShaderProgram); if (vertexShaderCode != d->m_vertexShaderCode) { d->m_vertexShaderCode = vertexShaderCode; - notifyPropertyChange(QByteArrayLiteral("vertexSourceCode"), - vertexShaderCode); + d->notifyPropertyChange(QByteArrayLiteral("vertexSourceCode"), + vertexShaderCode); emit vertexShaderCodeChanged(); } } @@ -268,8 +264,8 @@ void QShaderProgram::setTessellationControlShaderCode(const QByteArray &tessella Q_D(QShaderProgram); if (tessellationControlShaderCode != d->m_tessControlShaderCode) { d->m_tessControlShaderCode = tessellationControlShaderCode; - notifyPropertyChange(QByteArrayLiteral("tessellationControlSourceCode"), - tessellationControlShaderCode); + d->notifyPropertyChange(QByteArrayLiteral("tessellationControlSourceCode"), + tessellationControlShaderCode); emit tessellationControlShaderCodeChanged(); } } @@ -285,8 +281,8 @@ void QShaderProgram::setTessellationEvaluationShaderCode(const QByteArray &tesse Q_D(QShaderProgram); if (tessellationEvaluationShaderCode != d->m_tessEvalShaderCode) { d->m_tessEvalShaderCode = tessellationEvaluationShaderCode; - notifyPropertyChange(QByteArrayLiteral("tessellationEvaluationSourceCode"), - tessellationEvaluationShaderCode); + d->notifyPropertyChange(QByteArrayLiteral("tessellationEvaluationSourceCode"), + tessellationEvaluationShaderCode); emit tessellationEvaluationShaderCodeChanged(); } } @@ -302,8 +298,8 @@ void QShaderProgram::setGeometryShaderCode(const QByteArray &geometryShaderCode) Q_D(QShaderProgram); if (geometryShaderCode != d->m_geometryShaderCode) { d->m_geometryShaderCode = geometryShaderCode; - notifyPropertyChange(QByteArrayLiteral("geometrySourceCode"), - geometryShaderCode); + d->notifyPropertyChange(QByteArrayLiteral("geometrySourceCode"), + geometryShaderCode); emit geometryShaderCodeChanged(); } } @@ -322,8 +318,8 @@ void QShaderProgram::setFragmentShaderCode(const QByteArray &fragmentShaderCode) Q_D(QShaderProgram); if (fragmentShaderCode != d->m_fragmentShaderCode) { d->m_fragmentShaderCode = fragmentShaderCode; - notifyPropertyChange(QByteArrayLiteral("fragmentSourceCode"), - fragmentShaderCode); + d->notifyPropertyChange(QByteArrayLiteral("fragmentSourceCode"), + fragmentShaderCode); emit fragmentShaderCodeChanged(); } } @@ -339,8 +335,8 @@ void QShaderProgram::setComputeShaderCode(const QByteArray &computeShaderCode) Q_D(QShaderProgram); if (computeShaderCode != d->m_computeShaderCode) { d->m_computeShaderCode = computeShaderCode; - notifyPropertyChange(QByteArrayLiteral("computeSourceCode"), - computeShaderCode); + d->notifyPropertyChange(QByteArrayLiteral("computeSourceCode"), + computeShaderCode); emit computeShaderCodeChanged(); } } diff --git a/src/render/frontend/qshaderprogram.h b/src/render/frontend/qshaderprogram.h index 26bbbb605..7c70f2fb1 100644 --- a/src/render/frontend/qshaderprogram.h +++ b/src/render/frontend/qshaderprogram.h @@ -82,8 +82,6 @@ public: Compute }; - void copy(const QNode *ref) Q_DECL_OVERRIDE; - // Source from file void setVertexShaderSourceFile(const QString &vertexShaderSourceFile); QString vertexShaderSourceFile() const; @@ -144,9 +142,11 @@ Q_SIGNALS: void computeShaderCodeChanged(); protected: - Q_DECLARE_PRIVATE(QShaderProgram) QShaderProgram(QShaderProgramPrivate &dd, QNode *parent = 0); - QShaderProgram *doClone(bool isClone) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QShaderProgram) + QShaderProgram *doClone() const Q_DECL_OVERRIDE; }; } diff --git a/src/render/frontend/qshaderprogram_p.h b/src/render/frontend/qshaderprogram_p.h index 2489c95da..cb79f5efb 100644 --- a/src/render/frontend/qshaderprogram_p.h +++ b/src/render/frontend/qshaderprogram_p.h @@ -55,6 +55,8 @@ class QShaderProgramPrivate : public QAbstractShaderPrivate public: QShaderProgramPrivate(QShaderProgram *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QShaderProgram) QString m_vertexSourceFile; QString m_tessControlSourceFile; diff --git a/src/render/frontend/qspheremesh.cpp b/src/render/frontend/qspheremesh.cpp index 36cb1f28f..24127c6d0 100644 --- a/src/render/frontend/qspheremesh.cpp +++ b/src/render/frontend/qspheremesh.cpp @@ -80,6 +80,8 @@ class QSphereMeshPrivate : public QAbstractShapeMeshPrivate , m_radius(1.0) {} + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC (QSphereMesh) bool m_generateTangents; int m_rings; @@ -93,17 +95,14 @@ QSphereMesh::QSphereMesh(QNode *parent) setDirty(true); } -void QSphereMesh::copy(const QNode *ref) +void QSphereMeshPrivate::copy(const QNodePrivate *ref) { - Q_D(QSphereMesh); - QAbstractShapeMesh::copy(ref); - const QSphereMesh *mesh = qobject_cast<const QSphereMesh *>(ref); - if (mesh != Q_NULLPTR) { - d->m_generateTangents = mesh->generateTangents(); - d->m_rings = mesh->rings(); - d->m_slices = mesh->slices(); - d->m_radius = mesh->radius(); - } + QAbstractShapeMeshPrivate::copy(ref); + const QSphereMeshPrivate *mesh = static_cast<const QSphereMeshPrivate *>(ref); + m_generateTangents = mesh->m_generateTangents; + m_rings = mesh->m_rings; + m_slices = mesh->m_slices; + m_radius = mesh->m_radius; } void QSphereMesh::setRings(int rings) @@ -158,11 +157,10 @@ QAbstractMeshFunctorPtr QSphereMesh::meshFunctor() const return QAbstractMeshFunctorPtr(new SphereMeshFunctor(d->m_rings, d->m_slices, d->m_radius, d->m_generateTangents)); } -QSphereMesh *QSphereMesh::doClone(bool isClone) const +QSphereMesh *QSphereMesh::doClone() const { QSphereMesh *clone = new QSphereMesh(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qspheremesh.h b/src/render/frontend/qspheremesh.h index e7b4dd73a..a3c040a05 100644 --- a/src/render/frontend/qspheremesh.h +++ b/src/render/frontend/qspheremesh.h @@ -63,8 +63,6 @@ class QT3DRENDERERSHARED_EXPORT QSphereMesh : public Qt3D::QAbstractShapeMesh public: explicit QSphereMesh(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setRings(int rings); void setSlices(int slices); void setRadius(float radius); @@ -86,7 +84,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QSphereMesh) - QSphereMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QSphereMesh *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qspotlight.cpp b/src/render/frontend/qspotlight.cpp index dbe572747..b3a2a3ec5 100644 --- a/src/render/frontend/qspotlight.cpp +++ b/src/render/frontend/qspotlight.cpp @@ -74,20 +74,17 @@ QSpotLightPrivate::QSpotLightPrivate(QSpotLight *qq) { } -QSpotLight::QSpotLight(QNode *parent) - : QAbstractLight(*new QSpotLightPrivate(this), parent) +void QSpotLightPrivate::copy(const QNodePrivate *ref) { + QAbstractLightPrivate::copy(ref); + const QSpotLightPrivate *light = static_cast<const QSpotLightPrivate *>(ref); + m_direction = light->m_direction; + m_cutOffAngle = light->m_cutOffAngle; } -void QSpotLight::copy(const QNode *ref) +QSpotLight::QSpotLight(QNode *parent) + : QAbstractLight(*new QSpotLightPrivate(this), parent) { - Q_D(QSpotLight); - QAbstractLight::copy(ref); - const QSpotLight *light = qobject_cast<const QSpotLight *>(ref); - if (light != Q_NULLPTR) { - d->m_direction = light->direction(); - d->m_cutOffAngle = light->cutOffAngle(); - } } QSpotLight::QSpotLight(QSpotLightPrivate &dd, QNode *parent) @@ -95,11 +92,10 @@ QSpotLight::QSpotLight(QSpotLightPrivate &dd, QNode *parent) { } -QSpotLight *QSpotLight::doClone(bool isClone) const +QSpotLight *QSpotLight::doClone() const { QSpotLight *clone = new QSpotLight(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -124,7 +120,7 @@ void QSpotLight::setDirection(const QVector3D &direction) QScenePropertyChangePtr change(new QScenePropertyChange(ComponentAdded, this)); change->setPropertyName(QByteArrayLiteral("direction")); change->setValue(d->m_direction); - notifyObservers(change); + d->notifyObservers(change); } } @@ -137,7 +133,7 @@ void QSpotLight::setCutOffAngle(float cutOffAngle) QScenePropertyChangePtr change(new QScenePropertyChange(ComponentAdded, this)); change->setPropertyName(QByteArrayLiteral("cutOffAngle")); change->setValue(d->m_cutOffAngle); - notifyObservers(change); + d->notifyObservers(change); } } diff --git a/src/render/frontend/qspotlight.h b/src/render/frontend/qspotlight.h index 2449ab8df..ece7ba70f 100644 --- a/src/render/frontend/qspotlight.h +++ b/src/render/frontend/qspotlight.h @@ -59,8 +59,6 @@ class QT3DRENDERERSHARED_EXPORT QSpotLight : public QAbstractLight public: explicit QSpotLight(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - QVector3D direction() const; float cutOffAngle() const; @@ -76,9 +74,11 @@ Q_SIGNALS: void cutOffAngleChanged(); protected: - Q_DECLARE_PRIVATE(QSpotLight) QSpotLight(QSpotLightPrivate &dd, QNode *parent = 0); - QSpotLight *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QSpotLight) + QSpotLight *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qspotlight_p.h b/src/render/frontend/qspotlight_p.h index 24a11300c..f6a1cc366 100644 --- a/src/render/frontend/qspotlight_p.h +++ b/src/render/frontend/qspotlight_p.h @@ -53,6 +53,8 @@ class QT3DRENDERERSHARED_EXPORT QSpotLightPrivate : public QAbstractLightPrivate public: QSpotLightPrivate(QSpotLight *qq); + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QSpotLight) float m_cutOffAngle; QVector3D m_direction; diff --git a/src/render/frontend/qstenciltest.cpp b/src/render/frontend/qstenciltest.cpp index 2b5c2ab38..883769bed 100644 --- a/src/render/frontend/qstenciltest.cpp +++ b/src/render/frontend/qstenciltest.cpp @@ -41,6 +41,7 @@ ****************************************************************************/ #include "qstenciltest.h" +#include "qrenderstate_p.h" #include <private/qnode_p.h> #include <Qt3DCore/qscenepropertychange.h> @@ -49,17 +50,19 @@ QT_BEGIN_NAMESPACE namespace Qt3D { -class QStencilTestPrivate : public QNodePrivate +class QStencilTestPrivate : public QRenderStatePrivate { public: QStencilTestPrivate(QStencilTest *qq) - : QNodePrivate(qq) + : QRenderStatePrivate(qq) , m_mask(0) , m_func(QStencilTest::Never) , m_faceMode(QStencilTest::FrontAndBack) { } + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QStencilTest) uint m_mask; QStencilTest::StencilFunc m_func; @@ -71,16 +74,13 @@ QStencilTest::QStencilTest(QNode *parent) { } -void QStencilTest::copy(const QNode *ref) +void QStencilTestPrivate::copy(const QNodePrivate *ref) { - QRenderState::copy(ref); - Q_D(QStencilTest); - const QStencilTest *refState = qobject_cast<const QStencilTest *>(ref); - if (refState != Q_NULLPTR) { - d->m_mask = refState->mask(); - d->m_faceMode = refState->faceMode(); - d->m_func = refState->func(); - } + QRenderStatePrivate::copy(ref); + const QStencilTestPrivate *refState = static_cast<const QStencilTestPrivate *>(ref); + m_mask = refState->m_mask; + m_faceMode = refState->m_faceMode; + m_func = refState->m_func; } uint QStencilTest::mask() const @@ -99,7 +99,7 @@ void QStencilTest::setMask(uint mask) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("mask")); propertyChange->setValue(d->m_mask); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -120,7 +120,7 @@ void QStencilTest::setFaceMode(QStencilTest::StencilFaceMode mode) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("faceMode")); propertyChange->setValue(d->m_faceMode); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } @@ -141,16 +141,15 @@ void QStencilTest::setFunc(QStencilTest::StencilFunc func) QScenePropertyChangePtr propertyChange(new QScenePropertyChange(NodeUpdated, this)); propertyChange->setPropertyName(QByteArrayLiteral("func")); propertyChange->setValue(d->m_func); - notifyObservers(propertyChange); + d->notifyObservers(propertyChange); } } } -QNode *QStencilTest::doClone(bool isClone) const +QNode *QStencilTest::doClone() const { QStencilTest *clone = new QStencilTest(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qstenciltest.h b/src/render/frontend/qstenciltest.h index 5e423f396..4530295d8 100644 --- a/src/render/frontend/qstenciltest.h +++ b/src/render/frontend/qstenciltest.h @@ -82,8 +82,6 @@ public: explicit QStencilTest(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - uint mask() const; void setMask(uint mask); @@ -100,7 +98,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QStencilTest) - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QNode *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/qtechnique.cpp b/src/render/frontend/qtechnique.cpp index 53f460d02..5bbfcd0ce 100644 --- a/src/render/frontend/qtechnique.cpp +++ b/src/render/frontend/qtechnique.cpp @@ -68,14 +68,11 @@ QTechnique::QTechnique(QNode *parent) QObject::connect(d->m_openGLFilter, SIGNAL(openGLFilterChanged()), this, SLOT(openGLFilterChanged())); } -void QTechnique::copy(const QNode *ref) +void QTechniquePrivate::copy(const QNodePrivate *ref) { - Q_D(QTechnique); - QAbstractTechnique::copy(ref); - const QTechnique *tech = qobject_cast<const QTechnique *>(ref); - if (tech != Q_NULLPTR) { - d->m_openGLFilter->copy(tech->openGLFilter()); - } + QAbstractTechniquePrivate::copy(ref); + const QTechniquePrivate *tech = static_cast<const QTechniquePrivate *>(ref); + m_openGLFilter->copy(tech->m_openGLFilter); } QTechnique::QTechnique(QTechniquePrivate &dd, QNode *parent) @@ -85,20 +82,19 @@ QTechnique::QTechnique(QTechniquePrivate &dd, QNode *parent) QObject::connect(d->m_openGLFilter, SIGNAL(openGLFilterChanged()), this, SLOT(openGLFilterChanged())); } -QTechnique *QTechnique::doClone(bool isClone) const +QTechnique *QTechnique::doClone() const { Q_D(const QTechnique); QTechnique *technique = new QTechnique(); - technique->copy(this); - technique->d_func()->m_isClone = isClone; + technique->d_func()->copy(d_func()); Q_FOREACH (QCriterion *criterion, d->m_criteriaList) - technique->addCriterion(qobject_cast<QCriterion *>(criterion->clone(isClone))); + technique->addCriterion(qobject_cast<QCriterion *>(QNodePrivate::get(criterion)->clone())); Q_FOREACH (QAbstractRenderPass *pass, d->m_renderPasses) - technique->addPass(qobject_cast<QAbstractRenderPass *>(pass->clone(isClone))); + technique->addPass(qobject_cast<QAbstractRenderPass *>(QNodePrivate::get(pass)->clone())); Q_FOREACH (QParameter *p, d->m_parameters) - technique->addParameter(qobject_cast<QParameter *>(p->clone(isClone))); + technique->addParameter(qobject_cast<QParameter *>(QNodePrivate::get(p)->clone())); return technique; } @@ -112,7 +108,7 @@ void QTechnique::openGLFilterChanged() QOpenGLFilter *clone = new QOpenGLFilter(); clone->copy(d->m_openGLFilter); change->setValue(QVariant::fromValue(clone)); - notifyObservers(change); + d->notifyObservers(change); } } @@ -126,14 +122,14 @@ void QTechnique::addCriterion(QCriterion *criterion) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, it gets destroyed as well - if (!criterion->parent() || criterion->parent() == this) - QNode::addChild(criterion); + if (!criterion->parent()) + criterion->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("criterion")); - change->setValue(QVariant::fromValue(criterion->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(criterion)->clone())); + d->notifyObservers(change); } } } @@ -145,7 +141,7 @@ void QTechnique::removeCriterion(QCriterion *criterion) QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("criterion")); change->setValue(QVariant::fromValue(criterion->uuid())); - notifyObservers(change); + d->notifyObservers(change); } d->m_criteriaList.removeOne(criterion); } @@ -173,14 +169,14 @@ void QTechnique::addParameter(QParameter *parameter) // Or not previously added as a child of the current node so that // 1) The backend gets notified about it's creation // 2) When the current node is destroyed, the child parameters get destroyed as well - if (!parameter->parent() || parameter->parent() == this) - QNode::addChild(parameter); + if (!parameter->parent()) + parameter->setParent(this); if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this)); change->setPropertyName(QByteArrayLiteral("parameter")); - change->setValue(QVariant::fromValue(parameter->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(parameter)->clone())); + d->notifyObservers(change); } } } @@ -192,8 +188,8 @@ void QTechnique::removeParameter(QParameter *parameter) if (d->m_changeArbiter != Q_NULLPTR) { QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this)); change->setPropertyName(QByteArrayLiteral("parameter")); - change->setValue(QVariant::fromValue(parameter->clone())); - notifyObservers(change); + change->setValue(QVariant::fromValue(QNodePrivate::get(parameter)->clone())); + d->notifyObservers(change); } d->m_parameters.removeOne(parameter); } diff --git a/src/render/frontend/qtechnique.h b/src/render/frontend/qtechnique.h index 5f622a6d4..5ec4d5ba0 100644 --- a/src/render/frontend/qtechnique.h +++ b/src/render/frontend/qtechnique.h @@ -66,8 +66,6 @@ class QT3DRENDERERSHARED_EXPORT QTechnique : public QAbstractTechnique public: explicit QTechnique(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void addCriterion(QCriterion *criterion); void removeCriterion(QCriterion *criterion); @@ -82,12 +80,14 @@ public: QOpenGLFilter *openGLFilter() const; protected: - Q_DECLARE_PRIVATE(QTechnique) QTechnique(QTechniquePrivate &dd, QNode *parent = 0); - QTechnique *doClone(bool isClone = true) const Q_DECL_OVERRIDE; protected Q_SLOTS: void openGLFilterChanged(); + +private: + Q_DECLARE_PRIVATE(QTechnique) + QTechnique *doClone() const Q_DECL_OVERRIDE; }; } diff --git a/src/render/frontend/qtechnique_p.h b/src/render/frontend/qtechnique_p.h index 72b03cf46..265a46bcc 100644 --- a/src/render/frontend/qtechnique_p.h +++ b/src/render/frontend/qtechnique_p.h @@ -59,6 +59,9 @@ class QT3DRENDERERSHARED_EXPORT QTechniquePrivate : public QAbstractTechniquePri public: QTechniquePrivate(QTechnique *dd); ~QTechniquePrivate(); + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QTechnique) QList<QCriterion *> m_criteriaList; QList<QParameter *> m_parameters; diff --git a/src/render/frontend/qtexture.cpp b/src/render/frontend/qtexture.cpp index 5e44465be..842c3ccd0 100644 --- a/src/render/frontend/qtexture.cpp +++ b/src/render/frontend/qtexture.cpp @@ -69,6 +69,8 @@ public : , m_status(QTexture::Loading) {} + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QTexture) QTexture::Target m_target; @@ -84,6 +86,20 @@ public : QTexture::Status m_status; }; +void QTexturePrivate::copy(const QNodePrivate *ref) +{ + QNodePrivate::copy(ref); + const QTexturePrivate *t = static_cast<const QTexturePrivate *>(ref); + m_target = t->m_target; + m_width = t->m_width; + m_height = t->m_height; + m_depth = t->m_depth; + m_format = t->m_format; + m_wrapMode = t->m_wrapMode; + m_minFilter = t->m_minFilter; + m_magFilter = t->m_magFilter; + m_autoMipMap = t->m_autoMipMap; +} QTexture::QTexture(QNode *parent) : QNode(*new QTexturePrivate(this), parent) @@ -99,21 +115,6 @@ QTexture::~QTexture() { } -void QTexture::copy(const QNode *ref) -{ - QNode::copy(ref); - const QTexture *t = qobject_cast<const QTexture *>(ref); - if (t != Q_NULLPTR) { - setTarget(t->target()); - setSize(t->width(), t->height(), t->depth()); - setFormat(t->format()); - setTarget(t->target()); - setWrapMode(t->wrapMode()); - setMinificationFilter(t->minificationFilter()); - setMagnificationFilter(t->magnificationFilter()); - setGenerateMipMaps(t->generateMipMaps()); - } -} void QTexture::setTarget(Target target) { @@ -126,7 +127,7 @@ void QTexture::setTarget(Target target) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("target")); change->setValue(target); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -149,7 +150,7 @@ void QTexture::setWidth(int width) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("width")); change->setValue(width); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -165,7 +166,7 @@ void QTexture::setHeight(int height) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("height")); change->setValue(height); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -181,7 +182,7 @@ void QTexture::setDepth(int depth) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("depth")); change->setValue(depth); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -215,7 +216,7 @@ void QTexture::setFormat(TextureFormat format) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("format")); change->setValue(format); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -235,12 +236,11 @@ void QTexture::setStatus(Status status) } } -QNode *QTexture::doClone(bool isClone) const +QNode *QTexture::doClone() const { // TO DO: Copy TexImageDataPtr QTexture *clone = new QTexture(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } @@ -263,8 +263,7 @@ bool QTexture::setFromQImage(QImage img, int layer) if ((d->m_target != Target2D) && (d->m_target != Target2DArray) && - (d->m_target == TargetRectangle)) - { + (d->m_target == TargetRectangle)) { qWarning() << Q_FUNC_INFO << "invalid texture target"; setStatus(Error); return false; @@ -300,7 +299,7 @@ void QTexture::setGenerateMipMaps(bool gen) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("mipmaps")); change->setValue(gen); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -322,7 +321,7 @@ void QTexture::setMinificationFilter(Filter f) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("minificationFilter")); change->setValue(f); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -338,7 +337,7 @@ void QTexture::setMagnificationFilter(Filter f) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("magnificationFilter")); change->setValue(f); - notifyObservers(change); + d->notifyObservers(change); } } } @@ -366,7 +365,7 @@ void QTexture::setWrapMode(WrapMode wrapMode) QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, this)); change->setPropertyName(QByteArrayLiteral("wrapMode")); change->setValue(wrapMode); - notifyObservers(change); + d->notifyObservers(change); } } } diff --git a/src/render/frontend/qtexture.h b/src/render/frontend/qtexture.h index 6138716b2..6f26cc37c 100644 --- a/src/render/frontend/qtexture.h +++ b/src/render/frontend/qtexture.h @@ -228,8 +228,6 @@ public: ClampToBorder = 0x812D // GL_CLAMP_TO_BORDER }; - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setTarget(Target target); Target target() const; @@ -287,11 +285,12 @@ Q_SIGNALS: void minificationFilterChanged(); protected: - - Q_DECLARE_PRIVATE(QTexture) QTexture(QTexturePrivate &dd, QNode *parent = 0); void setStatus(Status status); - QNode *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QTexture) + QNode *doClone() const Q_DECL_OVERRIDE; }; } // namespace Qt3D diff --git a/src/render/frontend/qtorusmesh.cpp b/src/render/frontend/qtorusmesh.cpp index 7e5fbf539..f317ff17e 100644 --- a/src/render/frontend/qtorusmesh.cpp +++ b/src/render/frontend/qtorusmesh.cpp @@ -79,6 +79,8 @@ class QTorusMeshPrivate : public QAbstractShapeMeshPrivate , m_minorRadius(1.0) {} + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + Q_DECLARE_PUBLIC(QTorusMesh) int m_rings; int m_slices; @@ -86,25 +88,22 @@ class QTorusMeshPrivate : public QAbstractShapeMeshPrivate float m_minorRadius; }; -QTorusMesh::QTorusMesh(QNode *parent) - : QAbstractShapeMesh(*new QTorusMeshPrivate(this), parent) +void QTorusMeshPrivate::copy(const QNodePrivate *ref) { - setDirty(true); + QAbstractShapeMeshPrivate::copy(ref); + const QTorusMeshPrivate *mesh = static_cast<const QTorusMeshPrivate *>(ref); + m_rings = mesh->m_rings; + m_slices = mesh->m_slices; + m_radius = mesh->m_radius; + m_minorRadius = mesh->m_minorRadius; } -void QTorusMesh::copy(const QNode *ref) + +QTorusMesh::QTorusMesh(QNode *parent) + : QAbstractShapeMesh(*new QTorusMeshPrivate(this), parent) { - Q_D(QTorusMesh); - QAbstractShapeMesh::copy(ref); - const QTorusMesh *mesh = qobject_cast<const QTorusMesh *>(ref); - if (mesh != Q_NULLPTR) { - d->m_rings = mesh->rings(); - d->m_slices = mesh->slices(); - d->m_radius = mesh->radius(); - d->m_minorRadius = mesh->minorRadius(); - } + setDirty(true); } - void QTorusMesh::setRings(int rings) { Q_D(QTorusMesh); @@ -267,11 +266,10 @@ QAbstractMeshFunctorPtr QTorusMesh::meshFunctor() const return QAbstractMeshFunctorPtr(new TorusMeshFunctor(d->m_rings, d->m_slices, d->m_radius, d->m_minorRadius)); } -QTorusMesh *QTorusMesh::doClone(bool isClone) const +QTorusMesh *QTorusMesh::doClone() const { QTorusMesh *clone = new QTorusMesh(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } diff --git a/src/render/frontend/qtorusmesh.h b/src/render/frontend/qtorusmesh.h index 322486cd8..4dbd2fae6 100644 --- a/src/render/frontend/qtorusmesh.h +++ b/src/render/frontend/qtorusmesh.h @@ -62,8 +62,6 @@ class QT3DRENDERERSHARED_EXPORT QTorusMesh : public Qt3D::QAbstractShapeMesh public: explicit QTorusMesh(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; - void setRings(int rings); void setSlices(int slices); void setRadius(float radius); @@ -85,7 +83,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QTorusMesh) - QTorusMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; + QTorusMesh *doClone() const Q_DECL_OVERRIDE; }; } // Qt3D diff --git a/src/render/frontend/render-frontend.pri b/src/render/frontend/render-frontend.pri index 82b079894..a56fc0c7f 100644 --- a/src/render/frontend/render-frontend.pri +++ b/src/render/frontend/render-frontend.pri @@ -60,7 +60,9 @@ HEADERS += \ $$PWD/qrenderattachment.h \ $$PWD/qrenderattachment_p.h \ $$PWD/qrendertarget.h \ - $$PWD/qrendertarget_p.h + $$PWD/qrendertarget_p.h \ + $$PWD/qcriterion_p.h \ + $$PWD/qrenderstate_p.h SOURCES += \ $$PWD/qmaterial.cpp \ diff --git a/src/render/io/gltfparser.cpp b/src/render/io/gltfparser.cpp index 35c21563c..d74a4756e 100644 --- a/src/render/io/gltfparser.cpp +++ b/src/render/io/gltfparser.cpp @@ -204,6 +204,8 @@ const QString KEY_INTERNAL_FORMAT = QStringLiteral("internalFormat"); } // of anonymous namespace +class GLTFParserMeshPrivate; + class GLTFParserMesh : public QAbstractMesh { Q_OBJECT @@ -222,13 +224,27 @@ private: public: explicit GLTFParserMesh(QNode *parent = 0); - void copy(const QNode *ref) Q_DECL_OVERRIDE; void setData(QMeshDataPtr data); QAbstractMeshFunctorPtr meshFunctor() const Q_DECL_OVERRIDE; private: + GLTFParserMesh *doClone() const Q_DECL_OVERRIDE; + Q_DECLARE_PRIVATE(GLTFParserMesh) +}; + +class GLTFParserMeshPrivate : public QAbstractMeshPrivate +{ +public: + + GLTFParserMeshPrivate(GLTFParserMesh *qq) + : QAbstractMeshPrivate(qq) + { + } + + void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE; + + Q_DECLARE_PUBLIC(GLTFParserMesh) QMeshDataPtr m_meshData; - GLTFParserMesh *doClone(bool isClone = true) const Q_DECL_OVERRIDE; }; GLTFParser::GLTFParser() : AbstractSceneParser(), @@ -337,8 +353,7 @@ QEntity* GLTFParser::scene(QString id) QEntity* child = node(nodeName); if (!child) continue; - - sceneEntity->addChild(child); + child->setParent(sceneEntity); } return sceneEntity; @@ -362,7 +377,7 @@ QEntity* GLTFParser::node(QString id) QEntity* child = node(c.toString()); if (!child) continue; - result->addChild(child); + child->setParent(result); } } @@ -395,7 +410,7 @@ QEntity* GLTFParser::node(QString id) // need to make a child entity per material foreach (QString matId, materialDict.keys()) { QEntity* subEntity(new QEntity); - result->addChild(subEntity); + subEntity->setParent(result); subEntity->addComponent(material(matId)); foreach (GLTFParserMesh* m, materialDict.value(matId)) @@ -990,36 +1005,36 @@ QVariant GLTFParser::parameterValueFromJSON(QParameter* p, QJsonValue val) return QVariant(); } -GLTFParserMesh::GLTFParserMesh(QNode *parent) - : QAbstractMesh(parent) +void GLTFParserMeshPrivate::copy(const QNodePrivate *ref) { + QAbstractMeshPrivate::copy(ref); + const GLTFParserMeshPrivate *gltfMesh = static_cast<const GLTFParserMeshPrivate *>(ref); + m_meshData = gltfMesh->m_meshData; } -void GLTFParserMesh::copy(const QNode *ref) +GLTFParserMesh::GLTFParserMesh(QNode *parent) + : QAbstractMesh(*new GLTFParserMeshPrivate(this), parent) { - QAbstractMesh::copy(ref); - const GLTFParserMesh *gltfMesh = qobject_cast<const GLTFParserMesh *>(ref); - if (gltfMesh != Q_NULLPTR) { - m_meshData = gltfMesh->m_meshData; - } } + void GLTFParserMesh::setData(QMeshDataPtr data) { - m_meshData = data; + Q_D(GLTFParserMesh); + d->m_meshData = data; QAbstractMesh::setDirty(this); } QAbstractMeshFunctorPtr GLTFParserMesh::meshFunctor() const { - return QAbstractMeshFunctorPtr(new GLTFParserMeshFunctor(m_meshData)); + Q_D(const GLTFParserMesh); + return QAbstractMeshFunctorPtr(new GLTFParserMeshFunctor(d->m_meshData)); } -GLTFParserMesh *GLTFParserMesh::doClone(bool isClone) const +GLTFParserMesh *GLTFParserMesh::doClone() const { GLTFParserMesh *clone = new GLTFParserMesh(); - clone->copy(this); - clone->d_func()->m_isClone = isClone; + clone->d_func()->copy(d_func()); return clone; } |