summaryrefslogtreecommitdiffstats
path: root/src/imports/particles/spriteparticle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports/particles/spriteparticle.cpp')
-rw-r--r--src/imports/particles/spriteparticle.cpp95
1 files changed, 70 insertions, 25 deletions
diff --git a/src/imports/particles/spriteparticle.cpp b/src/imports/particles/spriteparticle.cpp
index 93c956cf1a..dcd8f4a89b 100644
--- a/src/imports/particles/spriteparticle.cpp
+++ b/src/imports/particles/spriteparticle.cpp
@@ -1,31 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Declarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include "spriteparticle.h"
#include "spritestate.h"
#include "spriteengine.h"
#include "particleemitter.h"
-#include <qsgcontext.h>
-#include <adaptationlayer.h>
-#include <node.h>
-#include <texturematerial.h>
+#include <private/qsgcontext_p.h>
+#include <private/qsgadaptationlayer_p.h>
+#include <qsgnode.h>
+#include <qsgtexturematerial.h>
+#include <qsgengine.h>
#include <qsgtexture.h>
#include <QFile>
#include <cmath>
#include <qmath.h>
#include <QDebug>
+
QT_BEGIN_NAMESPACE
-class SpriteParticlesMaterial : public AbstractMaterial
+class SpriteParticlesMaterial : public QSGMaterial
{
public:
SpriteParticlesMaterial();
virtual ~SpriteParticlesMaterial();
- virtual AbstractMaterialType *type() const { static AbstractMaterialType type; return &type; }
- virtual AbstractMaterialShader *createShader() const;
- virtual int compare(const AbstractMaterial *other) const
+ virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
+ virtual QSGMaterialShader *createShader() const;
+ virtual int compare(const QSGMaterial *other) const
{
return this - static_cast<const SpriteParticlesMaterial *>(other);
}
- QSGTextureRef texture;
+ QSGTexture *texture;
qreal timestamp;
int framecount;
@@ -42,10 +85,10 @@ SpriteParticlesMaterial::SpriteParticlesMaterial()
SpriteParticlesMaterial::~SpriteParticlesMaterial()
{
-
+ delete texture;
}
-class SpriteParticlesMaterialData : public AbstractMaterialShader
+class SpriteParticlesMaterialData : public QSGMaterialShader
{
public:
SpriteParticlesMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
@@ -63,25 +106,25 @@ public:
}
void deactivate() {
- AbstractMaterialShader::deactivate();
+ QSGMaterialShader::deactivate();
for (int i=0; i<8; ++i) {
m_program.setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
}
}
- virtual void updateState(Renderer *renderer, AbstractMaterial *newEffect, AbstractMaterial *, Renderer::Updates updates)
+ virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
{
SpriteParticlesMaterial *m = static_cast<SpriteParticlesMaterial *>(newEffect);
m->texture->bind();
- m_program.setUniformValue(m_opacity_id, (float) renderer->renderOpacity());
+ m_program.setUniformValue(m_opacity_id, state.opacity());
m_program.setUniformValue(m_timestamp_id, (float) m->timestamp);
m_program.setUniformValue(m_framecount_id, (float) m->framecount);
m_program.setUniformValue(m_animcount_id, (float) m->animcount);
- if (updates & Renderer::UpdateMatrices)
- m_program.setUniformValue(m_matrix_id, renderer->combinedMatrix());
+ if (state.isMatrixDirty())
+ m_program.setUniformValue(m_matrix_id, state.combinedMatrix());
}
virtual void initialize() {
@@ -122,7 +165,7 @@ public:
};
float SpriteParticlesMaterialData::chunkOfBytes[1024];
-AbstractMaterialShader *SpriteParticlesMaterial::createShader() const
+QSGMaterialShader *SpriteParticlesMaterial::createShader() const
{
return new SpriteParticlesMaterialData;
}
@@ -200,10 +243,8 @@ static QSGGeometry::AttributeSet SpriteParticle_AttributeSet =
-GeometryNode* SpriteParticle::buildParticleNode()
+QSGGeometryNode* SpriteParticle::buildParticleNode()
{
- QSGContext *sg = QSGContext::current;
-
if (m_count * 4 > 0xffff) {
qWarning() << "SpriteParticle: too many particles...";
return 0;
@@ -229,7 +270,8 @@ GeometryNode* SpriteParticle::buildParticleNode()
QImage image = m_spriteEngine->assembledImage();
if(image.isNull())
return 0;
- m_material->texture = sg->createTexture(image);
+ m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
+ m_material->texture->setFiltering(QSGTexture::Linear);
m_material->framecount = m_spriteEngine->maxFrames();
m_spriteEngine->setCount(m_count);
@@ -287,7 +329,7 @@ GeometryNode* SpriteParticle::buildParticleNode()
}
- m_node = new GeometryNode();
+ m_node = new QSGGeometryNode();
m_node->setGeometry(g);
m_node->setMaterial(m_material);
m_last_particle = 0;
@@ -348,7 +390,7 @@ void SpriteParticle::reload(ParticleData *d)
}
-Node *SpriteParticle::updatePaintNode(Node *, UpdatePaintNodeData *)
+QSGNode *SpriteParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
{
if(m_pleaseReset){
if(m_node)
@@ -360,10 +402,11 @@ Node *SpriteParticle::updatePaintNode(Node *, UpdatePaintNodeData *)
m_material = 0;
m_pleaseReset = false;
}
- prepareNextFrame();
+ if(m_system&& m_system->isRunning())
+ prepareNextFrame();
if (m_node){
update();
- m_node->markDirty(Node::DirtyMaterial);
+ m_node->markDirty(QSGNode::DirtyMaterial);
}
return m_node;
@@ -400,6 +443,8 @@ void SpriteParticle::prepareNextFrame()
void SpriteParticle::reset()
{
+ ParticleType::reset();
m_pleaseReset = true;
}
+
QT_END_NAMESPACE