use Configuration::getInstance()->supportsShareableVAO() in place of CC_TEXTURE_ATLAS_USE_VAO;

This commit is contained in:
bmanGH 2013-10-13 11:47:51 +08:00
parent 072c4503c3
commit aa68544b43
8 changed files with 171 additions and 189 deletions

View File

@ -259,7 +259,11 @@ bool Configuration::supportsDiscardFramebuffer() const
bool Configuration::supportsShareableVAO() const
{
#if CC_TEXTURE_ATLAS_USE_VAO
return _supportsShareableVAO;
#else
return false;
#endif
}
//

View File

@ -25,6 +25,7 @@
#include "CCGL.h"
#include "support/CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCConfiguration.h"
NS_CC_BEGIN
@ -114,11 +115,11 @@ DrawNode::~DrawNode()
glDeleteBuffers(1, &_vbo);
_vbo = 0;
#if CC_TEXTURE_ATLAS_USE_VAO
glDeleteVertexArrays(1, &_vao);
GL::bindVAO(0);
_vao = 0;
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
glDeleteVertexArrays(1, &_vao);
GL::bindVAO(0);
_vao = 0;
}
#if CC_ENABLE_CACHE_TEXTURE_DATA
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
@ -159,10 +160,10 @@ bool DrawNode::init()
ensureCapacity(512);
#if CC_TEXTURE_ATLAS_USE_VAO
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
}
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
@ -179,9 +180,9 @@ bool DrawNode::init()
glBindBuffer(GL_ARRAY_BUFFER, 0);
#if CC_TEXTURE_ATLAS_USE_VAO
GL::bindVAO(0);
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
GL::bindVAO(0);
}
CHECK_GL_ERROR_DEBUG();
@ -206,21 +207,22 @@ void DrawNode::render()
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacity, _buffer, GL_STREAM_DRAW);
_dirty = false;
}
#if CC_TEXTURE_ATLAS_USE_VAO
GL::bindVAO(_vao);
#else
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
if (Configuration::getInstance()->supportsShareableVAO()) {
GL::bindVAO(_vao);
}
else {
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
// vertex
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
// vertex
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// color
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
#endif
// texcood
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
}
glDrawArrays(GL_TRIANGLES, 0, _bufferCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);

View File

