Merge pull request #781 from minggo/android_gles20

set up gles2.0 environment on Android
This commit is contained in:
minggo 2012-03-20 02:31:22 -07:00
commit 272fa58b81
27 changed files with 184 additions and 101 deletions

View File

@ -4,7 +4,7 @@
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="8"/>
<uses-sdk android:minSdkVersion="8"/>
<application android:label="@string/app_name"
android:debuggable="true"

View File

@ -1,5 +1,5 @@
# set params
NDK_ROOT_LOCAL=/cygdrive/d/programe/android/ndk/android-ndk-r6b
NDK_ROOT_LOCAL=/cygdrive/d/programe/android/ndk/android-ndk-r7b
COCOS2DX_ROOT_LOCAL=/cygdrive/e/cocos2d-x
# try to get global variable

View File

@ -1,2 +0,0 @@
# Project target.
target=android-15

View File

@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-9

View File

@ -26,8 +26,13 @@ package org.cocos2dx.application;
import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxEditText;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import org.cocos2dx.lib.Cocos2dxRenderer;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.os.Bundle;
import android.util.Log;
public class ApplicationDemo extends Cocos2dxActivity{
private Cocos2dxGLSurfaceView mGLView;
@ -35,6 +40,7 @@ public class ApplicationDemo extends Cocos2dxActivity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (detectOpenGLES20()) {
// get the packageName,it's used to set the resource path
String packageName = getApplication().getPackageName();
super.setPackageName(packageName);
@ -42,6 +48,13 @@ public class ApplicationDemo extends Cocos2dxActivity{
setContentView(R.layout.helloworld_demo);
mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.helloworld_gl_surfaceview);
mGLView.setTextField((Cocos2dxEditText)findViewById(R.id.textField));
mGLView.setEGLContextClientVersion(2);
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
}
else {
Log.d("activity", "don't support gles2.0");
finish();
}
}
@Override
@ -56,6 +69,14 @@ public class ApplicationDemo extends Cocos2dxActivity{
mGLView.onResume();
}
private boolean detectOpenGLES20()
{
ActivityManager am =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
return (info.reqGlEsVersion >= 0x20000);
}
static {
System.loadLibrary("cocosdenshion");
System.loadLibrary("helloworld");

View File

@ -145,10 +145,13 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
initView();
}
protected void initView() {
mRenderer = new Cocos2dxRenderer();
setFocusableInTouchMode(true);
public void setCocos2dxRenderer(Cocos2dxRenderer renderer){
mRenderer = renderer;
setRenderer(mRenderer);
}
protected void initView() {
setFocusableInTouchMode(true);
textInputWraper = new TextInputWraper(this);

View File

@ -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,6 +38,19 @@ CCDirector.cpp \
effects/CCGrabber.cpp \
effects/CCGrid.cpp \
extensions/CCNotificationCenter.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 +59,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 +87,10 @@ platform/android/jni/SensorJni.cpp \
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 \
@ -88,6 +104,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 +126,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

View File

@ -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

View File

@ -33,6 +33,8 @@ THE SOFTWARE.
#include "../platform/CCSAXParser.h"
#include <string>
NS_CC_BEGIN
class CCTMXObjectGroup;

View File

@ -114,6 +114,7 @@ THE SOFTWARE.
#include "CCImage.h"
#include "CCFileUtils.h"
#include "CCAccelerometer.h"
#include "CCGL.h"
// extensions
#include "extensions/CCNotificationCenter.h"

View File

@ -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.

View File

@ -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 <GLES/glplatform.h>
#include <GLES2/gl2platform.h>
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES 1
#endif
// normal process
#include <GLES/gl.h>
#include <GLES/glext.h>
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
#include <GLES/gl.h>
#include <GLES/glext.h>
// normal process
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
// 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)

View File

@ -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

View File

@ -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 <stdlib.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <android/log.h>
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)

View File

@ -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 = "";

View File

@ -1263,10 +1263,6 @@
RelativePath="..\shaders\ccShaders.cpp"
>
</File>
<File
RelativePath="..\shaders\ccShaders.h"
>
</File>
</Filter>
<File
RelativePath="..\CCCamera.cpp"

View File

@ -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 { \

View File

@ -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;

View File

@ -252,7 +252,7 @@ int CCLuaEngine::pushCCObjectToLuaStack(CCObject* pObject, const char* typeName)
// functions for excute touch event
int CCLuaEngine::executeTouchEvent(int nHandler, int eventType, CCTouch *pTouch)
{
CCPoint pt = CCDirector::sharedDirector()->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);

View File

@ -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 \

View File

@ -4,7 +4,7 @@
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="8"/>
<uses-sdk android:minSdkVersion="8"/>
<application android:label="@string/app_name"
android:debuggable="true"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# set params
NDK_ROOT_LOCAL=/cygdrive/e/android/android-ndk-r6b
COCOS2DX_ROOT_LOCAL=/cygdrive/f/Project/dumganhar/cocos2d-x
NDK_ROOT_LOCAL=/cygdrive/d/programe/android/ndk/android-ndk-r7b
COCOS2DX_ROOT_LOCAL=/cygdrive/e/cocos2d-x
# try to get global variable
if [ $NDK_ROOT"aaa" != "aaa" ]; then

View File

@ -1,2 +0,0 @@
# Project target.
target=android-7

View File

@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-10

View File

@ -145,10 +145,13 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView {
initView();
}
protected void initView() {
mRenderer = new Cocos2dxRenderer();
setFocusableInTouchMode(true);
public void setCocos2dxRenderer(Cocos2dxRenderer renderer){
mRenderer = renderer;
setRenderer(mRenderer);
}
protected void initView() {
setFocusableInTouchMode(true);
textInputWraper = new TextInputWraper(this);

View File

@ -26,8 +26,13 @@ package org.cocos2dx.tests;
import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxEditText;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import org.cocos2dx.lib.Cocos2dxRenderer;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.os.Bundle;
import android.util.Log;
public class TestsDemo extends Cocos2dxActivity{
private Cocos2dxGLSurfaceView mGLView;
@ -35,13 +40,22 @@ public class TestsDemo extends Cocos2dxActivity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (detectOpenGLES20()) {
// get the packageName,it's used to set the resource path
String packageName = getApplication().getPackageName();
super.setPackageName(packageName);
setContentView(R.layout.test_demo);
mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.test_demo_gl_surfaceview);
mGLView.setTextField((Cocos2dxEditText)findViewById(R.id.textField));
mGLView.setEGLContextClientVersion(2);
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
}
else {
Log.d("activity", "don't support gles2.0");
finish();
}
}
@Override
@ -58,6 +72,14 @@ public class TestsDemo extends Cocos2dxActivity{
mGLView.onResume();
}
private boolean detectOpenGLES20()
{
ActivityManager am =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
return (info.reqGlEsVersion >= 0x20000);
}
static {
System.loadLibrary("cocosdenshion");
System.loadLibrary("chipmunk");