2010-08-02 10:58:00 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 14:45:51 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-05 10:47:25 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-07-16 16:28:11 +08:00
|
|
|
// cocos2d
|
|
|
|
#include "CCTextureAtlas.h"
|
|
|
|
#include "CCTextureCache.h"
|
2010-12-31 14:56:24 +08:00
|
|
|
#include "ccMacros.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "shaders/CCGLProgram.h"
|
|
|
|
#include "shaders/ccGLStateCache.h"
|
2012-07-19 17:22:36 +08:00
|
|
|
#include "support/CCNotificationCenter.h"
|
2012-04-24 15:02:18 +08:00
|
|
|
#include "CCEventType.h"
|
2010-07-16 16:28:11 +08:00
|
|
|
// support
|
|
|
|
#include "CCTexture2D.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "cocoa/CCString.h"
|
2010-11-03 10:59:07 +08:00
|
|
|
#include <stdlib.h>
|
2010-08-02 10:58:00 +08:00
|
|
|
|
2010-07-16 16:28:11 +08:00
|
|
|
//According to some tests GL_TRIANGLE_STRIP is slower, MUCH slower. Probably I'm doing something very wrong
|
|
|
|
|
|
|
|
// implementation CCTextureAtlas
|
|
|
|
|
2012-03-26 18:44:28 +08:00
|
|
|
NS_CC_BEGIN
|
2010-07-16 16:28:11 +08:00
|
|
|
|
|
|
|
CCTextureAtlas::CCTextureAtlas()
|
2011-06-10 17:51:37 +08:00
|
|
|
:m_pIndices(NULL)
|
2012-03-14 14:55:17 +08:00
|
|
|
,m_bDirty(false)
|
2011-10-19 15:24:19 +08:00
|
|
|
,m_pTexture(NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
,m_pQuads(NULL)
|
2010-09-06 14:15:06 +08:00
|
|
|
{}
|
2010-07-16 16:28:11 +08:00
|
|
|
|
|
|
|
CCTextureAtlas::~CCTextureAtlas()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOGINFO("cocos2d: CCTextureAtlas deallocing %p.", this);
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_FREE(m_pQuads);
|
|
|
|
CC_SAFE_FREE(m_pIndices);
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
glDeleteBuffers(2, m_pBuffersVBO);
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-03-26 18:44:28 +08:00
|
|
|
#if CC_TEXTURE_ATLAS_USE_VAO
|
2012-04-19 14:35:52 +08:00
|
|
|
glDeleteVertexArrays(1, &m_uVAOname);
|
2012-03-26 18:44:28 +08:00
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_RELEASE(m_pTexture);
|
2012-04-24 15:02:18 +08:00
|
|
|
|
2012-07-19 17:22:36 +08:00
|
|
|
CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
unsigned int CCTextureAtlas::getTotalQuads()
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return m_uTotalQuads;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
unsigned int CCTextureAtlas::getCapacity()
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return m_uCapacity;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCTexture2D* CCTextureAtlas::getTexture()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return m_pTexture;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::setTexture(CCTexture2D * var)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_RETAIN(var);
|
|
|
|
CC_SAFE_RELEASE(m_pTexture);
|
|
|
|
m_pTexture = var;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ccV3F_C4B_T2F_Quad* CCTextureAtlas::getQuads()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//if someone accesses the quads directly, presume that changes will be made
|
|
|
|
m_bDirty = true;
|
|
|
|
return m_pQuads;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::setQuads(ccV3F_C4B_T2F_Quad *var)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pQuads = var;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TextureAtlas - alloc & init
|
2010-08-02 10:58:00 +08:00
|
|
|
CCTextureAtlas * CCTextureAtlas::textureAtlasWithFile(const char* file, unsigned int capacity)
|
2012-06-27 14:21:29 +08:00
|
|
|
{
|
|
|
|
return CCTextureAtlas::create(file, capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCTextureAtlas * CCTextureAtlas::create(const char* file, unsigned int capacity)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTextureAtlas * pTextureAtlas = new CCTextureAtlas();
|
|
|
|
if(pTextureAtlas && pTextureAtlas->initWithFile(file, capacity))
|
|
|
|
{
|
|
|
|
pTextureAtlas->autorelease();
|
|
|
|
return pTextureAtlas;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(pTextureAtlas);
|
|
|
|
return NULL;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-06 14:32:32 +08:00
|
|
|
CCTextureAtlas * CCTextureAtlas::textureAtlasWithTexture(CCTexture2D *texture, unsigned int capacity)
|
2012-06-27 14:21:29 +08:00
|
|
|
{
|
|
|
|
return CCTextureAtlas::create(texture, capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCTextureAtlas * CCTextureAtlas::create(CCTexture2D *texture, unsigned int capacity)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTextureAtlas * pTextureAtlas = new CCTextureAtlas();
|
|
|
|
if (pTextureAtlas && pTextureAtlas->initWithTexture(texture, capacity))
|
|
|
|
{
|
|
|
|
pTextureAtlas->autorelease();
|
|
|
|
return pTextureAtlas;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(pTextureAtlas);
|
|
|
|
return NULL;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-09-04 12:02:52 +08:00
|
|
|
bool CCTextureAtlas::initWithFile(const char * file, unsigned int capacity)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// retained in property
|
|
|
|
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(file);
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (texture)
|
|
|
|
{
|
2010-12-30 17:30:11 +08:00
|
|
|
return initWithTexture(texture, capacity);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: Could not open file: %s", file);
|
|
|
|
delete this;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-09-04 12:02:52 +08:00
|
|
|
bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCAssert(texture != NULL, "texture should not be null");
|
|
|
|
m_uCapacity = capacity;
|
|
|
|
m_uTotalQuads = 0;
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// retained in property
|
|
|
|
this->m_pTexture = texture;
|
|
|
|
CC_SAFE_RETAIN(m_pTexture);
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Re-initialization is not allowed
|
|
|
|
CCAssert(m_pQuads == NULL && m_pIndices == NULL, "");
|
2011-07-05 10:47:25 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) );
|
|
|
|
m_pIndices = (GLushort *)malloc( m_uCapacity * 6 * sizeof(GLushort) );
|
2012-04-07 12:02:40 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if( ! ( m_pQuads && m_pIndices) && m_uCapacity > 0)
|
2012-04-07 12:02:40 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//CCLOG("cocos2d: CCTextureAtlas: not enough memory");
|
|
|
|
CC_SAFE_FREE(m_pQuads);
|
|
|
|
CC_SAFE_FREE(m_pIndices);
|
2011-05-06 18:09:31 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// release texture, should set it to null, because the destruction will
|
|
|
|
// release it too. see cocos2d-x issue #484
|
|
|
|
CC_SAFE_RELEASE_NULL(m_pTexture);
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-07 12:02:40 +08:00
|
|
|
memset( m_pQuads, 0, m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) );
|
|
|
|
memset( m_pIndices, 0, m_uCapacity * 6 * sizeof(GLushort) );
|
2012-04-24 15:02:18 +08:00
|
|
|
|
|
|
|
// listen the event when app go to background
|
2012-07-19 17:22:36 +08:00
|
|
|
CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
|
2012-04-24 15:02:18 +08:00
|
|
|
callfuncO_selector(CCTextureAtlas::listenBackToForeground),
|
|
|
|
EVNET_COME_TO_FOREGROUND,
|
|
|
|
NULL);
|
2012-04-07 12:02:40 +08:00
|
|
|
|
2012-04-17 17:55:26 +08:00
|
|
|
this->setupIndices();
|
|
|
|
|
|
|
|
#if CC_TEXTURE_ATLAS_USE_VAO
|
2012-04-19 14:35:52 +08:00
|
|
|
setupVBOandVAO();
|
|
|
|
#else
|
2012-04-17 17:55:26 +08:00
|
|
|
setupVBO();
|
2012-03-26 18:44:28 +08:00
|
|
|
#endif
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = true;
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
void CCTextureAtlas::listenBackToForeground(CCObject *obj)
|
|
|
|
{
|
|
|
|
#if CC_TEXTURE_ATLAS_USE_VAO
|
|
|
|
setupVBOandVAO();
|
|
|
|
#else
|
|
|
|
setupVBO();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// set m_bDirty to true to force it rebinding buffer
|
|
|
|
m_bDirty = true;
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:53:03 +08:00
|
|
|
const char* CCTextureAtlas::description()
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-06-14 16:05:58 +08:00
|
|
|
return CCString::createWithFormat("<CCTextureAtlas | totalQuads = %u>", m_uTotalQuads)->getCString();
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-26 18:44:28 +08:00
|
|
|
void CCTextureAtlas::setupIndices()
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_uCapacity == 0)
|
|
|
|
return;
|
2011-11-10 16:44:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for( unsigned int i=0; i < m_uCapacity; i++)
|
|
|
|
{
|
2010-07-16 16:28:11 +08:00
|
|
|
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pIndices[i*6+0] = i*4+0;
|
|
|
|
m_pIndices[i*6+1] = i*4+0;
|
|
|
|
m_pIndices[i*6+2] = i*4+2;
|
|
|
|
m_pIndices[i*6+3] = i*4+1;
|
|
|
|
m_pIndices[i*6+4] = i*4+3;
|
|
|
|
m_pIndices[i*6+5] = i*4+3;
|
2010-07-16 16:28:11 +08:00
|
|
|
#else
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pIndices[i*6+0] = i*4+0;
|
|
|
|
m_pIndices[i*6+1] = i*4+1;
|
|
|
|
m_pIndices[i*6+2] = i*4+2;
|
|
|
|
|
|
|
|
// inverted index. issue #179
|
|
|
|
m_pIndices[i*6+3] = i*4+3;
|
|
|
|
m_pIndices[i*6+4] = i*4+2;
|
|
|
|
m_pIndices[i*6+5] = i*4+1;
|
|
|
|
#endif
|
|
|
|
}
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
//TextureAtlas - VAO / VBO specific
|
|
|
|
|
|
|
|
#if CC_TEXTURE_ATLAS_USE_VAO
|
|
|
|
void CCTextureAtlas::setupVBOandVAO()
|
|
|
|
{
|
|
|
|
glGenVertexArrays(1, &m_uVAOname);
|
|
|
|
glBindVertexArray(m_uVAOname);
|
|
|
|
|
|
|
|
#define kQuadSize sizeof(m_pQuads[0].bl)
|
|
|
|
|
|
|
|
glGenBuffers(2, &m_pBuffersVBO[0]);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0]) * m_uCapacity, m_pQuads, GL_DYNAMIC_DRAW);
|
|
|
|
|
|
|
|
// vertices
|
|
|
|
glEnableVertexAttribArray(kCCVertexAttrib_Position);
|
|
|
|
glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, vertices));
|
|
|
|
|
|
|
|
// colors
|
|
|
|
glEnableVertexAttribArray(kCCVertexAttrib_Color);
|
|
|
|
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, colors));
|
|
|
|
|
|
|
|
// tex coords
|
|
|
|
glEnableVertexAttribArray(kCCVertexAttrib_TexCoords);
|
|
|
|
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, texCoords));
|
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_pIndices[0]) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
CHECK_GL_ERROR_DEBUG();
|
|
|
|
}
|
|
|
|
#else // CC_TEXTURE_ATLAS_USE_VAO
|
|
|
|
void CCTextureAtlas::setupVBO()
|
|
|
|
{
|
|
|
|
glGenBuffers(2, &m_pBuffersVBO[0]);
|
|
|
|
|
|
|
|
mapBuffers();
|
|
|
|
}
|
|
|
|
#endif // ! // CC_TEXTURE_ATLAS_USE_VAO
|
|
|
|
|
2012-03-26 18:44:28 +08:00
|
|
|
void CCTextureAtlas::mapBuffers()
|
2012-04-17 17:55:26 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0]) * m_uCapacity, m_pQuads, GL_DYNAMIC_DRAW);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_pIndices[0]) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TextureAtlas - Update, Insert, Move & Remove
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
void CCTextureAtlas::updateQuad(ccV3F_C4B_T2F_Quad *quad, unsigned int index)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert( index >= 0 && index < m_uCapacity, "updateQuadWithTexture: Invalid index");
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_uTotalQuads = MAX( index+1, m_uTotalQuads);
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pQuads[index] = *quad;
|
2011-07-05 10:47:25 +08:00
|
|
|
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = true;
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
void CCTextureAtlas::insertQuad(ccV3F_C4B_T2F_Quad *quad, unsigned int index)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert( index < m_uCapacity, "insertQuadWithTexture: Invalid index");
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_uTotalQuads++;
|
|
|
|
CCAssert( m_uTotalQuads <= m_uCapacity, "invalid totalQuads");
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// issue #575. index can be > totalQuads
|
|
|
|
unsigned int remaining = (m_uTotalQuads-1) - index;
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// last object doesn't need to be moved
|
|
|
|
if( remaining > 0)
|
2012-03-26 22:37:09 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// texture coordinates
|
|
|
|
memmove( &m_pQuads[index+1],&m_pQuads[index], sizeof(m_pQuads[0]) * remaining );
|
|
|
|
}
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pQuads[index] = *quad;
|
2011-07-05 10:47:25 +08:00
|
|
|
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = true;
|
2012-03-14 14:55:17 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::insertQuads(ccV3F_C4B_T2F_Quad* quads, unsigned int index, unsigned int amount)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert(index + amount <= m_uCapacity, "insertQuadWithTexture: Invalid index + amount");
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_uTotalQuads += amount;
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert( m_uTotalQuads <= m_uCapacity, "invalid totalQuads");
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// issue #575. index can be > totalQuads
|
|
|
|
int remaining = (m_uTotalQuads-1) - index - amount;
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// last object doesn't need to be moved
|
|
|
|
if( remaining > 0)
|
2012-04-17 17:55:26 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// tex coordinates
|
|
|
|
memmove( &m_pQuads[index+amount],&m_pQuads[index], sizeof(m_pQuads[0]) * remaining );
|
2012-04-17 17:55:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int max = index + amount;
|
|
|
|
unsigned int j = 0;
|
|
|
|
for (unsigned int i = index; i < max ; i++)
|
|
|
|
{
|
|
|
|
m_pQuads[index] = quads[j];
|
|
|
|
index++;
|
|
|
|
j++;
|
|
|
|
}
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = true;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
void CCTextureAtlas::insertQuadFromIndex(unsigned int oldIndex, unsigned int newIndex)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert( newIndex >= 0 && newIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
|
|
|
CCAssert( oldIndex >= 0 && oldIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if( oldIndex == newIndex )
|
2012-03-26 22:37:09 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
2012-03-26 22:37:09 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
// because it is ambigious in iphone, so we implement abs ourself
|
|
|
|
// unsigned int howMany = abs( oldIndex - newIndex);
|
|
|
|
unsigned int howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex);
|
|
|
|
unsigned int dst = oldIndex;
|
|
|
|
unsigned int src = oldIndex + 1;
|
|
|
|
if( oldIndex > newIndex)
|
2012-03-26 22:37:09 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
dst = newIndex+1;
|
|
|
|
src = newIndex;
|
|
|
|
}
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// texture coordinates
|
|
|
|
ccV3F_C4B_T2F_Quad quadsBackup = m_pQuads[oldIndex];
|
|
|
|
memmove( &m_pQuads[dst],&m_pQuads[src], sizeof(m_pQuads[0]) * howMany );
|
|
|
|
m_pQuads[newIndex] = quadsBackup;
|
2011-07-05 10:47:25 +08:00
|
|
|
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = true;
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
void CCTextureAtlas::removeQuadAtIndex(unsigned int index)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert( index < m_uTotalQuads, "removeQuadAtIndex: Invalid index");
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int remaining = (m_uTotalQuads-1) - index;
|
2010-07-16 16:28:11 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// last object doesn't need to be moved
|
|
|
|
if( remaining )
|
2012-03-26 22:37:09 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// texture coordinates
|
|
|
|
memmove( &m_pQuads[index],&m_pQuads[index+1], sizeof(m_pQuads[0]) * remaining );
|
|
|
|
}
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_uTotalQuads--;
|
2011-07-05 10:47:25 +08:00
|
|
|
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = true;
|
2012-03-14 14:55:17 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::removeQuadsAtIndex(unsigned int index, unsigned int amount)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert(index + amount <= m_uTotalQuads, "removeQuadAtIndex: index + amount out of bounds");
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int remaining = (m_uTotalQuads) - (index + amount);
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_uTotalQuads -= amount;
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if ( remaining )
|
2012-04-17 17:55:26 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
memmove( &m_pQuads[index], &m_pQuads[index+amount], sizeof(m_pQuads[0]) * remaining );
|
2012-04-17 17:55:26 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = true;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::removeAllQuads()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_uTotalQuads = 0;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TextureAtlas - Resize
|
2010-08-02 10:58:00 +08:00
|
|
|
bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity)
|
2010-07-16 16:28:11 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if( newCapacity == m_uCapacity )
|
2012-03-26 22:37:09 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2012-03-26 22:37:09 +08:00
|
|
|
}
|
2012-04-07 12:02:40 +08:00
|
|
|
unsigned int uOldCapactiy = m_uCapacity;
|
2012-04-19 14:35:52 +08:00
|
|
|
// update capacity and totolQuads
|
|
|
|
m_uTotalQuads = MIN(m_uTotalQuads, newCapacity);
|
|
|
|
m_uCapacity = newCapacity;
|
|
|
|
|
|
|
|
ccV3F_C4B_T2F_Quad* tmpQuads = NULL;
|
|
|
|
GLushort* tmpIndices = NULL;
|
|
|
|
|
|
|
|
// when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return NULL,
|
|
|
|
// so here must judge whether m_pQuads and m_pIndices is NULL.
|
|
|
|
if (m_pQuads == NULL)
|
2012-03-21 21:53:03 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
tmpQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(m_pQuads[0]) );
|
2012-04-07 12:02:40 +08:00
|
|
|
if (tmpQuads != NULL)
|
|
|
|
{
|
|
|
|
memset(tmpQuads, 0, m_uCapacity * sizeof(m_pQuads[0]) );
|
|
|
|
}
|
2012-03-21 21:53:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
tmpQuads = (ccV3F_C4B_T2F_Quad*)realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity );
|
2012-04-07 12:02:40 +08:00
|
|
|
if (tmpQuads != NULL && m_uCapacity > uOldCapactiy)
|
|
|
|
{
|
|
|
|
memset(tmpQuads+uOldCapactiy, 0, (m_uCapacity - uOldCapactiy)*sizeof(m_pQuads[0]) );
|
|
|
|
}
|
2012-03-21 21:53:03 +08:00
|
|
|
}
|
2011-11-10 16:44:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_pIndices == NULL)
|
|
|
|
{
|
2012-04-07 12:02:40 +08:00
|
|
|
tmpIndices = (GLushort*)malloc( m_uCapacity * 6 * sizeof(m_pIndices[0]) );
|
|
|
|
if (tmpIndices != NULL)
|
|
|
|
{
|
|
|
|
memset( tmpIndices, 0, m_uCapacity * 6 * sizeof(m_pIndices[0]) );
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:53:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
tmpIndices = (GLushort*)realloc( m_pIndices, sizeof(m_pIndices[0]) * m_uCapacity * 6 );
|
2012-04-07 12:02:40 +08:00
|
|
|
if (tmpIndices != NULL && m_uCapacity > uOldCapactiy)
|
|
|
|
{
|
|
|
|
memset( tmpIndices+uOldCapactiy, 0, (m_uCapacity-uOldCapactiy) * 6 * sizeof(m_pIndices[0]) );
|
|
|
|
}
|
2012-03-21 21:53:03 +08:00
|
|
|
}
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if( ! ( tmpQuads && tmpIndices) ) {
|
|
|
|
CCLOG("cocos2d: CCTextureAtlas: not enough memory");
|
2012-03-21 21:53:03 +08:00
|
|
|
CC_SAFE_FREE(tmpQuads);
|
|
|
|
CC_SAFE_FREE(tmpIndices);
|
|
|
|
CC_SAFE_FREE(m_pQuads);
|
|
|
|
CC_SAFE_FREE(m_pIndices);
|
2012-04-19 14:35:52 +08:00
|
|
|
m_uCapacity = m_uTotalQuads = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pQuads = tmpQuads;
|
|
|
|
m_pIndices = tmpIndices;
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2012-03-26 18:44:28 +08:00
|
|
|
setupIndices();
|
2012-04-19 14:35:52 +08:00
|
|
|
mapBuffers();
|
2010-07-16 16:28:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = true;
|
2011-07-05 10:47:25 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2012-04-17 17:55:26 +08:00
|
|
|
void CCTextureAtlas::increaseTotalQuadsWith(unsigned int amount)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_uTotalQuads += amount;
|
2012-04-17 17:55:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::moveQuadsFromIndex(unsigned int oldIndex, unsigned int amount, unsigned int newIndex)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert(newIndex + amount <= m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
|
|
|
CCAssert(oldIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if( oldIndex == newIndex )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//create buffer
|
|
|
|
size_t quadSize = sizeof(ccV3F_C4B_T2F_Quad);
|
|
|
|
ccV3F_C4B_T2F_Quad* tempQuads = (ccV3F_C4B_T2F_Quad*)malloc( quadSize * amount);
|
|
|
|
memcpy( tempQuads, &m_pQuads[oldIndex], quadSize * amount );
|
|
|
|
|
|
|
|
if (newIndex < oldIndex)
|
|
|
|
{
|
|
|
|
// move quads from newIndex to newIndex + amount to make room for buffer
|
|
|
|
memmove( &m_pQuads[newIndex], &m_pQuads[newIndex+amount], (oldIndex-newIndex)*quadSize);
|
|
|
|
}
|
|
|
|
else
|
2012-04-17 17:55:26 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// move quads above back
|
|
|
|
memmove( &m_pQuads[oldIndex], &m_pQuads[oldIndex+amount], (newIndex-oldIndex)*quadSize);
|
2012-04-17 17:55:26 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
memcpy( &m_pQuads[newIndex], tempQuads, amount*quadSize);
|
|
|
|
|
|
|
|
free(tempQuads);
|
|
|
|
|
|
|
|
m_bDirty = true;
|
2012-04-17 17:55:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::moveQuadsFromIndex(unsigned int index, unsigned int newIndex)
|
2012-03-14 14:55:17 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert(newIndex + (m_uTotalQuads - index) <= m_uCapacity, "moveQuadsFromIndex move is out of bounds");
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
memmove(m_pQuads + newIndex,m_pQuads + index, (m_uTotalQuads - index) * sizeof(m_pQuads[0]));
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::fillWithEmptyQuadsFromIndex(unsigned int index, unsigned int amount)
|
|
|
|
{
|
2012-04-17 17:55:26 +08:00
|
|
|
ccV3F_C4B_T2F_Quad quad;
|
|
|
|
memset(&quad, 0, sizeof(quad));
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int to = index + amount;
|
2012-05-29 17:11:33 +08:00
|
|
|
for (unsigned int i = index ; i < to ; i++)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
m_pQuads[i] = quad;
|
|
|
|
}
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
|
|
|
|
2010-07-16 16:28:11 +08:00
|
|
|
// TextureAtlas - Drawing
|
|
|
|
|
|
|
|
void CCTextureAtlas::drawQuads()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->drawNumberOfQuads(m_uTotalQuads, 0);
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
void CCTextureAtlas::drawNumberOfQuads(unsigned int n)
|
2011-07-05 10:47:25 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->drawNumberOfQuads(n, 0);
|
2011-07-05 10:47:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-04-24 15:02:18 +08:00
|
|
|
if (0 == n)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ccGLBindTexture2D(m_pTexture->getName());
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
#if CC_TEXTURE_ATLAS_USE_VAO
|
|
|
|
|
|
|
|
//
|
|
|
|
// Using VBO and VAO
|
|
|
|
//
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// XXX: update is done in draw... perhaps it should be done in a timer
|
|
|
|
if (m_bDirty)
|
2012-04-17 17:55:26 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] );
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bDirty = false;
|
|
|
|
}
|
2012-04-17 17:55:26 +08:00
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
glBindVertexArray(m_uVAOname);
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
#if CC_REBIND_INDICES_BUFFER
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
|
2012-04-19 14:35:52 +08:00
|
|
|
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) );
|
2012-04-17 17:55:26 +08:00
|
|
|
#else
|
2012-04-19 14:35:52 +08:00
|
|
|
glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) );
|
2012-04-17 17:55:26 +08:00
|
|
|
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
|
|
|
|
|
|
|
|
#if CC_REBIND_INDICES_BUFFER
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
#endif
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
glBindVertexArray(0);
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
#else // ! CC_TEXTURE_ATLAS_USE_VAO
|
|
|
|
|
|
|
|
//
|
|
|
|
// Using VBO without VAO
|
|
|
|
//
|
|
|
|
|
|
|
|
#define kQuadSize sizeof(m_pQuads[0].bl)
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
|
|
|
|
|
|
|
|
// XXX: update is done in draw... perhaps it should be done in a timer
|
2012-04-24 15:02:18 +08:00
|
|
|
if (m_bDirty)
|
|
|
|
{
|
2012-04-17 17:55:26 +08:00
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] );
|
|
|
|
m_bDirty = false;
|
|
|
|
}
|
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
// vertices
|
2012-04-24 15:02:18 +08:00
|
|
|
glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(ccV3F_C4B_T2F, vertices));
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
// colors
|
2012-04-24 15:02:18 +08:00
|
|
|
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof(ccV3F_C4B_T2F, colors));
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
// tex coords
|
2012-04-24 15:02:18 +08:00
|
|
|
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(ccV3F_C4B_T2F, texCoords));
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
|
|
|
|
|
|
|
|
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
|
2012-04-24 15:02:18 +08:00
|
|
|
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei)n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])));
|
2012-04-17 17:55:26 +08:00
|
|
|
#else
|
2012-04-24 15:02:18 +08:00
|
|
|
glDrawElements(GL_TRIANGLES, (GLsizei)n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])));
|
2012-04-17 17:55:26 +08:00
|
|
|
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
#endif // CC_TEXTURE_ATLAS_USE_VAO
|
|
|
|
|
|
|
|
CC_INCREMENT_GL_DRAWS(1);
|
2012-04-19 14:35:52 +08:00
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2010-07-16 16:28:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:58:00 +08:00
|
|
|
|
2012-03-26 18:44:28 +08:00
|
|
|
NS_CC_END
|
|
|
|
|