From f1a9c5e4f4031921f8ae3ec32512bfc9971a97da Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Mon, 22 Aug 2011 09:25:51 +0200 Subject: Reintroduce the QSGTextureProvider as a separate object The texture provider needs to live completely in the rendering thread and needs to be selfcontained during rendering. During the items updatePaintNode() all needed state is copied into the texture provider. Texture providers have thread affinity in the rendering thread and are deleted there using deleteLater() and the added processEvents() in the rendering loop. This fixes the bug where a QSGItem is deleted as a result from an animation while the same item is being used as a texture provider in the rendering thread. There is also a small optimzation to QSGShaderEffectSource in that we don't create a paint node when the shader source is not going to be shown. Change-Id: I6b9bc1da2a0f55d3d5356d4091fd6af6a7ea6f01 Reviewed-on: http://codereview.qt.nokia.com/3293 Reviewed-by: Qt Sanity Bot Reviewed-by: Kim M. Kalland --- src/declarative/particles/qsgcustomparticle.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/declarative/particles/qsgcustomparticle.cpp') diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp index 7397fc6b50..770c5fd382 100644 --- a/src/declarative/particles/qsgcustomparticle.cpp +++ b/src/declarative/particles/qsgcustomparticle.cpp @@ -490,21 +490,21 @@ void QSGCustomParticle::buildData() if (!m_rootNode) return; QVector > values; - QVector > > textures; - const QVector > > &oldTextures = m_material.textureProviders(); + QVector > textures; + const QVector > &oldTextures = m_material.textureProviders(); for (int i = 0; i < oldTextures.size(); ++i) { - QSGTextureProvider *oldSource = QSGTextureProvider::from(oldTextures.at(i).second); - if (oldSource && oldSource->textureChangedSignal()) + QSGTextureProvider *t = oldTextures.at(i).second; + if (t) foreach (QSGShaderEffectNode* node, m_nodes) - disconnect(oldTextures.at(i).second, oldSource->textureChangedSignal(), node, SLOT(markDirtyTexture())); + disconnect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture())); } for (int i = 0; i < m_sources.size(); ++i) { const SourceData &source = m_sources.at(i); - textures.append(qMakePair(source.name, source.item)); QSGTextureProvider *t = QSGTextureProvider::from(source.item); - if (t && t->textureChangedSignal()) + textures.append(qMakePair(source.name, t)); + if (t) foreach (QSGShaderEffectNode* node, m_nodes) - connect(source.item, t->textureChangedSignal(), node, SLOT(markDirtyTexture()), Qt::DirectConnection); + connect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()), Qt::DirectConnection); } for (QSet::const_iterator it = m_source.uniformNames.begin(); it != m_source.uniformNames.end(); ++it) { -- cgit v1.2.3 From 9d1c8f04e172ff8dda7d04916366a75cf916a280 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Mon, 22 Aug 2011 13:48:13 +0200 Subject: Make textureProvider() a virtual accessor in QSGItem. This gets us one step closer to a public QSGTextureProvider API. This patch also includes a fix to the material ownership in QSGCustomParticle. Change-Id: I620e3006816db0c37eedf3a20a0d4cbe7a783b82 Reviewed-on: http://codereview.qt.nokia.com/3317 Reviewed-by: Qt Sanity Bot Reviewed-by: Kim M. Kalland --- src/declarative/particles/qsgcustomparticle.cpp | 37 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/declarative/particles/qsgcustomparticle.cpp') diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp index 770c5fd382..53cb131bc5 100644 --- a/src/declarative/particles/qsgcustomparticle.cpp +++ b/src/declarative/particles/qsgcustomparticle.cpp @@ -132,11 +132,20 @@ QSGCustomParticle::QSGCustomParticle(QSGItem* parent) : QSGParticlePainter(parent) , m_pleaseReset(true) , m_dirtyData(true) + , m_material(0) , m_rootNode(0) { setFlag(QSGItem::ItemHasContents); } +class QSGShaderEffectMaterialObject : public QObject, public QSGShaderEffectMaterial { }; + +QSGCustomParticle::~QSGCustomParticle() +{ + if (m_material) + m_material->deleteLater(); +} + void QSGCustomParticle::componentComplete() { reset(); @@ -236,13 +245,12 @@ void QSGCustomParticle::setSource(const QVariant &var, int index) } QObject *obj = qVariantValue(var); - - QSGTextureProvider *int3rface = QSGTextureProvider::from(obj); - if (!int3rface) { - qWarning("Could not assign property '%s', did not implement QSGTextureProvider.", source.name.constData()); - } - source.item = qobject_cast(obj); + if (!source.item || !source.item->isTextureProvider()) { + qWarning("ShaderEffect: source uniform [%s] is not assigned a valid texture provider: %s [%s]", + qPrintable(source.name), qPrintable(obj->objectName()), obj->metaObject()->className()); + return; + } // TODO: Copy better solution in QSGShaderEffect when they find it. // 'source.item' needs a canvas to get a scenegraph node. @@ -429,7 +437,12 @@ QSGShaderEffectNode* QSGCustomParticle::buildCustomNodes() s.fragmentCode = qt_particles_default_fragment_code; if (s.vertexCode.isEmpty()) s.vertexCode = qt_particles_default_vertex_code; - m_material.setProgramSource(s); + + if (!m_material) { + m_material = new QSGShaderEffectMaterialObject; + } + + m_material->setProgramSource(s); foreach (const QString &str, m_particles){ int gIdx = m_system->m_groupIds[str]; int count = m_system->m_groupData[gIdx]->size(); @@ -469,7 +482,7 @@ QSGShaderEffectNode* QSGCustomParticle::buildCustomNodes() QSGShaderEffectNode* node = new QSGShaderEffectNode(); node->setGeometry(g); - node->setMaterial(&m_material); + node->setMaterial(m_material); node->markDirty(QSGNode::DirtyMaterial); m_nodes.insert(gIdx, node); @@ -491,7 +504,7 @@ void QSGCustomParticle::buildData() return; QVector > values; QVector > textures; - const QVector > &oldTextures = m_material.textureProviders(); + const QVector > &oldTextures = m_material->textureProviders(); for (int i = 0; i < oldTextures.size(); ++i) { QSGTextureProvider *t = oldTextures.at(i).second; if (t) @@ -500,7 +513,7 @@ void QSGCustomParticle::buildData() } for (int i = 0; i < m_sources.size(); ++i) { const SourceData &source = m_sources.at(i); - QSGTextureProvider *t = QSGTextureProvider::from(source.item); + QSGTextureProvider *t = source.item->textureProvider(); textures.append(qMakePair(source.name, t)); if (t) foreach (QSGShaderEffectNode* node, m_nodes) @@ -511,8 +524,8 @@ void QSGCustomParticle::buildData() values.append(qMakePair(*it, property(*it))); } values.append(qMakePair(timestampName, QVariant(m_lastTime))); - m_material.setUniforms(values); - m_material.setTextureProviders(textures); + m_material->setUniforms(values); + m_material->setTextureProviders(textures); m_dirtyData = false; foreach (QSGShaderEffectNode* node, m_nodes) node->markDirty(QSGNode::DirtyMaterial); -- cgit v1.2.3 From 01335edc94d2961bd4061ed2cb81ebd1151797bf Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 31 Aug 2011 16:43:22 +0200 Subject: Fix export symbols for QtDeclarative and QtQuick1. Fix build on Windows and compiler warnings. Requires 090ee21eac7257644422e35395194e5fd7fb8efa in qtbase. Change-Id: Ief8da504ccd3e2c2e78644cc9943d685c4302019 Reviewed-on: http://codereview.qt.nokia.com/3988 Reviewed-by: Qt Sanity Bot Reviewed-by: Friedemann Kleint --- src/declarative/particles/qsgcustomparticle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/declarative/particles/qsgcustomparticle.cpp') diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp index 12d32a27b4..373d050627 100644 --- a/src/declarative/particles/qsgcustomparticle.cpp +++ b/src/declarative/particles/qsgcustomparticle.cpp @@ -281,7 +281,7 @@ void QSGCustomParticle::setSource(const QVariant &var, int index) source.item = qobject_cast(obj); if (!source.item || !source.item->isTextureProvider()) { qWarning("ShaderEffect: source uniform [%s] is not assigned a valid texture provider: %s [%s]", - qPrintable(source.name), qPrintable(obj->objectName()), obj->metaObject()->className()); + source.name.constData(), qPrintable(obj->objectName()), obj->metaObject()->className()); return; } -- cgit v1.2.3 From e5a93d6ea1c9eb9982e98a6a5b1f52719fe446e6 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Mon, 5 Sep 2011 07:50:58 +0200 Subject: Added QSGGeometry::Attribute::isPosition to give a hint about vertex data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also added a QSGGeomtry::sizeOfIndex() function for convenience Change-Id: If1f13afd4c1c5295dcfb00254144ef6b8b8b7878 Reviewed-on: http://codereview.qt.nokia.com/4307 Reviewed-by: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/declarative/particles/qsgcustomparticle.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/declarative/particles/qsgcustomparticle.cpp') diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp index 373d050627..eb6f45e2f0 100644 --- a/src/declarative/particles/qsgcustomparticle.cpp +++ b/src/declarative/particles/qsgcustomparticle.cpp @@ -83,11 +83,11 @@ static const char qt_particles_default_fragment_code[] =//TODO: Default frag req "}"; static QSGGeometry::Attribute PlainParticle_Attributes[] = { - { 0, 2, GL_FLOAT }, // Position - { 1, 2, GL_FLOAT }, // TexCoord - { 2, 4, GL_FLOAT }, // Data - { 3, 4, GL_FLOAT }, // Vectors - { 4, 1, GL_FLOAT } // r + QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position + QSGGeometry::Attribute::create(1, 2, GL_FLOAT), // TexCoord + QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Data + QSGGeometry::Attribute::create(3, 4, GL_FLOAT), // Vectors + QSGGeometry::Attribute::create(4, 1, GL_FLOAT) // r }; static QSGGeometry::AttributeSet PlainParticle_AttributeSet = -- cgit v1.2.3