From 74aaf4c6cadca62ca0e9a85a8fc490961c391276 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 20 Mar 2012 16:10:12 +0800 Subject: [PATCH 1/2] issue #1056:gles20 runs ok on android --- HelloWorld/android/AndroidManifest.xml | 2 +- HelloWorld/android/build_native.sh | 2 +- HelloWorld/android/default.properties | 2 - HelloWorld/android/project.properties | 11 ++++++ .../cocos2dx/application/ApplicationDemo.java | 35 +++++++++++++---- .../cocos2dx/lib/Cocos2dxGLSurfaceView.java | 9 +++-- cocos2dx/Android.mk | 34 +++++++++++++---- cocos2dx/{shaders => include}/ccShaders.h | 0 cocos2dx/include/cocos2d.h | 1 + .../include/kazmath/neon_matrix_impl.h | 6 ++- cocos2dx/platform/CCGL.h | 24 ++++++++---- cocos2dx/platform/CCPlatformConfig.h | 22 +++-------- .../platform/android/CCEGLView_android.cpp | 16 +++++++- cocos2dx/proj.win32/cocos2d-win32.vcproj | 4 -- lua/cocos2dx_support/CCLuaEngine.cpp | 4 +- tests/Android.mk | 28 +------------- tests/test.android/AndroidManifest.xml | 2 +- tests/test.android/build_native.sh | 4 +- tests/test.android/default.properties | 2 - tests/test.android/project.properties | 11 ++++++ .../cocos2dx/lib/Cocos2dxGLSurfaceView.java | 9 +++-- .../src/org/cocos2dx/tests/TestsDemo.java | 38 +++++++++++++++---- 22 files changed, 169 insertions(+), 97 deletions(-) delete mode 100644 HelloWorld/android/default.properties create mode 100644 HelloWorld/android/project.properties rename cocos2dx/{shaders => include}/ccShaders.h (100%) delete mode 100644 tests/test.android/default.properties create mode 100644 tests/test.android/project.properties diff --git a/HelloWorld/android/AndroidManifest.xml b/HelloWorld/android/AndroidManifest.xml index 522dad8cbd..c0d0c51ab1 100644 --- a/HelloWorld/android/AndroidManifest.xml +++ b/HelloWorld/android/AndroidManifest.xml @@ -4,7 +4,7 @@ android:versionCode="1" android:versionName="1.0"> - + = 0x20000); + } static { System.loadLibrary("cocosdenshion"); diff --git a/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java b/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java index ef43af7835..e7c4721cf3 100644 --- a/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java +++ b/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java @@ -144,11 +144,14 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView { super(context, attrs); initView(); } + + public void setCocos2dxRenderer(Cocos2dxRenderer renderer){ + mRenderer = renderer; + setRenderer(mRenderer); + } - protected void initView() { - mRenderer = new Cocos2dxRenderer(); + protected void initView() { setFocusableInTouchMode(true); - setRenderer(mRenderer); textInputWraper = new TextInputWraper(this); diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index 801defc7aa..97dabc5447 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -37,6 +37,22 @@ CCDirector.cpp \ effects/CCGrabber.cpp \ effects/CCGrid.cpp \ extensions/CCNotificationCenter.cpp \ +gles2/CCGLProgram.cpp \ +gles2/ccGLStateCache.cpp \ +gles2/CCShaderCache.cpp \ +kazmath/src/aabb.c \ +kazmath/src/mat3.c \ +kazmath/src/mat4.c \ +kazmath/src/neon_matrix_impl.c \ +kazmath/src/plane.c \ +kazmath/src/quaternion.c \ +kazmath/src/ray2.c \ +kazmath/src/utility.c \ +kazmath/src/vec2.c \ +kazmath/src/vec3.c \ +kazmath/src/vec4.c \ +kazmath/src/GL/mat4stack.c \ +kazmath/src/GL/matrix.c \ keypad_dispatcher/CCKeypadDelegate.cpp \ keypad_dispatcher/CCKeypadDispatcher.cpp \ label_nodes/CCLabelAtlas.cpp \ @@ -45,17 +61,15 @@ label_nodes/CCLabelTTF.cpp \ layers_scenes_transitions_nodes/CCLayer.cpp \ layers_scenes_transitions_nodes/CCScene.cpp \ layers_scenes_transitions_nodes/CCTransitionPageTurn.cpp \ -layers_scenes_transitions_nodes/CCTransitionRadial.cpp \ layers_scenes_transitions_nodes/CCTransition.cpp \ menu_nodes/CCMenu.cpp \ menu_nodes/CCMenuItem.cpp \ misc_nodes/CCMotionStreak.cpp \ misc_nodes/CCProgressTimer.cpp \ misc_nodes/CCRenderTexture.cpp \ -misc_nodes/CCRibbon.cpp \ particle_nodes/CCParticleExamples.cpp \ particle_nodes/CCParticleSystem.cpp \ -particle_nodes/CCParticleSystemPoint.cpp \ +particle_nodes/CCParticleBatchNode.cpp \ particle_nodes/CCParticleSystemQuad.cpp \ platform/CCFileUtils.cpp \ platform/CCGL.cpp \ @@ -75,6 +89,7 @@ platform/android/jni/SensorJni.cpp \ platform/android/jni/SystemInfoJni.cpp \ platform/android/jni/TouchesJni.cpp \ script_support/CCScriptSupport.cpp \ +shaders/ccShaders.cpp \ sprite_nodes/CCAnimation.cpp \ sprite_nodes/CCAnimationCache.cpp \ sprite_nodes/CCSprite.cpp \ @@ -88,6 +103,7 @@ support/TransformUtils.cpp \ support/CCUserDefault.cpp \ support/base64.cpp \ support/ccUtils.cpp \ +support/CCVertex.cpp \ support/image_support/TGAlib.cpp \ support/zip_support/ZipUtils.cpp \ support/zip_support/ioapi.cpp \ @@ -109,17 +125,21 @@ touch_dispatcher/CCTouchHandler.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ \ $(LOCAL_PATH)/include \ - $(LOCAL_PATH)/platform + $(LOCAL_PATH)/platform \ + $(LOCAL_PATH)/kazmath/include LOCAL_EXPORT_LDLIBS := -llog\ -lz \ - -lGLESv1_CM + -lGLESv2 \ + -lEGL LOCAL_C_INCLUDES := $(LOCAL_PATH)/ \ $(LOCAL_PATH)/include \ - $(LOCAL_PATH)/platform + $(LOCAL_PATH)/platform \ + $(LOCAL_PATH)/kazmath/include -LOCAL_LDLIBS := -lGLESv1_CM \ +LOCAL_LDLIBS := -lGLESv2 \ + -lEGL \ -llog \ -lz diff --git a/cocos2dx/shaders/ccShaders.h b/cocos2dx/include/ccShaders.h similarity index 100% rename from cocos2dx/shaders/ccShaders.h rename to cocos2dx/include/ccShaders.h diff --git a/cocos2dx/include/cocos2d.h b/cocos2dx/include/cocos2d.h index b780bf451b..1c5fb8a5b8 100755 --- a/cocos2dx/include/cocos2d.h +++ b/cocos2dx/include/cocos2d.h @@ -114,6 +114,7 @@ THE SOFTWARE. #include "CCImage.h" #include "CCFileUtils.h" #include "CCAccelerometer.h" +#include "CCGL.h" // extensions #include "extensions/CCNotificationCenter.h" diff --git a/cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h b/cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h index 3fcf3e4459..0a7e605820 100644 --- a/cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h +++ b/cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h @@ -25,8 +25,12 @@ #define __NEON_MATRIX_IMPL_H__ #ifdef __arm__ +#ifdef ANDROID +// android don't have arm/arch.h but it defines __arm__ +#else #include "arm/arch.h" -#endif +#endif //ANDROID +#endif // __arm__ // Matrixes are assumed to be stored in column major format according to OpenGL // specification. diff --git a/cocos2dx/platform/CCGL.h b/cocos2dx/platform/CCGL.h index c33322e9ad..92715f3722 100644 --- a/cocos2dx/platform/CCGL.h +++ b/cocos2dx/platform/CCGL.h @@ -47,18 +47,26 @@ THE SOFTWARE. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // GL_GLEXT_PROTOTYPES isn't defined in glplatform.h on android ndk r7 // we manually define it here -#include +#include #ifndef GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES 1 #endif -// normal process -#include -#include -#endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE) -#include -#include +// normal process +#include +#include +// gl2.h don't define GLchar on Android +typedef char GLchar; + +//declare here while define in CCEGLView_android.cpp +extern PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT; +extern PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT; +extern PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT; + +#define glGenVertexArraysOES glGenVertexArraysOESEXT +#define glBindVertexArrayOES glBindVertexArrayOESEXT +#define glDeleteVertexArraysOES glDeleteVertexArraysOESEXT + #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) diff --git a/cocos2dx/platform/CCPlatformConfig.h b/cocos2dx/platform/CCPlatformConfig.h index 10666efc85..ed12c4552c 100644 --- a/cocos2dx/platform/CCPlatformConfig.h +++ b/cocos2dx/platform/CCPlatformConfig.h @@ -40,12 +40,11 @@ build for which target platform #define CC_PLATFORM_UNKNOWN 0 #define CC_PLATFORM_IOS 1 #define CC_PLATFORM_ANDROID 2 -#define CC_PLATFORM_WOPHONE 3 -#define CC_PLATFORM_WIN32 4 -#define CC_PLATFORM_MARMALADE 5 -#define CC_PLATFORM_LINUX 6 -#define CC_PLATFORM_BADA 7 -#define CC_PLATFORM_QNX 8 +#define CC_PLATFORM_WIN32 3 +#define CC_PLATFORM_MARMALADE 4 +#define CC_PLATFORM_LINUX 5 +#define CC_PLATFORM_BADA 6 +#define CC_PLATFORM_QNX 7 // Determine tartet platform by compile environment macro. #define CC_TARGET_PLATFORM CC_PLATFORM_UNKNOWN @@ -65,12 +64,6 @@ build for which target platform #define CC_TARGET_PLATFORM CC_PLATFORM_ANDROID #endif -// wophone -#if ! CC_TARGET_PLATFORM && defined(_TRANZDA_VM_) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_WOPHONE -#endif - // win32 #if ! CC_TARGET_PLATFORM && (defined(WIN32) && defined(_WINDOWS)) #undef CC_TARGET_PLATFORM @@ -122,11 +115,6 @@ build for which target platform #define CC_TARGET_PLATFORM CC_PLATFORM_ANDROID #endif -#if defined(CC_UNDER_WOPHONE) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_WOPHONE -#endif - #if defined(CC_UNDER_WIN32) #undef CC_TARGET_PLATFORM #define CC_TARGET_PLATFORM CC_PLATFORM_WIN32 diff --git a/cocos2dx/platform/android/CCEGLView_android.cpp b/cocos2dx/platform/android/CCEGLView_android.cpp index 2a63b60863..5ead4600d7 100644 --- a/cocos2dx/platform/android/CCEGLView_android.cpp +++ b/cocos2dx/platform/android/CCEGLView_android.cpp @@ -22,7 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #include "CCEGLView_android.h" -#include "GLES/gl.h" #include "CCSet.h" #include "CCDirector.h" #include "ccMacros.h" @@ -31,6 +30,20 @@ THE SOFTWARE. #include "jni/MessageJni.h" #include +#include +#include +#include +#include + +PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT = 0; +PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = 0; +PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = 0; + +void initExtensions() { + glGenVertexArraysOESEXT = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES"); + glBindVertexArrayOESEXT = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES"); + glDeleteVertexArraysOESEXT = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES"); +} namespace cocos2d { @@ -39,6 +52,7 @@ CCEGLView::CCEGLView() m_pDelegate(NULL), m_fScreenScaleFactor(1.0) { + initExtensions(); } void CCEGLView::setFrameWidthAndHeight(int width, int height) diff --git a/cocos2dx/proj.win32/cocos2d-win32.vcproj b/cocos2dx/proj.win32/cocos2d-win32.vcproj index 7bc0e29028..512285ec2b 100644 --- a/cocos2dx/proj.win32/cocos2d-win32.vcproj +++ b/cocos2dx/proj.win32/cocos2d-win32.vcproj @@ -1255,10 +1255,6 @@ RelativePath="..\shaders\ccShaders.cpp" > - - convertToGL(pTouch->locationInView(pTouch->view())); + CCPoint pt = CCDirector::sharedDirector()->convertToGL(pTouch->locationInView()); lua_pushinteger(m_state, eventType); lua_pushnumber(m_state, pt.x); lua_pushnumber(m_state, pt.y); @@ -271,7 +271,7 @@ int CCLuaEngine::executeTouchesEvent(int nHandler, int eventType, CCSet *pTouche while (it != pTouches->end()) { pTouch = (CCTouch*)*it; - CCPoint pt = pDirector->convertToGL(pTouch->locationInView(pTouch->view())); + CCPoint pt = pDirector->convertToGL(pTouch->locationInView()); lua_pushnumber(m_state, pt.x); lua_rawseti(m_state, -2, n++); lua_pushnumber(m_state, pt.y); diff --git a/tests/Android.mk b/tests/Android.mk index 255705f26a..9c295241e0 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -10,11 +10,7 @@ LOCAL_SRC_FILES := \ tests/AccelerometerTest/AccelerometerTest.cpp \ tests/ActionManagerTest/ActionManagerTest.cpp \ tests/ActionsTest/ActionsTest.cpp \ -tests/Box2DTest/Box2dTest.cpp \ -tests/Box2DTestBed/Box2dView.cpp \ -tests/Box2DTestBed/GLES-Render.cpp \ -tests/Box2DTestBed/Test.cpp \ -tests/Box2DTestBed/TestEntries.cpp \ +tests/ActionsProgressTest/ActionsProgressTest.cpp \ tests/BugsTest/Bug-1159.cpp \ tests/BugsTest/Bug-1174.cpp \ tests/BugsTest/Bug-350.cpp \ @@ -26,27 +22,6 @@ tests/BugsTest/Bug-914.cpp \ tests/BugsTest/BugsTest.cpp \ tests/BugsTest/Bug-458/Bug-458.cpp \ tests/BugsTest/Bug-458/QuestionContainerSprite.cpp \ -tests/ChipmunkTest/Bounce.cpp \ -tests/ChipmunkTest/Joints.cpp \ -tests/ChipmunkTest/LogoSmash.cpp \ -tests/ChipmunkTest/MagnetsElectric.cpp \ -tests/ChipmunkTest/OneWay.cpp \ -tests/ChipmunkTest/Planet.cpp \ -tests/ChipmunkTest/Player.cpp \ -tests/ChipmunkTest/Plink.cpp \ -tests/ChipmunkTest/Pump.cpp \ -tests/ChipmunkTest/PyramidStack.cpp \ -tests/ChipmunkTest/PyramidTopple.cpp \ -tests/ChipmunkTest/Query.cpp \ -tests/ChipmunkTest/Sensors.cpp \ -tests/ChipmunkTest/Simple.cpp \ -tests/ChipmunkTest/Springies.cpp \ -tests/ChipmunkTest/Tank.cpp \ -tests/ChipmunkTest/TheoJansen.cpp \ -tests/ChipmunkTest/Tumble.cpp \ -tests/ChipmunkTest/UnsafeOps.cpp \ -tests/ChipmunkTest/cocos2dChipmunkDemo.cpp \ -tests/ChipmunkTest/drawSpace.cpp \ tests/ClickAndMoveTest/ClickAndMoveTest.cpp \ tests/CocosDenshionTest/CocosDenshionTest.cpp \ tests/CocosNodeTest/CocosNodeTest.cpp \ @@ -76,7 +51,6 @@ tests/PerformanceTest/PerformanceSpriteTest.cpp \ tests/PerformanceTest/PerformanceTest.cpp \ tests/PerformanceTest/PerformanceTextureTest.cpp \ tests/PerformanceTest/PerformanceTouchesTest.cpp \ -tests/ProgressActionsTest/ProgressActionsTest.cpp \ tests/RenderTextureTest/RenderTextureTest.cpp \ tests/RotateWorldTest/RotateWorldTest.cpp \ tests/SceneTest/SceneTest.cpp \ diff --git a/tests/test.android/AndroidManifest.xml b/tests/test.android/AndroidManifest.xml index ca2370f47f..2820f4cdcf 100644 --- a/tests/test.android/AndroidManifest.xml +++ b/tests/test.android/AndroidManifest.xml @@ -4,7 +4,7 @@ android:versionCode="1" android:versionName="1.0"> - + = 0x20000); + } static { System.loadLibrary("cocosdenshion"); From 382e4e7eb8e535c9f4f91987bd6411fc464d6dbd Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 20 Mar 2012 17:27:06 +0800 Subject: [PATCH 2/2] issue #1056: modify code according new code after pull --- cocos2dx/Android.mk | 7 ++++--- cocos2dx/include/CCDictionary.h | 4 ++-- cocos2dx/include/CCTMXXMLParser.h | 2 ++ cocos2dx/platform/android/CCFileUtils_android.cpp | 2 ++ cocos2dx/support/data_support/uthash.h | 6 ++++++ cocos2dx/textures/CCTextureAtlas.cpp | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index 97dabc5447..77153b1000 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -28,6 +28,7 @@ cocoa/CCAffineTransform.cpp \ cocoa/CCGeometry.cpp \ cocoa/CCAutoreleasePool.cpp \ cocoa/CCData.cpp \ +cocoa/CCDictionary.cpp \ cocoa/CCNS.cpp \ cocoa/CCObject.cpp \ cocoa/CCSet.cpp \ @@ -37,9 +38,6 @@ CCDirector.cpp \ effects/CCGrabber.cpp \ effects/CCGrid.cpp \ extensions/CCNotificationCenter.cpp \ -gles2/CCGLProgram.cpp \ -gles2/ccGLStateCache.cpp \ -gles2/CCShaderCache.cpp \ kazmath/src/aabb.c \ kazmath/src/mat3.c \ kazmath/src/mat4.c \ @@ -90,6 +88,9 @@ platform/android/jni/SystemInfoJni.cpp \ platform/android/jni/TouchesJni.cpp \ script_support/CCScriptSupport.cpp \ shaders/ccShaders.cpp \ +shaders/CCGLProgram.cpp \ +shaders/ccGLStateCache.cpp \ +shaders/CCShaderCache.cpp \ sprite_nodes/CCAnimation.cpp \ sprite_nodes/CCAnimationCache.cpp \ sprite_nodes/CCSprite.cpp \ diff --git a/cocos2dx/include/CCDictionary.h b/cocos2dx/include/CCDictionary.h index eeb20d76c1..168f10e8ee 100644 --- a/cocos2dx/include/CCDictionary.h +++ b/cocos2dx/include/CCDictionary.h @@ -89,8 +89,8 @@ public: // pElement = (CCDictElement*)pElement->hh.next) #define CCDICT_FOREACH(__dict__, __el__) \ - CCDictElement* ##__dict__##__el__##tmp = NULL; \ - HASH_ITER(hh, (__dict__)->m_pElements, __el__, ##__dict__##__el__##tmp) + CCDictElement* tmp##__dict____el__ = NULL; \ + HASH_ITER(hh, (__dict__)->m_pElements, __el__, tmp##__dict____el__) class CC_DLL CCDictionary : public CCObject diff --git a/cocos2dx/include/CCTMXXMLParser.h b/cocos2dx/include/CCTMXXMLParser.h index 2b1561d44c..a1d14f3184 100755 --- a/cocos2dx/include/CCTMXXMLParser.h +++ b/cocos2dx/include/CCTMXXMLParser.h @@ -33,6 +33,8 @@ THE SOFTWARE. #include "../platform/CCSAXParser.h" +#include + NS_CC_BEGIN class CCTMXObjectGroup; diff --git a/cocos2dx/platform/android/CCFileUtils_android.cpp b/cocos2dx/platform/android/CCFileUtils_android.cpp index 905d2e7b50..66f6417dbf 100644 --- a/cocos2dx/platform/android/CCFileUtils_android.cpp +++ b/cocos2dx/platform/android/CCFileUtils_android.cpp @@ -27,6 +27,8 @@ NS_CC_BEGIN; #include "CCCommon.h" #include "jni/SystemInfoJni.h" +using namespace std; + // record the resource path static string s_strResourcePath = ""; diff --git a/cocos2dx/support/data_support/uthash.h b/cocos2dx/support/data_support/uthash.h index 04f672371b..d335c8bd95 100644 --- a/cocos2dx/support/data_support/uthash.h +++ b/cocos2dx/support/data_support/uthash.h @@ -45,6 +45,12 @@ namespace cocos2d { #define DECLTYPE(x) (__typeof(x)) #endif +#ifdef ANDROID +#define NO_DECLTYPE +#undef DECLTYPE +#define DECLTYPE(x) +#endif + #ifdef NO_DECLTYPE #define DECLTYPE_ASSIGN(dst,src) \ do { \ diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index a196e0630e..4d5e2e4030 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -268,7 +268,7 @@ void CCTextureAtlas::updateQuad(ccV3F_C4B_T2F_Quad *quad, unsigned int index) { CCAssert( index >= 0 && index < m_uCapacity, "updateQuadWithTexture: Invalid index"); - m_uTotalQuads = max( index+1, m_uTotalQuads); + m_uTotalQuads = MAX( index+1, m_uTotalQuads); m_pQuads[index] = *quad; @@ -404,7 +404,7 @@ bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity) return true; // update capacity and totolQuads - m_uTotalQuads = min(m_uTotalQuads, newCapacity); + m_uTotalQuads = MIN(m_uTotalQuads, newCapacity); m_uCapacity = newCapacity; void * tmpQuads = NULL;