Fixes #1422, restores GL context automatically under Android

This commit is contained in:
Gabriel Jacobo 2012-06-19 13:57:42 -03:00
parent b2b4372f55
commit 8fbd4fb107
7 changed files with 77 additions and 10 deletions

View file

@ -68,17 +68,17 @@ public class SDLActivity extends Activity {
}
// Events
protected void onPause() {
/*protected void onPause() {
Log.v("SDL", "onPause()");
super.onPause();
SDLActivity.nativePause();
// Don't call SDLActivity.nativePause(); here, it will be called by SDLSurface::surfaceDestroyed
}
protected void onResume() {
Log.v("SDL", "onResume()");
super.onResume();
SDLActivity.nativeResume();
}
// Don't call SDLActivity.nativeResume(); here, it will be called via SDLSurface::surfaceChanged->SDLActivity::startApp
}*/
protected void onDestroy() {
super.onDestroy();
@ -249,12 +249,15 @@ public class SDLActivity extends Activity {
return false;
}
if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) {
Log.e("SDL", "Old EGL Context doesnt work, trying with a new one");
createEGLContext();
if (egl.eglGetCurrentContext() != SDLActivity.mEGLContext) {
if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) {
Log.e("SDL", "Failed making EGL Context current");
return false;
Log.e("SDL", "Old EGL Context doesnt work, trying with a new one");
// TODO: Notify the user via a message that the old context could not be restored, and that textures need to be manually restored.
createEGLContext();
if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) {
Log.e("SDL", "Failed making EGL Context current");
return false;
}
}
}
SDLActivity.mEGLSurface = surface;
@ -426,7 +429,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
public void surfaceCreated(SurfaceHolder holder) {
Log.v("SDL", "surfaceCreated()");
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
SDLActivity.createEGLSurface();
enableSensor(Sensor.TYPE_ACCELEROMETER, true);
}