From 131a0725030ecdade9ac8ebbbfc615c9d9f7b582 Mon Sep 17 00:00:00 2001 From: Gabriel Jacobo Date: Tue, 19 Nov 2013 11:04:05 -0300 Subject: [PATCH] Find the best EGL config available between those returned by eglChooseConfig This existed in the old Android Java code, it got lost in the migration to the commong EGL code. --- src/video/SDL_egl.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index f9ab8faf5..73a6df16f 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -218,7 +218,9 @@ SDL_EGL_ChooseConfig(_THIS) /* 64 seems nice. */ EGLint attribs[64]; EGLint found_configs = 0; - int i; + /* 128 seems even nicer here */ + EGLConfig configs[128]; + int i, j, best_bitdiff = -1, bitdiff, value; if (!_this->egl_data) { /* The EGL library wasn't loaded, SDL_GetError() should have info */ @@ -273,12 +275,44 @@ SDL_EGL_ChooseConfig(_THIS) if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display, attribs, - &_this->egl_data->egl_config, 1, + configs, SDL_arraysize(configs), &found_configs) == EGL_FALSE || found_configs == 0) { return SDL_SetError("Couldn't find matching EGL config"); } + /* 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 via a makeshift algorithm */ + + for ( i=0; iegl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value); + bitdiff += value - attribs[j + 1]; /* value is always >= attrib */ + } + } + + if (bitdiff < best_bitdiff || best_bitdiff == -1) { + _this->egl_data->egl_config = configs[i]; + + best_bitdiff = bitdiff; + } + + if (bitdiff == 0) break; /* we found an exact match! */ + } + return 0; }