Fixes bug #1889, allows for GL Context deletion/recreation on Android
Thanks ny00!
This commit is contained in:
parent
a99dfca578
commit
2a6b235190
3 changed files with 41 additions and 14 deletions
|
@ -72,6 +72,7 @@ public class SDLActivity extends Activity {
|
||||||
// Set up the surface
|
// Set up the surface
|
||||||
mEGLSurface = EGL10.EGL_NO_SURFACE;
|
mEGLSurface = EGL10.EGL_NO_SURFACE;
|
||||||
mSurface = new SDLSurface(getApplication());
|
mSurface = new SDLSurface(getApplication());
|
||||||
|
mEGLContext = EGL10.EGL_NO_CONTEXT;
|
||||||
|
|
||||||
mLayout = new AbsoluteLayout(this);
|
mLayout = new AbsoluteLayout(this);
|
||||||
mLayout.addView(mSurface);
|
mLayout.addView(mSurface);
|
||||||
|
@ -250,6 +251,20 @@ public class SDLActivity extends Activity {
|
||||||
return initEGL(majorVersion, minorVersion, attribs);
|
return initEGL(majorVersion, minorVersion, attribs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteGLContext() {
|
||||||
|
if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLContext != EGL10.EGL_NO_CONTEXT) {
|
||||||
|
EGL10 egl = (EGL10)EGLContext.getEGL();
|
||||||
|
egl.eglMakeCurrent(SDLActivity.mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
|
||||||
|
egl.eglDestroyContext(SDLActivity.mEGLDisplay, SDLActivity.mEGLContext);
|
||||||
|
SDLActivity.mEGLContext = EGL10.EGL_NO_CONTEXT;
|
||||||
|
|
||||||
|
if (SDLActivity.mEGLSurface != EGL10.EGL_NO_SURFACE) {
|
||||||
|
egl.eglDestroySurface(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface);
|
||||||
|
SDLActivity.mEGLSurface = EGL10.EGL_NO_SURFACE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void flipBuffers() {
|
public static void flipBuffers() {
|
||||||
flipEGL();
|
flipEGL();
|
||||||
}
|
}
|
||||||
|
@ -314,19 +329,20 @@ public class SDLActivity extends Activity {
|
||||||
// EGL functions
|
// EGL functions
|
||||||
public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs) {
|
public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs) {
|
||||||
try {
|
try {
|
||||||
|
EGL10 egl = (EGL10)EGLContext.getEGL();
|
||||||
|
|
||||||
if (SDLActivity.mEGLDisplay == null) {
|
if (SDLActivity.mEGLDisplay == null) {
|
||||||
Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion);
|
SDLActivity.mEGLDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
||||||
|
|
||||||
EGL10 egl = (EGL10)EGLContext.getEGL();
|
|
||||||
|
|
||||||
EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
|
||||||
|
|
||||||
int[] version = new int[2];
|
int[] version = new int[2];
|
||||||
egl.eglInitialize(dpy, version);
|
egl.eglInitialize(SDLActivity.mEGLDisplay, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) {
|
||||||
|
// No current GL context exists, we will create a new one.
|
||||||
|
Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion);
|
||||||
EGLConfig[] configs = new EGLConfig[128];
|
EGLConfig[] configs = new EGLConfig[128];
|
||||||
int[] num_config = new int[1];
|
int[] num_config = new int[1];
|
||||||
if (!egl.eglChooseConfig(dpy, attribs, configs, 1, num_config) || num_config[0] == 0) {
|
if (!egl.eglChooseConfig(SDLActivity.mEGLDisplay, attribs, configs, 1, num_config) || num_config[0] == 0) {
|
||||||
Log.e("SDL", "No EGL config available");
|
Log.e("SDL", "No EGL config available");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -350,7 +366,7 @@ public class SDLActivity extends Activity {
|
||||||
attribs[j] == EGL10.EGL_ALPHA_SIZE ||
|
attribs[j] == EGL10.EGL_ALPHA_SIZE ||
|
||||||
attribs[j] == EGL10.EGL_DEPTH_SIZE ||
|
attribs[j] == EGL10.EGL_DEPTH_SIZE ||
|
||||||
attribs[j] == EGL10.EGL_STENCIL_SIZE)) {
|
attribs[j] == EGL10.EGL_STENCIL_SIZE)) {
|
||||||
egl.eglGetConfigAttrib(dpy, configs[i], attribs[j], value);
|
egl.eglGetConfigAttrib(SDLActivity.mEGLDisplay, configs[i], attribs[j], value);
|
||||||
bitdiff += value[0] - attribs[j + 1]; // value is always >= attrib
|
bitdiff += value[0] - attribs[j + 1]; // value is always >= attrib
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,12 +381,11 @@ public class SDLActivity extends Activity {
|
||||||
|
|
||||||
Log.d("SDL", "Selected mode with a total bit difference of " + bestdiff);
|
Log.d("SDL", "Selected mode with a total bit difference of " + bestdiff);
|
||||||
|
|
||||||
|
|
||||||
SDLActivity.mEGLDisplay = dpy;
|
|
||||||
SDLActivity.mEGLConfig = config;
|
SDLActivity.mEGLConfig = config;
|
||||||
SDLActivity.mGLMajor = majorVersion;
|
SDLActivity.mGLMajor = majorVersion;
|
||||||
SDLActivity.mGLMinor = minorVersion;
|
SDLActivity.mGLMinor = minorVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SDLActivity.createEGLSurface();
|
return SDLActivity.createEGLSurface();
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
@ -397,7 +412,7 @@ public class SDLActivity extends Activity {
|
||||||
public static boolean createEGLSurface() {
|
public static boolean createEGLSurface() {
|
||||||
if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) {
|
if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) {
|
||||||
EGL10 egl = (EGL10)EGLContext.getEGL();
|
EGL10 egl = (EGL10)EGLContext.getEGL();
|
||||||
if (SDLActivity.mEGLContext == null) createEGLContext();
|
if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) createEGLContext();
|
||||||
|
|
||||||
if (SDLActivity.mEGLSurface == EGL10.EGL_NO_SURFACE) {
|
if (SDLActivity.mEGLSurface == EGL10.EGL_NO_SURFACE) {
|
||||||
Log.v("SDL", "Creating new EGL Surface");
|
Log.v("SDL", "Creating new EGL Surface");
|
||||||
|
|
|
@ -71,6 +71,7 @@ static jclass mActivityClass;
|
||||||
|
|
||||||
// method signatures
|
// method signatures
|
||||||
static jmethodID midCreateGLContext;
|
static jmethodID midCreateGLContext;
|
||||||
|
static jmethodID midDeleteGLContext;
|
||||||
static jmethodID midFlipBuffers;
|
static jmethodID midFlipBuffers;
|
||||||
static jmethodID midAudioInit;
|
static jmethodID midAudioInit;
|
||||||
static jmethodID midAudioWriteShortBuffer;
|
static jmethodID midAudioWriteShortBuffer;
|
||||||
|
@ -120,6 +121,8 @@ void SDL_Android_Init(JNIEnv* mEnv, jclass cls)
|
||||||
|
|
||||||
midCreateGLContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
midCreateGLContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
"createGLContext","(II[I)Z");
|
"createGLContext","(II[I)Z");
|
||||||
|
midDeleteGLContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
"deleteGLContext","()V");
|
||||||
midFlipBuffers = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
midFlipBuffers = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
"flipBuffers","()V");
|
"flipBuffers","()V");
|
||||||
midAudioInit = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
midAudioInit = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||||
|
@ -361,6 +364,13 @@ SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion,
|
||||||
return success ? SDL_TRUE : SDL_FALSE;
|
return success ? SDL_TRUE : SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_bool Android_JNI_DeleteContext(SDL_GLContext context)
|
||||||
|
{
|
||||||
|
/* There's only one context, so the parameter is ignored for now */
|
||||||
|
JNIEnv *env = Android_JNI_GetEnv();
|
||||||
|
(*env)->CallStaticBooleanMethod(env, mActivityClass, midDeleteGLContext);
|
||||||
|
}
|
||||||
|
|
||||||
void Android_JNI_SwapWindow()
|
void Android_JNI_SwapWindow()
|
||||||
{
|
{
|
||||||
JNIEnv *mEnv = Android_JNI_GetEnv();
|
JNIEnv *mEnv = Android_JNI_GetEnv();
|
||||||
|
|
|
@ -119,7 +119,9 @@ Android_GL_SwapWindow(_THIS, SDL_Window * window)
|
||||||
void
|
void
|
||||||
Android_GL_DeleteContext(_THIS, SDL_GLContext context)
|
Android_GL_DeleteContext(_THIS, SDL_GLContext context)
|
||||||
{
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
|
if (context) {
|
||||||
|
Android_JNI_DeleteContext(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SDL_VIDEO_DRIVER_ANDROID */
|
#endif /* SDL_VIDEO_DRIVER_ANDROID */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue