# HG changeset patch # User Paul Hunkin # Date 1276769967 -43200 # Node ID 611d39792201ce32febcc4ba441d7e78c924305b # Parent c93b44ddc63e6a4b0800234bebb182dab169030b Added minimal test project diff -r c93b44ddc63e -r 611d39792201 android/testproject/AndroidManifest.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/AndroidManifest.xml Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,15 @@ + + + + + + + + + + + diff -r c93b44ddc63e -r 611d39792201 android/testproject/build.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/build.properties Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,17 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked in Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + diff -r c93b44ddc63e -r 611d39792201 android/testproject/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/build.xml Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r c93b44ddc63e -r 611d39792201 android/testproject/default.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/default.properties Thu Jun 17 22:19:27 2010 +1200 @@ -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, +# "build.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=Google Inc.:Google APIs:7 diff -r c93b44ddc63e -r 611d39792201 android/testproject/jni/Android.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/jni/Android.mk Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,16 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := sanangeles + +LOCAL_CFLAGS := -DANDROID_NDK \ + -DDISABLE_IMPORTGL + +LOCAL_SRC_FILES := \ + importgl.c \ + app-android.c \ + +LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog + +include $(BUILD_SHARED_LIBRARY) diff -r c93b44ddc63e -r 611d39792201 android/testproject/jni/app-android.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/jni/app-android.c Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,79 @@ +/******************************************************************************* + Headers +*******************************************************************************/ +#include +#include +#include +#include +#include + +/******************************************************************************* + Globals +*******************************************************************************/ +int gAppAlive = 1; + +static int sWindowWidth = 320; +static int sWindowHeight = 480; +static int sDemoStopped = 0; + +static long _getTime(void){ + struct timeval now; + gettimeofday(&now, NULL); + return (long)(now.tv_sec*1000 + now.tv_usec/1000); +} + +/******************************************************************************* + Initialize the graphics state +*******************************************************************************/ +void Java_org_libsdl_android_TestRenderer_nativeInit( JNIEnv* env ) +{ + importGLInit(); + + gAppAlive = 1; + sDemoStopped = 0; +} + +/******************************************************************************* + Resize +*******************************************************************************/ +void Java_org_libsdl_android_TestRenderer_nativeResize( JNIEnv* env, + jobject thiz, + jint w, + jint h ) +{ + sWindowWidth = w; + sWindowHeight = h; + __android_log_print(ANDROID_LOG_INFO, "SDL", "resize w=%d h=%d", w, h); +} + +/******************************************************************************* + Finalize (ie: shutdown) +*******************************************************************************/ +void Java_org_libsdl_android_TestRenderer_nativeDone( JNIEnv* env ) +{ + + //shut down the app + + importGLDeinit(); +} + +/******************************************************************************* + Pause (ie: stop as soon as possible) +*******************************************************************************/ +void Java_org_libsdl_android_TestGLSurfaceView_nativePause( JNIEnv* env ) +{ + sDemoStopped = !sDemoStopped; + if (sDemoStopped) { + //we paused + } else { + //we resumed + } +} + +/******************************************************************************* + Render the next frame +*******************************************************************************/ +void Java_org_libsdl_android_TestRenderer_nativeRender( JNIEnv* env ) +{ + //TODO: Render here +} diff -r c93b44ddc63e -r 611d39792201 android/testproject/jni/importgl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/jni/importgl.c Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,168 @@ +/* San Angeles Observation OpenGL ES version example + * Copyright 2004-2005 Jetro Lauha + * All rights reserved. + * Web: http://iki.fi/jetro/ + * + * This source is free software; you can redistribute it and/or + * modify it under the terms of EITHER: + * (1) The GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. The text of the GNU Lesser + * General Public License is included with this source in the + * file LICENSE-LGPL.txt. + * (2) The BSD-style license that is included with this source in + * the file LICENSE-BSD.txt. + * + * This source is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files + * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details. + * + * $Id: importgl.c,v 1.4 2005/02/08 18:42:55 tonic Exp $ + * $Revision: 1.4 $ + */ + +#undef WIN32 +#undef LINUX +#ifdef _MSC_VER +// Desktop or mobile Win32 environment: +#define WIN32 +#else +// Linux environment: +#define LINUX +#endif + +#ifndef DISABLE_IMPORTGL + +#if defined(WIN32) +#define WIN32_LEAN_AND_MEAN +#include +#include +static HMODULE sGLESDLL = NULL; +#endif // WIN32 + +#ifdef LINUX +#include +#include +static void *sGLESSO = NULL; +#endif // LINUX + +#endif /* DISABLE_IMPORTGL */ + +#define IMPORTGL_NO_FNPTR_DEFS +#define IMPORTGL_API +#define IMPORTGL_FNPTRINIT = NULL +#include "importgl.h" + + +/* Imports function pointers to selected function calls in OpenGL ES Common + * or Common Lite profile DLL or shared object. The function pointers are + * stored as global symbols with equivalent function name but prefixed with + * "funcPtr_". Standard gl/egl calls are redirected to the function pointers + * with preprocessor macros (see importgl.h). + */ +int importGLInit() +{ + int result = 1; + +#ifndef DISABLE_IMPORTGL + +#undef IMPORT_FUNC + +#ifdef WIN32 + sGLESDLL = LoadLibrary(_T("libGLES_CM.dll")); + if (sGLESDLL == NULL) + sGLESDLL = LoadLibrary(_T("libGLES_CL.dll")); + if (sGLESDLL == NULL) + return 0; // Cannot find OpenGL ES Common or Common Lite DLL. + + /* The following fetches address to each egl & gl function call + * and stores it to the related function pointer. Casting through + * void * results in warnings with VC warning level 4, which + * could be fixed by casting to the true type for each fetch. + */ +#define IMPORT_FUNC(funcName) do { \ + void *procAddress = (void *)GetProcAddress(sGLESDLL, _T(#funcName)); \ + if (procAddress == NULL) result = 0; \ + *((void **)&FNPTR(funcName)) = procAddress; } while (0) +#endif // WIN32 + +#ifdef LINUX +#ifdef ANDROID_NDK + sGLESSO = dlopen("libGLESv1_CM.so", RTLD_NOW); +#else /* !ANDROID_NDK */ + sGLESSO = dlopen("libGLES_CM.so", RTLD_NOW); + if (sGLESSO == NULL) + sGLESSO = dlopen("libGLES_CL.so", RTLD_NOW); +#endif /* !ANDROID_NDK */ + if (sGLESSO == NULL) + return 0; // Cannot find OpenGL ES Common or Common Lite SO. + +#define IMPORT_FUNC(funcName) do { \ + void *procAddress = (void *)dlsym(sGLESSO, #funcName); \ + if (procAddress == NULL) result = 0; \ + *((void **)&FNPTR(funcName)) = procAddress; } while (0) +#endif // LINUX + +#ifndef ANDROID_NDK + IMPORT_FUNC(eglChooseConfig); + IMPORT_FUNC(eglCreateContext); + IMPORT_FUNC(eglCreateWindowSurface); + IMPORT_FUNC(eglDestroyContext); + IMPORT_FUNC(eglDestroySurface); + IMPORT_FUNC(eglGetConfigAttrib); + IMPORT_FUNC(eglGetConfigs); + IMPORT_FUNC(eglGetDisplay); + IMPORT_FUNC(eglGetError); + IMPORT_FUNC(eglInitialize); + IMPORT_FUNC(eglMakeCurrent); + IMPORT_FUNC(eglSwapBuffers); + IMPORT_FUNC(eglTerminate); +#endif /* !ANDROID_NDK */ + + IMPORT_FUNC(glBlendFunc); + IMPORT_FUNC(glClear); + IMPORT_FUNC(glClearColorx); + IMPORT_FUNC(glColor4x); + IMPORT_FUNC(glColorPointer); + IMPORT_FUNC(glDisable); + IMPORT_FUNC(glDisableClientState); + IMPORT_FUNC(glDrawArrays); + IMPORT_FUNC(glEnable); + IMPORT_FUNC(glEnableClientState); + IMPORT_FUNC(glFrustumx); + IMPORT_FUNC(glGetError); + IMPORT_FUNC(glLightxv); + IMPORT_FUNC(glLoadIdentity); + IMPORT_FUNC(glMaterialx); + IMPORT_FUNC(glMaterialxv); + IMPORT_FUNC(glMatrixMode); + IMPORT_FUNC(glMultMatrixx); + IMPORT_FUNC(glNormalPointer); + IMPORT_FUNC(glPopMatrix); + IMPORT_FUNC(glPushMatrix); + IMPORT_FUNC(glRotatex); + IMPORT_FUNC(glScalex); + IMPORT_FUNC(glShadeModel); + IMPORT_FUNC(glTranslatex); + IMPORT_FUNC(glVertexPointer); + IMPORT_FUNC(glViewport); + +#endif /* DISABLE_IMPORTGL */ + + return result; +} + + +void importGLDeinit() +{ +#ifndef DISABLE_IMPORTGL +#ifdef WIN32 + FreeLibrary(sGLESDLL); +#endif + +#ifdef LINUX + dlclose(sGLESSO); +#endif +#endif /* DISABLE_IMPORTGL */ +} diff -r c93b44ddc63e -r 611d39792201 android/testproject/jni/importgl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/jni/importgl.h Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,172 @@ +/* San Angeles Observation OpenGL ES version example + * Copyright 2004-2005 Jetro Lauha + * All rights reserved. + * Web: http://iki.fi/jetro/ + * + * This source is free software; you can redistribute it and/or + * modify it under the terms of EITHER: + * (1) The GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at + * your option) any later version. The text of the GNU Lesser + * General Public License is included with this source in the + * file LICENSE-LGPL.txt. + * (2) The BSD-style license that is included with this source in + * the file LICENSE-BSD.txt. + * + * This source is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files + * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details. + * + * $Id: importgl.h,v 1.4 2005/02/24 20:29:33 tonic Exp $ + * $Revision: 1.4 $ + */ + +#ifndef IMPORTGL_H_INCLUDED +#define IMPORTGL_H_INCLUDED + + +#ifdef __cplusplus +extern "C" { +#endif + + +#include +#ifndef ANDROID_NDK +#include +#endif /* !ANDROID_NDK */ + +/* Use DISABLE_IMPORTGL if you want to link the OpenGL ES at + * compile/link time and not import it dynamically runtime. + */ +#ifndef DISABLE_IMPORTGL + + +/* Dynamically fetches pointers to the egl & gl functions. + * Should be called once on application initialization. + * Returns non-zero on success and 0 on failure. + */ +extern int importGLInit(); + +/* Frees the handle to egl & gl functions library. + */ +extern void importGLDeinit(); + + +#ifndef IMPORTGL_API +#define IMPORTGL_API extern +#endif +#ifndef IMPORTGL_FNPTRINIT +#define IMPORTGL_FNPTRINIT +#endif + +#define FNDEF(retType, funcName, args) IMPORTGL_API retType (*funcPtr_##funcName) args IMPORTGL_FNPTRINIT + +#ifndef ANDROID_NDK +FNDEF(EGLBoolean, eglChooseConfig, (EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)); +FNDEF(EGLContext, eglCreateContext, (EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list)); +FNDEF(EGLSurface, eglCreateWindowSurface, (EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list)); +FNDEF(EGLBoolean, eglDestroyContext, (EGLDisplay dpy, EGLContext ctx)); +FNDEF(EGLBoolean, eglDestroySurface, (EGLDisplay dpy, EGLSurface surface)); +FNDEF(EGLBoolean, eglGetConfigAttrib, (EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)); +FNDEF(EGLBoolean, eglGetConfigs, (EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)); +FNDEF(EGLDisplay, eglGetDisplay, (NativeDisplayType display)); +FNDEF(EGLint, eglGetError, (void)); +FNDEF(EGLBoolean, eglInitialize, (EGLDisplay dpy, EGLint *major, EGLint *minor)); +FNDEF(EGLBoolean, eglMakeCurrent, (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)); +FNDEF(EGLBoolean, eglSwapBuffers, (EGLDisplay dpy, EGLSurface draw)); +FNDEF(EGLBoolean, eglTerminate, (EGLDisplay dpy)); +#endif /* !ANDROID_NDK */ + +FNDEF(void, glBlendFunc, (GLenum sfactor, GLenum dfactor)); +FNDEF(void, glClear, (GLbitfield mask)); +FNDEF(void, glClearColorx, (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha)); +FNDEF(void, glColor4x, (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)); +FNDEF(void, glColorPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)); +FNDEF(void, glDisable, (GLenum cap)); +FNDEF(void, glDisableClientState, (GLenum array)); +FNDEF(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count)); +FNDEF(void, glEnable, (GLenum cap)); +FNDEF(void, glEnableClientState, (GLenum array)); +FNDEF(void, glFrustumx, (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)); +FNDEF(GLenum, glGetError, (void)); +FNDEF(void, glLightxv, (GLenum light, GLenum pname, const GLfixed *params)); +FNDEF(void, glLoadIdentity, (void)); +FNDEF(void, glMaterialx, (GLenum face, GLenum pname, GLfixed param)); +FNDEF(void, glMaterialxv, (GLenum face, GLenum pname, const GLfixed *params)); +FNDEF(void, glMatrixMode, (GLenum mode)); +FNDEF(void, glMultMatrixx, (const GLfixed *m)); +FNDEF(void, glNormalPointer, (GLenum type, GLsizei stride, const GLvoid *pointer)); +FNDEF(void, glPopMatrix, (void)); +FNDEF(void, glPushMatrix, (void)); +FNDEF(void, glRotatex, (GLfixed angle, GLfixed x, GLfixed y, GLfixed z)); +FNDEF(void, glScalex, (GLfixed x, GLfixed y, GLfixed z)); +FNDEF(void, glShadeModel, (GLenum mode)); +FNDEF(void, glTranslatex, (GLfixed x, GLfixed y, GLfixed z)); +FNDEF(void, glVertexPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)); +FNDEF(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height)); + + +#undef FN +#define FNPTR(name) funcPtr_##name + +#ifndef IMPORTGL_NO_FNPTR_DEFS + +// Redirect egl* and gl* function calls to funcPtr_egl* and funcPtr_gl*. + +#ifndef ANDROID_NDK +#define eglChooseConfig FNPTR(eglChooseConfig) +#define eglCreateContext FNPTR(eglCreateContext) +#define eglCreateWindowSurface FNPTR(eglCreateWindowSurface) +#define eglDestroyContext FNPTR(eglDestroyContext) +#define eglDestroySurface FNPTR(eglDestroySurface) +#define eglGetConfigAttrib FNPTR(eglGetConfigAttrib) +#define eglGetConfigs FNPTR(eglGetConfigs) +#define eglGetDisplay FNPTR(eglGetDisplay) +#define eglGetError FNPTR(eglGetError) +#define eglInitialize FNPTR(eglInitialize) +#define eglMakeCurrent FNPTR(eglMakeCurrent) +#define eglSwapBuffers FNPTR(eglSwapBuffers) +#define eglTerminate FNPTR(eglTerminate) +#endif /* !ANDROID_NDK */ + +#define glBlendFunc FNPTR(glBlendFunc) +#define glClear FNPTR(glClear) +#define glClearColorx FNPTR(glClearColorx) +#define glColor4x FNPTR(glColor4x) +#define glColorPointer FNPTR(glColorPointer) +#define glDisable FNPTR(glDisable) +#define glDisableClientState FNPTR(glDisableClientState) +#define glDrawArrays FNPTR(glDrawArrays) +#define glEnable FNPTR(glEnable) +#define glEnableClientState FNPTR(glEnableClientState) +#define glFrustumx FNPTR(glFrustumx) +#define glGetError FNPTR(glGetError) +#define glLightxv FNPTR(glLightxv) +#define glLoadIdentity FNPTR(glLoadIdentity) +#define glMaterialx FNPTR(glMaterialx) +#define glMaterialxv FNPTR(glMaterialxv) +#define glMatrixMode FNPTR(glMatrixMode) +#define glMultMatrixx FNPTR(glMultMatrixx) +#define glNormalPointer FNPTR(glNormalPointer) +#define glPopMatrix FNPTR(glPopMatrix) +#define glPushMatrix FNPTR(glPushMatrix) +#define glRotatex FNPTR(glRotatex) +#define glScalex FNPTR(glScalex) +#define glShadeModel FNPTR(glShadeModel) +#define glTranslatex FNPTR(glTranslatex) +#define glVertexPointer FNPTR(glVertexPointer) +#define glViewport FNPTR(glViewport) + +#endif // !IMPORTGL_NO_FNPTR_DEFS + + +#endif // !DISABLE_IMPORTGL + + +#ifdef __cplusplus +} +#endif + + +#endif // !IMPORTGL_H_INCLUDED diff -r c93b44ddc63e -r 611d39792201 android/testproject/libs/armeabi/libsanangeles.so Binary file android/testproject/libs/armeabi/libsanangeles.so has changed diff -r c93b44ddc63e -r 611d39792201 android/testproject/local.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/local.properties Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,10 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must *NOT* be checked in Version Control Systems, +# as it contains information specific to your local configuration. + +# location of the SDK. This is only used by Ant +# For customization when using a Version Control System, please read the +# header note. +sdk.dir=/home/paul/Projects/gsoc/sdk/android-sdk-linux_86 diff -r c93b44ddc63e -r 611d39792201 android/testproject/res/drawable-hdpi/icon.png Binary file android/testproject/res/drawable-hdpi/icon.png has changed diff -r c93b44ddc63e -r 611d39792201 android/testproject/res/drawable-ldpi/icon.png Binary file android/testproject/res/drawable-ldpi/icon.png has changed diff -r c93b44ddc63e -r 611d39792201 android/testproject/res/drawable-mdpi/icon.png Binary file android/testproject/res/drawable-mdpi/icon.png has changed diff -r c93b44ddc63e -r 611d39792201 android/testproject/res/layout/main.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/res/layout/main.xml Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,13 @@ + + + + + diff -r c93b44ddc63e -r 611d39792201 android/testproject/res/values/strings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/res/values/strings.xml Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,4 @@ + + + TestActivity + diff -r c93b44ddc63e -r 611d39792201 android/testproject/src/org/libsdl/android/TestActivity.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/android/testproject/src/org/libsdl/android/TestActivity.java Thu Jun 17 22:19:27 2010 +1200 @@ -0,0 +1,76 @@ +package org.libsdl.android; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +import android.app.Activity; +import android.content.Context; +import android.opengl.GLSurfaceView; +import android.os.Bundle; +import android.view.MotionEvent; + +public class TestActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mGLView = new TestGLSurfaceView(this); + setContentView(mGLView); + } + + @Override + protected void onPause() { + super.onPause(); + mGLView.onPause(); + } + + @Override + protected void onResume() { + super.onResume(); + mGLView.onResume(); + } + + private GLSurfaceView mGLView; + + static { + System.loadLibrary("sanangeles"); + } +} + +class TestGLSurfaceView extends GLSurfaceView { + public TestGLSurfaceView(Context context) { + super(context); + mRenderer = new TestRenderer(); + setRenderer(mRenderer); + } + + public boolean onTouchEvent(final MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + nativePause(); + } + return true; + } + + TestRenderer mRenderer; + + private static native void nativePause(); +} + +class TestRenderer implements GLSurfaceView.Renderer { + public void onSurfaceCreated(GL10 gl, EGLConfig config) { + nativeInit(); + } + + public void onSurfaceChanged(GL10 gl, int w, int h) { + //gl.glViewport(0, 0, w, h); + nativeResize(w, h); + } + + public void onDrawFrame(GL10 gl) { + nativeRender(); + } + + private static native void nativeInit(); + private static native void nativeResize(int w, int h); + private static native void nativeRender(); + private static native void nativeDone(); +}