Skip to content

Commit

Permalink
SDL_EGL_ChooseConfig: don't fall through if no matching format exists
Browse files Browse the repository at this point in the history
On Raspberry Pi 3 via the VC4 driver in firmware KMS mode, none of the
found configs match the desired format, causing the function to fall through
without any config being selected.

Fix by first iterating over the found configs, and if no match exists,
don't exclude the non-matching configs. This should fix RPI3 and possibly other
targets without breaking targets that have a matching native format (such as RPI4).
  • Loading branch information
psyke83 committed Apr 13, 2020
1 parent 64617d2 commit c0a875f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/video/SDL_egl.c
Expand Up @@ -683,6 +683,7 @@ SDL_EGL_ChooseConfig(_THIS)
EGLint found_configs = 0, value;
/* 128 seems even nicer here */
EGLConfig configs[128];
SDL_bool has_matching_format = SDL_FALSE;
int i, j, best_bitdiff = -1, bitdiff;

if (!_this->egl_data) {
Expand Down Expand Up @@ -766,11 +767,24 @@ SDL_EGL_ChooseConfig(_THIS)
return SDL_EGL_SetError("Couldn't find matching EGL config", "eglChooseConfig");
}

/* first ensure that a found config has a matching format, or the function will fall through. */
for (i = 0; i < found_configs; i++ ) {
if (_this->egl_data->egl_required_visual_id)
{
EGLint format;
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
configs[i],
EGL_NATIVE_VISUAL_ID, &format);
if (_this->egl_data->egl_required_visual_id == format)
has_matching_format = SDL_TRUE;
}
}

/* 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; i < found_configs; i++ ) {
if (_this->egl_data->egl_required_visual_id)
if (has_matching_format && _this->egl_data->egl_required_visual_id)
{
EGLint format;
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
Expand Down

0 comments on commit c0a875f

Please sign in to comment.