From 7a58cb5a29d11f1589e466915f243e161f7ffe40 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 5 Dec 2013 10:20:22 +0800 Subject: [PATCH 1/2] use quad command instead of custom command for ParticleSystemQuad::draw() --- cocos/2d/CCParticleSystemQuad.cpp | 44 ++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index ad5c1b834e..f723480d36 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -409,20 +409,44 @@ void ParticleSystemQuad::postStep() // CHECK_GL_ERROR_DEBUG(); //} - void ParticleSystemQuad::draw() { CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad"); - kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); + //quad command + if(_particleIdx > 0) + { + //transform vertices + std::vector drawQuads(_particleIdx); + memcpy(&drawQuads[0], _quads, sizeof(V3F_C4B_T2F_Quad) * _particleIdx); + AffineTransform worldTM = getNodeToWorldTransform(); + for(int index = 0; index <_particleIdx; ++index) + { + V3F_C4B_T2F_Quad* quad = _quads + index; + + Point pt(0,0); + pt = PointApplyAffineTransform( Point(quad->bl.vertices.x, quad->bl.vertices.y), worldTM); + drawQuads[index].bl.vertices.x = pt.x; + drawQuads[index].bl.vertices.y = pt.y; + + pt = PointApplyAffineTransform( Point(quad->br.vertices.x, quad->br.vertices.y), worldTM); + drawQuads[index].br.vertices.x = pt.x; + drawQuads[index].br.vertices.y = pt.y; + + pt = PointApplyAffineTransform( Point(quad->tl.vertices.x, quad->tl.vertices.y), worldTM); + drawQuads[index].tl.vertices.x = pt.x; + drawQuads[index].tl.vertices.y = pt.y; + + pt = PointApplyAffineTransform( Point(quad->tr.vertices.x, quad->tr.vertices.y), worldTM); + drawQuads[index].tr.vertices.x = pt.x; + drawQuads[index].tr.vertices.y = pt.y; + + } + + QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &drawQuads[0], _particleIdx); + Renderer::getInstance()->addCommand(cmd); + } - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(ParticleSystemQuad::onDraw, this); - Renderer::getInstance()->addCommand(cmd); - - //TODO render particle using quad command -// QuadCommand* cmd = new QuadCommand(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, _quads, _particleIdx); -// Renderer::getInstance()->addCommand(cmd); } void ParticleSystemQuad::onDraw() From e6823875d566459fb2d175b0a193e1b65b000074 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 5 Dec 2013 10:20:54 +0800 Subject: [PATCH 2/2] change VBO_SIZE to a big number to avoid crash temporarily --- cocos/2d/renderer/Renderer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/renderer/Renderer.h b/cocos/2d/renderer/Renderer.h index 067df355bf..3618187740 100644 --- a/cocos/2d/renderer/Renderer.h +++ b/cocos/2d/renderer/Renderer.h @@ -14,7 +14,7 @@ #include #include -#define VBO_SIZE 1024 +#define VBO_SIZE 8192 #define DEFAULT_RENDER_QUEUE 0 NS_CC_BEGIN