Skip to content

Commit 2e2f0ed

Browse files
committed
Merge pull request cocos2d#5 from dabingnn/newRendererParticleSystem
New renderer particle system
2 parents fdb7ce2 + c9c168e commit 2e2f0ed

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

cocos/2d/CCParticleSystemQuad.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,44 @@ void ParticleSystemQuad::postStep()
409409
// CHECK_GL_ERROR_DEBUG();
410410
//}
411411

412-
413412
void ParticleSystemQuad::draw()
414413
{
415414
CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad");
416-
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
417-
418-
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
419-
cmd->init(0, _vertexZ);
420-
cmd->func = CC_CALLBACK_0(ParticleSystemQuad::onDraw, this);
421-
Renderer::getInstance()->addCommand(cmd);
415+
//quad command
416+
if(_particleIdx > 0)
417+
{
418+
//transform vertices
419+
std::vector<V3F_C4B_T2F_Quad> drawQuads(_particleIdx);
420+
memcpy(&drawQuads[0], _quads, sizeof(V3F_C4B_T2F_Quad) * _particleIdx);
421+
AffineTransform worldTM = getNodeToWorldTransform();
422+
for(int index = 0; index <_particleIdx; ++index)
423+
{
424+
V3F_C4B_T2F_Quad* quad = _quads + index;
425+
426+
Point pt(0,0);
427+
pt = PointApplyAffineTransform( Point(quad->bl.vertices.x, quad->bl.vertices.y), worldTM);
428+
drawQuads[index].bl.vertices.x = pt.x;
429+
drawQuads[index].bl.vertices.y = pt.y;
430+
431+
pt = PointApplyAffineTransform( Point(quad->br.vertices.x, quad->br.vertices.y), worldTM);
432+
drawQuads[index].br.vertices.x = pt.x;
433+
drawQuads[index].br.vertices.y = pt.y;
434+
435+
pt = PointApplyAffineTransform( Point(quad->tl.vertices.x, quad->tl.vertices.y), worldTM);
436+
drawQuads[index].tl.vertices.x = pt.x;
437+
drawQuads[index].tl.vertices.y = pt.y;
438+
439+
pt = PointApplyAffineTransform( Point(quad->tr.vertices.x, quad->tr.vertices.y), worldTM);
440+
drawQuads[index].tr.vertices.x = pt.x;
441+
drawQuads[index].tr.vertices.y = pt.y;
442+
443+
}
444+
445+
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
446+
cmd->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &drawQuads[0], _particleIdx);
447+
Renderer::getInstance()->addCommand(cmd);
448+
}
422449

423-
//TODO render particle using quad command
424-
// QuadCommand* cmd = new QuadCommand(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, _quads, _particleIdx);
425-
// Renderer::getInstance()->addCommand(cmd);
426450
}
427451

428452
void ParticleSystemQuad::onDraw()

cocos/2d/renderer/Renderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <vector>
1515
#include <stack>
1616

17-
#define VBO_SIZE 1024
17+
#define VBO_SIZE 8192
1818
#define DEFAULT_RENDER_QUEUE 0
1919

2020
NS_CC_BEGIN

0 commit comments

Comments
 (0)