mirror of https://github.com/axmolengine/axmol.git
SpriteBatchCommand and ParticleBatchCommand use the BatchCommand
BatchCommand is being used by SpriteBatchCommand and ParticlesBatchCommand This improves performance in batches
This commit is contained in:
parent
65602a4574
commit
9388253606
|
@ -382,26 +382,14 @@ void ParticleBatchNode::draw(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CC_NODE_DRAW_SETUP();
|
_batchCommand.init(0,
|
||||||
//
|
_vertexZ,
|
||||||
// GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
_textureAtlas->getTexture()->getName(),
|
||||||
//
|
_shaderProgram,
|
||||||
// _textureAtlas->drawQuads();
|
_blendFunc,
|
||||||
|
_textureAtlas,
|
||||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
_modelViewTransform);
|
||||||
|
Director::getInstance()->getRenderer()->addCommand(&_batchCommand);
|
||||||
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);
|
|
||||||
CC_PROFILER_STOP("CCParticleBatchNode - draw");
|
CC_PROFILER_STOP("CCParticleBatchNode - draw");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "renderer/CCQuadCommand.h"
|
#include "renderer/CCBatchCommand.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ private:
|
||||||
/** the blend function used for drawing the quads */
|
/** the blend function used for drawing the quads */
|
||||||
BlendFunc _blendFunc;
|
BlendFunc _blendFunc;
|
||||||
// quad command
|
// quad command
|
||||||
QuadCommand _quadCommand;
|
BatchCommand _batchCommand;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of particle_nodes group
|
// end of particle_nodes group
|
||||||
|
|
|
@ -99,7 +99,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity)
|
||||||
|
|
||||||
_descendants.reserve(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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,18 +356,14 @@ void SpriteBatchNode::draw()
|
||||||
for(const auto &child: _children)
|
for(const auto &child: _children)
|
||||||
child->updateTransform();
|
child->updateTransform();
|
||||||
|
|
||||||
kmMat4 mv;
|
_batchCommand.init(0,
|
||||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
_vertexZ,
|
||||||
|
_textureAtlas->getTexture()->getName(),
|
||||||
_quadCommand.init(0,
|
_shaderProgram,
|
||||||
_vertexZ,
|
_blendFunc,
|
||||||
_textureAtlas->getTexture()->getName(),
|
_textureAtlas,
|
||||||
_shaderProgram,
|
_modelViewTransform);
|
||||||
_blendFunc,
|
Director::getInstance()->getRenderer()->addCommand(&_batchCommand);
|
||||||
_textureAtlas->getQuads(),
|
|
||||||
_textureAtlas->getTotalQuads(),
|
|
||||||
mv);
|
|
||||||
Director::getInstance()->getRenderer()->addCommand(&_quadCommand);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatchNode::increaseAtlasCapacity(void)
|
void SpriteBatchNode::increaseAtlasCapacity(void)
|
||||||
|
|
|
@ -35,7 +35,7 @@ THE SOFTWARE.
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCTextureAtlas.h"
|
#include "CCTextureAtlas.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "renderer/CCQuadCommand.h"
|
#include "renderer/CCBatchCommand.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ protected:
|
||||||
|
|
||||||
TextureAtlas *_textureAtlas;
|
TextureAtlas *_textureAtlas;
|
||||||
BlendFunc _blendFunc;
|
BlendFunc _blendFunc;
|
||||||
QuadCommand _quadCommand; // quad command
|
BatchCommand _batchCommand; // render command
|
||||||
|
|
||||||
// all descendants: children, grand children, etc...
|
// all descendants: children, grand children, etc...
|
||||||
// There is not need to retain/release these objects, since they are already retained by _children
|
// There is not need to retain/release these objects, since they are already retained by _children
|
||||||
|
|
|
@ -27,8 +27,7 @@
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
CustomCommand::CustomCommand()
|
CustomCommand::CustomCommand()
|
||||||
:RenderCommand()
|
: func(nullptr)
|
||||||
, func(nullptr)
|
|
||||||
, _viewport(0)
|
, _viewport(0)
|
||||||
, _depth(0)
|
, _depth(0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,8 +86,7 @@ void GroupCommandManager::releaseGroupID(int groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupCommand::GroupCommand()
|
GroupCommand::GroupCommand()
|
||||||
:RenderCommand()
|
: _viewport(0)
|
||||||
, _viewport(0)
|
|
||||||
, _depth(0)
|
, _depth(0)
|
||||||
{
|
{
|
||||||
_type = RenderCommand::Type::GROUP_COMMAND;
|
_type = RenderCommand::Type::GROUP_COMMAND;
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
QuadCommand::QuadCommand()
|
QuadCommand::QuadCommand()
|
||||||
:RenderCommand()
|
:_viewport(0)
|
||||||
,_viewport(0)
|
|
||||||
,_depth(0)
|
,_depth(0)
|
||||||
,_textureID(0)
|
,_textureID(0)
|
||||||
,_blendType(BlendFunc::DISABLE)
|
,_blendType(BlendFunc::DISABLE)
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
{
|
{
|
||||||
QUAD_COMMAND,
|
QUAD_COMMAND,
|
||||||
CUSTOM_COMMAND,
|
CUSTOM_COMMAND,
|
||||||
|
BATCH_COMMAND,
|
||||||
GROUP_COMMAND,
|
GROUP_COMMAND,
|
||||||
UNKNOWN_COMMAND,
|
UNKNOWN_COMMAND,
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "ccGLStateCache.h"
|
#include "ccGLStateCache.h"
|
||||||
#include "CCCustomCommand.h"
|
#include "CCCustomCommand.h"
|
||||||
#include "renderer/CCQuadCommand.h"
|
#include "renderer/CCQuadCommand.h"
|
||||||
|
#include "renderer/CCBatchCommand.h"
|
||||||
#include "CCGroupCommand.h"
|
#include "CCGroupCommand.h"
|
||||||
#include "CCConfiguration.h"
|
#include "CCConfiguration.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
|
@ -267,6 +268,12 @@ void Renderer::render()
|
||||||
CustomCommand* cmd = static_cast<CustomCommand*>(command);
|
CustomCommand* cmd = static_cast<CustomCommand*>(command);
|
||||||
cmd->execute();
|
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)
|
else if(commandType == RenderCommand::Type::GROUP_COMMAND)
|
||||||
{
|
{
|
||||||
flush();
|
flush();
|
||||||
|
|
Loading…
Reference in New Issue