From f8dc8f0b380175d4e548543e0bbca935c0a79302 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 14:35:26 -0800 Subject: [PATCH 1/4] Renderer performance fixes QuadCommand no longer stores a copy of the quads. Instead it just stores a reference and the MV matrix. Later, the Renderer when it copies the Quads to the queue, it will convert the Quads to world coordinates --- CHANGELOG | 1 + cocos/2d/renderer/CCQuadCommand.cpp | 58 +++-------------------------- cocos/2d/renderer/CCQuadCommand.h | 15 +++++--- cocos/2d/renderer/CCRenderer.cpp | 47 ++++++++++++++++++++++- cocos/2d/renderer/CCRenderer.h | 3 ++ 5 files changed, 64 insertions(+), 60 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4e7311b166..3b3b55d33e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ cocos2d-x-3.0final ?.? ? [FIX] ControlSlider doesn't support to set selected thumb sprite. [FIX] ControlButton doesn't support to set scale ratio of touchdown state. [FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file. + [FIX] Renderer: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster [FIX] Tests: TestCpp works with CMake on Windows. [FIX] Tests: Sprites Performance Test has 3 new tests [FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index b69fd075d3..f60446871c 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -34,12 +34,11 @@ QuadCommand::QuadCommand() ,_depth(0) ,_textureID(0) ,_blendType(BlendFunc::DISABLE) -,_quadCount(0) -,_capacity(0) +,_quadsCount(0) { _type = RenderCommand::Type::QUAD_COMMAND; _shader = nullptr; - _quad = nullptr; + _quads = nullptr; } void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const kmMat4 &mv) @@ -48,63 +47,16 @@ void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* _depth = depth; _textureID = textureID; _blendType = blendType; - _quadCount = quadCount; _shader = shader; - if(quadCount > _capacity ) { - //TODO find a better way to manage quads, current way will result in memory be wasted -// _quad = (V3F_C4B_T2F_Quad*)malloc(sizeof(V3F_C4B_T2F_Quad) * quadCount); - _quad = (V3F_C4B_T2F_Quad*) realloc(_quad, sizeof(*quad) * quadCount ); - _capacity = quadCount; - } + _quadsCount = quadCount; + _quads = quad; - _quadCount = quadCount; - memcpy(_quad, quad, sizeof(V3F_C4B_T2F_Quad) * quadCount); - - for(int i=0; ibl.vertices.x; - vec1.y = q->bl.vertices.y; - vec1.z = q->bl.vertices.z; - kmVec3Transform(&out1, &vec1, &mv); - q->bl.vertices.x = out1.x; - q->bl.vertices.y = out1.y; - q->bl.vertices.z = out1.z; - - kmVec3 vec2, out2; - vec2.x = q->br.vertices.x; - vec2.y = q->br.vertices.y; - vec2.z = q->br.vertices.z; - kmVec3Transform(&out2, &vec2, &mv); - q->br.vertices.x = out2.x; - q->br.vertices.y = out2.y; - q->br.vertices.z = out2.z; - - kmVec3 vec3, out3; - vec3.x = q->tr.vertices.x; - vec3.y = q->tr.vertices.y; - vec3.z = q->tr.vertices.z; - kmVec3Transform(&out3, &vec3, &mv); - q->tr.vertices.x = out3.x; - q->tr.vertices.y = out3.y; - q->tr.vertices.z = out3.z; - - kmVec3 vec4, out4; - vec4.x = q->tl.vertices.x; - vec4.y = q->tl.vertices.y; - vec4.z = q->tl.vertices.z; - kmVec3Transform(&out4, &vec4, &mv); - q->tl.vertices.x = out4.x; - q->tl.vertices.y = out4.y; - q->tl.vertices.z = out4.z; - } + _mv = mv; } QuadCommand::~QuadCommand() { - free(_quad); } int64_t QuadCommand::generateID() diff --git a/cocos/2d/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index 411dc4913b..b21999ea58 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -41,7 +41,7 @@ public: QuadCommand(); ~QuadCommand(); - void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, + void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quads, ssize_t quadCount, const kmMat4& mv); // +----------+----------+-----+-----------------------------------+ @@ -60,13 +60,15 @@ public: inline GLuint getTextureID() const { return _textureID; } - inline V3F_C4B_T2F_Quad* getQuad() const { return _quad; } + inline V3F_C4B_T2F_Quad* getQuads() const { return _quads; } - inline ssize_t getQuadCount() const { return _quadCount; } + inline ssize_t getQuadCount() const { return _quadsCount; } inline GLProgram* getShader() const { return _shader; } inline BlendFunc getBlendType() const { return _blendType; } + + inline const kmMat4& getModelView() const { return _mv; } protected: int32_t _materialID; @@ -85,9 +87,10 @@ protected: BlendFunc _blendType; - V3F_C4B_T2F_Quad* _quad; - ssize_t _quadCount; - ssize_t _capacity; + V3F_C4B_T2F_Quad* _quads; + ssize_t _quadsCount; + + kmMat4 _mv; }; NS_CC_END diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 2763f71ef6..5c97dfdae4 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -256,7 +256,9 @@ void Renderer::render() _lastCommand ++; } - memcpy(_quads + _numQuads, cmd->getQuad(), sizeof(V3F_C4B_T2F_Quad) * cmdQuadCount); + memcpy(_quads + _numQuads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmdQuadCount); + convertToWorldCoordiantes(_quads + _numQuads, cmdQuadCount, cmd->getModelView()); + _numQuads += cmdQuadCount; } else if(commandType == RenderCommand::Type::CUSTOM_COMMAND) @@ -319,6 +321,49 @@ void Renderer::render() _lastMaterialID = 0; } +void Renderer::convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quantity, const kmMat4& modelView) +{ + for(ssize_t i=0; ibl.vertices.x; + vec1.y = q->bl.vertices.y; + vec1.z = q->bl.vertices.z; + kmVec3Transform(&out1, &vec1, &modelView); + q->bl.vertices.x = out1.x; + q->bl.vertices.y = out1.y; + q->bl.vertices.z = out1.z; + + kmVec3 vec2, out2; + vec2.x = q->br.vertices.x; + vec2.y = q->br.vertices.y; + vec2.z = q->br.vertices.z; + kmVec3Transform(&out2, &vec2, &modelView); + q->br.vertices.x = out2.x; + q->br.vertices.y = out2.y; + q->br.vertices.z = out2.z; + + kmVec3 vec3, out3; + vec3.x = q->tr.vertices.x; + vec3.y = q->tr.vertices.y; + vec3.z = q->tr.vertices.z; + kmVec3Transform(&out3, &vec3, &modelView); + q->tr.vertices.x = out3.x; + q->tr.vertices.y = out3.y; + q->tr.vertices.z = out3.z; + + kmVec3 vec4, out4; + vec4.x = q->tl.vertices.x; + vec4.y = q->tl.vertices.y; + vec4.z = q->tl.vertices.z; + kmVec3Transform(&out4, &vec4, &modelView); + q->tl.vertices.x = out4.x; + q->tl.vertices.y = out4.y; + q->tl.vertices.z = out4.z; + } +} + void Renderer::drawBatchedQuads() { //TODO we can improve the draw performance by insert material switching command before hand. diff --git a/cocos/2d/renderer/CCRenderer.h b/cocos/2d/renderer/CCRenderer.h index e732547130..c2dcdccc6f 100644 --- a/cocos/2d/renderer/CCRenderer.h +++ b/cocos/2d/renderer/CCRenderer.h @@ -75,9 +75,12 @@ protected: void mapBuffers(); void drawBatchedQuads(); + //Draw the previews queued quads and flush previous context void flush(); + void convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quantity, const kmMat4& modelView); + std::stack _commandGroupStack; std::stack _renderStack; From 65602a4574750b469c093d1dc7f06a36d6627310 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 16:06:47 -0800 Subject: [PATCH 2/4] Updates Xcode, Android and Linux project with new BatchCommand --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos/2d/Android.mk | 1 + cocos/2d/CMakeLists.txt | 1 + cocos/2d/renderer/CCBatchCommand.cpp | 125 ++++++++++++++++++ cocos/2d/renderer/CCBatchCommand.h | 81 ++++++++++++ 5 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 cocos/2d/renderer/CCBatchCommand.cpp create mode 100644 cocos/2d/renderer/CCBatchCommand.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index faa1e4571d..e14906c550 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -3d6ada05d55194dd8e4c10ed8316add7c0d8705c \ No newline at end of file +88c095bbe123ab56df3f7870692c6631f4464c8d \ No newline at end of file diff --git a/cocos/2d/Android.mk b/cocos/2d/Android.mk index 303a1da40f..9fca766934 100644 --- a/cocos/2d/Android.mk +++ b/cocos/2d/Android.mk @@ -122,6 +122,7 @@ renderer/CCFrustum.cpp \ renderer/CCGroupCommand.cpp \ renderer/CCMaterialManager.cpp \ renderer/CCQuadCommand.cpp \ +renderer/CCBatchCommand.cpp \ renderer/CCRenderCommand.cpp \ renderer/CCRenderer.cpp \ renderer/CCRenderMaterial.cpp \ diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index 88090ec7c5..8340903c8b 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -144,6 +144,7 @@ set(COCOS2D_SRC renderer/CCGroupCommand.cpp renderer/CCMaterialManager.cpp renderer/CCQuadCommand.cpp + renderer/CCBatchCommand.cpp renderer/CCRenderCommand.cpp renderer/CCRenderer.cpp renderer/CCRenderMaterial.cpp diff --git a/cocos/2d/renderer/CCBatchCommand.cpp b/cocos/2d/renderer/CCBatchCommand.cpp new file mode 100644 index 0000000000..de3fc511cd --- /dev/null +++ b/cocos/2d/renderer/CCBatchCommand.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + + +#include "renderer/CCBatchCommand.h" +#include "ccGLStateCache.h" +#include "CCTextureAtlas.h" + +NS_CC_BEGIN + +BatchCommand::BatchCommand() +: _viewport(0) +, _depth(0) +, _textureID(0) +, _blendType(BlendFunc::DISABLE) +, _textureAtlas(nullptr) +{ + _type = RenderCommand::Type::BATCH_COMMAND; + _shader = nullptr; +} + +void BatchCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform) +{ + _viewport = viewport; + _depth = depth; + _textureID = textureID; + _blendType = blendType; + _shader = shader; + + _textureAtlas = textureAtlas; + + _mv = modelViewTransform; +} + +BatchCommand::~BatchCommand() +{ +} + +int64_t BatchCommand::generateID() +{ + _id = 0; + + //Generate Material ID + //TODO fix shader ID generation + CCASSERT(_shader->getProgram() < pow(2,10), "ShaderID is greater than 2^10"); + //TODO fix texture ID generation + CCASSERT(_textureID < pow(2,18), "TextureID is greater than 2^18"); + + //TODO fix blend id generation + int blendID = 0; + if(_blendType == BlendFunc::DISABLE) + { + blendID = 0; + } + else if(_blendType == BlendFunc::ALPHA_PREMULTIPLIED) + { + blendID = 1; + } + else if(_blendType == BlendFunc::ALPHA_NON_PREMULTIPLIED) + { + blendID = 2; + } + else if(_blendType == BlendFunc::ADDITIVE) + { + blendID = 3; + } + else + { + blendID = 4; + } + + //TODO Material ID should be part of the ID + // + // Temporal hack (later, these 32-bits should be packed in 24-bits + // + // +---------------------+-------------------+----------------------+ + // | Shader ID (10 bits) | Blend ID (4 bits) | Texture ID (18 bits) | + // +---------------------+-------------------+----------------------+ + + _materialID = (int32_t)_shader->getProgram() << 22 + | (int32_t)blendID << 18 + | (int32_t)_textureID << 0; + + //Generate RenderCommandID + _id = (int64_t)_viewport << 61 + | (int64_t)1 << 60 //translucent + | (int64_t)_depth << 36; + + return _id; +} + +void BatchCommand::execute() +{ + // Set material + _shader->use(); + _shader->setUniformsForBuiltins(_mv); + GL::bindTexture2D(_textureID); + GL::blendFunc(_blendType.src, _blendType.dst); + + // Draw + _textureAtlas->drawQuads(); +} + +NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCBatchCommand.h b/cocos/2d/renderer/CCBatchCommand.h new file mode 100644 index 0000000000..d3b2a5245e --- /dev/null +++ b/cocos/2d/renderer/CCBatchCommand.h @@ -0,0 +1,81 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef _CC_BATCHCOMMAND_H_ +#define _CC_BATCHCOMMAND_H_ + +#include "CCRenderCommand.h" +#include "CCGLProgram.h" +#include "CCRenderCommandPool.h" +#include "kazmath/kazmath.h" + +NS_CC_BEGIN + +class TextureAtlas; + +#define CC_NO_TEXTURE 0 + +class BatchCommand : public RenderCommand +{ +public: + + BatchCommand(); + ~BatchCommand(); + + void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform); + + // +----------+----------+-----+-----------------------------------+ + // | | | | | | + // | ViewPort | Transluc | | Depth | Material ID | + // | 3 bits | 1 bit | | 24 bits | 24 bit2 | + // +----------+----------+-----+----------------+------------------+ + virtual int64_t generateID(); + + void execute(); + +protected: + int32_t _materialID; + + //Key Data + int _viewport; /// Which view port it belongs to + + //TODO use material to determine if it's translucent + int32_t _depth; + + //Maternal + GLuint _textureID; + + GLProgram* _shader; +// GLuint _shaderID; + + BlendFunc _blendType; + + TextureAtlas *_textureAtlas; + + // ModelView transform + kmMat4 _mv; +}; +NS_CC_END + +#endif //_CC_BATCHCOMMAND_H_ From 938825360678b8a79c218613ca88f515df4f80e5 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 16:07:38 -0800 Subject: [PATCH 3/4] SpriteBatchCommand and ParticleBatchCommand use the BatchCommand BatchCommand is being used by SpriteBatchCommand and ParticlesBatchCommand This improves performance in batches --- cocos/2d/CCParticleBatchNode.cpp | 28 ++++++++------------------- cocos/2d/CCParticleBatchNode.h | 4 ++-- cocos/2d/CCSpriteBatchNode.cpp | 22 +++++++++------------ cocos/2d/CCSpriteBatchNode.h | 4 ++-- cocos/2d/renderer/CCCustomCommand.cpp | 3 +-- cocos/2d/renderer/CCGroupCommand.cpp | 3 +-- cocos/2d/renderer/CCQuadCommand.cpp | 3 +-- cocos/2d/renderer/CCRenderCommand.h | 1 + cocos/2d/renderer/CCRenderer.cpp | 7 +++++++ 9 files changed, 32 insertions(+), 43 deletions(-) diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 5b78d1256f..773b780997 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -382,26 +382,14 @@ void ParticleBatchNode::draw(void) return; } -// CC_NODE_DRAW_SETUP(); -// -// GL::blendFunc( _blendFunc.src, _blendFunc.dst ); -// -// _textureAtlas->drawQuads(); - - auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - - kmMat4 mv; - kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - - _quadCommand.init(0, - _vertexZ, - _textureAtlas->getTexture()->getName(), - shader, - _blendFunc, - _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), - mv); - Director::getInstance()->getRenderer()->addCommand(&_quadCommand); + _batchCommand.init(0, + _vertexZ, + _textureAtlas->getTexture()->getName(), + _shaderProgram, + _blendFunc, + _textureAtlas, + _modelViewTransform); + Director::getInstance()->getRenderer()->addCommand(&_batchCommand); CC_PROFILER_STOP("CCParticleBatchNode - draw"); } diff --git a/cocos/2d/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h index d4fd276603..bb092e96d2 100644 --- a/cocos/2d/CCParticleBatchNode.h +++ b/cocos/2d/CCParticleBatchNode.h @@ -32,7 +32,7 @@ #include "CCNode.h" #include "CCProtocols.h" -#include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" NS_CC_BEGIN @@ -146,7 +146,7 @@ private: /** the blend function used for drawing the quads */ BlendFunc _blendFunc; // quad command - QuadCommand _quadCommand; + BatchCommand _batchCommand; }; // end of particle_nodes group diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 3ef2e183e9..502474d00e 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -99,7 +99,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity) _descendants.reserve(capacity); - setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; } @@ -356,18 +356,14 @@ void SpriteBatchNode::draw() for(const auto &child: _children) child->updateTransform(); - kmMat4 mv; - kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - - _quadCommand.init(0, - _vertexZ, - _textureAtlas->getTexture()->getName(), - _shaderProgram, - _blendFunc, - _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), - mv); - Director::getInstance()->getRenderer()->addCommand(&_quadCommand); + _batchCommand.init(0, + _vertexZ, + _textureAtlas->getTexture()->getName(), + _shaderProgram, + _blendFunc, + _textureAtlas, + _modelViewTransform); + Director::getInstance()->getRenderer()->addCommand(&_batchCommand); } void SpriteBatchNode::increaseAtlasCapacity(void) diff --git a/cocos/2d/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h index fc140aa391..bbb6294e6d 100644 --- a/cocos/2d/CCSpriteBatchNode.h +++ b/cocos/2d/CCSpriteBatchNode.h @@ -35,7 +35,7 @@ THE SOFTWARE. #include "CCProtocols.h" #include "CCTextureAtlas.h" #include "ccMacros.h" -#include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" NS_CC_BEGIN @@ -189,7 +189,7 @@ protected: TextureAtlas *_textureAtlas; BlendFunc _blendFunc; - QuadCommand _quadCommand; // quad command + BatchCommand _batchCommand; // render 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/CCCustomCommand.cpp b/cocos/2d/renderer/CCCustomCommand.cpp index 790bd13e69..b0c39f2049 100644 --- a/cocos/2d/renderer/CCCustomCommand.cpp +++ b/cocos/2d/renderer/CCCustomCommand.cpp @@ -27,8 +27,7 @@ NS_CC_BEGIN CustomCommand::CustomCommand() -:RenderCommand() -, func(nullptr) +: func(nullptr) , _viewport(0) , _depth(0) { diff --git a/cocos/2d/renderer/CCGroupCommand.cpp b/cocos/2d/renderer/CCGroupCommand.cpp index 8bd6f85888..4f7707cd76 100644 --- a/cocos/2d/renderer/CCGroupCommand.cpp +++ b/cocos/2d/renderer/CCGroupCommand.cpp @@ -86,8 +86,7 @@ void GroupCommandManager::releaseGroupID(int groupID) } GroupCommand::GroupCommand() -:RenderCommand() -, _viewport(0) +: _viewport(0) , _depth(0) { _type = RenderCommand::Type::GROUP_COMMAND; diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index f60446871c..a19e3f7053 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -29,8 +29,7 @@ NS_CC_BEGIN QuadCommand::QuadCommand() -:RenderCommand() -,_viewport(0) +:_viewport(0) ,_depth(0) ,_textureID(0) ,_blendType(BlendFunc::DISABLE) diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index 930ed1ecde..7b6ec54e0c 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -42,6 +42,7 @@ public: { QUAD_COMMAND, CUSTOM_COMMAND, + BATCH_COMMAND, GROUP_COMMAND, UNKNOWN_COMMAND, }; diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 5c97dfdae4..4454f1480f 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -27,6 +27,7 @@ #include "ccGLStateCache.h" #include "CCCustomCommand.h" #include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" #include "CCGroupCommand.h" #include "CCConfiguration.h" #include "CCDirector.h" @@ -267,6 +268,12 @@ void Renderer::render() CustomCommand* cmd = static_cast(command); cmd->execute(); } + else if(commandType == RenderCommand::Type::BATCH_COMMAND) + { + flush(); + BatchCommand* cmd = static_cast(command); + cmd->execute(); + } else if(commandType == RenderCommand::Type::GROUP_COMMAND) { flush(); From ae84650713ea3cbaf8426b45e721d5cef0cd1e98 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 16:09:38 -0800 Subject: [PATCH 4/4] Updates CHANGELOG --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 3b3b55d33e..14a94ba772 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,12 +2,14 @@ cocos2d-x-3.0final ?.? ? [All] [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. + [NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10% [FIX] Console: log(format, va_args) is private to prevent possible resolution errors [FIX] Configuration: dumpInfo() -> getInfo() [FIX] ControlSlider doesn't support to set selected thumb sprite. [FIX] ControlButton doesn't support to set scale ratio of touchdown state. [FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file. [FIX] Renderer: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster + [FIX] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20% [FIX] Tests: TestCpp works with CMake on Windows. [FIX] Tests: Sprites Performance Test has 3 new tests [FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected