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. :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 2083cfc..811fe19 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -261,6 +261,7 @@ struct SDL_VideoDevice
int (*GL_GetSwapInterval) (_THIS);
int (*GL_SwapWindow) (_THIS, SDL_Window * window);
void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
+ void (*GL_DefaultProfileConfig) (_THIS, int *mask, int *major, int *minor);
/* * * */
/*
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 321eb25..5a456c9 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -2987,19 +2987,27 @@ SDL_GL_ResetAttributes()
_this->gl_config.multisamplesamples = 0;
_this->gl_config.retained_backing = 1;
_this->gl_config.accelerated = -1; /* accelerated or not, both are fine */
- _this->gl_config.profile_mask = 0;
+
+ if (_this->GL_DefaultProfileConfig) {
+ _this->GL_DefaultProfileConfig(_this, &_this->gl_config.profile_mask,
+ &_this->gl_config.major_version,
+ &_this->gl_config.minor_version);
+ } else {
#if SDL_VIDEO_OPENGL
- _this->gl_config.major_version = 2;
- _this->gl_config.minor_version = 1;
+ _this->gl_config.major_version = 2;
+ _this->gl_config.minor_version = 1;
+ _this->gl_config.profile_mask = 0;
#elif SDL_VIDEO_OPENGL_ES2
- _this->gl_config.major_version = 2;
- _this->gl_config.minor_version = 0;
- _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
+ _this->gl_config.major_version = 2;
+ _this->gl_config.minor_version = 0;
+ _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
#elif SDL_VIDEO_OPENGL_ES
- _this->gl_config.major_version = 1;
- _this->gl_config.minor_version = 1;
- _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
+ _this->gl_config.major_version = 1;
+ _this->gl_config.minor_version = 1;
+ _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
#endif
+ }
+
_this->gl_config.flags = 0;
_this->gl_config.framebuffer_srgb_capable = 0;
_this->gl_config.no_error = 0;
diff --git a/src/video/raspberry/SDL_rpiopengles.c b/src/video/raspberry/SDL_rpiopengles.c
index 44188e6..5b23a3f 100644
--- a/src/video/raspberry/SDL_rpiopengles.c
+++ b/src/video/raspberry/SDL_rpiopengles.c
@@ -27,6 +27,14 @@
/* EGL implementation of SDL OpenGL support */
+void
+RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor)
+{
+ *mask = SDL_GL_CONTEXT_PROFILE_ES;
+ *major = 2;
+ *minor = 0;
+}
+
int
RPI_GLES_LoadLibrary(_THIS, const char *path) {
return SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0);
diff --git a/src/video/raspberry/SDL_rpiopengles.h b/src/video/raspberry/SDL_rpiopengles.h
index 4a8b8d6..fca8a49 100644
--- a/src/video/raspberry/SDL_rpiopengles.h
+++ b/src/video/raspberry/SDL_rpiopengles.h
@@ -40,6 +40,7 @@ extern int RPI_GLES_LoadLibrary(_THIS, const char *path);
extern SDL_GLContext RPI_GLES_CreateContext(_THIS, SDL_Window * window);
extern int RPI_GLES_SwapWindow(_THIS, SDL_Window * window);
extern int RPI_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor);
#endif /* SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL */
diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c
index 1c6b66f..1e1f569 100644
--- a/src/video/raspberry/SDL_rpivideo.c
+++ b/src/video/raspberry/SDL_rpivideo.c
@@ -123,6 +123,7 @@ RPI_Create()
device->GL_GetSwapInterval = RPI_GLES_GetSwapInterval;
device->GL_SwapWindow = RPI_GLES_SwapWindow;
device->GL_DeleteContext = RPI_GLES_DeleteContext;
+ device->GL_DefaultProfileConfig = RPI_GLES_DefaultProfileConfig;
device->PumpEvents = RPI_PumpEvents;