From cf6785ffcf4576f28cbcdc4d66bfb39be9ea3545 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 22 Jan 2014 15:18:27 +0800 Subject: [PATCH] issue #3812: using std::vector to hold current batched command --- cocos/2d/renderer/CCRenderer.cpp | 29 ++++++++++++++++------------- cocos/2d/renderer/CCRenderer.h | 4 ++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 15da8cfbdd..e91b2de927 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -244,23 +244,25 @@ void Renderer::render() if(commandType == RenderCommand::Type::QUAD_COMMAND) { QuadCommand* cmd = static_cast(command); - ssize_t cmdQuadCount = cmd->getQuadCount(); + CCASSERT(nullptr!= cmd, "Illegal command for RenderCommand Taged as QUAD_COMMAND"); //Batch quads - if(_numQuads + cmdQuadCount > VBO_SIZE) + if(_numQuads + cmd->getQuadCount() > VBO_SIZE) { - CCASSERT(cmdQuadCount < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command"); + CCASSERT(cmd->getQuadCount() < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command"); //Draw batched quads if VBO is full _lastCommand --; drawBatchedQuads(); _lastCommand ++; } + + _batchedQuadCommands.push_back(cmd); + + memcpy(_quads + _numQuads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmd->getQuadCount()); + convertToWorldCoordiantes(_quads + _numQuads, cmd->getQuadCount(), cmd->getModelView()); - memcpy(_quads + _numQuads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmdQuadCount); - convertToWorldCoordiantes(_quads + _numQuads, cmdQuadCount, cmd->getModelView()); - - _numQuads += cmdQuadCount; + _numQuads += cmd->getQuadCount(); } else if(commandType == RenderCommand::Type::CUSTOM_COMMAND) { @@ -355,7 +357,7 @@ void Renderer::drawBatchedQuads() int startQuad = 0; //Upload buffer to VBO - if(_numQuads <= 0) + if(_numQuads <= 0 || 0 == _batchedQuadCommands.size()) { _firstCommand = _lastCommand; return; @@ -398,12 +400,13 @@ void Renderer::drawBatchedQuads() } //Start drawing verties in batch - for(size_t i = _firstCommand; i <= _lastCommand; i++) + //for(size_t i = _firstCommand; i <= _lastCommand; i++) + for(auto i = _batchedQuadCommands.begin(); i != _batchedQuadCommands.end(); ++i) { - RenderCommand* command = _renderGroups[_renderStack.top().renderQueueID][i]; - if (command->getType() == RenderCommand::Type::QUAD_COMMAND) + //RenderCommand* command = _renderGroups[_renderStack.top().renderQueueID][i]; + //if (command->getType() == RenderCommand::Type::QUAD_COMMAND) { - QuadCommand* cmd = static_cast(command); + QuadCommand* cmd = *i; if(_lastMaterialID != cmd->getMaterialID()) { //Draw quads @@ -443,7 +446,7 @@ void Renderer::drawBatchedQuads() glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } - + _batchedQuadCommands.clear(); _firstCommand = _lastCommand + 1; _numQuads = 0; } diff --git a/cocos/2d/renderer/CCRenderer.h b/cocos/2d/renderer/CCRenderer.h index c2dcdccc6f..0a0d26a9f9 100644 --- a/cocos/2d/renderer/CCRenderer.h +++ b/cocos/2d/renderer/CCRenderer.h @@ -32,10 +32,12 @@ #include "CCGL.h" #include #include +#include NS_CC_BEGIN class EventListenerCustom; +class QuadCommand; typedef std::vector RenderQueue; @@ -91,6 +93,8 @@ protected: size_t _firstCommand; size_t _lastCommand; + std::vector _batchedQuadCommands; + V3F_C4B_T2F_Quad _quads[VBO_SIZE]; GLushort _indices[6 * VBO_SIZE]; GLuint _quadVAO;