Add some more properties to JS particle type
[profile/ivi/qtdeclarative.git] / src / declarative / particles / qsgimageparticle.cpp
index a910cc6..52e94b1 100644 (file)
@@ -59,7 +59,11 @@ class UltraMaterial : public QSGMaterial
 {
 public:
     UltraMaterial(bool withSprites=false)
-        : timestamp(0)
+        : texture(0)
+        , colortable(0)
+        , sizetable(0)
+        , opacitytable(0)
+        , timestamp(0)
         , framecount(1)
         , animcount(1)
         , usesSprites(withSprites)
@@ -69,10 +73,14 @@ public:
 
     ~UltraMaterial()
     {
-        delete texture;
-        delete colortable;
-        delete sizetable;
-        delete opacitytable;
+        if (texture)
+            delete texture;
+        if (colortable)
+            delete colortable;
+        if (sizetable)
+            delete sizetable;
+        if (opacitytable)
+            delete opacitytable;
     }
 
     virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
@@ -122,17 +130,15 @@ public:
         UltraMaterial *m = static_cast<UltraMaterial *>(newEffect);
         state.context()->functions()->glActiveTexture(GL_TEXTURE1);
         m->colortable->bind();
-        program()->setUniformValue(m_colortable_id, 1);
 
         state.context()->functions()->glActiveTexture(GL_TEXTURE2);
         m->sizetable->bind();
-        program()->setUniformValue(m_sizetable_id, 2);
 
         state.context()->functions()->glActiveTexture(GL_TEXTURE3);
         m->opacitytable->bind();
-        program()->setUniformValue(m_opacitytable_id, 3);
 
-        state.context()->functions()->glActiveTexture(GL_TEXTURE0);//Investigate why this screws up Text{} if placed before 1
+        // make sure we end by setting GL_TEXTURE0 as active texture
+        state.context()->functions()->glActiveTexture(GL_TEXTURE0);
         m->texture->bind();
 
         program()->setUniformValue(m_opacity_id, state.opacity());
@@ -145,9 +151,11 @@ public:
     }
 
     virtual void initialize() {
-        m_colortable_id = program()->uniformLocation("colortable");
-        m_sizetable_id = program()->uniformLocation("sizetable");
-        m_opacitytable_id = program()->uniformLocation("opacitytable");
+        program()->bind();
+        program()->setUniformValue("texture", 0);
+        program()->setUniformValue("colortable", 1);
+        program()->setUniformValue("sizetable", 2);
+        program()->setUniformValue("opacitytable", 3);
         m_matrix_id = program()->uniformLocation("matrix");
         m_opacity_id = program()->uniformLocation("opacity");
         m_timestamp_id = program()->uniformLocation("timestamp");
@@ -178,9 +186,6 @@ public:
     int m_matrix_id;
     int m_opacity_id;
     int m_timestamp_id;
-    int m_colortable_id;
-    int m_sizetable_id;
-    int m_opacitytable_id;
     int m_framecount_id;
     int m_animcount_id;
 
@@ -281,6 +286,78 @@ QSGMaterialShader *SimpleMaterial::createShader() const {
     return new SimpleMaterialData;
 }
 
+/*!
+    \qmlclass ImageParticle QSGImageParticle
+    \inqmlmodule QtQuick.Particles 2
+    \since QtQuick.Particles 2.0
+    \inherits ParticlePainter
+    \brief The ImageParticle element visualizes logical particles using an image
+
+    This element renders a logical particle as an image. The image can be
+        - colorized
+        - roatated
+        - deformed
+        - a sprite-based animation
+*/
+/*!
+    \qmlproperty url QtQuick.Particles2::ImageParticle::source
+*/
+/*!
+    \qmlproperty url QtQuick.Particles2::ImageParticle::colorTable
+*/
+/*!
+    \qmlproperty url QtQuick.Particles2::ImageParticle::sizeTable
+*/
+/*!
+    \qmlproperty url QtQuick.Particles2::ImageParticle::opacityTable
+*/
+/*!
+    \qmlproperty color QtQuick.Particles2::ImageParticle::color
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::colorVariation
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::redVariation
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::greenVariation
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::blueVariation
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::alpha
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::alphaVariation
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::rotation
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::rotationVariation
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::rotationSpeed
+*/
+/*!
+    \qmlproperty real QtQuick.Particles2::ImageParticle::rotationSpeedVariation
+*/
+/*!
+    \qmlproperty bool QtQuick.Particles2::ImageParticle::autoRotation
+*/
+/*!
+    \qmlproperty StochasticDirection QtQuick.Particles2::ImageParticle::xVector
+*/
+/*!
+    \qmlproperty StochasticDirection QtQuick.Particles2::ImageParticle::yVector
+*/
+/*!
+    \qmlproperty list<Sprite> QtQuick.Particles2::ImageParticle::sprites
+*/
+
+
 QSGImageParticle::QSGImageParticle(QSGItem* parent)
     : QSGParticlePainter(parent)
     , m_do_reset(false)
@@ -908,8 +985,8 @@ void QSGImageParticle::commit(int gIdx, int pIdx)
             ultraVertices[i].lifeSpan = datum->lifeSpan;
             ultraVertices[i].size = datum->size;
             ultraVertices[i].endSize = datum->endSize;
-            ultraVertices[i].sx = datum->sx;
-            ultraVertices[i].sy = datum->sy;
+            ultraVertices[i].vx = datum->vx;
+            ultraVertices[i].vy = datum->vy;
             ultraVertices[i].ax = datum->ax;
             ultraVertices[i].ay = datum->ay;
             ultraVertices[i].xx = datum->xx;
@@ -941,8 +1018,8 @@ void QSGImageParticle::commit(int gIdx, int pIdx)
             simpleVertices[i].lifeSpan = datum->lifeSpan;
             simpleVertices[i].size = datum->size;
             simpleVertices[i].endSize = datum->endSize;
-            simpleVertices[i].sx = datum->sx;
-            simpleVertices[i].sy = datum->sy;
+            simpleVertices[i].vx = datum->vx;
+            simpleVertices[i].vy = datum->vy;
             simpleVertices[i].ax = datum->ax;
             simpleVertices[i].ay = datum->ay;
         }