diff --git a/AUTHORS b/AUTHORS index e857757e3c..e6bebcaae3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -597,6 +597,7 @@ Developers: bmanGH Use gl caching functions in TexturePVR::createGLTexture() + Configuration of VAO in runtime metadao make create_project.py more pythonic and fix some typoes diff --git a/CHANGELOG b/CHANGELOG index e06e8d0e37..c0f33125bf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,13 +14,14 @@ cocos2d-x-3.0alpha1 @??? 2013 [FIX] When parsing XML using TinyXML, the data size has to be specified. [FIX] Parameter type: const char* -> const string& [FIX] Armature: many bug fixed, add more samples, add function to skip some frames when playing animation + [FIX] Configuration of VAO in runtime + [FIX] Webp Test Crashes. [NEW] Arm64 support. [NEW] Added Mouse Support For Desktop Platforms. [NEW] Point: Adds ANCHOR_XXX constants like ANCHOR_MIDDLE, ANCHOR_TOP_RIGHT, etc. [NEW] Sprite: Override setScale(float scaleX, float scaleY) [NEW] External: added | operator for Control::EventType [NEW] Android & iOS screen size change support - [FIX] Webp Test Crashes. [Android] [FIX] Added EGL_RENDERABLE_TYPE to OpenGL attributes [FIX] Fixed application will crash when pause and resume. diff --git a/cocos/2d/CCConfiguration.cpp b/cocos/2d/CCConfiguration.cpp index 6e5b5cf966..48b4156ca5 100644 --- a/cocos/2d/CCConfiguration.cpp +++ b/cocos/2d/CCConfiguration.cpp @@ -259,7 +259,11 @@ bool Configuration::supportsDiscardFramebuffer() const bool Configuration::supportsShareableVAO() const { - return _supportsShareableVAO; + #if CC_TEXTURE_ATLAS_USE_VAO + return _supportsShareableVAO; + #else + return false; + #endif } // diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index d373709686..67ba1075b1 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -25,6 +25,7 @@ #include "CCGL.h" #include "CCNotificationCenter.h" #include "CCEventType.h" +#include "CCConfiguration.h" NS_CC_BEGIN @@ -114,11 +115,12 @@ 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 +161,11 @@ 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 +182,10 @@ 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 +210,24 @@ 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); diff --git a/cocos/2d/CCEventListener.h b/cocos/2d/CCEventListener.h index 04a1a779a4..a24b709e5b 100644 --- a/cocos/2d/CCEventListener.h +++ b/cocos/2d/CCEventListener.h @@ -57,7 +57,7 @@ public: CUSTOM }; - typedef int ListenerID; + typedef std::size_t ListenerID; protected: /** Constructor */ diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index 3cf7d9e1d4..36d2567809 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -37,6 +37,7 @@ THE SOFTWARE. #include "TransformUtils.h" #include "CCNotificationCenter.h" #include "CCEventType.h" +#include "CCConfiguration.h" // extern #include "kazmath/GL/matrix.h" @@ -57,11 +58,14 @@ 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 +85,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 +97,11 @@ 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 +358,48 @@ 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_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]); - 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]); + 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 +458,14 @@ 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 +475,6 @@ void ParticleSystemQuad::setTotalParticles(int tp) resetSystem(); } -#if CC_TEXTURE_ATLAS_USE_VAO void ParticleSystemQuad::setupVBOandVAO() { // clean VAO @@ -508,7 +514,6 @@ void ParticleSystemQuad::setupVBOandVAO() CHECK_GL_ERROR_DEBUG(); } -#else void ParticleSystemQuad::setupVBO() { @@ -527,15 +532,16 @@ 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 +584,14 @@ 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 +606,12 @@ 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; + } } } } diff --git a/cocos/2d/CCParticleSystemQuad.h b/cocos/2d/CCParticleSystemQuad.h index 0106118b43..594810cf96 100644 --- a/cocos/2d/CCParticleSystemQuad.h +++ b/cocos/2d/CCParticleSystemQuad.h @@ -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 }; diff --git a/cocos/2d/CCTextureAtlas.cpp b/cocos/2d/CCTextureAtlas.cpp index efb944db25..ec42b9dbfd 100644 --- a/cocos/2d/CCTextureAtlas.cpp +++ b/cocos/2d/CCTextureAtlas.cpp @@ -34,6 +34,7 @@ THE SOFTWARE. #include "CCEventType.h" #include "CCDirector.h" #include "CCGL.h" +#include "CCConfiguration.h" // support #include "CCTexture2D.h" #include "CCString.h" @@ -61,10 +62,11 @@ 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 @@ -191,11 +193,14 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, long capacity) this->setupIndices(); -#if CC_TEXTURE_ATLAS_USE_VAO - setupVBOandVAO(); -#else - setupVBO(); -#endif + if (Configuration::getInstance()->supportsShareableVAO()) + { + setupVBOandVAO(); + } + else + { + setupVBO(); + } _dirty = true; @@ -204,11 +209,14 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, long 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; @@ -249,7 +257,6 @@ void TextureAtlas::setupIndices() //TextureAtlas - VAO / VBO specific -#if CC_TEXTURE_ATLAS_USE_VAO void TextureAtlas::setupVBOandVAO() { glGenVertexArrays(1, &_VAOname); @@ -284,14 +291,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() { @@ -604,90 +610,89 @@ void TextureAtlas::drawNumberOfQuads(long numberOfQuads, long start) GL::bindTexture2D(_texture->getName()); -#if CC_TEXTURE_ATLAS_USE_VAO - - // - // Using VBO and VAO - // - - // XXX: update is done in draw... perhaps it should be done in a timer - if (_dirty) + if (Configuration::getInstance()->supportsShareableVAO()) { - 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); + // + // Using VBO and VAO + // - _dirty = false; - } + // 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 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); - GL::bindVAO(_VAOname); + _dirty = false; + } + + 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(); diff --git a/cocos/2d/CCTextureAtlas.h b/cocos/2d/CCTextureAtlas.h index 2d5e273ff2..b7b74af225 100644 --- a/cocos/2d/CCTextureAtlas.h +++ b/cocos/2d/CCTextureAtlas.h @@ -219,17 +219,12 @@ 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 */ diff --git a/cocos/2d/ccGLStateCache.cpp b/cocos/2d/ccGLStateCache.cpp index 0e8054bd40..c4de9784b8 100644 --- a/cocos/2d/ccGLStateCache.cpp +++ b/cocos/2d/ccGLStateCache.cpp @@ -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,20 @@ 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 diff --git a/cocos/2d/platform/android/CCEGLView.cpp b/cocos/2d/platform/android/CCEGLView.cpp index 0347d70a87..c22babd3c1 100644 --- a/cocos/2d/platform/android/CCEGLView.cpp +++ b/cocos/2d/platform/android/CCEGLView.cpp @@ -33,23 +33,16 @@ THE SOFTWARE. #include - -#if CC_TEXTURE_ATLAS_USE_VAO - // exists since android 2.3 #include 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 diff --git a/cocos/2d/platform/ios/EAGLView.mm b/cocos/2d/platform/ios/EAGLView.mm index 5536a63752..f16f399b7d 100644 --- a/cocos/2d/platform/ios/EAGLView.mm +++ b/cocos/2d/platform/ios/EAGLView.mm @@ -237,8 +237,11 @@ static CCEAGLView *__view = 0; context_ = [renderer_ context]; - - //discardFramebufferSupported_ = [[Configuration sharedConfiguration] supportsDiscardFramebuffer]; + #if GL_EXT_discard_framebuffer == 1 + discardFramebufferSupported_ = YES; + #else + discardFramebufferSupported_ = NO; + #endif CHECK_GL_ERROR(); @@ -288,7 +291,7 @@ static CCEAGLView *__view = 0; glResolveMultisampleFramebufferAPPLE(); } - if( discardFramebufferSupported_) + if(discardFramebufferSupported_) { if (multiSampling_) { diff --git a/docs/CODING_STYLE.md.REMOVED.git-id b/docs/CODING_STYLE.md.REMOVED.git-id index 2a00974e4b..14fe782823 100644 --- a/docs/CODING_STYLE.md.REMOVED.git-id +++ b/docs/CODING_STYLE.md.REMOVED.git-id @@ -1 +1 @@ -f86eb12e6d4835f93bd6f59d860970bcd2f74128 \ No newline at end of file +811c4efefbe80ac5bcc88d74e56cc093166dd64a \ No newline at end of file