video: Let video targets optionally decide their default OpenGL configs.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 02 Sep 2017 19:35:32 -0400
changeset 1144438f181f81476
parent 11443 a15af5a487a1
child 11445 8d0fb04ecb13
video: Let video targets optionally decide their default OpenGL configs.

This is necessary because the Raspberry Pi is a strange beast, that believes
it has OpenGL support (through glX?) but generally has GLES2 support.

So when using the raspberry video target, we need to force this to default
to a GLES2 context, or by default SDL_CreateWindow() will fail, deep down
when it tries to load the proper GL library.

Fixes testsprite2 (and basically everything else that wasn't testgles2) when
run on a Raspberry Pi without a X server.

Please note that other targets might also need this filled in, the Raspberry
Pi is just the most prominent and readily-available System-On-A-Chip style
thing on my desk. :)
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/raspberry/SDL_rpiopengles.c
src/video/raspberry/SDL_rpiopengles.h
src/video/raspberry/SDL_rpivideo.c
     1.1 --- a/src/video/SDL_sysvideo.h	Sat Sep 02 16:41:14 2017 -0400
     1.2 +++ b/src/video/SDL_sysvideo.h	Sat Sep 02 19:35:32 2017 -0400
     1.3 @@ -261,6 +261,7 @@
     1.4      int (*GL_GetSwapInterval) (_THIS);
     1.5      int (*GL_SwapWindow) (_THIS, SDL_Window * window);
     1.6      void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
     1.7 +    void (*GL_DefaultProfileConfig) (_THIS, int *mask, int *major, int *minor);
     1.8  
     1.9      /* * * */
    1.10      /*
     2.1 --- a/src/video/SDL_video.c	Sat Sep 02 16:41:14 2017 -0400
     2.2 +++ b/src/video/SDL_video.c	Sat Sep 02 19:35:32 2017 -0400
     2.3 @@ -2987,19 +2987,27 @@
     2.4      _this->gl_config.multisamplesamples = 0;
     2.5      _this->gl_config.retained_backing = 1;
     2.6      _this->gl_config.accelerated = -1;  /* accelerated or not, both are fine */
     2.7 -    _this->gl_config.profile_mask = 0;
     2.8 +
     2.9 +    if (_this->GL_DefaultProfileConfig) {
    2.10 +        _this->GL_DefaultProfileConfig(_this, &_this->gl_config.profile_mask,
    2.11 +                                       &_this->gl_config.major_version,
    2.12 +                                       &_this->gl_config.minor_version);
    2.13 +    } else {
    2.14  #if SDL_VIDEO_OPENGL
    2.15 -    _this->gl_config.major_version = 2;
    2.16 -    _this->gl_config.minor_version = 1;
    2.17 +        _this->gl_config.major_version = 2;
    2.18 +        _this->gl_config.minor_version = 1;
    2.19 +        _this->gl_config.profile_mask = 0;
    2.20  #elif SDL_VIDEO_OPENGL_ES2
    2.21 -    _this->gl_config.major_version = 2;
    2.22 -    _this->gl_config.minor_version = 0;
    2.23 -    _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
    2.24 +        _this->gl_config.major_version = 2;
    2.25 +        _this->gl_config.minor_version = 0;
    2.26 +        _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
    2.27  #elif SDL_VIDEO_OPENGL_ES
    2.28 -    _this->gl_config.major_version = 1;
    2.29 -    _this->gl_config.minor_version = 1;
    2.30 -    _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
    2.31 +        _this->gl_config.major_version = 1;
    2.32 +        _this->gl_config.minor_version = 1;
    2.33 +        _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
    2.34  #endif
    2.35 +    }
    2.36 +
    2.37      _this->gl_config.flags = 0;
    2.38      _this->gl_config.framebuffer_srgb_capable = 0;
    2.39      _this->gl_config.no_error = 0;
     3.1 --- a/src/video/raspberry/SDL_rpiopengles.c	Sat Sep 02 16:41:14 2017 -0400
     3.2 +++ b/src/video/raspberry/SDL_rpiopengles.c	Sat Sep 02 19:35:32 2017 -0400
     3.3 @@ -27,6 +27,14 @@
     3.4  
     3.5  /* EGL implementation of SDL OpenGL support */
     3.6  
     3.7 +void
     3.8 +RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor)
     3.9 +{
    3.10 +    *mask = SDL_GL_CONTEXT_PROFILE_ES;
    3.11 +    *major = 2;
    3.12 +    *minor = 0;
    3.13 +}
    3.14 +
    3.15  int
    3.16  RPI_GLES_LoadLibrary(_THIS, const char *path) {
    3.17      return SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0);
     4.1 --- a/src/video/raspberry/SDL_rpiopengles.h	Sat Sep 02 16:41:14 2017 -0400
     4.2 +++ b/src/video/raspberry/SDL_rpiopengles.h	Sat Sep 02 19:35:32 2017 -0400
     4.3 @@ -40,6 +40,7 @@
     4.4  extern SDL_GLContext RPI_GLES_CreateContext(_THIS, SDL_Window * window);
     4.5  extern int RPI_GLES_SwapWindow(_THIS, SDL_Window * window);
     4.6  extern int RPI_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
     4.7 +extern void RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor);
     4.8  
     4.9  #endif /* SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL */
    4.10  
     5.1 --- a/src/video/raspberry/SDL_rpivideo.c	Sat Sep 02 16:41:14 2017 -0400
     5.2 +++ b/src/video/raspberry/SDL_rpivideo.c	Sat Sep 02 19:35:32 2017 -0400
     5.3 @@ -123,6 +123,7 @@
     5.4      device->GL_GetSwapInterval = RPI_GLES_GetSwapInterval;
     5.5      device->GL_SwapWindow = RPI_GLES_SwapWindow;
     5.6      device->GL_DeleteContext = RPI_GLES_DeleteContext;
     5.7 +    device->GL_DefaultProfileConfig = RPI_GLES_DefaultProfileConfig;
     5.8  
     5.9      device->PumpEvents = RPI_PumpEvents;
    5.10