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 | |
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')
-rw-r--r-- | src/declarative/particles/qsgcustomparticle.cpp | 65 | ||||
-rw-r--r-- | src/declarative/particles/qsgcustomparticle_p.h | 6 | ||||
-rw-r--r-- | src/declarative/particles/qsgimageparticle.cpp | 98 | ||||
-rw-r--r-- | src/declarative/particles/qsgimageparticle_p.h | 1 |
4 files changed, 97 insertions, 73 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); diff --git a/src/declarative/particles/qsgcustomparticle_p.h b/src/declarative/particles/qsgcustomparticle_p.h index 1fec963d84..f51e576d34 100644 --- a/src/declarative/particles/qsgcustomparticle_p.h +++ b/src/declarative/particles/qsgcustomparticle_p.h @@ -53,6 +53,9 @@ QT_MODULE(Declarative) class QSGNode; struct PlainVertices; + +class QSGShaderEffectMaterialObject; + //Genealogy: Hybrid of UltraParticle and ShaderEffect class QSGCustomParticle : public QSGParticlePainter { @@ -62,6 +65,7 @@ class QSGCustomParticle : public QSGParticlePainter public: explicit QSGCustomParticle(QSGItem* parent=0); + ~QSGCustomParticle(); QByteArray fragmentShader() const { return m_source.fragmentCode; } void setFragmentShader(const QByteArray &code); @@ -105,7 +109,7 @@ private: QByteArray name; }; QVector<SourceData> m_sources; - QSGShaderEffectMaterial m_material; + QSGShaderEffectMaterialObject *m_material; QSGShaderEffectNode* m_rootNode; QHash<int, QSGShaderEffectNode*> m_nodes; qreal m_lastTime; diff --git a/src/declarative/particles/qsgimageparticle.cpp b/src/declarative/particles/qsgimageparticle.cpp index b1aef784e8..ea1bf389df 100644 --- a/src/declarative/particles/qsgimageparticle.cpp +++ b/src/declarative/particles/qsgimageparticle.cpp @@ -49,7 +49,7 @@ #include "qsgparticleemitter_p.h" #include "qsgsprite_p.h" #include "qsgspriteengine_p.h" -#include <QGLFunctions> +#include <QOpenGLFunctions> #include <qsgengine.h> QT_BEGIN_NAMESPACE @@ -65,7 +65,7 @@ DEFINE_BOOL_CONFIG_OPTION(qmlParticlesDebug, QML_PARTICLES_DEBUG) //TODO: Make it larger on desktop? Requires fixing up shader code with the same define #define UNIFORM_ARRAY_SIZE 64 -const float CONV = 0.017453292519943295; +const qreal CONV = 0.017453292519943295; class ImageMaterialData { public: @@ -98,13 +98,13 @@ class TabledMaterial : public QSGSimpleMaterialShader<TabledMaterialData> public: TabledMaterial() { - QFile vf(":defaultshaders/imagevertex.shader"); + QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader")); vf.open(QFile::ReadOnly); m_vertex_code = QByteArray(SHADER_DEFINES) + QByteArray("#define TABLE\n#define DEFORM\n#define COLOR\n") + vf.readAll(); - QFile ff(":defaultshaders/imagefragment.shader"); + QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader")); ff.open(QFile::ReadOnly); m_fragment_code = QByteArray(SHADER_DEFINES) + QByteArray("#define TABLE\n#define DEFORM\n#define COLOR\n") @@ -127,7 +127,7 @@ public: program()->bind(); program()->setUniformValue("texture", 0); program()->setUniformValue("colortable", 1); - glFuncs = QGLContext::currentContext()->functions(); + glFuncs = QOpenGLContext::currentContext()->functions(); m_timestamp_id = program()->uniformLocation("timestamp"); m_entry_id = program()->uniformLocation("entry"); m_sizetable_id = program()->uniformLocation("sizetable"); @@ -155,7 +155,7 @@ public: int m_opacitytable_id; QByteArray m_vertex_code; QByteArray m_fragment_code; - QGLFunctions* glFuncs; + QOpenGLFunctions* glFuncs; }; class DeformableMaterialData : public ImageMaterialData {}; @@ -166,13 +166,13 @@ class DeformableMaterial : public QSGSimpleMaterialShader<DeformableMaterialData public: DeformableMaterial() { - QFile vf(":defaultshaders/imagevertex.shader"); + QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader")); vf.open(QFile::ReadOnly); m_vertex_code = QByteArray(SHADER_DEFINES) + QByteArray("#define DEFORM\n#define COLOR\n") + vf.readAll(); - QFile ff(":defaultshaders/imagefragment.shader"); + QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader")); ff.open(QFile::ReadOnly); m_fragment_code = QByteArray(SHADER_DEFINES) + QByteArray("#define DEFORM\n#define COLOR\n") @@ -194,7 +194,7 @@ public: QSGSimpleMaterialShader<DeformableMaterialData>::initialize(); program()->bind(); program()->setUniformValue("texture", 0); - glFuncs = QGLContext::currentContext()->functions(); + glFuncs = QOpenGLContext::currentContext()->functions(); m_timestamp_id = program()->uniformLocation("timestamp"); m_entry_id = program()->uniformLocation("entry"); } @@ -211,7 +211,7 @@ public: int m_timestamp_id; QByteArray m_vertex_code; QByteArray m_fragment_code; - QGLFunctions* glFuncs; + QOpenGLFunctions* glFuncs; }; class SpriteMaterialData : public ImageMaterialData {}; @@ -222,13 +222,13 @@ class SpriteMaterial : public QSGSimpleMaterialShader<SpriteMaterialData> public: SpriteMaterial() { - QFile vf(":defaultshaders/imagevertex.shader"); + QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader")); vf.open(QFile::ReadOnly); m_vertex_code = QByteArray(SHADER_DEFINES) + QByteArray("#define SPRITE\n#define TABLE\n#define DEFORM\n#define COLOR\n") + vf.readAll(); - QFile ff(":defaultshaders/imagefragment.shader"); + QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader")); ff.open(QFile::ReadOnly); m_fragment_code = QByteArray(SHADER_DEFINES) + QByteArray("#define SPRITE\n#define TABLE\n#define DEFORM\n#define COLOR\n") @@ -251,7 +251,7 @@ public: program()->bind(); program()->setUniformValue("texture", 0); program()->setUniformValue("colortable", 1); - glFuncs = QGLContext::currentContext()->functions(); + glFuncs = QOpenGLContext::currentContext()->functions(); m_timestamp_id = program()->uniformLocation("timestamp"); m_framecount_id = program()->uniformLocation("framecount"); m_animcount_id = program()->uniformLocation("animcount"); @@ -284,7 +284,7 @@ public: int m_opacitytable_id; QByteArray m_vertex_code; QByteArray m_fragment_code; - QGLFunctions* glFuncs; + QOpenGLFunctions* glFuncs; }; class ColoredMaterialData : public ImageMaterialData {}; @@ -295,13 +295,13 @@ class ColoredMaterial : public QSGSimpleMaterialShader<ColoredMaterialData> public: ColoredMaterial() { - QFile vf(":defaultshaders/imagevertex.shader"); + QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader")); vf.open(QFile::ReadOnly); m_vertex_code = QByteArray(SHADER_DEFINES) + QByteArray("#define COLOR\n") + vf.readAll(); - QFile ff(":defaultshaders/imagefragment.shader"); + QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader")); ff.open(QFile::ReadOnly); m_fragment_code = QByteArray(SHADER_DEFINES) + QByteArray("#define COLOR\n") @@ -316,7 +316,7 @@ public: void activate() { QSGSimpleMaterialShader<ColoredMaterialData>::activate(); -#ifndef QT_OPENGL_ES_2 +#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) glEnable(GL_POINT_SPRITE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif @@ -324,7 +324,7 @@ public: void deactivate() { QSGSimpleMaterialShader<ColoredMaterialData>::deactivate(); -#ifndef QT_OPENGL_ES_2 +#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) glDisable(GL_POINT_SPRITE); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif @@ -338,7 +338,7 @@ public: QSGSimpleMaterialShader<ColoredMaterialData>::initialize(); program()->bind(); program()->setUniformValue("texture", 0); - glFuncs = QGLContext::currentContext()->functions(); + glFuncs = QOpenGLContext::currentContext()->functions(); m_timestamp_id = program()->uniformLocation("timestamp"); m_entry_id = program()->uniformLocation("entry"); } @@ -355,7 +355,7 @@ public: int m_entry_id; QByteArray m_vertex_code; QByteArray m_fragment_code; - QGLFunctions* glFuncs; + QOpenGLFunctions* glFuncs; }; class SimpleMaterialData : public ImageMaterialData {}; @@ -366,12 +366,12 @@ class SimpleMaterial : public QSGSimpleMaterialShader<SimpleMaterialData> public: SimpleMaterial() { - QFile vf(":defaultshaders/imagevertex.shader"); + QFile vf(QStringLiteral(":defaultshaders/imagevertex.shader")); vf.open(QFile::ReadOnly); m_vertex_code = QByteArray(SHADER_DEFINES) + vf.readAll(); - QFile ff(":defaultshaders/imagefragment.shader"); + QFile ff(QStringLiteral(":defaultshaders/imagefragment.shader")); ff.open(QFile::ReadOnly); m_fragment_code = QByteArray(SHADER_DEFINES) + ff.readAll(); @@ -385,7 +385,7 @@ public: void activate() { QSGSimpleMaterialShader<SimpleMaterialData>::activate(); -#ifndef QT_OPENGL_ES_2 +#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) glEnable(GL_POINT_SPRITE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif @@ -393,7 +393,7 @@ public: void deactivate() { QSGSimpleMaterialShader<SimpleMaterialData>::deactivate(); -#ifndef QT_OPENGL_ES_2 +#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) glDisable(GL_POINT_SPRITE); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif @@ -407,7 +407,7 @@ public: QSGSimpleMaterialShader<SimpleMaterialData>::initialize(); program()->bind(); program()->setUniformValue("texture", 0); - glFuncs = QGLContext::currentContext()->functions(); + glFuncs = QOpenGLContext::currentContext()->functions(); m_timestamp_id = program()->uniformLocation("timestamp"); m_entry_id = program()->uniformLocation("entry"); } @@ -424,7 +424,7 @@ public: int m_entry_id; QByteArray m_vertex_code; QByteArray m_fragment_code; - QGLFunctions* glFuncs; + QOpenGLFunctions* glFuncs; }; void fillUniformArrayFromImage(float* array, const QImage& img, int size) @@ -871,9 +871,9 @@ void QSGImageParticle::createEngine() } static QSGGeometry::Attribute SimpleParticle_Attributes[] = { - { 0, 2, GL_FLOAT }, // Position - { 1, 4, GL_FLOAT }, // Data - { 2, 4, GL_FLOAT } // Vectors + QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position + QSGGeometry::Attribute::create(1, 4, GL_FLOAT), // Data + QSGGeometry::Attribute::create(2, 4, GL_FLOAT) // Vectors }; static QSGGeometry::AttributeSet SimpleParticle_AttributeSet = @@ -884,10 +884,10 @@ static QSGGeometry::AttributeSet SimpleParticle_AttributeSet = }; static QSGGeometry::Attribute ColoredParticle_Attributes[] = { - { 0, 2, GL_FLOAT }, // Position - { 1, 4, GL_FLOAT }, // Data - { 2, 4, GL_FLOAT }, // Vectors - { 3, 4, GL_UNSIGNED_BYTE }, // Colors + QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position + QSGGeometry::Attribute::create(1, 4, GL_FLOAT), // Data + QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Vectors + QSGGeometry::Attribute::create(3, 4, GL_UNSIGNED_BYTE), // Colors }; static QSGGeometry::AttributeSet ColoredParticle_AttributeSet = @@ -898,13 +898,13 @@ static QSGGeometry::AttributeSet ColoredParticle_AttributeSet = }; static QSGGeometry::Attribute DeformableParticle_Attributes[] = { - { 0, 2, GL_FLOAT }, // Position - { 1, 2, GL_FLOAT }, // TexCoord - { 2, 4, GL_FLOAT }, // Data - { 3, 4, GL_FLOAT }, // Vectors - { 4, 4, GL_UNSIGNED_BYTE }, // Colors - { 5, 4, GL_FLOAT }, // DeformationVectors - { 6, 3, GL_FLOAT }, // Rotation + 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, 4, GL_UNSIGNED_BYTE), // Colors + QSGGeometry::Attribute::create(5, 4, GL_FLOAT), // DeformationVectors + QSGGeometry::Attribute::create(6, 3, GL_FLOAT), // Rotation }; static QSGGeometry::AttributeSet DeformableParticle_AttributeSet = @@ -915,14 +915,14 @@ static QSGGeometry::AttributeSet DeformableParticle_AttributeSet = }; static QSGGeometry::Attribute SpriteParticle_Attributes[] = { - { 0, 2, GL_FLOAT }, // Position - { 1, 2, GL_FLOAT }, // TexCoord - { 2, 4, GL_FLOAT }, // Data - { 3, 4, GL_FLOAT }, // Vectors - { 4, 4, GL_UNSIGNED_BYTE }, // Colors - { 5, 4, GL_FLOAT }, // DeformationVectors - { 6, 3, GL_FLOAT }, // Rotation - { 7, 4, GL_FLOAT } // Anim Data + 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, 4, GL_UNSIGNED_BYTE), // Colors + QSGGeometry::Attribute::create(5, 4, GL_FLOAT), // DeformationVectors + QSGGeometry::Attribute::create(6, 3, GL_FLOAT), // Rotation + QSGGeometry::Attribute::create(7, 4, GL_FLOAT) // Anim Data }; static QSGGeometry::AttributeSet SpriteParticle_AttributeSet = @@ -1001,7 +1001,7 @@ QSGGeometryNode* QSGImageParticle::buildParticleNodes() sizetable = QImage(m_sizetable_name.toLocalFile()); opacitytable = QImage(m_opacitytable_name.toLocalFile()); if (colortable.isNull()) - colortable = QImage(":defaultshaders/identitytable.png"); + colortable = QImage(QStringLiteral(":defaultshaders/identitytable.png")); Q_ASSERT(!colortable.isNull()); getState<ImageMaterialData>(m_material)->colorTable = sceneGraphEngine()->createTextureFromImage(colortable); fillUniformArrayFromImage(getState<ImageMaterialData>(m_material)->sizeTable, sizetable, UNIFORM_ARRAY_SIZE); diff --git a/src/declarative/particles/qsgimageparticle_p.h b/src/declarative/particles/qsgimageparticle_p.h index 1f87b16f63..d40be5daa7 100644 --- a/src/declarative/particles/qsgimageparticle_p.h +++ b/src/declarative/particles/qsgimageparticle_p.h @@ -45,6 +45,7 @@ #include "qsgdirection_p.h" #include <QDeclarativeListProperty> #include <qsgsimplematerial.h> +#include <QtGui/qcolor.h> QT_BEGIN_HEADER |