Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.

This commit is contained in:
Sam Lantinga
2011-02-07 17:44:07 -08:00
parent 47818cfba9
commit 1f86c7c17d
6 changed files with 61 additions and 14 deletions

View File

@@ -20,6 +20,7 @@
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "SDL_stdinc.h"
#include "SDL_android.h"
@@ -80,7 +81,7 @@ extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls)
mActivityClass = cls;
midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass,
"createGLContext","()V");
"createGLContext","(II)Z");
midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass,
"flipBuffers","()V");
midAudioInit = mEnv->GetStaticMethodID(mActivityClass,
@@ -159,9 +160,13 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativeRunAudioThread(
/*******************************************************************************
Functions called by SDL into Java
*******************************************************************************/
extern "C" void Android_JNI_CreateContext()
extern "C" SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion)
{
mEnv->CallStaticVoidMethod(mActivityClass, midCreateGLContext);
if (mEnv->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion)) {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}
extern "C" void Android_JNI_SwapWindow()

View File

@@ -29,7 +29,7 @@ extern "C" {
#endif
/* Interface from the SDL library into the Android Java activity */
extern void Android_JNI_CreateContext();
extern SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion);
extern void Android_JNI_SwapWindow();
extern void Android_JNI_SetActivityTitle(const char *title);
extern void Android_JNI_GetAccelerometerValues(float values[3]);

View File

@@ -1071,11 +1071,19 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
{
SDL_Renderer *renderer;
GLES2_DriverContext *rdata;
Uint32 window_flags;
GLint nFormats;
#ifndef ZUNE_HD
GLboolean hasCompiler;
#endif
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL)) {
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
return NULL;
}
}
/* Create the renderer struct */
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
if (!renderer) {

View File

@@ -55,7 +55,11 @@ Android_GL_UnloadLibrary(_THIS)
SDL_GLContext
Android_GL_CreateContext(_THIS, SDL_Window * window)
{
Android_JNI_CreateContext();
if (!Android_JNI_CreateContext(_this->gl_config.major_version,
_this->gl_config.minor_version)) {
SDL_SetError("Couldn't create OpenGL context - see Android log for details");
return NULL;
}
return (SDL_GLContext)1;
}
@@ -91,3 +95,5 @@ Android_GL_DeleteContext(_THIS, SDL_GLContext context)
{
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -41,6 +41,12 @@ Android_CreateWindow(_THIS, SDL_Window * window)
window->w = Android_ScreenWidth;
window->h = Android_ScreenHeight;
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
window->flags |= SDL_WINDOW_OPENGL; /* window is always OpenGL */
window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
return 0;
}