diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2011-08-23 18:20:58 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-24 10:11:29 +0200 |
commit | 017265b9383cbd616aaa2f5fee17dae8e28a161b (patch) | |
tree | 49e45cd13a00f0ccf2c3641b1256dd3d2904842b /src/declarative/particles/qsgimageparticle.cpp | |
parent | e6c0633a9c386817017a97dac9e541a45f42fd7f (diff) |
Switch from textures to uniform arrays for size/opacity tables
Change-Id: Iafc5eaa80f68345cc3b14fe0b2d997c1af435419
Reviewed-on: http://codereview.qt.nokia.com/3388
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Diffstat (limited to 'src/declarative/particles/qsgimageparticle.cpp')
-rw-r--r-- | src/declarative/particles/qsgimageparticle.cpp | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/src/declarative/particles/qsgimageparticle.cpp b/src/declarative/particles/qsgimageparticle.cpp index f2fb289ab5..3b58bfc208 100644 --- a/src/declarative/particles/qsgimageparticle.cpp +++ b/src/declarative/particles/qsgimageparticle.cpp @@ -62,25 +62,27 @@ DEFINE_BOOL_CONFIG_OPTION(qmlParticlesDebug, QML_PARTICLES_DEBUG) #else #define SHADER_DEFINES "" #endif + +//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; class ImageMaterialData { public: ImageMaterialData() - : texture(0), colortable(0), sizetable(0), opacitytable(0) + : texture(0), colorTable(0) {} ~ImageMaterialData(){ delete texture; - delete colortable; - delete sizetable; - delete opacitytable; + delete colorTable; } QSGTexture *texture; - QSGTexture *colortable; - QSGTexture *sizetable; - QSGTexture *opacitytable; + QSGTexture *colorTable; + float sizeTable[UNIFORM_ARRAY_SIZE]; + float opacityTable[UNIFORM_ARRAY_SIZE]; qreal timestamp; qreal entry; @@ -126,24 +128,17 @@ public: program()->bind(); program()->setUniformValue("texture", 0); program()->setUniformValue("colortable", 1); - program()->setUniformValue("sizetable", 2); - program()->setUniformValue("opacitytable", 3); glFuncs = QGLContext::currentContext()->functions(); m_timestamp_id = program()->uniformLocation("timestamp"); m_entry_id = program()->uniformLocation("entry"); + m_sizetable_id = program()->uniformLocation("sizetable"); + m_opacitytable_id = program()->uniformLocation("opacitytable"); } void updateState(const TabledMaterialData* d, const TabledMaterialData*) { glFuncs->glActiveTexture(GL_TEXTURE1); - d->colortable->bind(); - - glFuncs->glActiveTexture(GL_TEXTURE2); - d->sizetable->bind(); + d->colorTable->bind(); - glFuncs->glActiveTexture(GL_TEXTURE3); - d->opacitytable->bind(); - - // make sure we end by setting GL_TEXTURE0 as active texture glFuncs->glActiveTexture(GL_TEXTURE0); d->texture->bind(); @@ -151,10 +146,14 @@ public: program()->setUniformValue("framecount", (float) 1); program()->setUniformValue("animcount", (float) 1); program()->setUniformValue(m_entry_id, (float) d->entry); + program()->setUniformValueArray(m_sizetable_id, (float*) d->sizeTable, UNIFORM_ARRAY_SIZE, 1); + program()->setUniformValueArray(m_opacitytable_id, (float*) d->opacityTable, UNIFORM_ARRAY_SIZE, 1); } int m_entry_id; int m_timestamp_id; + int m_sizetable_id; + int m_opacitytable_id; QByteArray m_vertex_code; QByteArray m_fragment_code; QGLFunctions* glFuncs; @@ -253,24 +252,18 @@ public: program()->bind(); program()->setUniformValue("texture", 0); program()->setUniformValue("colortable", 1); - program()->setUniformValue("sizetable", 2); - program()->setUniformValue("opacitytable", 3); glFuncs = QGLContext::currentContext()->functions(); m_timestamp_id = program()->uniformLocation("timestamp"); m_framecount_id = program()->uniformLocation("framecount"); m_animcount_id = program()->uniformLocation("animcount"); m_entry_id = program()->uniformLocation("entry"); + m_sizetable_id = program()->uniformLocation("sizetable"); + m_opacitytable_id = program()->uniformLocation("sizetable"); } void updateState(const SpriteMaterialData* d, const SpriteMaterialData*) { glFuncs->glActiveTexture(GL_TEXTURE1); - d->colortable->bind(); - - glFuncs->glActiveTexture(GL_TEXTURE2); - d->sizetable->bind(); - - glFuncs->glActiveTexture(GL_TEXTURE3); - d->opacitytable->bind(); + d->colorTable->bind(); // make sure we end by setting GL_TEXTURE0 as active texture glFuncs->glActiveTexture(GL_TEXTURE0); @@ -280,12 +273,16 @@ public: program()->setUniformValue(m_framecount_id, (float) d->framecount); program()->setUniformValue(m_animcount_id, (float) d->animcount); program()->setUniformValue(m_entry_id, (float) d->entry); + program()->setUniformValueArray(m_sizetable_id, (float*) d->sizeTable, 64, 1); + program()->setUniformValueArray(m_opacitytable_id, (float*) d->opacityTable, UNIFORM_ARRAY_SIZE, 1); } int m_timestamp_id; int m_framecount_id; int m_animcount_id; int m_entry_id; + int m_sizetable_id; + int m_opacitytable_id; QByteArray m_vertex_code; QByteArray m_fragment_code; QGLFunctions* glFuncs; @@ -431,6 +428,18 @@ public: QGLFunctions* glFuncs; }; +void fillUniformArrayFromImage(float* array, const QImage& img, int size) +{ + if (img.isNull()){ + for (int i=0; i<size; i++) + array[i] = 1; + return; + } + QImage scaled = img.scaled(size,1); + for (int i=0; i<size; i++) + array[i] = qAlpha(scaled.pixel(i,0))/255.0; +} + /*! \qmlclass ImageParticle QSGImageParticle \inqmlmodule QtQuick.Particles 2 @@ -903,16 +912,10 @@ QSGGeometryNode* QSGImageParticle::buildParticleNodes() opacitytable = QImage(m_opacitytable_name.toLocalFile()); if (colortable.isNull()) colortable = QImage(":defaultshaders/identitytable.png"); - if (sizetable.isNull()) - sizetable = QImage(":defaultshaders/identitytable.png"); - if (opacitytable.isNull()) - opacitytable = QImage(":defaultshaders/defaultFadeInOut.png"); Q_ASSERT(!colortable.isNull()); - Q_ASSERT(!sizetable.isNull()); - Q_ASSERT(!opacitytable.isNull()); - getState<ImageMaterialData>(m_material)->colortable = sceneGraphEngine()->createTextureFromImage(colortable); - getState<ImageMaterialData>(m_material)->sizetable = sceneGraphEngine()->createTextureFromImage(sizetable); - getState<ImageMaterialData>(m_material)->opacitytable = sceneGraphEngine()->createTextureFromImage(opacitytable); + getState<ImageMaterialData>(m_material)->colorTable = sceneGraphEngine()->createTextureFromImage(colortable); + fillUniformArrayFromImage(getState<ImageMaterialData>(m_material)->sizeTable, sizetable, UNIFORM_ARRAY_SIZE); + fillUniformArrayFromImage(getState<ImageMaterialData>(m_material)->opacityTable, opacitytable, UNIFORM_ARRAY_SIZE); case Deformable: if (!m_material) m_material = DeformableMaterial::createMaterial(); |