src/core/android/SDL_android.cpp
changeset 6792 a15821a3471f
parent 6654 2ecfb25be1e2
child 6802 8a6b8ce97656
     1.1 --- a/src/core/android/SDL_android.cpp	Mon Dec 31 14:14:01 2012 -0800
     1.2 +++ b/src/core/android/SDL_android.cpp	Mon Dec 31 14:57:36 2012 -0800
     1.3 @@ -27,6 +27,7 @@
     1.4  
     1.5  #include "SDL_system.h"
     1.6  #include "SDL_android.h"
     1.7 +#include <EGL/egl.h>
     1.8  
     1.9  extern "C" {
    1.10  #include "../../events/SDL_events_c.h"
    1.11 @@ -115,7 +116,7 @@
    1.12      mActivityClass = (jclass)mEnv->NewGlobalRef(cls);
    1.13  
    1.14      midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass,
    1.15 -                                "createGLContext","(II)Z");
    1.16 +                                "createGLContext","(II[I)Z");
    1.17      midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass,
    1.18                                  "flipBuffers","()V");
    1.19      midAudioInit = mEnv->GetStaticMethodID(mActivityClass, 
    1.20 @@ -292,14 +293,38 @@
    1.21  };
    1.22  int LocalReferenceHolder::s_active;
    1.23  
    1.24 -extern "C" SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion)
    1.25 +extern "C" SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion,
    1.26 +                                int red, int green, int blue, int alpha,
    1.27 +                                int buffer, int depth, int stencil,
    1.28 +                                int buffers, int samples)
    1.29  {
    1.30 -    JNIEnv *mEnv = Android_JNI_GetEnv();
    1.31 -    if (mEnv->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion)) {
    1.32 -        return SDL_TRUE;
    1.33 -    } else {
    1.34 -        return SDL_FALSE;
    1.35 -    }
    1.36 +    JNIEnv *env = Android_JNI_GetEnv();
    1.37 +
    1.38 +    jint attribs[] = {
    1.39 +        EGL_RED_SIZE, red,
    1.40 +        EGL_GREEN_SIZE, green,
    1.41 +        EGL_BLUE_SIZE, blue,
    1.42 +        EGL_ALPHA_SIZE, alpha,
    1.43 +        EGL_BUFFER_SIZE, buffer,
    1.44 +        EGL_DEPTH_SIZE, depth,
    1.45 +        EGL_STENCIL_SIZE, stencil,
    1.46 +        EGL_SAMPLE_BUFFERS, buffers,
    1.47 +        EGL_SAMPLES, samples,
    1.48 +        EGL_RENDERABLE_TYPE, (majorVersion == 1 ? EGL_OPENGL_ES_BIT : EGL_OPENGL_ES2_BIT),
    1.49 +        EGL_NONE
    1.50 +    };
    1.51 +    int len = SDL_arraysize(attribs);
    1.52 +
    1.53 +    jintArray array;
    1.54 +
    1.55 +    array = env->NewIntArray(len);
    1.56 +    env->SetIntArrayRegion(array, 0, len, attribs);
    1.57 +
    1.58 +    jboolean success = env->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion, array);
    1.59 +
    1.60 +    env->DeleteLocalRef(array);
    1.61 +
    1.62 +    return success ? SDL_TRUE : SDL_FALSE;
    1.63  }
    1.64  
    1.65  extern "C" void Android_JNI_SwapWindow()