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 bool Configuration::supportsShareableVAO() const
{ {
#if CC_TEXTURE_ATLAS_USE_VAO
return _supportsShareableVAO; return _supportsShareableVAO;
#else
return false;
#endif
} }
// //

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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