Fixed bug 4041 - Android, SDL_Renderer OpenGLES 1 is loading GLESv2 library
authorSam Lantinga
Sat, 08 Jun 2019 18:40:11 -0700
changeset 1280500a1aa5a1fc0
parent 12804 1a330416800d
child 12806 b06fa7da012b
Fixed bug 4041 - Android, SDL_Renderer OpenGLES 1 is loading GLESv2 library

Sylvain

On Android, if you set no attribute using SDL_GL_SetAttribute(), and try to create a SDL Render OpenGLES 1:

- it loads first by default GLESv2 libraries
- creates the rendere OpenGLES 1
- recreates the Window to have a context 1.1 ( https://hg.libsdl.org/SDL/file/00fb5966c44f/src/render/opengles/SDL_render_gles.c#l298 )

But it doesn't unload libraries, then reload GLESv1 lib. So the SDL_Renderer OpenGLES 1 is working with GLES 2 libs, which seems inconsistent.


If you, at first, set
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
It will correctly load GLES v1 libraries.

Here's a small patch to reload egl libs when SDL_RecreateWindow() is called.
It fixes the issue, also the case from bug 4042

( SDL_RecreateWindow() is used by SDL_Renderer gl, gles1, gles2. )
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_video.c	Sat Jun 08 18:32:29 2019 -0700
     1.2 +++ b/src/video/SDL_video.c	Sat Jun 08 18:40:11 2019 -0700
     1.3 @@ -1654,6 +1654,12 @@
     1.4          } else {
     1.5              SDL_GL_UnloadLibrary();
     1.6          }
     1.7 +    } else if (window->flags & SDL_WINDOW_OPENGL) {
     1.8 +        SDL_GL_UnloadLibrary();
     1.9 +        if (SDL_GL_LoadLibrary(NULL) < 0) {
    1.10 +            return -1;
    1.11 +        }
    1.12 +        loaded_opengl = SDL_TRUE;
    1.13      }
    1.14  
    1.15      if ((window->flags & SDL_WINDOW_VULKAN) != (flags & SDL_WINDOW_VULKAN)) {