Fixed bug 1616 - SDL does not use values set with SDL_GL_SetAttribute on Android

Philipp Wiesemann 2012-10-06 07:19:57 PDT

SDL does not use values set with SDL_GL_SetAttribute on Android.

I attached a patch which adds this functionality and makes it possible to set
(for example) depth buffer size or anti-aliasing in the actual application
instead of modifying the Java source (which seems currently the only way).
This commit is contained in:
Sam Lantinga 2012-12-31 14:57:36 -08:00
parent 69c062e757
commit b1185a32e3
4 changed files with 48 additions and 27 deletions

View file

@ -167,8 +167,8 @@ public class SDLActivity extends Activity {
// Java functions called from C
public static boolean createGLContext(int majorVersion, int minorVersion) {
return initEGL(majorVersion, minorVersion);
public static boolean createGLContext(int majorVersion, int minorVersion, int[] attribs) {
return initEGL(majorVersion, minorVersion, attribs);
}
public static void flipBuffers() {
@ -251,7 +251,7 @@ public class SDLActivity extends Activity {
// EGL functions
public static boolean initEGL(int majorVersion, int minorVersion) {
public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs) {
try {
if (SDLActivity.mEGLDisplay == null) {
Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion);
@ -263,22 +263,9 @@ public class SDLActivity extends Activity {
int[] version = new int[2];
egl.eglInitialize(dpy, version);
int EGL_OPENGL_ES_BIT = 1;
int EGL_OPENGL_ES2_BIT = 4;
int renderableType = 0;
if (majorVersion == 2) {
renderableType = EGL_OPENGL_ES2_BIT;
} else if (majorVersion == 1) {
renderableType = EGL_OPENGL_ES_BIT;
}
int[] configSpec = {
//EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_RENDERABLE_TYPE, renderableType,
EGL10.EGL_NONE
};
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) {
if (!egl.eglChooseConfig(dpy, attribs, configs, 1, num_config) || num_config[0] == 0) {
Log.e("SDL", "No EGL config available");
return false;
}

View file

@ -27,6 +27,7 @@
#include "SDL_system.h"
#include "SDL_android.h"
#include <EGL/egl.h>
extern "C" {
#include "../../events/SDL_events_c.h"
@ -115,7 +116,7 @@ extern "C" void SDL_Android_Init(JNIEnv* mEnv, jclass cls)
mActivityClass = (jclass)mEnv->NewGlobalRef(cls);
midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass,
"createGLContext","(II)Z");
"createGLContext","(II[I)Z");
midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass,
"flipBuffers","()V");
midAudioInit = mEnv->GetStaticMethodID(mActivityClass,
@ -292,14 +293,38 @@ protected:
};
int LocalReferenceHolder::s_active;
extern "C" SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion)
extern "C" SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion,
int red, int green, int blue, int alpha,
int buffer, int depth, int stencil,
int buffers, int samples)
{
JNIEnv *mEnv = Android_JNI_GetEnv();
if (mEnv->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion)) {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
JNIEnv *env = Android_JNI_GetEnv();
jint attribs[] = {
EGL_RED_SIZE, red,
EGL_GREEN_SIZE, green,
EGL_BLUE_SIZE, blue,
EGL_ALPHA_SIZE, alpha,
EGL_BUFFER_SIZE, buffer,
EGL_DEPTH_SIZE, depth,
EGL_STENCIL_SIZE, stencil,
EGL_SAMPLE_BUFFERS, buffers,
EGL_SAMPLES, samples,
EGL_RENDERABLE_TYPE, (majorVersion == 1 ? EGL_OPENGL_ES_BIT : EGL_OPENGL_ES2_BIT),
EGL_NONE
};
int len = SDL_arraysize(attribs);
jintArray array;
array = env->NewIntArray(len);
env->SetIntArrayRegion(array, 0, len, attribs);
jboolean success = env->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion, array);
env->DeleteLocalRef(array);
return success ? SDL_TRUE : SDL_FALSE;
}
extern "C" void Android_JNI_SwapWindow()

View file

@ -30,7 +30,7 @@ extern "C" {
#include "SDL_rect.h"
/* Interface from the SDL library into the Android Java activity */
extern SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion);
extern SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion, int red, int green, int blue, int alpha, int buffer, int depth, int stencil, int buffers, int samples);
extern void Android_JNI_SwapWindow();
extern void Android_JNI_SetActivityTitle(const char *title);
extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);

View file

@ -74,7 +74,16 @@ SDL_GLContext
Android_GL_CreateContext(_THIS, SDL_Window * window)
{
if (!Android_JNI_CreateContext(_this->gl_config.major_version,
_this->gl_config.minor_version)) {
_this->gl_config.minor_version,
_this->gl_config.red_size,
_this->gl_config.green_size,
_this->gl_config.blue_size,
_this->gl_config.alpha_size,
_this->gl_config.buffer_size,
_this->gl_config.depth_size,
_this->gl_config.stencil_size,
_this->gl_config.multisamplebuffers,
_this->gl_config.multisamplesamples)) {
SDL_SetError("Couldn't create OpenGL context - see Android log for details");
return NULL;
}