1.1 --- a/android/testproject/AndroidManifest.xml Tue Jun 29 00:40:12 2010 +1200
1.2 +++ b/android/testproject/AndroidManifest.xml Tue Jun 29 01:30:11 2010 +1200
1.3 @@ -4,7 +4,7 @@
1.4 android:versionCode="1"
1.5 android:versionName="1.0">
1.6 <application android:label="@string/app_name" android:icon="@drawable/icon">
1.7 - <activity android:name="TestActivity"
1.8 + <activity android:name="SDLActivity"
1.9 android:label="@string/app_name">
1.10 <intent-filter>
1.11 <action android:name="android.intent.action.MAIN" />
2.1 --- a/android/testproject/jni/Android.mk Tue Jun 29 00:40:12 2010 +1200
2.2 +++ b/android/testproject/jni/Android.mk Tue Jun 29 01:30:11 2010 +1200
2.3 @@ -2,7 +2,7 @@
2.4
2.5 include $(CLEAR_VARS)
2.6
2.7 -LOCAL_MODULE := sanangeles
2.8 +LOCAL_MODULE := sdltest
2.9
2.10 SDL := /home/paul/Projects/gsoc/SDL-gsoc2010_android/
2.11
3.1 --- a/android/testproject/jni/app-android.cpp Tue Jun 29 00:40:12 2010 +1200
3.2 +++ b/android/testproject/jni/app-android.cpp Tue Jun 29 01:30:11 2010 +1200
3.3 @@ -41,7 +41,7 @@
3.4 Functions called by JNI
3.5 *******************************************************************************/
3.6
3.7 -extern "C" void Java_org_libsdl_android_TestActivity_nativeInit( JNIEnv* env, jobject obj )
3.8 +extern "C" void Java_org_libsdl_android_SDLActivity_nativeInit( JNIEnv* env, jobject obj )
3.9 {
3.10 __android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: NativeInit");
3.11
3.12 @@ -63,7 +63,7 @@
3.13
3.14 __android_log_print(ANDROID_LOG_INFO, "SDL", "JNI: OnLoad");
3.15
3.16 - jclass cls = mEnv->FindClass ("org/libsdl/android/TestActivity");
3.17 + jclass cls = mEnv->FindClass ("org/libsdl/android/SDLActivity");
3.18 mActivityInstance = cls;
3.19 midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
3.20 midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/android/testproject/src/org/libsdl/android/SDLActivity.java Tue Jun 29 01:30:11 2010 +1200
4.3 @@ -0,0 +1,216 @@
4.4 +package org.libsdl.android;
4.5 +
4.6 +import javax.microedition.khronos.egl.EGLConfig;
4.7 +import javax.microedition.khronos.opengles.GL10;
4.8 +import javax.microedition.khronos.egl.*;
4.9 +
4.10 +import android.app.Activity;
4.11 +import android.content.Context;
4.12 +import android.view.SurfaceHolder;
4.13 +import android.view.SurfaceView;
4.14 +import android.os.Bundle;
4.15 +import android.view.MotionEvent;
4.16 +import android.util.Log;
4.17 +import android.graphics.*;
4.18 +
4.19 +import java.lang.*;
4.20 +
4.21 +
4.22 +/**
4.23 + SDL Activity
4.24 +*/
4.25 +public class SDLActivity extends Activity {
4.26 +
4.27 + //Main components
4.28 + private static SDLActivity mSingleton;
4.29 + private static SDLSurface mSurface;
4.30 +
4.31 + //Load the .so
4.32 + static {
4.33 + System.loadLibrary("sdltest");
4.34 + }
4.35 +
4.36 + //Setup
4.37 + protected void onCreate(Bundle savedInstanceState) {
4.38 + super.onCreate(savedInstanceState);
4.39 +
4.40 + //So we can call stuff from static callbacks
4.41 + mSingleton = this;
4.42 +
4.43 + //Set up the surface
4.44 + mSurface = new SDLSurface(getApplication());
4.45 + setContentView(mSurface);
4.46 + SurfaceHolder holder = mSurface.getHolder();
4.47 + holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
4.48 +
4.49 +
4.50 + }
4.51 +
4.52 + //Events
4.53 + protected void onPause() {
4.54 + super.onPause();
4.55 + }
4.56 +
4.57 + protected void onResume() {
4.58 + super.onResume();
4.59 + }
4.60 +
4.61 +
4.62 +
4.63 +
4.64 +
4.65 +
4.66 + //C functions we call
4.67 + public static native void nativeInit();
4.68 +
4.69 +
4.70 +
4.71 +
4.72 +
4.73 +
4.74 + //Java functions called from C
4.75 + private static void createGLContext(){
4.76 + mSurface.initEGL();
4.77 + }
4.78 +
4.79 + public static void flipBuffers(){
4.80 + mSurface.flipEGL();
4.81 + }
4.82 +
4.83 +
4.84 +
4.85 +
4.86 +
4.87 +
4.88 +
4.89 + //EGL context creation
4.90 +
4.91 +}
4.92 +
4.93 +/**
4.94 + Simple nativeInit() runnable
4.95 +*/
4.96 +class SDLRunner implements Runnable{
4.97 + public void run(){
4.98 + //Runs SDL_main()
4.99 + SDLActivity.nativeInit();
4.100 + }
4.101 +}
4.102 +
4.103 +
4.104 +/**
4.105 + SDLSurface. This is what we draw on, so we need to know when it's created
4.106 + in order to do anything useful.
4.107 +
4.108 + Because of this, that's where we set up the SDL thread
4.109 +*/
4.110 +class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
4.111 +
4.112 + //This is what SDL runs in. It invokes SDL_main(), eventually
4.113 + private Thread mSDLThread;
4.114 +
4.115 + //EGL private objects
4.116 + private EGLContext mEGLContext;
4.117 + private EGLSurface mEGLSurface;
4.118 + private EGLDisplay mEGLDisplay;
4.119 +
4.120 + //Startup
4.121 + public SDLSurface(Context context) {
4.122 + super(context);
4.123 + getHolder().addCallback(this);
4.124 + }
4.125 +
4.126 + //Called when we have a valid drawing surface
4.127 + public void surfaceCreated(SurfaceHolder holder) {
4.128 + Log.v("SDL","Surface created");
4.129 +
4.130 + mSDLThread = new Thread(new SDLRunner(), "SDLThread");
4.131 + mSDLThread.start();
4.132 + }
4.133 +
4.134 + //Called when we lose the surface
4.135 + public void surfaceDestroyed(SurfaceHolder holder) {
4.136 + Log.v("SDL","Surface destroyed");
4.137 + }
4.138 +
4.139 + //Called when the surface is resized
4.140 + public void surfaceChanged(SurfaceHolder holder, int format,
4.141 + int width, int height) {
4.142 + Log.v("SDL","Surface resized");
4.143 + }
4.144 +
4.145 + //unused
4.146 + public void onDraw(Canvas canvas) {}
4.147 +
4.148 +
4.149 + //EGL functions
4.150 + public boolean initEGL(){
4.151 + Log.v("SDL","Starting up");
4.152 +
4.153 + try{
4.154 +
4.155 + EGL10 egl = (EGL10)EGLContext.getEGL();
4.156 +
4.157 + EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
4.158 +
4.159 + int[] version = new int[2];
4.160 + egl.eglInitialize(dpy, version);
4.161 +
4.162 + int[] configSpec = {
4.163 + //EGL10.EGL_DEPTH_SIZE, 16,
4.164 + EGL10.EGL_NONE
4.165 + };
4.166 + EGLConfig[] configs = new EGLConfig[1];
4.167 + int[] num_config = new int[1];
4.168 + egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
4.169 + EGLConfig config = configs[0];
4.170 +
4.171 + EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);
4.172 +
4.173 + EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null);
4.174 +
4.175 + egl.eglMakeCurrent(dpy, surface, surface, ctx);
4.176 +
4.177 + mEGLContext = ctx;
4.178 + mEGLDisplay = dpy;
4.179 + mEGLSurface = surface;
4.180 +
4.181 + }catch(Exception e){
4.182 + Log.v("SDL", e + "");
4.183 + for(StackTraceElement s : e.getStackTrace()){
4.184 + Log.v("SDL", s.toString());
4.185 + }
4.186 + }
4.187 +
4.188 + Log.v("SDL","Done making!");
4.189 +
4.190 + return true;
4.191 + }
4.192 +
4.193 + //EGL buffer flip
4.194 + public void flipEGL(){
4.195 + try{
4.196 +
4.197 + EGL10 egl = (EGL10)EGLContext.getEGL();
4.198 + GL10 gl = (GL10)mEGLContext.getGL();
4.199 +
4.200 + egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
4.201 +
4.202 + //drawing here
4.203 +
4.204 + egl.eglWaitGL();
4.205 +
4.206 + egl.eglSwapBuffers(mEGLDisplay, mEGLSurface);
4.207 +
4.208 +
4.209 + }catch(Exception e){
4.210 + Log.v("SDL", "flipEGL(): " + e);
4.211 +
4.212 + for(StackTraceElement s : e.getStackTrace()){
4.213 + Log.v("SDL", s.toString());
4.214 + }
4.215 + }
4.216 + }
4.217 +}
4.218 +
4.219 +
5.1 --- a/android/testproject/src/org/libsdl/android/TestActivity.java Tue Jun 29 00:40:12 2010 +1200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,211 +0,0 @@
5.4 -package org.libsdl.android;
5.5 -
5.6 -import javax.microedition.khronos.egl.EGLConfig;
5.7 -import javax.microedition.khronos.opengles.GL10;
5.8 -import javax.microedition.khronos.egl.*;
5.9 -
5.10 -import android.app.Activity;
5.11 -import android.content.Context;
5.12 -import android.view.SurfaceHolder;
5.13 -import android.view.SurfaceView;
5.14 -import android.os.Bundle;
5.15 -import android.view.MotionEvent;
5.16 -import android.util.Log;
5.17 -import android.graphics.*;
5.18 -
5.19 -import java.lang.*;
5.20 -
5.21 -
5.22 -//http://www.mail-archive.com/android-beginners@googlegroups.com/msg01830.html
5.23 -
5.24 -/*
5.25 -In TestActivity::onResume() call SDL_Init
5.26 -SDL_GL_CreateContext call SDLSurface::createSDLGLContext()
5.27 -SDL_GL_FlipBuffers calls SDLSurface::flip()
5.28 -
5.29 -*/
5.30 -
5.31 -
5.32 -
5.33 -public class TestActivity extends Activity {
5.34 -
5.35 - protected void onCreate(Bundle savedInstanceState) {
5.36 - super.onCreate(savedInstanceState);
5.37 - mSurface = new SDLSurface(getApplication());
5.38 - setContentView(mSurface);
5.39 - SurfaceHolder holder = mSurface.getHolder();
5.40 - holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
5.41 - }
5.42 -
5.43 - protected void onPause() {
5.44 - super.onPause();
5.45 - }
5.46 -
5.47 - protected void onResume() {
5.48 - super.onResume();
5.49 -
5.50 - //All set up. Start up SDL
5.51 -
5.52 -
5.53 - }
5.54 -
5.55 - private static SDLSurface mSurface;
5.56 -
5.57 - static {
5.58 - System.loadLibrary("sanangeles");
5.59 - }
5.60 -
5.61 - //C functions we call
5.62 - public static native void nativeInit();
5.63 -
5.64 -
5.65 - //Java functions called from C
5.66 - private static void createGLContext(){
5.67 - mSurface.initEGL();
5.68 - }
5.69 -
5.70 - public static void flipBuffers(){
5.71 - mSurface.flipBuffers();
5.72 - }
5.73 -}
5.74 -
5.75 -class SDLThread implements Runnable{
5.76 - public void run(){
5.77 - TestActivity.nativeInit();
5.78 - }
5.79 -}
5.80 -
5.81 -class SDLSurface extends SurfaceView implements SurfaceHolder.Callback{
5.82 -
5.83 - private EGLContext mEGLContext;
5.84 - private EGLSurface mEGLSurface;
5.85 - private EGLDisplay mEGLDisplay;
5.86 -
5.87 - public void surfaceCreated(SurfaceHolder holder) {
5.88 - Log.v("SDL","Surface created");
5.89 -
5.90 - Thread runner = new Thread(new SDLThread(), "SDLThread"); // (1) Create a new thread.
5.91 - runner.start(); // (2) Start the thread
5.92 -
5.93 - }
5.94 -
5.95 - public void surfaceDestroyed(SurfaceHolder holder) {
5.96 - Log.v("SDL","Surface destroyed");
5.97 - }
5.98 -
5.99 - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
5.100 -
5.101 - }
5.102 -
5.103 -
5.104 - boolean initEGL(){
5.105 - Log.v("SDL","Starting up");
5.106 -
5.107 - try{
5.108 -
5.109 - // Get an EGL instance
5.110 - EGL10 egl = (EGL10)EGLContext.getEGL();
5.111 -
5.112 - // Get to the default display.
5.113 - EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
5.114 -
5.115 - // We can now initialize EGL for that display
5.116 - int[] version = new int[2];
5.117 - egl.eglInitialize(dpy, version);
5.118 -
5.119 - // Specify a configuration for our opengl session
5.120 - // and grab the first configuration that matches is
5.121 - int[] configSpec = {
5.122 - //EGL10.EGL_DEPTH_SIZE, 16,
5.123 - EGL10.EGL_NONE
5.124 - };
5.125 - EGLConfig[] configs = new EGLConfig[1];
5.126 - int[] num_config = new int[1];
5.127 - egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
5.128 - EGLConfig config = configs[0];
5.129 -
5.130 - // Create an OpenGL ES context. This must be done only once
5.131 - EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);
5.132 -
5.133 - // Create an EGL surface we can render into.
5.134 - EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null);
5.135 -
5.136 - // Before we can issue GL commands, we need to make sure
5.137 - // the context is current and bound to a surface.
5.138 - egl.eglMakeCurrent(dpy, surface, surface, ctx);
5.139 -
5.140 - mEGLContext = ctx;
5.141 - mEGLDisplay = dpy;
5.142 - mEGLSurface = surface;
5.143 - }catch(Exception e){
5.144 - Log.v("SDL", e + "");
5.145 - }
5.146 -
5.147 - Log.v("SDL","Done making!");
5.148 -
5.149 - return true;
5.150 - }
5.151 -
5.152 - public SDLSurface(Context context) {
5.153 - super(context);
5.154 -
5.155 - getHolder().addCallback(this);
5.156 -
5.157 - }
5.158 -
5.159 - public void onDraw(Canvas canvas) {
5.160 -
5.161 -
5.162 - }
5.163 -
5.164 -
5.165 - public void flipBuffers(){
5.166 - //Log.v("test","Draw!");
5.167 -
5.168 - try{
5.169 -
5.170 - EGL10 egl = (EGL10)EGLContext.getEGL();
5.171 - GL10 gl = (GL10)mEGLContext.getGL();
5.172 -
5.173 - egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
5.174 -
5.175 - //drawing here
5.176 -
5.177 - egl.eglWaitGL();
5.178 -
5.179 - egl.eglSwapBuffers(mEGLDisplay, mEGLSurface);
5.180 -
5.181 -
5.182 - }catch(Exception e){
5.183 - Log.v("SDL", e + "");
5.184 - }
5.185 -
5.186 - }
5.187 -
5.188 -}
5.189 -
5.190 -
5.191 -/*
5.192 -class TestRenderer implements GLSurfaceView.Renderer {
5.193 - public void onSurfaceCreated(GL10 gl, EGLConfig config) {
5.194 - nativeInit();
5.195 - }
5.196 -
5.197 -
5.198 -
5.199 - public void onSurfaceChanged(GL10 gl, int w, int h) {
5.200 - //gl.glViewport(0, 0, w, h);
5.201 - nativeResize(w, h);
5.202 - }
5.203 -
5.204 - public void onDrawFrame(GL10 gl) {
5.205 - nativeRender();
5.206 - }
5.207 -
5.208 - private static native void nativeInit();
5.209 - private static native void nativeResize(int w, int h);
5.210 - private static native void nativeRender();
5.211 - private static native void nativeDone();
5.212 -
5.213 -}
5.214 -*/