diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index cb9c493df5..19892ac30e 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -695,7 +695,8 @@ void LayerColor::updateColor() void LayerColor::draw() { kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); - CustomCommand* cmd = new CustomCommand(0, _vertexZ); + CustomCommand* cmd = new CustomCommand(); + cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this); Renderer::getInstance()->addCommand(cmd); } diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index d4228cb8f0..a7a43aa55f 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -415,7 +415,8 @@ void ParticleSystemQuad::draw() CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad"); kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); - CustomCommand* cmd = new CustomCommand(0, _vertexZ); + CustomCommand* cmd = new CustomCommand(); + cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(ParticleSystemQuad::onDraw, this); Renderer::getInstance()->addCommand(cmd); diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 095bf243d2..a77be3c41c 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -663,8 +663,8 @@ void Sprite::draw(void) { updateQuadVertices(); //TODO implement z order - QuadCommand* renderCommand = new QuadCommand(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1); - + QuadCommand* renderCommand = new QuadCommand(); + renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1); Renderer::getInstance()->addCommand(renderCommand); } diff --git a/cocos/2d/renderer/CCNewDrawNode.cpp b/cocos/2d/renderer/CCNewDrawNode.cpp index c10c472dcd..e2da995dcc 100644 --- a/cocos/2d/renderer/CCNewDrawNode.cpp +++ b/cocos/2d/renderer/CCNewDrawNode.cpp @@ -44,7 +44,8 @@ void NewDrawNode::draw() { kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); - CustomCommand* cmd = new CustomCommand(0, _vertexZ); + CustomCommand* cmd = new CustomCommand(); + cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(NewDrawNode::onDraw, this); Renderer::getInstance()->addCommand(cmd); } diff --git a/cocos/2d/renderer/CCNewSprite.cpp b/cocos/2d/renderer/CCNewSprite.cpp index f09d0b549c..4cce8cb3df 100644 --- a/cocos/2d/renderer/CCNewSprite.cpp +++ b/cocos/2d/renderer/CCNewSprite.cpp @@ -142,7 +142,8 @@ void NewSprite::draw(void) } //TODO implement z order - QuadCommand* renderCommand = new QuadCommand(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1); + QuadCommand* renderCommand = new QuadCommand(); + renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1); Renderer::getInstance()->addCommand(renderCommand); } diff --git a/cocos/2d/renderer/CCNewSpriteBatchNode.cpp b/cocos/2d/renderer/CCNewSpriteBatchNode.cpp index 8d4aac156e..d10becd344 100644 --- a/cocos/2d/renderer/CCNewSpriteBatchNode.cpp +++ b/cocos/2d/renderer/CCNewSpriteBatchNode.cpp @@ -60,7 +60,8 @@ void NewSpriteBatchNode::draw() arrayMakeObjectsPerformSelector(_children, updateTransform, NewSprite*); - QuadCommand* cmd = new QuadCommand(0, _vertexZ, _textureAtlas->getTexture()->getName(), _shaderProgram, _blendFunc, _textureAtlas->getQuads(), _textureAtlas->getTotalQuads()); + QuadCommand* cmd = new QuadCommand(); + cmd->init(0, _vertexZ, _textureAtlas->getTexture()->getName(), _shaderProgram, _blendFunc, _textureAtlas->getQuads(), _textureAtlas->getTotalQuads()); Renderer::getInstance()->addCommand(cmd); } diff --git a/cocos/2d/renderer/CustomCommand.cpp b/cocos/2d/renderer/CustomCommand.cpp index 86befadde6..7ff11d6310 100644 --- a/cocos/2d/renderer/CustomCommand.cpp +++ b/cocos/2d/renderer/CustomCommand.cpp @@ -7,15 +7,21 @@ NS_CC_BEGIN -CustomCommand::CustomCommand(int viewport, int32_t depth) +CustomCommand::CustomCommand() :RenderCommand() -, _viewport(viewport) -, _depth(depth) +, _viewport(0) +, _depth(0) , func(nullptr) { _type = CUSTOM_COMMAND; } +void CustomCommand::init(int viewport, int32_t depth) +{ + _viewport = viewport; + _depth = depth; +} + CustomCommand::~CustomCommand() { diff --git a/cocos/2d/renderer/CustomCommand.h b/cocos/2d/renderer/CustomCommand.h index bc6dc99684..cf66612b37 100644 --- a/cocos/2d/renderer/CustomCommand.h +++ b/cocos/2d/renderer/CustomCommand.h @@ -15,7 +15,8 @@ using namespace std; class CustomCommand : public RenderCommand { public: - CustomCommand(int viewport, int32_t depth); + CustomCommand(); + void init(int viewport, int32_t depth); ~CustomCommand(); // +----------+----------+-----+-----------------------------------+ diff --git a/cocos/2d/renderer/GroupCommand.cpp b/cocos/2d/renderer/GroupCommand.cpp index 0e52cd9b76..93530fb31f 100644 --- a/cocos/2d/renderer/GroupCommand.cpp +++ b/cocos/2d/renderer/GroupCommand.cpp @@ -63,15 +63,23 @@ void GroupCommandManager::releaseGroupID(int groupID) _groupMapping[groupID] = false; } -GroupCommand::GroupCommand(int viewport, int32_t depth) +GroupCommand::GroupCommand() :RenderCommand() -, _viewport(viewport) -, _depth(depth) +, _viewport(0) +, _depth(0) { _type = GROUP_COMMAND; _renderQueueID = GroupCommandManager::getInstance()->getGroupID(); } +void GroupCommand::init(int viewport, int32_t depth) +{ + _viewport = viewport; + _depth = depth; + GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID); + _renderQueueID = GroupCommandManager::getInstance()->getGroupID(); +} + GroupCommand::~GroupCommand() { GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID); diff --git a/cocos/2d/renderer/GroupCommand.h b/cocos/2d/renderer/GroupCommand.h index 997f6e9622..fdfce93be2 100644 --- a/cocos/2d/renderer/GroupCommand.h +++ b/cocos/2d/renderer/GroupCommand.h @@ -35,7 +35,8 @@ class GroupCommand : public RenderCommand { public: - GroupCommand(int viewport, int32_t depth); + GroupCommand(); + void init(int viewport, int32_t depth); ~GroupCommand(); // +----------+----------+-----+-----------------------------------+ diff --git a/cocos/2d/renderer/NewClippingNode.cpp b/cocos/2d/renderer/NewClippingNode.cpp index b480e2d837..8caccbcbd6 100644 --- a/cocos/2d/renderer/NewClippingNode.cpp +++ b/cocos/2d/renderer/NewClippingNode.cpp @@ -85,24 +85,28 @@ void NewClippingNode::visit() Renderer* renderer = Renderer::getInstance(); - GroupCommand* groupCommand = new GroupCommand(0,_vertexZ); + GroupCommand* groupCommand = new GroupCommand(); + groupCommand->init(0,_vertexZ); renderer->addCommand(groupCommand); renderer->pushGroup(groupCommand->getRenderQueueID()); - CustomCommand* beforeVisitCmd = new CustomCommand(0,_vertexZ); + CustomCommand* beforeVisitCmd = new CustomCommand(); + beforeVisitCmd->init(0,_vertexZ); beforeVisitCmd->func = CC_CALLBACK_0(NewClippingNode::beforeVisit, this); renderer->addCommand(beforeVisitCmd, groupCommand->getRenderQueueID()); _stencil->visit(); - CustomCommand* afterDrawStencilCmd = new CustomCommand(0,_vertexZ); + CustomCommand* afterDrawStencilCmd = new CustomCommand(); + afterDrawStencilCmd->init(0,_vertexZ); afterDrawStencilCmd->func = CC_CALLBACK_0(NewClippingNode::afterDrawStencil, this); renderer->addCommand(afterDrawStencilCmd, groupCommand->getRenderQueueID()); Node::visit(); - CustomCommand* afterVisitCmd = new CustomCommand(0,_vertexZ); + CustomCommand* afterVisitCmd = new CustomCommand(); + afterVisitCmd->init(0,_vertexZ); afterVisitCmd->func = CC_CALLBACK_0(NewClippingNode::afterVisit, this); renderer->addCommand(afterVisitCmd, groupCommand->getRenderQueueID()); diff --git a/cocos/2d/renderer/QuadCommand.cpp b/cocos/2d/renderer/QuadCommand.cpp index ccacac4678..5fd6ca5de1 100644 --- a/cocos/2d/renderer/QuadCommand.cpp +++ b/cocos/2d/renderer/QuadCommand.cpp @@ -8,16 +8,28 @@ NS_CC_BEGIN -QuadCommand::QuadCommand(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, int quadCount) +QuadCommand::QuadCommand() :RenderCommand() -,_viewport(viewport) -,_depth(depth) -,_textureID(textureID) -,_blendType(blendType) -,_quadCount(quadCount) +,_viewport(0) +,_depth(0) +,_textureID(0) +,_blendType(BlendFunc::DISABLE) +,_quadCount(0) { _type = QUAD_COMMAND; + _shader = nullptr; + _quad = nullptr; +} + +void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, int quadCount) +{ + _viewport = viewport; + _depth = depth; + _textureID = textureID; + _blendType = blendType; + _quadCount = quadCount; _shader = shader; + free(_quad); _quad = (V3F_C4B_T2F_Quad*)malloc(sizeof(V3F_C4B_T2F_Quad) * quadCount); memcpy(_quad, quad, sizeof(V3F_C4B_T2F_Quad) * quadCount); } diff --git a/cocos/2d/renderer/QuadCommand.h b/cocos/2d/renderer/QuadCommand.h index 422f00202e..b15bb698a7 100644 --- a/cocos/2d/renderer/QuadCommand.h +++ b/cocos/2d/renderer/QuadCommand.h @@ -17,7 +17,8 @@ NS_CC_BEGIN class QuadCommand : public RenderCommand { public: - QuadCommand(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, int quadCount); + QuadCommand(); + void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, int quadCount); ~QuadCommand(); // +----------+----------+-----+-----------------------------------+