Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
[Android] Bug 1827, select the best matching config provided by eglCh…
Browse files Browse the repository at this point in the history
…ooseConfig
  • Loading branch information
gabomdq committed Jul 26, 2013
1 parent 8ca0c9b commit 44db9b3
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -323,13 +323,47 @@ public static boolean initEGL(int majorVersion, int minorVersion, int[] attribs)
int[] version = new int[2];
egl.eglInitialize(dpy, version);

EGLConfig[] configs = new EGLConfig[1];
EGLConfig[] configs = new EGLConfig[128];
int[] num_config = new int[1];
if (!egl.eglChooseConfig(dpy, attribs, configs, 1, num_config) || num_config[0] == 0) {
Log.e("SDL", "No EGL config available");
return false;
}
EGLConfig config = configs[0];
EGLConfig config = null;
int bestdiff = -1, bitdiff;
int[] value = new int[1];

// eglChooseConfig returns a number of configurations that match or exceed the requested attribs.
// From those, we select the one that matches our requirements more closely
Log.v("SDL", "Got " + num_config[0] + " valid modes from egl");
for(int i = 0; i < num_config[0]; i++) {
bitdiff = 0;
// Go through some of the attributes and compute the bit difference between what we want and what we get.
for (int j = 0; ; j += 2) {
if (attribs[j] == EGL10.EGL_NONE)
break;

if (attribs[j] == EGL10.EGL_RED_SIZE ||
attribs[j] == EGL10.EGL_GREEN_SIZE ||
attribs[j] == EGL10.EGL_BLUE_SIZE ||
attribs[j] == EGL10.EGL_ALPHA_SIZE ||
attribs[j] == EGL10.EGL_DEPTH_SIZE ||
attribs[j] == EGL10.EGL_STENCIL_SIZE) {
egl.eglGetConfigAttrib(dpy, configs[i], attribs[j], value);
bitdiff += value[0] - attribs[j + 1]; // value is always >= attrib
}
}

if (bitdiff < bestdiff || bestdiff == -1) {
config = configs[i];
bestdiff = bitdiff;
}

if (bitdiff == 0) break; // we found an exact match!
}

Log.d("SDL", "Selected mode with a total bit difference of " + bestdiff);


SDLActivity.mEGLDisplay = dpy;
SDLActivity.mEGLConfig = config;
Expand Down

0 comments on commit 44db9b3

Please sign in to comment.