Get CCGrid to work.

This commit is contained in:
James Gregory 2013-04-08 17:51:30 -07:00
parent 4581fa7309
commit 809b77d632
1 changed files with 42 additions and 0 deletions

View File

@ -45,6 +45,16 @@ CCObject::CCObject(void)
static unsigned int uObjectCount = 0;
m_uID = ++uObjectCount;
#ifdef EMSCRIPTEN
for(int i = 0; i < BUFFER_SLOTS; i++)
{
m_bufferObject[i] = 0;
m_bufferSize[i] = 0;
m_indexBufferObject[i] = 0;
m_indexBufferSize[i] = 0;
}
#endif //EMSCRIPTEN
}
CCObject::~CCObject(void)
@ -71,6 +81,38 @@ CCObject::~CCObject(void)
}
}
#ifdef EMSCRIPTEN
void CCObject::setGLBufferData(void *buf, GLuint bufSize, int slot)
{
// WebGL doesn't support client-side arrays, so generate a buffer and load the data first.
if(m_bufferSize[slot] < bufSize)
{
if(m_bufferObject[slot])
{
glDeleteBuffers(1, &(m_bufferObject[slot]));
}
glGenBuffers(1, &(m_bufferObject[slot]));
m_bufferSize[slot] = bufSize;
}
glBindBuffer(GL_ARRAY_BUFFER, m_bufferObject[slot]);
glBufferData(GL_ARRAY_BUFFER, bufSize, buf, GL_STATIC_DRAW);
}
void CCObject::setGLIndexData(void *buf, GLuint bufSize, int slot)
{
// WebGL doesn't support client-side arrays, so generate a buffer and load the data first.
if(m_indexBufferSize[slot] < bufSize)
{
if(m_indexBufferObject[slot])
{
glDeleteBuffers(1, &(m_indexBufferObject[slot]));
}
glGenBuffers(1, &(m_indexBufferObject[slot]));
m_indexBufferSize[slot] = bufSize;
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBufferObject[slot]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufSize, buf, GL_STATIC_DRAW);
}
#endif // EMSCRIPTEN
CCObject* CCObject::copy()
{
return copyWithZone(0);