SpriteBatchCommand and ParticleBatchCommand use the BatchCommand

BatchCommand is being used by SpriteBatchCommand and ParticlesBatchCommand

This improves performance in batches
This commit is contained in:
Ricardo Quesada 2014-01-15 16:07:38 -08:00
parent 65602a4574
commit 9388253606
9 changed files with 32 additions and 43 deletions

View File

@ -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");
}

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -27,8 +27,7 @@
NS_CC_BEGIN
CustomCommand::CustomCommand()
:RenderCommand()
, func(nullptr)
: func(nullptr)
, _viewport(0)
, _depth(0)
{

View File

@ -86,8 +86,7 @@ void GroupCommandManager::releaseGroupID(int groupID)
}
GroupCommand::GroupCommand()
:RenderCommand()
, _viewport(0)
: _viewport(0)
, _depth(0)
{
_type = RenderCommand::Type::GROUP_COMMAND;

View File

@ -29,8 +29,7 @@
NS_CC_BEGIN
QuadCommand::QuadCommand()
:RenderCommand()
,_viewport(0)
:_viewport(0)
,_depth(0)
,_textureID(0)
,_blendType(BlendFunc::DISABLE)

View File

@ -42,6 +42,7 @@ public:
{
QUAD_COMMAND,
CUSTOM_COMMAND,
BATCH_COMMAND,
GROUP_COMMAND,
UNKNOWN_COMMAND,
};

View File

@ -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<CustomCommand*>(command);
cmd->execute();
}
else if(commandType == RenderCommand::Type::BATCH_COMMAND)
{
flush();
BatchCommand* cmd = static_cast<BatchCommand*>(command);
cmd->execute();
}
else if(commandType == RenderCommand::Type::GROUP_COMMAND)
{
flush();