From b4c61d5a7c93011df019bddbf8f2df9d58dec22d Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 26 Dec 2013 14:44:21 +0800 Subject: [PATCH 01/12] specialize RenderCommandPool --- cocos/2d/renderer/CCQuadCommand.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cocos/2d/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index 14a5531fac..6516b9c1c6 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -97,6 +97,21 @@ protected: static RenderCommandPool _commandPool; }; +template <> +class RenderCommandPool +{ +public: + QuadCommand* generateCommand() + { + return new QuadCommand(); + } + + void pushBackCommand(QuadCommand* ptr) + { + delete ptr; + } +}; + NS_CC_END #endif //_CC_QUADCOMMAND_H_ From 963d63719865ffdee9b501d2878522a8232096b2 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 26 Dec 2013 14:45:44 +0800 Subject: [PATCH 02/12] use raw new instead of generateCommand --- cocos/2d/CCSprite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 642e865aee..af3dcd8891 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -671,7 +671,7 @@ void Sprite::updateTransform(void) void Sprite::draw(void) { //TODO implement z order - QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand(); + QuadCommand* renderCommand = new QuadCommand(); renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); // if(!culling()) From f878864794dcdd0f6f471ff8cb0be71b3546d2aa Mon Sep 17 00:00:00 2001 From: boyu0 Date: Thu, 26 Dec 2013 15:41:47 +0800 Subject: [PATCH 03/12] Specialize GroupCommand and CustomCommand, change generateCommand to new. --- cocos/2d/CCAtlasNode.cpp | 2 +- cocos/2d/CCClippingNode.cpp | 8 +++---- cocos/2d/CCDrawNode.cpp | 2 +- cocos/2d/CCLayer.cpp | 2 +- cocos/2d/CCMotionStreak.cpp | 2 +- cocos/2d/CCNodeGrid.cpp | 6 ++--- cocos/2d/CCParticleBatchNode.cpp | 2 +- cocos/2d/CCParticleSystemQuad.cpp | 2 +- cocos/2d/CCProgressTimer.cpp | 2 +- cocos/2d/CCRenderTexture.cpp | 12 +++++----- cocos/2d/CCSpriteBatchNode.cpp | 2 +- cocos/2d/renderer/CCCustomCommand.h | 22 ++++++++++++++++--- cocos/2d/renderer/CCGroupCommand.h | 22 ++++++++++++++++--- .../editor-support/cocostudio/CCBatchNode.cpp | 2 +- cocos/editor-support/cocostudio/CCSkin.cpp | 2 +- .../Classes/ActionsTest/ActionsTest.cpp | 10 ++++----- .../TestCpp/Classes/Box2DTest/Box2dTest.cpp | 2 +- .../DrawPrimitivesTest/DrawPrimitivesTest.cpp | 2 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 2 +- .../TestCpp/Classes/LabelTest/LabelTest.cpp | 6 ++--- .../RenderTextureTest/RenderTextureTest.cpp | 2 +- .../TestCpp/Classes/ShaderTest/ShaderTest.cpp | 4 ++-- 22 files changed, 75 insertions(+), 43 deletions(-) diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index 741197e233..1cc4d752b2 100644 --- a/cocos/2d/CCAtlasNode.cpp +++ b/cocos/2d/CCAtlasNode.cpp @@ -151,7 +151,7 @@ void AtlasNode::draw(void) auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand(); + QuadCommand* cmd = new QuadCommand(); cmd->init(0, _vertexZ, _textureAtlas->getTexture()->getName(), diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index 552b1f081c..ef47c97a8f 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -209,20 +209,20 @@ void ClippingNode::visit() Renderer* renderer = Director::getInstance()->getRenderer(); - GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand(); + GroupCommand* groupCommand = new GroupCommand(); groupCommand->init(0,_vertexZ); renderer->addCommand(groupCommand); renderer->pushGroup(groupCommand->getRenderQueueID()); - CustomCommand* beforeVisitCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* beforeVisitCmd = new CustomCommand(); beforeVisitCmd->init(0,_vertexZ); beforeVisitCmd->func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this); renderer->addCommand(beforeVisitCmd); _stencil->visit(); - CustomCommand* afterDrawStencilCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* afterDrawStencilCmd = new CustomCommand(); afterDrawStencilCmd->init(0,_vertexZ); afterDrawStencilCmd->func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this); renderer->addCommand(afterDrawStencilCmd); @@ -253,7 +253,7 @@ void ClippingNode::visit() this->draw(); } - CustomCommand* afterVisitCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* afterVisitCmd = new CustomCommand(); afterVisitCmd->init(0,_vertexZ); afterVisitCmd->func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this); renderer->addCommand(afterVisitCmd); diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index e0a15ef65f..9228db0441 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -241,7 +241,7 @@ void DrawNode::render() void DrawNode::draw() { - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(DrawNode::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index 71c0b16dbc..55b17d5b28 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -564,7 +564,7 @@ void LayerColor::updateColor() void LayerColor::draw() { - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/cocos/2d/CCMotionStreak.cpp b/cocos/2d/CCMotionStreak.cpp index 70a00b622c..939245b238 100644 --- a/cocos/2d/CCMotionStreak.cpp +++ b/cocos/2d/CCMotionStreak.cpp @@ -358,7 +358,7 @@ void MotionStreak::draw() if(_nuPoints <= 1) return; kmGLGetMatrix(KM_GL_MODELVIEW,&_cachedMV); - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0,_vertexZ); cmd->func = CC_CALLBACK_0(MotionStreak::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index 7053d184cf..47ca7272d0 100644 --- a/cocos/2d/CCNodeGrid.cpp +++ b/cocos/2d/CCNodeGrid.cpp @@ -92,7 +92,7 @@ void NodeGrid::visit() Renderer* renderer = Director::getInstance()->getRenderer(); - GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand(); + GroupCommand* groupCommand = new GroupCommand(); groupCommand->init(0,_vertexZ); renderer->addCommand(groupCommand); renderer->pushGroup(groupCommand->getRenderQueueID()); @@ -105,7 +105,7 @@ void NodeGrid::visit() _nodeGrid->set2DProjection(); } - CustomCommand* gridBeginCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* gridBeginCmd = new CustomCommand(); gridBeginCmd->init(0,_vertexZ); gridBeginCmd->func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this); renderer->addCommand(gridBeginCmd); @@ -154,7 +154,7 @@ void NodeGrid::visit() director->setProjection(beforeProjectionType); } - CustomCommand* gridEndCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* gridEndCmd = new CustomCommand(); gridEndCmd->init(0,_vertexZ); gridEndCmd->func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this); renderer->addCommand(gridEndCmd); diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index e046833d79..0156c33554 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -392,7 +392,7 @@ void ParticleBatchNode::draw(void) kmMat4 mv; kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand(); + QuadCommand* cmd = new QuadCommand(); cmd->init(0, _vertexZ, _textureAtlas->getTexture()->getName(), diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index e63fe84baa..98c3f00c15 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -443,7 +443,7 @@ void ParticleSystemQuad::draw() auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand(); + QuadCommand* cmd = new QuadCommand(); cmd->init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(cmd); } diff --git a/cocos/2d/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp index 35aaefc832..e9f85d9840 100644 --- a/cocos/2d/CCProgressTimer.cpp +++ b/cocos/2d/CCProgressTimer.cpp @@ -532,7 +532,7 @@ void ProgressTimer::draw() if( ! _vertexData || ! _sprite) return; - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(ProgressTimer::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 3ba91d0771..95a2944bad 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -329,7 +329,7 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep this->begin(); //clear screen - CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* clearCmd = new CustomCommand(); clearCmd->init(0, _vertexZ); clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(clearCmd); @@ -348,7 +348,7 @@ void RenderTexture::clearDepth(float depthValue) this->begin(); - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(RenderTexture::onClearDepth, this); @@ -614,7 +614,7 @@ void RenderTexture::draw() begin(); //clear screen - CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* clearCmd = new CustomCommand(); clearCmd->init(0, _vertexZ); clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(clearCmd); @@ -643,14 +643,14 @@ void RenderTexture::begin() kmGLPushMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); - GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand(); + GroupCommand* groupCommand = new GroupCommand(); groupCommand->init(0, _vertexZ); Renderer *renderer = Director::getInstance()->getRenderer(); renderer->addCommand(groupCommand); renderer->pushGroup(groupCommand->getRenderQueueID()); - CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* beginCmd = new CustomCommand(); beginCmd->init(0, _vertexZ); beginCmd->func = CC_CALLBACK_0(RenderTexture::onBegin, this); @@ -659,7 +659,7 @@ void RenderTexture::begin() void RenderTexture::end() { - CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* endCmd = new CustomCommand(); endCmd->init(0, _vertexZ); endCmd->func = CC_CALLBACK_0(RenderTexture::onEnd, this); diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 024d438931..f553b3314c 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -360,7 +360,7 @@ void SpriteBatchNode::draw() kmMat4 mv; kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand(); + QuadCommand* cmd = new QuadCommand(); cmd->init(0, _vertexZ, _textureAtlas->getTexture()->getName(), diff --git a/cocos/2d/renderer/CCCustomCommand.h b/cocos/2d/renderer/CCCustomCommand.h index 23986e5643..7e64a0a6dd 100644 --- a/cocos/2d/renderer/CCCustomCommand.h +++ b/cocos/2d/renderer/CCCustomCommand.h @@ -33,6 +33,10 @@ NS_CC_BEGIN class CustomCommand : public RenderCommand { +public: + CustomCommand(); + ~CustomCommand(); + public: static RenderCommandPool& getCommandPool() { return _commandPool; } @@ -52,9 +56,6 @@ public: std::function func; protected: - CustomCommand(); - ~CustomCommand(); - int _viewport; int32_t _depth; static RenderCommandPool _commandPool; @@ -62,6 +63,21 @@ protected: friend class RenderCommandPool; }; +template <> +class RenderCommandPool +{ +public: + CustomCommand* generateCommand() + { + return new CustomCommand(); + } + + void pushBackCommand(CustomCommand* ptr) + { + delete ptr; + } +}; + NS_CC_END #endif //_CC_CUSTOMCOMMAND_H_ diff --git a/cocos/2d/renderer/CCGroupCommand.h b/cocos/2d/renderer/CCGroupCommand.h index a265e00afe..d23a326141 100644 --- a/cocos/2d/renderer/CCGroupCommand.h +++ b/cocos/2d/renderer/CCGroupCommand.h @@ -52,6 +52,10 @@ protected: class GroupCommand : public RenderCommand { +public: + GroupCommand(); + ~GroupCommand(); + public: static RenderCommandPool& getCommandPool() { return _commandPool; } @@ -69,9 +73,6 @@ public: virtual void releaseToCommandPool() override; protected: - GroupCommand(); - ~GroupCommand(); - int _viewport; int32_t _depth; int _renderQueueID; @@ -80,6 +81,21 @@ protected: friend class RenderCommandPool; }; +template <> +class RenderCommandPool +{ +public: + GroupCommand* generateCommand() + { + return new GroupCommand(); + } + + void pushBackCommand(GroupCommand* ptr) + { + delete ptr; + } +}; + NS_CC_END #endif //_CC_GROUPCOMMAND_H_ diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index f441ade370..19465e4fea 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -147,7 +147,7 @@ void BatchNode::draw() void BatchNode::generateGroupCommand() { Renderer* renderer = Director::getInstance()->getRenderer(); - GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand(); + GroupCommand* groupCommand = new GroupCommand(); groupCommand->init(0,_vertexZ); renderer->addCommand(groupCommand); diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index f408e7c4cc..38450ff900 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -219,7 +219,7 @@ void Skin::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &mv); //TODO implement z order - QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand(); + QuadCommand* renderCommand = new QuadCommand(); renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); Director::getInstance()->getRenderer()->addCommand(renderCommand); } diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 66222daa7c..4470a7ea1f 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -1289,7 +1289,7 @@ void ActionFollow::onEnter() void ActionFollow::draw() { - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(ActionFollow::onDraw, this); @@ -1606,7 +1606,7 @@ void ActionCatmullRomStacked::draw() kmGLPopMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); @@ -1722,7 +1722,7 @@ void ActionCardinalSplineStacked::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); @@ -2085,7 +2085,7 @@ void ActionCatmullRom::draw() kmGLPopMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); @@ -2186,7 +2186,7 @@ void ActionCardinalSpline::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand* cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp index b02af726c2..a0fc2c6298 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp @@ -149,7 +149,7 @@ void Box2DTestLayer::draw() kmGLPushMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV); - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand *cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index 9fe6f6c3fe..152ee7dbda 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -116,7 +116,7 @@ DrawPrimitivesTest::DrawPrimitivesTest() void DrawPrimitivesTest::draw() { - CustomCommand * cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand * cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index f1afd308cd..a574e8f15b 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -1094,7 +1094,7 @@ std::string TestBoundingBox::title() const } void TestBoundingBox::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand *cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(TestBoundingBox::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index 09280e9b63..8fb6ea43a4 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -209,7 +209,7 @@ void Atlas1::draw() // GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // GL_TEXTURE_2D - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand *cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(Atlas1::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); @@ -526,7 +526,7 @@ Atlas4::Atlas4() void Atlas4::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand *cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(Atlas4::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); @@ -1613,7 +1613,7 @@ std::string LabelBMFontBounds::subtitle() const void LabelBMFontBounds::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand *cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(LabelBMFontBounds::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index 096a7899f9..c3478551cb 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -589,7 +589,7 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::crea void SpriteRenderTextureBug::SimpleSprite::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand *cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(SpriteRenderTextureBug::SimpleSprite::onBeforeDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp index d3b1565d01..d93a0c1e83 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -196,7 +196,7 @@ void ShaderNode::setPosition(const Point &newPosition) void ShaderNode::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand *cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(ShaderNode::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); @@ -532,7 +532,7 @@ void SpriteBlur::initProgram() void SpriteBlur::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + CustomCommand *cmd = new CustomCommand(); cmd->init(0, _vertexZ); cmd->func = CC_CALLBACK_0(SpriteBlur::onDraw, this); Director::getInstance()->getRenderer()->addCommand(cmd); From 2fb0179293fe7b255f66e9cb4a87235e91e66118 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Thu, 26 Dec 2013 16:36:03 +0800 Subject: [PATCH 04/12] change QuadCommand variable to class member. --- cocos/2d/CCAtlasNode.cpp | 7 +++---- cocos/2d/CCAtlasNode.h | 3 +++ cocos/2d/CCParticleBatchNode.cpp | 7 +++---- cocos/2d/CCParticleBatchNode.h | 3 +++ cocos/2d/CCParticleSystemQuad.cpp | 7 +++---- cocos/2d/CCParticleSystemQuad.h | 3 +++ cocos/2d/CCSprite.cpp | 7 +++---- cocos/2d/CCSprite.h | 2 ++ cocos/2d/CCSpriteBatchNode.cpp | 7 +++---- cocos/2d/CCSpriteBatchNode.h | 2 ++ cocos/2d/renderer/CCQuadCommand.cpp | 2 +- cocos/2d/renderer/CCQuadCommand.h | 1 - cocos/2d/renderer/CCRenderer.cpp | 2 +- cocos/editor-support/cocostudio/CCArmature.cpp | 2 +- cocos/editor-support/cocostudio/CCSkin.cpp | 5 ++--- cocos/editor-support/cocostudio/CCSkin.h | 2 ++ 16 files changed, 35 insertions(+), 27 deletions(-) diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index 1cc4d752b2..d63eee9aac 100644 --- a/cocos/2d/CCAtlasNode.cpp +++ b/cocos/2d/CCAtlasNode.cpp @@ -34,7 +34,7 @@ THE SOFTWARE. #include "CCDirector.h" #include "TransformUtils.h" #include "CCRenderer.h" -#include "CCQuadCommand.h" +#include "renderer/CCQuadCommand.h" // external #include "kazmath/GL/matrix.h" @@ -151,8 +151,7 @@ void AtlasNode::draw(void) auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - QuadCommand* cmd = new QuadCommand(); - cmd->init(0, + _quadCommand.init(0, _vertexZ, _textureAtlas->getTexture()->getName(), shader, @@ -161,7 +160,7 @@ void AtlasNode::draw(void) _textureAtlas->getTotalQuads(), _modelViewTransform); - Director::getInstance()->getRenderer()->addCommand(cmd); + Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } diff --git a/cocos/2d/CCAtlasNode.h b/cocos/2d/CCAtlasNode.h index fc0636326b..7aabea937d 100644 --- a/cocos/2d/CCAtlasNode.h +++ b/cocos/2d/CCAtlasNode.h @@ -30,6 +30,7 @@ THE SOFTWARE. #include "CCNode.h" #include "CCProtocols.h" #include "ccTypes.h" +#include "renderer/CCQuadCommand.h" NS_CC_BEGIN @@ -130,6 +131,8 @@ protected: GLint _uniformColor; // This varible is only used for LabelAtlas FPS display. So plz don't modify its value. bool _ignoreContentScaleFactor; + // quad command + QuadCommand _quadCommand; private: CC_DISALLOW_COPY_AND_ASSIGN(AtlasNode); diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 0156c33554..e58f919b92 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -42,7 +42,7 @@ #include "platform/CCFileUtils.h" #include "kazmath/GL/matrix.h" #include "CCProfiling.h" -#include "CCQuadCommand.h" +#include "renderer/CCQuadCommand.h" #include "CCRenderer.h" NS_CC_BEGIN @@ -392,8 +392,7 @@ void ParticleBatchNode::draw(void) kmMat4 mv; kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - QuadCommand* cmd = new QuadCommand(); - cmd->init(0, + _quadCommand.init(0, _vertexZ, _textureAtlas->getTexture()->getName(), shader, @@ -401,7 +400,7 @@ void ParticleBatchNode::draw(void) _textureAtlas->getQuads(), _textureAtlas->getTotalQuads(), mv); - Director::getInstance()->getRenderer()->addCommand(cmd); + Director::getInstance()->getRenderer()->addCommand(&_quadCommand); CC_PROFILER_STOP("CCParticleBatchNode - draw"); } diff --git a/cocos/2d/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h index 189bfc7da9..4162d3b9dd 100644 --- a/cocos/2d/CCParticleBatchNode.h +++ b/cocos/2d/CCParticleBatchNode.h @@ -31,6 +31,7 @@ #include "CCNode.h" #include "CCProtocols.h" +#include "renderer/CCQuadCommand.h" NS_CC_BEGIN @@ -140,6 +141,8 @@ private: private: /** the blend function used for drawing the quads */ BlendFunc _blendFunc; + // quad command + QuadCommand _quadCommand; }; // end of particle_nodes group diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index 98c3f00c15..30a45644e0 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -39,7 +39,7 @@ THE SOFTWARE. #include "CCEventType.h" #include "CCConfiguration.h" #include "CCRenderer.h" -#include "CCQuadCommand.h" +#include "renderer/CCQuadCommand.h" #include "CCCustomCommand.h" // extern @@ -443,9 +443,8 @@ void ParticleSystemQuad::draw() auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - QuadCommand* cmd = new QuadCommand(); - cmd->init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform); - Director::getInstance()->getRenderer()->addCommand(cmd); + _quadCommand.init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform); + Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } } diff --git a/cocos/2d/CCParticleSystemQuad.h b/cocos/2d/CCParticleSystemQuad.h index 07f8f6bffc..e5f54d0837 100644 --- a/cocos/2d/CCParticleSystemQuad.h +++ b/cocos/2d/CCParticleSystemQuad.h @@ -28,6 +28,7 @@ THE SOFTWARE. #define __CC_PARTICLE_SYSTEM_QUAD_H__ #include "CCParticleSystem.h" +#include "renderer/CCQuadCommand.h" NS_CC_BEGIN @@ -151,6 +152,8 @@ protected: GLuint _buffersVBO[2]; //0: vertex 1: indices kmMat4 _transformMatrix; + + QuadCommand _quadCommand; // quad command private: CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad); }; diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index af3dcd8891..f0e48184b0 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -45,7 +45,7 @@ THE SOFTWARE. #include "TransformUtils.h" #include "CCProfiling.h" #include "CCRenderer.h" -#include "CCQuadCommand.h" +#include "renderer/CCQuadCommand.h" #include "CCFrustum.h" // external @@ -671,8 +671,7 @@ void Sprite::updateTransform(void) void Sprite::draw(void) { //TODO implement z order - QuadCommand* renderCommand = new QuadCommand(); - renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); + _quadCommand.init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); // if(!culling()) // { @@ -680,7 +679,7 @@ void Sprite::draw(void) // } // else { - Director::getInstance()->getRenderer()->addCommand(renderCommand); + Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } } diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index 86df10a055..3b99769c07 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -37,6 +37,7 @@ THE SOFTWARE. #include "CCGLBufferedNode.h" #endif // EMSCRIPTEN #include "CCPhysicsBody.h" +#include "renderer/CCQuadCommand.h" #include "kazmath/kazmath.h" NS_CC_BEGIN @@ -545,6 +546,7 @@ protected: // BlendFunc _blendFunc; /// It's required for TextureProtocol inheritance Texture2D* _texture; /// Texture2D object that is used to render the sprite + QuadCommand _quadCommand; /// quad command // // Shared data diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index f553b3314c..41d57735cf 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -43,7 +43,7 @@ THE SOFTWARE. #include "CCLayer.h" #include "CCScene.h" #include "CCRenderer.h" -#include "CCQuadCommand.h" +#include "renderer/CCQuadCommand.h" // external #include "kazmath/GL/matrix.h" @@ -360,8 +360,7 @@ void SpriteBatchNode::draw() kmMat4 mv; kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - QuadCommand* cmd = new QuadCommand(); - cmd->init(0, + _quadCommand.init(0, _vertexZ, _textureAtlas->getTexture()->getName(), shader, @@ -369,7 +368,7 @@ void SpriteBatchNode::draw() _textureAtlas->getQuads(), _textureAtlas->getTotalQuads(), mv); - Director::getInstance()->getRenderer()->addCommand(cmd); + Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } void SpriteBatchNode::increaseAtlasCapacity(void) diff --git a/cocos/2d/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h index 82adde74af..28c7b382aa 100644 --- a/cocos/2d/CCSpriteBatchNode.h +++ b/cocos/2d/CCSpriteBatchNode.h @@ -34,6 +34,7 @@ THE SOFTWARE. #include "CCProtocols.h" #include "CCTextureAtlas.h" #include "ccMacros.h" +#include "renderer/CCQuadCommand.h" NS_CC_BEGIN @@ -187,6 +188,7 @@ protected: TextureAtlas *_textureAtlas; BlendFunc _blendFunc; + QuadCommand _quadCommand; // quad command // all descendants: children, grand children, etc... // There is not need to retain/release these objects, since they are already retained by _children diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index 89b5630db9..916519c6aa 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ -#include "CCQuadCommand.h" +#include "renderer/CCQuadCommand.h" #include "ccGLStateCache.h" NS_CC_BEGIN diff --git a/cocos/2d/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index 6516b9c1c6..afe306acbf 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -108,7 +108,6 @@ public: void pushBackCommand(QuadCommand* ptr) { - delete ptr; } }; diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 0eeca3844f..8841aff768 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -26,7 +26,7 @@ #include "CCShaderCache.h" #include "ccGLStateCache.h" #include "CCCustomCommand.h" -#include "CCQuadCommand.h" +#include "renderer/CCQuadCommand.h" #include "CCGroupCommand.h" #include "CCConfiguration.h" #include "CCNotificationCenter.h" diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index f063fe60f4..dd57487d0e 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. #include "cocostudio/CCDataReaderHelper.h" #include "cocostudio/CCDatas.h" #include "cocostudio/CCSkin.h" -#include "CCQuadCommand.h" +#include "renderer/CCQuadCommand.h" #include "CCRenderer.h" #include "CCGroupCommand.h" diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index 38450ff900..0f41b9f6f9 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -219,9 +219,8 @@ void Skin::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &mv); //TODO implement z order - QuadCommand* renderCommand = new QuadCommand(); - renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); - Director::getInstance()->getRenderer()->addCommand(renderCommand); + _quadCommand.init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); + Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } void Skin::setBone(Bone *bone) diff --git a/cocos/editor-support/cocostudio/CCSkin.h b/cocos/editor-support/cocostudio/CCSkin.h index d9e4c4e532..42ba994189 100644 --- a/cocos/editor-support/cocostudio/CCSkin.h +++ b/cocos/editor-support/cocostudio/CCSkin.h @@ -27,6 +27,7 @@ THE SOFTWARE. #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CCBone.h" +#include "renderer/CCQuadCommand.h" namespace cocostudio { @@ -74,6 +75,7 @@ protected: Armature *_armature; kmMat4 _skinTransform; std::string _displayName; + cocos2d::QuadCommand _quadCommand; // quad command }; } From d32fbbbfcaa5aeac5eff3fd0f93926ee4fc701da Mon Sep 17 00:00:00 2001 From: boyu0 Date: Thu, 26 Dec 2013 18:11:23 +0800 Subject: [PATCH 05/12] change GroupCommand variable to class member. --- cocos/2d/CCClippingNode.cpp | 7 +++--- cocos/2d/CCClippingNode.h | 3 +++ cocos/2d/CCNodeGrid.cpp | 7 +++--- cocos/2d/CCNodeGrid.h | 2 ++ cocos/2d/CCRenderTexture.cpp | 7 +++--- cocos/2d/CCRenderTexture.h | 2 ++ .../editor-support/cocostudio/CCBatchNode.cpp | 23 +++++++++++-------- cocos/editor-support/cocostudio/CCBatchNode.h | 7 ++++-- 8 files changed, 34 insertions(+), 24 deletions(-) diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index ef47c97a8f..580bc60997 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -209,11 +209,10 @@ void ClippingNode::visit() Renderer* renderer = Director::getInstance()->getRenderer(); - GroupCommand* groupCommand = new GroupCommand(); - groupCommand->init(0,_vertexZ); - renderer->addCommand(groupCommand); + _groupCommand.init(0,_vertexZ); + renderer->addCommand(&_groupCommand); - renderer->pushGroup(groupCommand->getRenderQueueID()); + renderer->pushGroup(_groupCommand.getRenderQueueID()); CustomCommand* beforeVisitCmd = new CustomCommand(); beforeVisitCmd->init(0,_vertexZ); diff --git a/cocos/2d/CCClippingNode.h b/cocos/2d/CCClippingNode.h index 656eb8ede9..ecf400926a 100644 --- a/cocos/2d/CCClippingNode.h +++ b/cocos/2d/CCClippingNode.h @@ -30,6 +30,7 @@ #include "CCNode.h" #include "CCGL.h" +#include "renderer/CCGroupCommand.h" NS_CC_BEGIN @@ -141,6 +142,8 @@ protected: GLclampf _currentAlphaTestRef; GLint _mask_layer_le; + + GroupCommand _groupCommand; private: CC_DISALLOW_COPY_AND_ASSIGN(ClippingNode); diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index 47ca7272d0..07fb4361cc 100644 --- a/cocos/2d/CCNodeGrid.cpp +++ b/cocos/2d/CCNodeGrid.cpp @@ -92,10 +92,9 @@ void NodeGrid::visit() Renderer* renderer = Director::getInstance()->getRenderer(); - GroupCommand* groupCommand = new GroupCommand(); - groupCommand->init(0,_vertexZ); - renderer->addCommand(groupCommand); - renderer->pushGroup(groupCommand->getRenderQueueID()); + _groupCommand.init(0,_vertexZ); + renderer->addCommand(&_groupCommand); + renderer->pushGroup(_groupCommand.getRenderQueueID()); kmGLPushMatrix(); Director::Projection beforeProjectionType; diff --git a/cocos/2d/CCNodeGrid.h b/cocos/2d/CCNodeGrid.h index e3bcfb8590..f8961fd4eb 100644 --- a/cocos/2d/CCNodeGrid.h +++ b/cocos/2d/CCNodeGrid.h @@ -27,6 +27,7 @@ #include "CCNode.h" #include "kazmath/GL/matrix.h" +#include "renderer/CCGroupCommand.h" NS_CC_BEGIN @@ -64,6 +65,7 @@ protected: Node* _gridTarget; GridBase* _nodeGrid; + GroupCommand _groupCommand; private: CC_DISALLOW_COPY_AND_ASSIGN(NodeGrid); diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 95a2944bad..1cc3bd5ac4 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -643,12 +643,11 @@ void RenderTexture::begin() kmGLPushMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); - GroupCommand* groupCommand = new GroupCommand(); - groupCommand->init(0, _vertexZ); + _groupCommand.init(0, _vertexZ); Renderer *renderer = Director::getInstance()->getRenderer(); - renderer->addCommand(groupCommand); - renderer->pushGroup(groupCommand->getRenderQueueID()); + renderer->addCommand(&_groupCommand); + renderer->pushGroup(_groupCommand.getRenderQueueID()); CustomCommand* beginCmd = new CustomCommand(); beginCmd->init(0, _vertexZ); diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 8df7eee817..eef080b948 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include "CCSprite.h" #include "kazmath/mat4.h" #include "platform/CCImage.h" +#include "renderer/CCGroupCommand.h" NS_CC_BEGIN @@ -187,6 +188,7 @@ protected: - [[renderTexture sprite] setBlendFunc:(BlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; */ Sprite* _sprite; + GroupCommand _groupCommand; protected: //renderer caches and callbacks void onBegin(); diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 19465e4fea..449aee1bb5 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -46,11 +46,13 @@ BatchNode *BatchNode::create() } BatchNode::BatchNode() +: _groupCommand(nullptr) { } BatchNode::~BatchNode() { + CC_SAFE_DELETE(_groupCommand); } bool BatchNode::init() @@ -78,6 +80,10 @@ void BatchNode::addChild(Node *child, int zOrder, int tag) if (armature != nullptr) { armature->setBatchNode(this); + if (_groupCommand == nullptr) + { + _groupCommand = new GroupCommand(); + } } } @@ -119,17 +125,17 @@ void BatchNode::draw() } CC_NODE_DRAW_SETUP(); - - generateGroupCommand(); + bool pushed = false; for(auto object : _children) { Armature *armature = dynamic_cast(object); if (armature) { - if (_popGroupCommand) + if (!pushed) { generateGroupCommand(); + pushed = true; } armature->visit(); @@ -137,7 +143,7 @@ void BatchNode::draw() else { Director::getInstance()->getRenderer()->popGroup(); - _popGroupCommand = true; + pushed = false; ((Node *)object)->visit(); } @@ -147,13 +153,10 @@ void BatchNode::draw() void BatchNode::generateGroupCommand() { Renderer* renderer = Director::getInstance()->getRenderer(); - GroupCommand* groupCommand = new GroupCommand(); - groupCommand->init(0,_vertexZ); - renderer->addCommand(groupCommand); + _groupCommand->init(0,_vertexZ); + renderer->addCommand(_groupCommand); - renderer->pushGroup(groupCommand->getRenderQueueID()); - - _popGroupCommand = false; + renderer->pushGroup(_groupCommand->getRenderQueueID()); } } diff --git a/cocos/editor-support/cocostudio/CCBatchNode.h b/cocos/editor-support/cocostudio/CCBatchNode.h index a068af5716..feff9c868d 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.h +++ b/cocos/editor-support/cocostudio/CCBatchNode.h @@ -27,6 +27,10 @@ THE SOFTWARE. #include "cocostudio/CCArmatureDefine.h" +namespace cocos2d { + class GroupCommand; +} + namespace cocostudio { class BatchNode : public cocos2d::Node @@ -61,11 +65,10 @@ public: */ void draw() override; - void setPopGroupCommand(bool pop) { _popGroupCommand = pop; } protected: void generateGroupCommand(); - bool _popGroupCommand; + cocos2d::GroupCommand* _groupCommand; }; } From dec003477c326435322eee9ac3119c1f7cabc027 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Thu, 26 Dec 2013 19:25:53 +0800 Subject: [PATCH 06/12] =?UTF-8?q?delete=20=E2=80=98delete=20ptr=E2=80=99?= =?UTF-8?q?=20and=20add=20CC=5FUNUSED=5FPARAM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/2d/renderer/CCGroupCommand.h | 2 +- cocos/2d/renderer/CCQuadCommand.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos/2d/renderer/CCGroupCommand.h b/cocos/2d/renderer/CCGroupCommand.h index d23a326141..3e002ed4fd 100644 --- a/cocos/2d/renderer/CCGroupCommand.h +++ b/cocos/2d/renderer/CCGroupCommand.h @@ -92,7 +92,7 @@ public: void pushBackCommand(GroupCommand* ptr) { - delete ptr; + CC_UNUSED_PARAM(ptr); } }; diff --git a/cocos/2d/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index afe306acbf..2b2fbfd718 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -108,6 +108,7 @@ public: void pushBackCommand(QuadCommand* ptr) { + CC_UNUSED_PARAM(ptr); } }; From 6bc0a7066f53a9d8988ef5198d68f9af26251889 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Thu, 26 Dec 2013 21:19:12 +0800 Subject: [PATCH 07/12] change CustomCommand variable to class member. --- cocos/2d/CCClippingNode.cpp | 21 +++++------ cocos/2d/CCClippingNode.h | 4 +++ cocos/2d/CCDrawNode.cpp | 7 ++-- cocos/2d/CCDrawNode.h | 2 ++ cocos/2d/CCLayer.cpp | 7 ++-- cocos/2d/CCLayer.h | 2 ++ cocos/2d/CCMotionStreak.cpp | 7 ++-- cocos/2d/CCMotionStreak.h | 3 ++ cocos/2d/CCNodeGrid.cpp | 14 ++++---- cocos/2d/CCNodeGrid.h | 3 ++ cocos/2d/CCProgressTimer.cpp | 7 ++-- cocos/2d/CCProgressTimer.h | 3 ++ cocos/2d/CCRenderTexture.cpp | 35 ++++++++----------- cocos/2d/CCRenderTexture.h | 7 ++++ cocos/2d/renderer/CCCustomCommand.h | 2 +- cocos/2d/renderer/CCGroupCommand.h | 2 +- .../Classes/ActionsTest/ActionsTest.cpp | 35 ++++++++----------- .../TestCpp/Classes/ActionsTest/ActionsTest.h | 7 ++++ .../TestCpp/Classes/Box2DTest/Box2dTest.cpp | 7 ++-- .../Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h | 1 + .../DrawPrimitivesTest/DrawPrimitivesTest.cpp | 7 ++-- .../DrawPrimitivesTest/DrawPrimitivesTest.h | 2 ++ .../CocoStudioArmatureTest/ArmatureScene.cpp | 7 ++-- .../CocoStudioArmatureTest/ArmatureScene.h | 2 ++ .../TestCpp/Classes/LabelTest/LabelTest.cpp | 21 +++++------ .../Cpp/TestCpp/Classes/LabelTest/LabelTest.h | 5 +++ .../RenderTextureTest/RenderTextureTest.cpp | 7 ++-- .../RenderTextureTest/RenderTextureTest.h | 2 ++ .../TestCpp/Classes/ShaderTest/ShaderTest.cpp | 16 ++++----- .../TestCpp/Classes/ShaderTest/ShaderTest.h | 1 + 30 files changed, 132 insertions(+), 114 deletions(-) diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index 580bc60997..d1f9c236e4 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -214,17 +214,15 @@ void ClippingNode::visit() renderer->pushGroup(_groupCommand.getRenderQueueID()); - CustomCommand* beforeVisitCmd = new CustomCommand(); - beforeVisitCmd->init(0,_vertexZ); - beforeVisitCmd->func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this); - renderer->addCommand(beforeVisitCmd); + _beforeVisitCmd.init(0,_vertexZ); + _beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this); + renderer->addCommand(&_beforeVisitCmd); _stencil->visit(); - CustomCommand* afterDrawStencilCmd = new CustomCommand(); - afterDrawStencilCmd->init(0,_vertexZ); - afterDrawStencilCmd->func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this); - renderer->addCommand(afterDrawStencilCmd); + _afterDrawStencilCmd.init(0,_vertexZ); + _afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this); + renderer->addCommand(&_afterDrawStencilCmd); int i = 0; @@ -252,10 +250,9 @@ void ClippingNode::visit() this->draw(); } - CustomCommand* afterVisitCmd = new CustomCommand(); - afterVisitCmd->init(0,_vertexZ); - afterVisitCmd->func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this); - renderer->addCommand(afterVisitCmd); + _afterVisitCmd.init(0,_vertexZ); + _afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this); + renderer->addCommand(&_afterVisitCmd); renderer->popGroup(); diff --git a/cocos/2d/CCClippingNode.h b/cocos/2d/CCClippingNode.h index ecf400926a..c18379f722 100644 --- a/cocos/2d/CCClippingNode.h +++ b/cocos/2d/CCClippingNode.h @@ -31,6 +31,7 @@ #include "CCNode.h" #include "CCGL.h" #include "renderer/CCGroupCommand.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN @@ -144,6 +145,9 @@ protected: GLint _mask_layer_le; GroupCommand _groupCommand; + CustomCommand _beforeVisitCmd; + CustomCommand _afterDrawStencilCmd; + CustomCommand _afterVisitCmd; private: CC_DISALLOW_COPY_AND_ASSIGN(ClippingNode); diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 9228db0441..ee4f218337 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -241,10 +241,9 @@ void DrawNode::render() void DrawNode::draw() { - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(DrawNode::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(DrawNode::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void DrawNode::onDraw() diff --git a/cocos/2d/CCDrawNode.h b/cocos/2d/CCDrawNode.h index 3a6f0b325f..e91f41e8ca 100644 --- a/cocos/2d/CCDrawNode.h +++ b/cocos/2d/CCDrawNode.h @@ -32,6 +32,7 @@ #include "CCNode.h" #include "ccTypes.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN @@ -105,6 +106,7 @@ protected: V2F_C4B_T2F *_buffer; BlendFunc _blendFunc; + CustomCommand _customCommand; bool _dirty; diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index 55b17d5b28..ea88ab6d06 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -564,10 +564,9 @@ void LayerColor::updateColor() void LayerColor::draw() { - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(LayerColor::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void LayerColor::onDraw() diff --git a/cocos/2d/CCLayer.h b/cocos/2d/CCLayer.h index 2650a4fc6b..adc938909e 100644 --- a/cocos/2d/CCLayer.h +++ b/cocos/2d/CCLayer.h @@ -35,6 +35,7 @@ THE SOFTWARE. #endif // EMSCRIPTEN #include "CCEventKeyboard.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN @@ -296,6 +297,7 @@ protected: BlendFunc _blendFunc; Vertex2F _squareVertices[4]; Color4F _squareColors[4]; + CustomCommand _customCommand; private: CC_DISALLOW_COPY_AND_ASSIGN(LayerColor); diff --git a/cocos/2d/CCMotionStreak.cpp b/cocos/2d/CCMotionStreak.cpp index 939245b238..a358399bf5 100644 --- a/cocos/2d/CCMotionStreak.cpp +++ b/cocos/2d/CCMotionStreak.cpp @@ -358,10 +358,9 @@ void MotionStreak::draw() if(_nuPoints <= 1) return; kmGLGetMatrix(KM_GL_MODELVIEW,&_cachedMV); - CustomCommand* cmd = new CustomCommand(); - cmd->init(0,_vertexZ); - cmd->func = CC_CALLBACK_0(MotionStreak::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0,_vertexZ); + _customCommand.func = CC_CALLBACK_0(MotionStreak::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/cocos/2d/CCMotionStreak.h b/cocos/2d/CCMotionStreak.h index a8aaf5e4b4..33ef3217d1 100644 --- a/cocos/2d/CCMotionStreak.h +++ b/cocos/2d/CCMotionStreak.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include "CCTexture2D.h" #include "ccTypes.h" #include "CCNode.h" +#include "renderer/CCCustomCommand.h" #ifdef EMSCRIPTEN #include "CCGLBufferedNode.h" #endif // EMSCRIPTEN @@ -144,6 +145,8 @@ protected: Vertex2F* _vertices; GLubyte* _colorPointer; Tex2F* _texCoords; + + CustomCommand _customCommand; private: CC_DISALLOW_COPY_AND_ASSIGN(MotionStreak); diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index 07fb4361cc..fe3c668377 100644 --- a/cocos/2d/CCNodeGrid.cpp +++ b/cocos/2d/CCNodeGrid.cpp @@ -104,10 +104,9 @@ void NodeGrid::visit() _nodeGrid->set2DProjection(); } - CustomCommand* gridBeginCmd = new CustomCommand(); - gridBeginCmd->init(0,_vertexZ); - gridBeginCmd->func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this); - renderer->addCommand(gridBeginCmd); + _gridBeginCommand.init(0,_vertexZ); + _gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this); + renderer->addCommand(&_gridBeginCommand); this->transform(); @@ -153,10 +152,9 @@ void NodeGrid::visit() director->setProjection(beforeProjectionType); } - CustomCommand* gridEndCmd = new CustomCommand(); - gridEndCmd->init(0,_vertexZ); - gridEndCmd->func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this); - renderer->addCommand(gridEndCmd); + _gridEndCommand.init(0,_vertexZ); + _gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this); + renderer->addCommand(&_gridEndCommand); renderer->popGroup(); diff --git a/cocos/2d/CCNodeGrid.h b/cocos/2d/CCNodeGrid.h index f8961fd4eb..c73ef07a76 100644 --- a/cocos/2d/CCNodeGrid.h +++ b/cocos/2d/CCNodeGrid.h @@ -28,6 +28,7 @@ #include "CCNode.h" #include "kazmath/GL/matrix.h" #include "renderer/CCGroupCommand.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN @@ -66,6 +67,8 @@ protected: Node* _gridTarget; GridBase* _nodeGrid; GroupCommand _groupCommand; + CustomCommand _gridBeginCommand; + CustomCommand _gridEndCommand; private: CC_DISALLOW_COPY_AND_ASSIGN(NodeGrid); diff --git a/cocos/2d/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp index e9f85d9840..ee783e0e82 100644 --- a/cocos/2d/CCProgressTimer.cpp +++ b/cocos/2d/CCProgressTimer.cpp @@ -532,10 +532,9 @@ void ProgressTimer::draw() if( ! _vertexData || ! _sprite) return; - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(ProgressTimer::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(ProgressTimer::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/cocos/2d/CCProgressTimer.h b/cocos/2d/CCProgressTimer.h index 7d369b09b5..5ed9308e81 100644 --- a/cocos/2d/CCProgressTimer.h +++ b/cocos/2d/CCProgressTimer.h @@ -26,6 +26,7 @@ THE SOFTWARE. #define __MISC_NODE_CCPROGRESS_TIMER_H__ #include "CCSprite.h" +#include "renderer/CCCustomCommand.h" #ifdef EMSCRIPTEN #include "CCGLBufferedNode.h" #endif // EMSCRIPTEN @@ -143,6 +144,8 @@ protected: Sprite *_sprite; int _vertexDataCount; V2F_C4B_T2F *_vertexData; + + CustomCommand _customCommand; bool _reverseDirection; diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 1cc3bd5ac4..146c39e050 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -329,10 +329,9 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep this->begin(); //clear screen - CustomCommand* clearCmd = new CustomCommand(); - clearCmd->init(0, _vertexZ); - clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this); - Director::getInstance()->getRenderer()->addCommand(clearCmd); + _beginWithClearCommand.init(0, _vertexZ); + _beginWithClearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); + Director::getInstance()->getRenderer()->addCommand(&_beginWithClearCommand); } //TODO find a better way to clear the screen, there is no need to rebind render buffer there. @@ -348,11 +347,10 @@ void RenderTexture::clearDepth(float depthValue) this->begin(); - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(RenderTexture::onClearDepth, this); + _clearDepthCommand.init(0, _vertexZ); + _clearDepthCommand.func = CC_CALLBACK_0(RenderTexture::onClearDepth, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + Director::getInstance()->getRenderer()->addCommand(&_clearDepthCommand); this->end(); } @@ -614,10 +612,9 @@ void RenderTexture::draw() begin(); //clear screen - CustomCommand* clearCmd = new CustomCommand(); - clearCmd->init(0, _vertexZ); - clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this); - Director::getInstance()->getRenderer()->addCommand(clearCmd); + _clearCommand.init(0, _vertexZ); + _clearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); + Director::getInstance()->getRenderer()->addCommand(&_clearCommand); //! make sure all children are drawn sortAllChildren(); @@ -649,21 +646,19 @@ void RenderTexture::begin() renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); - CustomCommand* beginCmd = new CustomCommand(); - beginCmd->init(0, _vertexZ); - beginCmd->func = CC_CALLBACK_0(RenderTexture::onBegin, this); + _beginCommand.init(0, _vertexZ); + _beginCommand.func = CC_CALLBACK_0(RenderTexture::onBegin, this); - Director::getInstance()->getRenderer()->addCommand(beginCmd); + Director::getInstance()->getRenderer()->addCommand(&_beginCommand); } void RenderTexture::end() { - CustomCommand* endCmd = new CustomCommand(); - endCmd->init(0, _vertexZ); - endCmd->func = CC_CALLBACK_0(RenderTexture::onEnd, this); + _endCommand.init(0, _vertexZ); + _endCommand.func = CC_CALLBACK_0(RenderTexture::onEnd, this); Renderer *renderer = Director::getInstance()->getRenderer(); - renderer->addCommand(endCmd); + renderer->addCommand(&_endCommand); renderer->popGroup(); } diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index eef080b948..fdf4910d4e 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -30,6 +30,7 @@ THE SOFTWARE. #include "kazmath/mat4.h" #include "platform/CCImage.h" #include "renderer/CCGroupCommand.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN @@ -188,7 +189,13 @@ protected: - [[renderTexture sprite] setBlendFunc:(BlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; */ Sprite* _sprite; + GroupCommand _groupCommand; + CustomCommand _beginWithClearCommand; + CustomCommand _clearDepthCommand; + CustomCommand _clearCommand; + CustomCommand _beginCommand; + CustomCommand _endCommand; protected: //renderer caches and callbacks void onBegin(); diff --git a/cocos/2d/renderer/CCCustomCommand.h b/cocos/2d/renderer/CCCustomCommand.h index 7e64a0a6dd..ed4af2d3af 100644 --- a/cocos/2d/renderer/CCCustomCommand.h +++ b/cocos/2d/renderer/CCCustomCommand.h @@ -74,7 +74,7 @@ public: void pushBackCommand(CustomCommand* ptr) { - delete ptr; + CC_UNUSED_PARAM(ptr); } }; diff --git a/cocos/2d/renderer/CCGroupCommand.h b/cocos/2d/renderer/CCGroupCommand.h index 3e002ed4fd..d23a326141 100644 --- a/cocos/2d/renderer/CCGroupCommand.h +++ b/cocos/2d/renderer/CCGroupCommand.h @@ -92,7 +92,7 @@ public: void pushBackCommand(GroupCommand* ptr) { - CC_UNUSED_PARAM(ptr); + delete ptr; } }; diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 4470a7ea1f..229d6f11e6 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -1289,11 +1289,10 @@ void ActionFollow::onEnter() void ActionFollow::draw() { - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(ActionFollow::onDraw, this); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(ActionFollow::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void ActionFollow::onDraw() @@ -1606,10 +1605,9 @@ void ActionCatmullRomStacked::draw() kmGLPopMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void ActionCatmullRomStacked::onDraw() @@ -1722,10 +1720,9 @@ void ActionCardinalSplineStacked::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void ActionCardinalSplineStacked::onDraw() @@ -2085,10 +2082,9 @@ void ActionCatmullRom::draw() kmGLPopMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -2186,10 +2182,9 @@ void ActionCardinalSpline::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); - CustomCommand* cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void ActionCardinalSpline::onDraw() diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index 5477fd2967..b5be2b348b 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -346,6 +346,9 @@ public: protected: void onDraw(); + +private: + CustomCommand _customCommand; }; class ActionTargeted : public ActionsDemo @@ -426,6 +429,7 @@ protected: private: PointArray* _array1; PointArray* _array2; + CustomCommand _customCommand; }; class ActionCardinalSplineStacked : public ActionsDemo @@ -444,6 +448,7 @@ protected: void onDraw(); kmMat4 _modelViewMV1; kmMat4 _modelViewMV2; + CustomCommand _customCommand; }; class Issue1305 : public ActionsDemo @@ -538,6 +543,7 @@ protected: void onDraw(); kmMat4 _modelViewMV1; kmMat4 _modelViewMV2; + CustomCommand _customCommand; }; class ActionCardinalSpline : public ActionsDemo @@ -557,6 +563,7 @@ protected: void onDraw(); kmMat4 _modelViewMV1; kmMat4 _modelViewMV2; + CustomCommand _customCommand; }; class PauseResumeActions : public ActionsDemo diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp index a0fc2c6298..70e55dae5d 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp @@ -149,10 +149,9 @@ void Box2DTestLayer::draw() kmGLPushMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV); - CustomCommand *cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); kmGLPopMatrix(); #endif diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h index f791c68256..24d0b43c65 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h @@ -28,6 +28,7 @@ public: protected: kmMat4 _modelViewMV; void onDraw(); + CustomCommand _customCommand; #endif } ; diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index 152ee7dbda..9a751b8d97 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -116,10 +116,9 @@ DrawPrimitivesTest::DrawPrimitivesTest() void DrawPrimitivesTest::draw() { - CustomCommand * cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void DrawPrimitivesTest::onDraw() diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h index 597d99f6c2..0022b1d387 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h @@ -30,6 +30,8 @@ public: virtual void draw(); protected: void onDraw(); +protected: + CustomCommand _customCommand; }; class DrawNodeTest : public BaseLayer diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index a574e8f15b..fdffc1f5c9 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -1094,10 +1094,9 @@ std::string TestBoundingBox::title() const } void TestBoundingBox::draw() { - CustomCommand *cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(TestBoundingBox::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(TestBoundingBox::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index 1fce072d63..bdb9f5dda1 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -297,6 +297,8 @@ public: Rect rect; protected: void onDraw(); +protected: + CustomCommand _customCommand; }; class TestAnchorPoint : public ArmatureTestLayer diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index 8fb6ea43a4..894309225d 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -209,10 +209,9 @@ void Atlas1::draw() // GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // GL_TEXTURE_2D - CustomCommand *cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(Atlas1::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(Atlas1::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); // [textureAtlas drawNumberOfQuads:3]; @@ -526,10 +525,9 @@ Atlas4::Atlas4() void Atlas4::draw() { - CustomCommand *cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(Atlas4::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(Atlas4::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void Atlas4::onDraw() @@ -1613,10 +1611,9 @@ std::string LabelBMFontBounds::subtitle() const void LabelBMFontBounds::draw() { - CustomCommand *cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(LabelBMFontBounds::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(LabelBMFontBounds::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void LabelBMFontBounds::onDraw() diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h index 11c9934f93..ec9339668b 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h @@ -38,6 +38,8 @@ public: virtual void draw(); protected: void onDraw(); +protected: + CustomCommand _customCommand; }; class LabelAtlasTest : public AtlasDemo @@ -106,6 +108,8 @@ public: virtual std::string subtitle() const override; protected: void onDraw(); +protected: + CustomCommand _customCommand; }; class Atlas5 : public AtlasDemo @@ -380,6 +384,7 @@ protected: void onDraw(); private: LabelBMFont *label1; + CustomCommand _customCommand; }; class NewLabelTTFUnicode : public AtlasDemo diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index c3478551cb..3438a8a84e 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -589,10 +589,9 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::crea void SpriteRenderTextureBug::SimpleSprite::draw() { - CustomCommand *cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(SpriteRenderTextureBug::SimpleSprite::onBeforeDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(SpriteRenderTextureBug::SimpleSprite::onBeforeDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); Sprite::draw(); diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h index 03a202deec..ea7dbaa7f1 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h @@ -117,6 +117,8 @@ public: void onBeforeDraw(); public: RenderTexture *_rt; + protected: + CustomCommand _customCommand; }; public: diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp index d93a0c1e83..4f69133030 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -196,10 +196,9 @@ void ShaderNode::setPosition(const Point &newPosition) void ShaderNode::draw() { - CustomCommand *cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(ShaderNode::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(ShaderNode::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void ShaderNode::onDraw() @@ -449,6 +448,8 @@ public: GLuint subLocation; protected: void onDraw(); +private: + CustomCommand _customCommand; }; SpriteBlur::~SpriteBlur() @@ -532,10 +533,9 @@ void SpriteBlur::initProgram() void SpriteBlur::draw() { - CustomCommand *cmd = new CustomCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(SpriteBlur::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCommand.init(0, _vertexZ); + _customCommand.func = CC_CALLBACK_0(SpriteBlur::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } void SpriteBlur::onDraw() diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h index ef5c04ef76..9459bd584a 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h @@ -137,6 +137,7 @@ private: GLuint _uniformCenter, _uniformResolution, _uniformTime; std::string _vertFileName; std::string _fragFileName; + CustomCommand _customCommand; }; class ShaderFail : public ShaderTestDemo From a19d212f4ff920dddafb84b9a8770d1f42c00177 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Thu, 26 Dec 2013 22:00:52 +0800 Subject: [PATCH 08/12] fix bug. --- cocos/2d/renderer/CCGroupCommand.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/renderer/CCGroupCommand.h b/cocos/2d/renderer/CCGroupCommand.h index d23a326141..3e002ed4fd 100644 --- a/cocos/2d/renderer/CCGroupCommand.h +++ b/cocos/2d/renderer/CCGroupCommand.h @@ -92,7 +92,7 @@ public: void pushBackCommand(GroupCommand* ptr) { - delete ptr; + CC_UNUSED_PARAM(ptr); } }; From 40af66a7bc39470f093d370747011ee124dbede9 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 27 Dec 2013 13:51:11 +0800 Subject: [PATCH 09/12] remove commandPool in renderCommand --- cocos/2d/renderer/CCCustomCommand.cpp | 6 ------ cocos/2d/renderer/CCCustomCommand.h | 20 -------------------- cocos/2d/renderer/CCGroupCommand.cpp | 7 ------- cocos/2d/renderer/CCGroupCommand.h | 20 -------------------- cocos/2d/renderer/CCQuadCommand.cpp | 6 ------ cocos/2d/renderer/CCQuadCommand.h | 23 ----------------------- cocos/2d/renderer/CCRenderCommand.h | 2 +- 7 files changed, 1 insertion(+), 83 deletions(-) diff --git a/cocos/2d/renderer/CCCustomCommand.cpp b/cocos/2d/renderer/CCCustomCommand.cpp index 49e7a0a06c..19ae7ae36e 100644 --- a/cocos/2d/renderer/CCCustomCommand.cpp +++ b/cocos/2d/renderer/CCCustomCommand.cpp @@ -25,7 +25,6 @@ #include "CCCustomCommand.h" NS_CC_BEGIN -RenderCommandPool CustomCommand::_commandPool; CustomCommand::CustomCommand() :RenderCommand() @@ -66,9 +65,4 @@ void CustomCommand::execute() } } -void CustomCommand::releaseToCommandPool() -{ - getCommandPool().pushBackCommand(this); -} - NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCCustomCommand.h b/cocos/2d/renderer/CCCustomCommand.h index ed4af2d3af..a837255594 100644 --- a/cocos/2d/renderer/CCCustomCommand.h +++ b/cocos/2d/renderer/CCCustomCommand.h @@ -38,7 +38,6 @@ public: ~CustomCommand(); public: - static RenderCommandPool& getCommandPool() { return _commandPool; } void init(int viewport, int32_t depth); @@ -52,30 +51,11 @@ public: void execute(); inline bool isTranslucent() { return true; } - virtual void releaseToCommandPool() override; std::function func; protected: int _viewport; int32_t _depth; - static RenderCommandPool _commandPool; - - friend class RenderCommandPool; -}; - -template <> -class RenderCommandPool -{ -public: - CustomCommand* generateCommand() - { - return new CustomCommand(); - } - - void pushBackCommand(CustomCommand* ptr) - { - CC_UNUSED_PARAM(ptr); - } }; NS_CC_END diff --git a/cocos/2d/renderer/CCGroupCommand.cpp b/cocos/2d/renderer/CCGroupCommand.cpp index d057b00218..12fddd3105 100644 --- a/cocos/2d/renderer/CCGroupCommand.cpp +++ b/cocos/2d/renderer/CCGroupCommand.cpp @@ -28,7 +28,6 @@ #include "CCDirector.h" NS_CC_BEGIN -RenderCommandPool GroupCommand::_commandPool; static GroupCommandManager* s_instance; GroupCommandManager *GroupCommandManager::getInstance() @@ -119,10 +118,4 @@ int64_t GroupCommand::generateID() return _id; } -void GroupCommand::releaseToCommandPool() -{ - getCommandPool().pushBackCommand(this); -} - - NS_CC_END diff --git a/cocos/2d/renderer/CCGroupCommand.h b/cocos/2d/renderer/CCGroupCommand.h index 3e002ed4fd..7e2ed1abb7 100644 --- a/cocos/2d/renderer/CCGroupCommand.h +++ b/cocos/2d/renderer/CCGroupCommand.h @@ -57,7 +57,6 @@ public: ~GroupCommand(); public: - static RenderCommandPool& getCommandPool() { return _commandPool; } void init(int viewport, int32_t depth); @@ -70,30 +69,11 @@ public: inline bool isTranslucent() {return true;} inline int getRenderQueueID() {return _renderQueueID;} - virtual void releaseToCommandPool() override; protected: int _viewport; int32_t _depth; int _renderQueueID; - static RenderCommandPool _commandPool; - - friend class RenderCommandPool; -}; - -template <> -class RenderCommandPool -{ -public: - GroupCommand* generateCommand() - { - return new GroupCommand(); - } - - void pushBackCommand(GroupCommand* ptr) - { - CC_UNUSED_PARAM(ptr); - } }; NS_CC_END diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index 916519c6aa..ff63200f4d 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -27,7 +27,6 @@ #include "ccGLStateCache.h" NS_CC_BEGIN -RenderCommandPool QuadCommand::_commandPool; QuadCommand::QuadCommand() :RenderCommand() @@ -172,9 +171,4 @@ void QuadCommand::useMaterial() GL::blendFunc(_blendType.src, _blendType.dst); } -void QuadCommand::releaseToCommandPool() -{ - getCommandPool().pushBackCommand(this); -} - NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index 2b2fbfd718..441bb842fe 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -37,7 +37,6 @@ NS_CC_BEGIN class QuadCommand : public RenderCommand { public: - static RenderCommandPool& getCommandPool() { return _commandPool; } QuadCommand(); ~QuadCommand(); @@ -69,8 +68,6 @@ public: inline BlendFunc getBlendType() const { return _blendType; } - virtual void releaseToCommandPool() override; - protected: int32_t _materialID; @@ -91,27 +88,7 @@ protected: V3F_C4B_T2F_Quad* _quad; ssize_t _quadCount; ssize_t _capacity; - - friend class RenderCommandPool; - - static RenderCommandPool _commandPool; }; - -template <> -class RenderCommandPool -{ -public: - QuadCommand* generateCommand() - { - return new QuadCommand(); - } - - void pushBackCommand(QuadCommand* ptr) - { - CC_UNUSED_PARAM(ptr); - } -}; - NS_CC_END #endif //_CC_QUADCOMMAND_H_ diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index 7d17c8e56b..21371a88e0 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -52,7 +52,7 @@ public: virtual inline int64_t getID() { return _id; } virtual inline Type getType() { return _type; } - virtual void releaseToCommandPool() =0; + void releaseToCommandPool() {} protected: RenderCommand(); From 268f2fcc21e6389a3a54d42369d63f548e26b07d Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 27 Dec 2013 13:52:44 +0800 Subject: [PATCH 10/12] adjust comment codes --- cocos/2d/CCSprite.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index f0e48184b0..761362d678 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -673,11 +673,7 @@ void Sprite::draw(void) //TODO implement z order _quadCommand.init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); -// if(!culling()) -// { -// renderCommand->releaseToCommandPool(); -// } -// else +// if(culling()) { Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } From 76d07fc76ef16c75f03ce82759765032fe741caa Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 27 Dec 2013 14:02:17 +0800 Subject: [PATCH 11/12] remove empty interface releaseToCommandPool --- cocos/2d/renderer/CCRenderCommand.h | 1 - cocos/2d/renderer/CCRenderer.cpp | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index 21371a88e0..35d5ac4fe8 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -52,7 +52,6 @@ public: virtual inline int64_t getID() { return _id; } virtual inline Type getType() { return _type; } - void releaseToCommandPool() {} protected: RenderCommand(); diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 8841aff768..1d4b602442 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -293,13 +293,13 @@ void Renderer::render() } } - //TODO give command back to command pool for (size_t j = 0 ; j < _renderGroups.size(); j++) { - for (const auto &cmd : _renderGroups[j]) - { - cmd->releaseToCommandPool(); - } + //commands are owned by nodes + // for (const auto &cmd : _renderGroups[j]) + // { + // cmd->releaseToCommandPool(); + // } _renderGroups[j].clear(); } From 81989704218d8d1a5c904ce89ca0b7ec0c690924 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 27 Dec 2013 14:42:45 +0800 Subject: [PATCH 12/12] fix testcase remove commandpool --- .../Classes/Box2DTestBed/Box2dView.cpp | 8 ++-- .../TestCpp/Classes/Box2DTestBed/Box2dView.h | 2 + .../ClippingNodeTest/ClippingNodeTest.cpp | 39 +++++++++++-------- .../ClippingNodeTest/ClippingNodeTest.h | 3 ++ .../Classes/LabelTest/LabelTestNew.cpp | 15 +++---- .../TestCpp/Classes/LabelTest/LabelTestNew.h | 3 ++ .../Classes/Texture2dTest/Texture2dTest.cpp | 15 +++---- .../Classes/Texture2dTest/Texture2dTest.h | 3 ++ .../Classes/TileMapTest/TileMapTest.cpp | 21 +++++----- .../TestCpp/Classes/TileMapTest/TileMapTest.h | 4 ++ 10 files changed, 61 insertions(+), 52 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp index 968b9dc99a..dd8d3f8693 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp @@ -2,7 +2,6 @@ #include "GLES-Render.h" #include "Test.h" #include "renderer/CCRenderer.h" -#include "renderer/CCCustomCommand.h" #define kAccelerometerFrequency 30 #define FRAMES_BETWEEN_PRESSES_FOR_DOUBLE_CLICK 10 @@ -212,10 +211,9 @@ void Box2DView::draw() { Layer::draw(); - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(Box2DView::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _customCmd.init(0, _vertexZ); + _customCmd.func = CC_CALLBACK_0(Box2DView::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCmd); } void Box2DView::onDraw() diff --git a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.h b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.h index b2fd4f6786..39bef0dbe2 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.h +++ b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.h @@ -3,6 +3,7 @@ //#include "cocos2d.h" #include "../testBasic.h" +#include "renderer/CCCustomCommand.h" class MenuLayer : public Layer { @@ -51,6 +52,7 @@ public: static Box2DView* viewWithEntryID(int entryId); protected: + CustomCommand _customCmd; void onDraw(); }; diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp index 655afd2af2..6d4dd13628 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -8,7 +8,6 @@ #include "ClippingNodeTest.h" #include "../testResource.h" #include "renderer/CCRenderer.h" -#include "renderer/CCCustomCommand.h" enum { kTagTitleLabel = 1, @@ -599,11 +598,18 @@ void RawStencilBufferTest::draw() auto planeSize = winPoint * (1.0 / _planeCount); Renderer *renderer = Director::getInstance()->getRenderer(); + size_t neededCmdSize = _planeCount * 2 + 2; + if(_renderCmds.size() != neededCmdSize) + { + _renderCmds.resize(neededCmdSize); + } - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(RawStencilBufferTest::onEnableStencil, this); - renderer->addCommand(cmd); + auto iter = _renderCmds.begin(); + + iter->init(0, _vertexZ); + iter->func = CC_CALLBACK_0(RawStencilBufferTest::onEnableStencil, this); + renderer->addCommand(&(*iter)); + ++iter; @@ -617,20 +623,20 @@ void RawStencilBufferTest::draw() spritePoint.y = 0; _sprite->setPosition( spritePoint ); - cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawClip, this, i, stencilPoint); - renderer->addCommand(cmd); + iter->init(0, _vertexZ); + iter->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawClip, this, i, stencilPoint); + renderer->addCommand(&(*iter)); + ++iter; kmGLPushMatrix(); this->transform(); _sprite->visit(); kmGLPopMatrix(); - cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawSprite, this, i, winPoint); - renderer->addCommand(cmd); + iter->init(0, _vertexZ); + iter->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawSprite, this, i, winPoint); + renderer->addCommand(&(*iter)); + ++iter; kmGLPushMatrix(); this->transform(); @@ -638,10 +644,9 @@ void RawStencilBufferTest::draw() kmGLPopMatrix(); } - cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(RawStencilBufferTest::onDisableStencil, this); - renderer->addCommand(cmd); + iter->init(0, _vertexZ); + iter->func = CC_CALLBACK_0(RawStencilBufferTest::onDisableStencil, this); + renderer->addCommand(&(*iter)); } diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h index f7fc9234db..41b3f7613b 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h @@ -3,6 +3,8 @@ #include "../testBasic.h" #include "../BaseTest.h" +#include "renderer/CCCustomCommand.h" +#include class BaseClippingNodeTest : public BaseTest { @@ -157,6 +159,7 @@ public: virtual void setupStencilForDrawingOnPlane(GLint plane); protected: + std::list _renderCmds; void onEnableStencil(); void onDisableStencil(); void onBeforeDrawClip(int planeIndex, const Point& pt); diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index a37038bbe6..9d3d063102 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -1,7 +1,6 @@ #include "LabelTestNew.h" #include "../testResource.h" #include "renderer/CCRenderer.h" -#include "renderer/CCCustomCommand.h" enum { kTagTileMap = 1, @@ -302,10 +301,9 @@ LabelFNTSpriteActions::LabelFNTSpriteActions() void LabelFNTSpriteActions::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(LabelFNTSpriteActions::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _renderCmd.init(0, _vertexZ); + _renderCmd.func = CC_CALLBACK_0(LabelFNTSpriteActions::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } @@ -914,10 +912,9 @@ std::string LabelFNTBounds::subtitle() const void LabelFNTBounds::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(LabelFNTBounds::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _renderCmd.init(0, _vertexZ); + _renderCmd.func = CC_CALLBACK_0(LabelFNTBounds::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } void LabelFNTBounds::onDraw() diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h index c1040bb270..ad6b53211c 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h @@ -3,6 +3,7 @@ #include "../testBasic.h" #include "../BaseTest.h" +#include "renderer/CCCustomCommand.h" class AtlasDemoNew : public BaseTest @@ -61,6 +62,7 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; protected: + CustomCommand _renderCmd; void onDraw(); }; @@ -226,6 +228,7 @@ public: private: Label *label1; protected: + CustomCommand _renderCmd; void onDraw(); }; diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp index 4f8f7c3290..3373be2eaf 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp @@ -2,7 +2,6 @@ #include "Texture2dTest.h" #include "../testResource.h" #include "renderer/CCRenderer.h" -#include "renderer/CCCustomCommand.h" enum { kTagLabel = 1, @@ -1768,10 +1767,9 @@ void TextureDrawAtPoint::draw() { TextureDemo::draw(); - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(TextureDrawAtPoint::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _renderCmd.init(0, _vertexZ); + _renderCmd.func = CC_CALLBACK_0(TextureDrawAtPoint::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } @@ -1810,10 +1808,9 @@ void TextureDrawInRect::draw() { TextureDemo::draw(); - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(TextureDrawInRect::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _renderCmd.init(0, _vertexZ); + _renderCmd.func = CC_CALLBACK_0(TextureDrawInRect::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h index 407365769a..5b8f9207ab 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h @@ -3,6 +3,7 @@ #include "../testBasic.h" #include "../BaseTest.h" +#include "renderer/CCCustomCommand.h" class TextureDemo : public BaseTest @@ -442,6 +443,7 @@ public: virtual void onEnter(); virtual void draw(); protected: + CustomCommand _renderCmd; void onDraw(); private: Texture2D* _tex1, *_Tex2F; @@ -457,6 +459,7 @@ public: virtual void onEnter(); virtual void draw(); protected: + CustomCommand _renderCmd; void onDraw(); private: Texture2D* _tex1, *_Tex2F; diff --git a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp index 12cbea668e..338838baf9 100644 --- a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp +++ b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp @@ -599,10 +599,9 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest() void TMXOrthoObjectsTest::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(TMXOrthoObjectsTest::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _renderCmd.init(0, _vertexZ); + _renderCmd.func = CC_CALLBACK_0(TMXOrthoObjectsTest::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } void TMXOrthoObjectsTest::onDraw() @@ -673,10 +672,9 @@ TMXIsoObjectsTest::TMXIsoObjectsTest() void TMXIsoObjectsTest::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(TMXIsoObjectsTest::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _renderCmd.init(0, _vertexZ); + _renderCmd.func = CC_CALLBACK_0(TMXIsoObjectsTest::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } void TMXIsoObjectsTest::onDraw() @@ -1475,10 +1473,9 @@ TMXGIDObjectsTest::TMXGIDObjectsTest() void TMXGIDObjectsTest::draw() { - CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(TMXGIDObjectsTest::onDraw, this); - Director::getInstance()->getRenderer()->addCommand(cmd); + _renderCmd.init(0, _vertexZ); + _renderCmd.func = CC_CALLBACK_0(TMXGIDObjectsTest::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } void TMXGIDObjectsTest::onDraw() diff --git a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.h b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.h index 4fb5cfd208..95d8ba1e85 100644 --- a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.h +++ b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.h @@ -3,6 +3,7 @@ #include "../testBasic.h" #include "../BaseTest.h" +#include "renderer/CCCustomCommand.h" class TileDemo : public BaseTest { @@ -136,6 +137,7 @@ public: virtual void draw(); virtual std::string subtitle() const override; protected: + CustomCommand _renderCmd; void onDraw(); }; @@ -148,6 +150,7 @@ public: virtual void draw(); virtual std::string subtitle() const override; protected: + CustomCommand _renderCmd; void onDraw(); }; @@ -285,6 +288,7 @@ public: virtual void draw(); protected: + CustomCommand _renderCmd; void onDraw(); };