diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-09-13 10:21:53 +0200 |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-09-13 10:22:22 +0200 |
commit | ce5ac7d67b59deb7c0e261e9ee21a475e6cb2e41 (patch) | |
tree | ed4dcec9a0e9002156e085ffb6715436bc2e27c5 /src/declarative/particles/qsgcustomparticle.cpp | |
parent | f828bee19dee73246c09af3aad913b5540f1cbd0 (diff) | |
parent | 63952084c085202e7eddca6840c518d8e07445d0 (diff) |
Merge branch 'refactor'
Conflicts:
src/declarative/items/context2d/qsgcanvasitem.cpp
src/declarative/items/context2d/qsgcontext2d.cpp
src/declarative/items/context2d/qsgcontext2d_p_p.h
src/declarative/particles/qsgcustomparticle.cpp
src/declarative/particles/qsgparticlesystem.cpp
Change-Id: I24e81d3652368c5031305ffa7f969f9f2c249c6c
Diffstat (limited to 'src/declarative/particles/qsgcustomparticle.cpp')
-rw-r--r-- | src/declarative/particles/qsgcustomparticle.cpp | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp index a1d65a5360..e0bbf28862 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[] = "}"; 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 = @@ -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]", + source.name.constData(), 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. @@ -463,9 +471,20 @@ 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; +<<<<<<< HEAD m_material.setProgramSource(s); foreach (const QString &str, m_groups){ +======= + m_material->setProgramSource(s); + + foreach (const QString &str, m_particles){ +>>>>>>> refactor int gIdx = m_system->m_groupIds[str]; int count = m_system->m_groupData[gIdx]->size(); //Create Particle Geometry @@ -504,7 +523,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); @@ -525,29 +544,29 @@ void QSGCustomParticle::buildData() return; const QByteArray timestampName("qt_Timestamp"); 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); |