diff options
Diffstat (limited to 'src/declarative/particles/qsgcustomparticle.cpp')
-rw-r--r-- | src/declarative/particles/qsgcustomparticle.cpp | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp index 11bc7e35fb..12d32a27b4 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(); @@ -269,13 +278,12 @@ void QSGCustomParticle::setSource(const QVariant &var, int index) } QObject *obj = qVariantValue<QObject *>(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<QSGItem *>(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. @@ -457,8 +465,14 @@ QSGShaderEffectNode* QSGCustomParticle::buildCustomNodes() s.fragmentCode = qt_particles_default_fragment_code; if (s.vertexCode.isEmpty()) s.vertexCode = qt_particles_default_vertex_code; + + if (!m_material) { + m_material = new QSGShaderEffectMaterialObject; + } + s.vertexCode = qt_particles_template_vertex_code + s.vertexCode; - m_material.setProgramSource(s); + 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(); @@ -498,7 +512,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); @@ -519,29 +533,29 @@ void QSGCustomParticle::buildData() if (!m_rootNode) return; QVector<QPair<QByteArray, QVariant> > values; - QVector<QPair<QByteArray, QPointer<QSGItem> > > textures; - const QVector<QPair<QByteArray, QPointer<QSGItem> > > &oldTextures = m_material.textureProviders(); + QVector<QPair<QByteArray, QSGTextureProvider *> > textures; + const QVector<QPair<QByteArray, QSGTextureProvider *> > &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()) + QSGTextureProvider *t = source.item->textureProvider(); + 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<QByteArray>::const_iterator it = m_source.uniformNames.begin(); it != m_source.uniformNames.end(); ++it) { 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); |