@ -37,6 +37,7 @@ THE SOFTWARE.
#include "support/TransformUtils.h"
#include "support/CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCConfiguration.h"
// extern
#include "kazmath/GL/matrix.h"
@ -57,11 +58,12 @@ bool ParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles)
}
initIndices();
#if CC_TEXTURE_ATLAS_USE_VAO
setupVBOandVAO();
#else
setupVBO();
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
setupVBOandVAO();
}
else {
setupVBO();
}
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
@ -81,9 +83,7 @@ bool ParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles)
ParticleSystemQuad::ParticleSystemQuad()
:_quads(NULL)
,_indices(NULL)
#if CC_TEXTURE_ATLAS_USE_VAO
,_VAOname(0)
#endif
{
memset(_buffersVBO, 0, sizeof(_buffersVBO));
}
@ -95,10 +95,10 @@ ParticleSystemQuad::~ParticleSystemQuad()
CC_SAFE_FREE(_quads);
CC_SAFE_FREE(_indices);
glDeleteBuffers(2, &_buffersVBO[0]);
#if CC_TEXTURE_ATLAS_USE_VAO
glDeleteVertexArrays(1, &_VAOname);
GL::bindVAO(0);
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
glDeleteVertexArrays(1, &_VAOname);
GL::bindVAO(0);
}
}
#if CC_ENABLE_CACHE_TEXTURE_DATA
@ -355,47 +355,46 @@ void ParticleSystemQuad::draw()
CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad");
#if CC_TEXTURE_ATLAS_USE_VAO
//
// Using VBO and VAO
//
GL::bindVAO(_VAOname);
if (Configuration::getInstance()->supportsShareableVAO()) {
//
// Using VBO and VAO
//
GL::bindVAO(_VAOname);
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
#endif
glDrawElements(GL_TRIANGLES, (GLsizei) _particleIdx*6, GL_UNSIGNED_SHORT, 0);
glDrawElements(GL_TRIANGLES, (GLsizei) _particleIdx*6, GL_UNSIGNED_SHORT, 0);
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif
}
else {
//
// Using VBO without VAO
//
#else
//
// Using VBO without VAO
//
#define kQuadSize sizeof(_quads[0].bl)
#define kQuadSize sizeof(_quads[0].bl)
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
// vertices
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices));
// colors
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors));
// tex coords
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
// vertices
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices));
// colors
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors));
// tex coords
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
glDrawElements(GL_TRIANGLES, (GLsizei) _particleIdx*6, GL_UNSIGNED_SHORT, 0);
glDrawElements(GL_TRIANGLES, (GLsizei) _particleIdx*6, GL_UNSIGNED_SHORT, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
CC_INCREMENT_GL_DRAWS(1);
CHECK_GL_ERROR_DEBUG();
@ -454,11 +453,12 @@ void ParticleSystemQuad::setTotalParticles(int tp)
}
initIndices();
#if CC_TEXTURE_ATLAS_USE_VAO
setupVBOandVAO();
#else
setupVBO();
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
setupVBOandVAO();
}
else {
setupVBO();
}
}
else
{
@ -468,7 +468,6 @@ void ParticleSystemQuad::setTotalParticles(int tp)
resetSystem();
}
#if CC_TEXTURE_ATLAS_USE_VAO
void ParticleSystemQuad::setupVBOandVAO()
{
// clean VAO
@ -508,7 +507,6 @@ void ParticleSystemQuad::setupVBOandVAO()
CHECK_GL_ERROR_DEBUG();
}
#else
void ParticleSystemQuad::setupVBO()
{
@ -527,15 +525,14 @@ void ParticleSystemQuad::setupVBO()
CHECK_GL_ERROR_DEBUG();
}
#endif
void ParticleSystemQuad::listenBackToForeground(Object *obj)
{
#if CC_TEXTURE_ATLAS_USE_VAO
if (Configuration::getInstance()->supportsShareableVAO()) {
setupVBOandVAO();
#else
}
else {
setupVBO();
#endif
}
}
bool ParticleSystemQuad::allocMemory()
@ -578,11 +575,12 @@ void ParticleSystemQuad::setBatchNode(ParticleBatchNode * batchNode)
allocMemory();
initIndices();
setTexture(oldBatch->getTexture());
#if CC_TEXTURE_ATLAS_USE_VAO
setupVBOandVAO();
#else
setupVBO();
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
setupVBOandVAO();
}
else {
setupVBO();
}
}
// OLD: was it self render ? cleanup
else if( !oldBatch )
@ -597,11 +595,11 @@ void ParticleSystemQuad::setBatchNode(ParticleBatchNode * batchNode)
glDeleteBuffers(2, &_buffersVBO[0]);
memset(_buffersVBO, 0, sizeof(_buffersVBO));
#if CC_TEXTURE_ATLAS_USE_VAO
glDeleteVertexArrays(1, &_VAOname);
GL::bindVAO(0);
_VAOname = 0;
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
glDeleteVertexArrays(1, &_VAOname);
GL::bindVAO(0);
_VAOname = 0;
}
}
}
}

View File

@ -135,20 +135,15 @@ public:
virtual void setTotalParticles(int tp) override;
private:
#if CC_TEXTURE_ATLAS_USE_VAO
void setupVBOandVAO();
#else
void setupVBO();
#endif
bool allocMemory();
protected:
V3F_C4B_T2F_Quad *_quads; // quads to be rendered
GLushort *_indices; // indices
#if CC_TEXTURE_ATLAS_USE_VAO
GLuint _VAOname;
#endif
GLuint _buffersVBO[2]; //0: vertex 1: indices
};

View File

