Renderer: When not using VAOs, call...

... glBufferData() to update the contents, and not glBufferSubData()
since the performance is better
This commit is contained in:
Ricardo Quesada 2014-01-16 15:02:39 -08:00
parent 4bd2b9364a
commit cb9761125b
6 changed files with 12 additions and 11 deletions

View File

@ -17,6 +17,7 @@ cocos2d-x-3.0final ?.? ?
[FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file. [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: 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] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20%
[FIX] Renderer: When note using VAO, call glBufferData() instead of glBufferSubData().
[FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well [FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well
[FIX] Tests: TestCpp works with CMake on Windows. [FIX] Tests: TestCpp works with CMake on Windows.
[FIX] Tests: Sprites Performance Test has 4 new tests [FIX] Tests: Sprites Performance Test has 4 new tests

View File

@ -56,7 +56,7 @@ public:
//TODO use material to decide if it is translucent //TODO use material to decide if it is translucent
inline bool isTranslucent() const { return true; } inline bool isTranslucent() const { return true; }
inline int32_t getMaterialID() const { return _materialID; } inline uint32_t getMaterialID() const { return _materialID; }
inline GLuint getTextureID() const { return _textureID; } inline GLuint getTextureID() const { return _textureID; }
@ -71,7 +71,7 @@ public:
inline const kmMat4& getModelView() const { return _mv; } inline const kmMat4& getModelView() const { return _mv; }
protected: protected:
int32_t _materialID; uint32_t _materialID;
//Key Data //Key Data
int _viewport; /// Which view port it belongs to int _viewport; /// Which view port it belongs to

View File

@ -249,7 +249,7 @@ void Renderer::render()
//Batch quads //Batch quads
if(_numQuads + cmdQuadCount > VBO_SIZE) if(_numQuads + cmdQuadCount > 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(cmdQuadCount>=0 && cmdQuadCount<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 //Draw batched quads if VBO is full
_lastCommand --; _lastCommand --;
@ -381,7 +381,7 @@ void Renderer::drawBatchedQuads()
#define kQuadSize sizeof(_quads[0].bl) #define kQuadSize sizeof(_quads[0].bl)
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(_quads[0]) * _numQuads , _quads); glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _numQuads , _quads, GL_DYNAMIC_DRAW);
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
@ -398,7 +398,7 @@ void Renderer::drawBatchedQuads()
} }
//Start drawing verties in batch //Start drawing verties in batch
for(size_t i = _firstCommand; i <= _lastCommand; i++) for(ssize_t i = _firstCommand; i <= _lastCommand; i++)
{ {
RenderCommand* command = _renderGroups[_renderStack.top().renderQueueID][i]; RenderCommand* command = _renderGroups[_renderStack.top().renderQueueID][i];
if (command->getType() == RenderCommand::Type::QUAD_COMMAND) if (command->getType() == RenderCommand::Type::QUAD_COMMAND)

View File

@ -42,7 +42,7 @@ typedef std::vector<RenderCommand*> RenderQueue;
struct RenderStackElement struct RenderStackElement
{ {
int renderQueueID; int renderQueueID;
size_t currentIndex; ssize_t currentIndex;
}; };
class Renderer class Renderer
@ -86,10 +86,10 @@ protected:
std::stack<RenderStackElement> _renderStack; std::stack<RenderStackElement> _renderStack;
std::vector<RenderQueue> _renderGroups; std::vector<RenderQueue> _renderGroups;
int _lastMaterialID; uint32_t _lastMaterialID;
size_t _firstCommand; ssize_t _firstCommand;
size_t _lastCommand; ssize_t _lastCommand;
V3F_C4B_T2F_Quad _quads[VBO_SIZE]; V3F_C4B_T2F_Quad _quads[VBO_SIZE];
GLushort _indices[6 * VBO_SIZE]; GLushort _indices[6 * VBO_SIZE];

View File

@ -391,7 +391,7 @@ void Console::commandTextures(int fd, const char *command)
{ {
Scheduler *sched = Director::getInstance()->getScheduler(); Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( [&](){ sched->performFunctionInCocosThread( [&](){
mydprintf(fd, "%s", TextureCache::getInstance()->getCachedTextureInfo().c_str()); mydprintf(fd, "%s", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str());
} }
); );
} }