diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index a8c0c7084b..c41ad49dc7 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -8,7 +8,6 @@ LOCAL_MODULE_FILENAME := libcocos2d LOCAL_SRC_FILES := \ CCConfiguration.cpp \ -CCDrawingPrimitives.cpp \ CCScheduler.cpp \ CCCamera.cpp \ actions/CCAction.cpp \ @@ -38,6 +37,8 @@ cocoa/CCZone.cpp \ cocoa/CCArray.cpp \ cocos2d.cpp \ CCDirector.cpp \ +draw_nodes/CCDrawingPrimitives.cpp \ +draw_nodes/CCDrawNode.cpp \ effects/CCGrabber.cpp \ effects/CCGrid.cpp \ kazmath/src/aabb.c \ @@ -65,6 +66,7 @@ layers_scenes_transitions_nodes/CCTransition.cpp \ layers_scenes_transitions_nodes/CCTransitionProgress.cpp \ menu_nodes/CCMenu.cpp \ menu_nodes/CCMenuItem.cpp \ +misc_nodes/CCClippingNode.cpp \ misc_nodes/CCMotionStreak.cpp \ misc_nodes/CCProgressTimer.cpp \ misc_nodes/CCRenderTexture.cpp \ @@ -72,6 +74,8 @@ particle_nodes/CCParticleExamples.cpp \ particle_nodes/CCParticleSystem.cpp \ particle_nodes/CCParticleBatchNode.cpp \ particle_nodes/CCParticleSystemQuad.cpp \ +physics_nodes/CCPhysicsDebugNode.cpp \ +physics_nodes/CCPhysicsSprite.cpp \ platform/CCSAXParser.cpp \ platform/CCThread.cpp \ platform/platform.cpp \ diff --git a/cocos2dx/CCCamera.cpp b/cocos2dx/CCCamera.cpp index d478a3fdad..a7ac554ee9 100644 --- a/cocos2dx/CCCamera.cpp +++ b/cocos2dx/CCCamera.cpp @@ -27,7 +27,7 @@ THE SOFTWARE. #include "cocoa/CCString.h" #include "CCGL.h" -#include "CCDrawingPrimitives.h" +#include "draw_nodes/CCDrawingPrimitives.h" #include "CCDirector.h" #include "kazmath/GL/matrix.h" diff --git a/cocos2dx/draw_nodes/CCDrawNode.cpp b/cocos2dx/draw_nodes/CCDrawNode.cpp index 9052ba9eb9..2ef71917e6 100644 --- a/cocos2dx/draw_nodes/CCDrawNode.cpp +++ b/cocos2dx/draw_nodes/CCDrawNode.cpp @@ -23,6 +23,7 @@ #include "CCDrawNode.h" #include "support/CCPointExtension.h" #include "shaders/CCShaderCache.h" +#include "CCGL.h" NS_CC_BEGIN @@ -110,8 +111,10 @@ CCDrawNode::~CCDrawNode() glDeleteBuffers(1, &m_uVbo); m_uVbo = 0; +#if CC_TEXTURE_ATLAS_USE_VAO glDeleteVertexArrays(1, &m_uVao); m_uVao = 0; +#endif } CCDrawNode* CCDrawNode::create() @@ -146,8 +149,10 @@ bool CCDrawNode::init() ensureCapacity(512); +#if CC_TEXTURE_ATLAS_USE_VAO glGenVertexArrays(1, &m_uVao); ccGLBindVAO(m_uVao); +#endif glGenBuffers(1, &m_uVbo); glBindBuffer(GL_ARRAY_BUFFER, m_uVbo); @@ -163,7 +168,10 @@ bool CCDrawNode::init() glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(ccV2F_C4B_T2F), (GLvoid *)offsetof(ccV2F_C4B_T2F, texCoords)); glBindBuffer(GL_ARRAY_BUFFER, 0); + +#if CC_TEXTURE_ATLAS_USE_VAO ccGLBindVAO(0); +#endif CHECK_GL_ERROR_DEBUG(); @@ -174,16 +182,34 @@ bool CCDrawNode::init() void CCDrawNode::render() { + glBindBuffer(GL_ARRAY_BUFFER, m_uVbo); + if (m_bDirty) { - glBindBuffer(GL_ARRAY_BUFFER, m_uVbo); glBufferData(GL_ARRAY_BUFFER, sizeof(ccV2F_C4B_T2F)*m_uBufferCapacity, m_pBuffer, GL_STREAM_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); m_bDirty = false; } - + +#if CC_TEXTURE_ATLAS_USE_VAO ccGLBindVAO(m_uVao); +#else + ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex); + + // vertex + int diff = offsetof(ccV2F_C4B_T2F, vertices); + glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, sizeof(ccV2F_C4B_T2F), (GLvoid *)(m_pBuffer+diff)); + + // color + diff = offsetof(ccV2F_C4B_T2F, colors); + glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(ccV2F_C4B_T2F), (GLvoid *)(m_pBuffer+diff)); + + // texcood + diff = offsetof(ccV2F_C4B_T2F, texCoords); + glVertexAttribPointer(kCCVertexAttrib_Color, 2, GL_FLOAT, GL_FALSE, sizeof(ccV2F_C4B_T2F), (GLvoid *)(m_pBuffer+diff)); +#endif + glDrawArrays(GL_TRIANGLES, 0, m_nBufferCount); + glBindBuffer(GL_ARRAY_BUFFER, 0); CC_INCREMENT_GL_DRAWS(1); CHECK_GL_ERROR_DEBUG(); diff --git a/cocos2dx/label_nodes/CCLabelAtlas.cpp b/cocos2dx/label_nodes/CCLabelAtlas.cpp index fa3beb358f..c88bdce0b9 100644 --- a/cocos2dx/label_nodes/CCLabelAtlas.cpp +++ b/cocos2dx/label_nodes/CCLabelAtlas.cpp @@ -26,7 +26,7 @@ THE SOFTWARE. #include "CCLabelAtlas.h" #include "textures/CCTextureAtlas.h" #include "support/CCPointExtension.h" -#include "CCDrawingPrimitives.h" +#include "draw_nodes/CCDrawingPrimitives.h" #include "ccConfig.h" #include "shaders/CCShaderCache.h" #include "shaders/CCGLProgram.h" diff --git a/cocos2dx/label_nodes/CCLabelBMFont.cpp b/cocos2dx/label_nodes/CCLabelBMFont.cpp index 318fe932b7..44d2b334e7 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.cpp +++ b/cocos2dx/label_nodes/CCLabelBMFont.cpp @@ -35,7 +35,7 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only) #include "platform/platform.h" #include "cocoa/CCDictionary.h" #include "CCConfiguration.h" -#include "CCDrawingPrimitives.h" +#include "draw_nodes/CCDrawingPrimitives.h" #include "sprite_nodes/CCSprite.h" #include "support/CCPointExtension.h" #include "platform/CCFileUtils.h" diff --git a/cocos2dx/misc_nodes/CCClippingNode.cpp b/cocos2dx/misc_nodes/CCClippingNode.cpp index 74da7d1415..615c465b15 100644 --- a/cocos2dx/misc_nodes/CCClippingNode.cpp +++ b/cocos2dx/misc_nodes/CCClippingNode.cpp @@ -26,7 +26,7 @@ */ #include "CCClippingNode.h" -#import "kazmath/GL/matrix.h" +#include "kazmath/GL/matrix.h" #include "shaders/CCGLProgram.h" #include "shaders/CCShaderCache.h" #include "CCDirector.h" diff --git a/cocos2dx/misc_nodes/CCProgressTimer.cpp b/cocos2dx/misc_nodes/CCProgressTimer.cpp index a348d7175f..6f61e3ff5a 100644 --- a/cocos2dx/misc_nodes/CCProgressTimer.cpp +++ b/cocos2dx/misc_nodes/CCProgressTimer.cpp @@ -32,7 +32,7 @@ THE SOFTWARE. #include "shaders/ccGLStateCache.h" #include "CCDirector.h" #include "support/TransformUtils.h" -#include "CCDrawingPrimitives.h" +#include "draw_nodes/CCDrawingPrimitives.h" // extern #include "kazmath/GL/matrix.h" diff --git a/cocos2dx/platform/android/CCEGLView.cpp b/cocos2dx/platform/android/CCEGLView.cpp index 7b41f5ca45..49a61a0d27 100644 --- a/cocos2dx/platform/android/CCEGLView.cpp +++ b/cocos2dx/platform/android/CCEGLView.cpp @@ -36,10 +36,13 @@ THE SOFTWARE. #if CC_TEXTURE_ATLAS_USE_VAO - #include - PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT = 0; - PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = 0; - PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = 0; + +// exists since android 2.3 +#include +PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT = 0; +PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = 0; +PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = 0; + #endif void initExtensions() { diff --git a/cocos2dx/platform/android/CCGL.h b/cocos2dx/platform/android/CCGL.h index aa690cd5cc..784ce44313 100644 --- a/cocos2dx/platform/android/CCGL.h +++ b/cocos2dx/platform/android/CCGL.h @@ -25,11 +25,15 @@ THE SOFTWARE. #ifndef __CCGL_H__ #define __CCGL_H__ -#define glClearDepth glClearDepthf -#define glDeleteVertexArrays glDeleteVertexArraysOES -#define glGenVertexArrays glGenVertexArraysOES -#define glBindVertexArray glBindVertexArrayOES -#define CC_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES +#define glClearDepth glClearDepthf +#define glDeleteVertexArrays glDeleteVertexArraysOES +#define glGenVertexArrays glGenVertexArraysOES +#define glBindVertexArray glBindVertexArrayOES +#define glMapBuffer glMapBufferOES +#define glUnmapBuffer glUnmapBufferOES + +#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES +#define GL_WRITE_ONLY GL_WRITE_ONLY_OES // GL_GLEXT_PROTOTYPES isn't defined in glplatform.h on android ndk r7 // we manually define it here @@ -43,6 +47,10 @@ THE SOFTWARE. #include // gl2.h doesn't define GLchar on Android typedef char GLchar; +// android defines GL_BGRA_EXT but not GL_BRGA +#ifndef GL_BGRA +#define GL_BGRA 0x80E1 +#endif //declare here while define in CCEGLView_android.cpp extern PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT; diff --git a/cocos2dx/shaders/ccGLStateCache.cpp b/cocos2dx/shaders/ccGLStateCache.cpp index a9be1cbdd9..f4fbbf01d5 100644 --- a/cocos2dx/shaders/ccGLStateCache.cpp +++ b/cocos2dx/shaders/ccGLStateCache.cpp @@ -179,6 +179,8 @@ void ccGLDeleteTextureN(GLuint textureUnit, GLuint textureId) void ccGLBindVAO(GLuint vaoId) { +#if CC_TEXTURE_ATLAS_USE_VAO + #if CC_ENABLE_GL_STATE_CACHE if (s_uVAO != vaoId) { @@ -187,6 +189,8 @@ void ccGLBindVAO(GLuint vaoId) } #else glBindVertexArray(vaoId); +#endif // CC_ENABLE_GL_STATE_CACHE + #endif } diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 1d65408f5f..b0dd2f49d7 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -32,13 +32,12 @@ THE SOFTWARE. #include "CCSpriteFrame.h" #include "CCSpriteFrameCache.h" #include "textures/CCTextureCache.h" -#include "CCDrawingPrimitives.h" +#include "draw_nodes/CCDrawingPrimitives.h" #include "shaders/CCShaderCache.h" #include "shaders/ccGLStateCache.h" #include "shaders/CCGLProgram.h" #include "CCDirector.h" #include "support/CCPointExtension.h" -#include "CCDrawingPrimitives.h" #include "cocoa/CCGeometry.h" #include "textures/CCTexture2D.h" #include "cocoa/CCAffineTransform.h" diff --git a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp index 75df860395..897dd5ce9f 100644 --- a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. #include "ccConfig.h" #include "CCSprite.h" #include "effects/CCGrid.h" -#include "CCDrawingPrimitives.h" +#include "draw_nodes/CCDrawingPrimitives.h" #include "textures/CCTextureCache.h" #include "support/CCPointExtension.h" #include "shaders/CCShaderCache.h" diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 0d89a6d614..8b0a21fd8d 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -900,11 +900,12 @@ void VolatileTexture::reloadAllTextures() case kString: { vt->texture->initWithString(vt->m_strText.c_str(), - vt->m_size, - vt->m_alignment, - vt->m_vAlignment, - vt->m_strFontName.c_str(), - vt->m_fFontSize); + vt->m_strFontName.c_str(), + vt->m_fFontSize, + vt->m_size, + vt->m_alignment, + vt->m_vAlignment + ); } break; case kImage: