From 414d67851fe3e692efb6308f9e03627389e6d092 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 4 Aug 2014 16:36:20 +0800 Subject: [PATCH] add _vertexBuffer back in Fast_tmx --- cocos/2d/CCFastTMXLayer.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/cocos/2d/CCFastTMXLayer.cpp b/cocos/2d/CCFastTMXLayer.cpp index 1399729f1b..ca7dd5f60c 100644 --- a/cocos/2d/CCFastTMXLayer.cpp +++ b/cocos/2d/CCFastTMXLayer.cpp @@ -121,6 +121,7 @@ TMXLayer::TMXLayer() , _useAutomaticVertexZ(false) , _dirty(true) , _quadsDirty(true) +, _vertexBuffer(nullptr) , _vData(nullptr) , _indexBuffer(nullptr) { @@ -132,6 +133,7 @@ TMXLayer::~TMXLayer() CC_SAFE_RELEASE(_texture); CC_SAFE_DELETE_ARRAY(_tiles); CC_SAFE_RELEASE(_vData); + CC_SAFE_RELEASE(_vertexBuffer); CC_SAFE_RELEASE(_indexBuffer); } @@ -283,29 +285,19 @@ void TMXLayer::updateTiles(const Rect& culledRect) void TMXLayer::updateVertexBuffer() { GL::bindVAO(0); - VertexBuffer *vertexBuffer(nullptr); if(nullptr == _vData) { -// glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer->getVBO()); -// GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); -// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*)0); -// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_T2F, colors)); -// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_T2F, texCoords)); -// glDrawElements(GL_TRIANGLES, (GLsizei)count * 6, GL_UNSIGNED_INT, (GLvoid*)(offset * 6 * sizeof(int))); - vertexBuffer = VertexBuffer::create(sizeof(V3F_C4B_T2F), (int)_totalQuads.size() * 4); + _vertexBuffer = VertexBuffer::create(sizeof(V3F_C4B_T2F), (int)_totalQuads.size() * 4); _vData = VertexData::create(); - _vData->setStream(vertexBuffer, VertexStreamAttribute(0, GLProgram::VERTEX_ATTRIB_POSITION, GL_FLOAT, 3)); - _vData->setStream(vertexBuffer, VertexStreamAttribute(offsetof(V3F_C4B_T2F, colors), GLProgram::VERTEX_ATTRIB_COLOR, GL_UNSIGNED_BYTE, 4, true)); - _vData->setStream(vertexBuffer, VertexStreamAttribute(offsetof(V3F_C4B_T2F, texCoords), GLProgram::VERTEX_ATTRIB_TEX_COORD, GL_FLOAT, 2)); + _vData->setStream(_vertexBuffer, VertexStreamAttribute(0, GLProgram::VERTEX_ATTRIB_POSITION, GL_FLOAT, 3)); + _vData->setStream(_vertexBuffer, VertexStreamAttribute(offsetof(V3F_C4B_T2F, colors), GLProgram::VERTEX_ATTRIB_COLOR, GL_UNSIGNED_BYTE, 4, true)); + _vData->setStream(_vertexBuffer, VertexStreamAttribute(offsetof(V3F_C4B_T2F, texCoords), GLProgram::VERTEX_ATTRIB_TEX_COORD, GL_FLOAT, 2)); CC_SAFE_RETAIN(_vData); + CC_SAFE_RETAIN(_vertexBuffer); } - else + if(_vertexBuffer) { - vertexBuffer = _vData->getStreamBuffer(GLProgram::VERTEX_ATTRIB_POSITION); - } - if(vertexBuffer) - { - vertexBuffer->updateVertices((void*)&_totalQuads[0], (int)_totalQuads.size() * 4, 0); + _vertexBuffer->updateVertices((void*)&_totalQuads[0], (int)_totalQuads.size() * 4, 0); } }