diff -r 58908b180ebd android-project/src/org/libsdl/app/SDLActivity.java --- a/android-project/src/org/libsdl/app/SDLActivity.java Sat Jul 13 03:13:41 2013 -0700 +++ b/android-project/src/org/libsdl/app/SDLActivity.java Sat Jul 13 17:40:10 2013 +0300 @@ -245,8 +245,8 @@ // Java functions called from C - public static boolean createGLContext(int majorVersion, int minorVersion, int[] attribs) { - return initEGL(majorVersion, minorVersion, attribs); + public static boolean createGLContext(int majorVersion, int minorVersion, int[] attribs, boolean forceRecreation) { + return initEGL(majorVersion, minorVersion, attribs, forceRecreation); } public static void flipBuffers() { @@ -311,13 +311,28 @@ // EGL functions - public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs) { + public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs, boolean forceContextRecreation) { try { + EGL10 egl = (EGL10)EGLContext.getEGL(); + // Destroy current context if it should be recreated + if ((SDLActivity.mEGLDisplay != null) && forceContextRecreation) { + Log.v("SDL", "Preparing to recreate OpenGL ES context"); + if (SDLActivity.mEGLContext != null) { + egl.eglMakeCurrent(SDLActivity.mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); + egl.eglDestroyContext(SDLActivity.mEGLDisplay, SDLActivity.mEGLContext); + SDLActivity.mEGLContext = null; + } + if (SDLActivity.mEGLSurface != EGL10.EGL_NO_SURFACE) { + egl.eglDestroySurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface); + SDLActivity.mEGLSurface = EGL10.EGL_NO_SURFACE; + } + egl.eglTerminate(SDLActivity.mEGLDisplay); + SDLActivity.mEGLDisplay = null; + } + // Create a new context if required if (SDLActivity.mEGLDisplay == null) { Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion); - EGL10 egl = (EGL10)EGLContext.getEGL(); - EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; diff -r 58908b180ebd src/core/android/SDL_android.cpp --- a/src/core/android/SDL_android.cpp Sat Jul 13 03:13:41 2013 -0700 +++ b/src/core/android/SDL_android.cpp Sat Jul 13 17:40:10 2013 +0300 @@ -120,7 +120,7 @@ mActivityClass = (jclass)mEnv->NewGlobalRef(cls); midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass, - "createGLContext","(II[I)Z"); + "createGLContext","(II[IZ)Z"); midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass, "flipBuffers","()V"); midAudioInit = mEnv->GetStaticMethodID(mActivityClass, @@ -340,7 +340,10 @@ array = env->NewIntArray(len); env->SetIntArrayRegion(array, 0, len, attribs); - jboolean success = env->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion, array); + /* Don't force context recreation if we are back from a resume. + * Note that the following call hides a cast from SDL_bool to jboolean. + */ + jboolean success = env->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion, array, Android_ForceGLContextRecreation); env->DeleteLocalRef(array); diff -r 58908b180ebd src/video/android/SDL_androidevents.c --- a/src/video/android/SDL_androidevents.c Sat Jul 13 03:13:41 2013 -0700 +++ b/src/video/android/SDL_androidevents.c Sat Jul 13 17:40:10 2013 +0300 @@ -58,7 +58,9 @@ * SDLActivity::createEGLContext will attempt to restore the GL context first, and if that fails it will create a new one * If a new GL context is created, the user needs to restore the textures manually (TODO: notify the user that this happened with a message) */ + Android_ForceGLContextRecreation = SDL_FALSE; SDL_GL_CreateContext(Android_Window); + Android_ForceGLContextRecreation = SDL_TRUE; } } else { diff -r 58908b180ebd src/video/android/SDL_androidvideo.c --- a/src/video/android/SDL_androidvideo.c Sat Jul 13 03:13:41 2013 -0700 +++ b/src/video/android/SDL_androidvideo.c Sat Jul 13 17:40:10 2013 +0300 @@ -63,7 +63,9 @@ int Android_ScreenWidth = 0; int Android_ScreenHeight = 0; Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN; +/* These are filled in Android_CreateWindow */ SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL; +SDL_bool Android_ForceGLContextRecreation = SDL_TRUE; /* Currently only one window */ SDL_Window *Android_Window = NULL; diff -r 58908b180ebd src/video/android/SDL_androidvideo.h --- a/src/video/android/SDL_androidvideo.h Sat Jul 13 03:13:41 2013 -0700 +++ b/src/video/android/SDL_androidvideo.h Sat Jul 13 17:40:10 2013 +0300 @@ -42,6 +42,7 @@ extern Uint32 Android_ScreenFormat; extern SDL_sem *Android_PauseSem, *Android_ResumeSem; extern SDL_Window *Android_Window; +extern SDL_bool Android_ForceGLContextRecreation; #endif /* _SDL_androidvideo_h */ diff -r 58908b180ebd src/video/android/SDL_androidwindow.c --- a/src/video/android/SDL_androidwindow.c Sat Jul 13 03:13:41 2013 -0700 +++ b/src/video/android/SDL_androidwindow.c Sat Jul 13 17:40:10 2013 +0300 @@ -40,6 +40,7 @@ Android_Window = window; Android_PauseSem = SDL_CreateSemaphore(0); Android_ResumeSem = SDL_CreateSemaphore(0); + Android_ForceGLContextRecreation = SDL_TRUE; /* Adjust the window data to match the screen */ window->x = 0;