@ -33,23 +33,16 @@ THE SOFTWARE.
#include <android/log.h>
#if CC_TEXTURE_ATLAS_USE_VAO
// <EGL/egl.h> exists since android 2.3
#include <EGL/egl.h>
PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT = 0;
PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = 0;
PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = 0;
#endif
void initExtensions() {
#if CC_TEXTURE_ATLAS_USE_VAO
glGenVertexArraysOESEXT = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
glBindVertexArrayOESEXT = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
glDeleteVertexArraysOESEXT = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");
#endif
}
NS_CC_BEGIN

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
#include "CCGLProgram.h"
#include "CCDirector.h"
#include "ccConfig.h"
#include "CCConfiguration.h"
// extern
#include "kazmath/GL/matrix.h"
@ -50,9 +51,7 @@ static GLuint s_uCurrentBoundTexture[kMaxActiveTexture] = {(GLuint)-1,(GLuin
static GLenum s_eBlendingSource = -1;
static GLenum s_eBlendingDest = -1;
static int s_eGLServerState = 0;
#if CC_TEXTURE_ATLAS_USE_VAO
static GLuint s_uVAO = 0;
#endif
#endif // CC_ENABLE_GL_STATE_CACHE
// GL State Cache functions
@ -78,9 +77,7 @@ void invalidateStateCache( void )
s_eBlendingSource = -1;
s_eBlendingDest = -1;
s_eGLServerState = 0;
#if CC_TEXTURE_ATLAS_USE_VAO
s_uVAO = 0;
#endif
#endif // CC_ENABLE_GL_STATE_CACHE
}
@ -187,19 +184,19 @@ void deleteTextureN(GLuint textureUnit, GLuint textureId)
void bindVAO(GLuint vaoId)
{
#if CC_TEXTURE_ATLAS_USE_VAO
if (Configuration::getInstance()->supportsShareableVAO()) {
#if CC_ENABLE_GL_STATE_CACHE
if (s_uVAO != vaoId)
{
s_uVAO = vaoId;
glBindVertexArray(vaoId);
}
if (s_uVAO != vaoId)
{
s_uVAO = vaoId;
glBindVertexArray(vaoId);
}
#else
glBindVertexArray(vaoId);
glBindVertexArray(vaoId);
#endif // CC_ENABLE_GL_STATE_CACHE
#endif
}
}
//#pragma mark - GL Vertex Attrib functions

View File

@ -33,6 +33,7 @@ THE SOFTWARE.
#include "support/CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCGL.h"
#include "CCConfiguration.h"
// support
#include "CCTexture2D.h"
#include "cocoa/CCString.h"
@ -60,10 +61,10 @@ TextureAtlas::~TextureAtlas()
glDeleteBuffers(2, _buffersVBO);
#if CC_TEXTURE_ATLAS_USE_VAO
glDeleteVertexArrays(1, &_VAOname);
GL::bindVAO(0);
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
glDeleteVertexArrays(1, &_VAOname);
GL::bindVAO(0);
}
CC_SAFE_RELEASE(_texture);
#if CC_ENABLE_CACHE_TEXTURE_DATA
@ -190,11 +191,12 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, int capacity)
this->setupIndices();
#if CC_TEXTURE_ATLAS_USE_VAO
setupVBOandVAO();
#else
setupVBO();
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
setupVBOandVAO();
}
else {
setupVBO();
}
_dirty = true;
@ -203,11 +205,12 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, int capacity)
void TextureAtlas::listenBackToForeground(Object *obj)
{
#if CC_TEXTURE_ATLAS_USE_VAO
setupVBOandVAO();
#else
setupVBO();
#endif
if (Configuration::getInstance()->supportsShareableVAO()) {
setupVBOandVAO();
}
else {
setupVBO();
}
// set _dirty to true to force it rebinding buffer
_dirty = true;
@ -248,7 +251,6 @@ void TextureAtlas::setupIndices()
//TextureAtlas - VAO / VBO specific
#if CC_TEXTURE_ATLAS_USE_VAO
void TextureAtlas::setupVBOandVAO()
{
glGenVertexArrays(1, &_VAOname);
@ -283,14 +285,13 @@ void TextureAtlas::setupVBOandVAO()
CHECK_GL_ERROR_DEBUG();
}
#else // CC_TEXTURE_ATLAS_USE_VAO
void TextureAtlas::setupVBO()
{
glGenBuffers(2, &_buffersVBO[0]);
mapBuffers();
}
#endif // ! // CC_TEXTURE_ATLAS_USE_VAO
void TextureAtlas::mapBuffers()
{
@ -603,90 +604,87 @@ void TextureAtlas::drawNumberOfQuads(int numberOfQuads, int start)
GL::bindTexture2D(_texture->getName());
#if CC_TEXTURE_ATLAS_USE_VAO
if (Configuration::getInstance()->supportsShareableVAO()) {
//
// Using VBO and VAO
//
//
// Using VBO and VAO
//
// XXX: update is done in draw... perhaps it should be done in a timer
if (_dirty)
{
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
// option 1: subdata
//glBufferSubData(GL_ARRAY_BUFFER, sizeof(_quads[0])*start, sizeof(_quads[0]) * n , &_quads[start] );
// XXX: update is done in draw... perhaps it should be done in a timer
if (_dirty)
{
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
// option 1: subdata
//glBufferSubData(GL_ARRAY_BUFFER, sizeof(_quads[0])*start, sizeof(_quads[0]) * n , &_quads[start] );
// option 2: data
// glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * (n-start), &quads_[start], GL_DYNAMIC_DRAW);
// option 2: data
// glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * (n-start), &quads_[start], GL_DYNAMIC_DRAW);
// option 3: orphaning + glMapBuffer
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * (numberOfQuads-start), NULL, GL_DYNAMIC_DRAW);
void *buf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
memcpy(buf, _quads, sizeof(_quads[0])* (numberOfQuads-start));
glUnmapBuffer(GL_ARRAY_BUFFER);
// option 3: orphaning + glMapBuffer
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * (numberOfQuads-start), NULL, GL_DYNAMIC_DRAW);
void *buf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
memcpy(buf, _quads, sizeof(_quads[0])* (numberOfQuads-start));
glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
_dirty = false;
}
_dirty = false;
}
GL::bindVAO(_VAOname);
GL::bindVAO(_VAOname);
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
#endif
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) numberOfQuads*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])) );
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) numberOfQuads*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])) );
#else
glDrawElements(GL_TRIANGLES, (GLsizei) numberOfQuads*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])) );
glDrawElements(GL_TRIANGLES, (GLsizei) numberOfQuads*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])) );
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
#if CC_REBIND_INDICES_BUFFER
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif
// glBindVertexArray(0);
#else // ! CC_TEXTURE_ATLAS_USE_VAO
//
// Using VBO without VAO
//
}
else {
//
// Using VBO without VAO
//
#define kQuadSize sizeof(_quads[0].bl)
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
// XXX: update is done in draw... perhaps it should be done in a timer
if (_dirty)
{
glBufferSubData(GL_ARRAY_BUFFER, sizeof(_quads[0])*start, sizeof(_quads[0]) * numberOfQuads , &_quads[start] );
_dirty = false;
}
// XXX: update is done in draw... perhaps it should be done in a timer
if (_dirty)
{
glBufferSubData(GL_ARRAY_BUFFER, sizeof(_quads[0])*start, sizeof(_quads[0]) * numberOfQuads , &_quads[start] );
_dirty = false;
}
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
// vertices
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, vertices));
// vertices
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, vertices));
// colors
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, colors));
// colors
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, colors));
// tex coords
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, texCoords));
// tex coords
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, texCoords));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei)numberOfQuads*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])));
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei)numberOfQuads*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])));
#else
glDrawElements(GL_TRIANGLES, (GLsizei)numberOfQuads*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])));
glDrawElements(GL_TRIANGLES, (GLsizei)numberOfQuads*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(_indices[0])));
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif // CC_TEXTURE_ATLAS_USE_VAO
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
CC_INCREMENT_GL_DRAWS(1);
CHECK_GL_ERROR_DEBUG();

View File

@ -217,17 +217,12 @@ public:
private:
void setupIndices();
void mapBuffers();
#if CC_TEXTURE_ATLAS_USE_VAO
void setupVBOandVAO();
#else
void setupVBO();
#endif
protected:
GLushort* _indices;
#if CC_TEXTURE_ATLAS_USE_VAO
GLuint _VAOname;
#endif
GLuint _buffersVBO[2]; //0: vertex 1: indices
bool _dirty; //indicates whether or not the array buffer of the VBO needs to be updated
/** quantity of quads that are going to be drawn */