EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension. Fixes bugzilla #2994.
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
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index edbf42c..c7184bd 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -414,6 +414,9 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
EGLContext egl_context, share_context = EGL_NO_CONTEXT;
EGLint profile_mask = _this->gl_config.profile_mask;
+ EGLint major_version = _this->gl_config.major_version;
+ EGLint minor_version = _this->gl_config.minor_version;
+ SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
if (!_this->egl_data) {
/* The EGL library wasn't loaded, SDL_GetError() should have info */
@@ -425,12 +428,18 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
}
/* Set the context version and other attributes. */
- if (_this->gl_config.major_version < 3 && _this->gl_config.flags == 0 &&
- (profile_mask == 0 || profile_mask == SDL_GL_CONTEXT_PROFILE_ES)) {
- /* Create a context without using EGL_KHR_create_context attribs. */
- if (profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+ if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
+ _this->gl_config.flags == 0 &&
+ (profile_mask == 0 || profile_es)) {
+ /* Create a context without using EGL_KHR_create_context attribs.
+ * When creating a GLES context without EGL_KHR_create_context we can
+ * only specify the major version. When creating a desktop GL context
+ * we can't specify any version, so we only try in that case when the
+ * version is less than 3.0 (matches SDL's GLX/WGL behavior.)
+ */
+ if (profile_es) {
attribs[attr++] = EGL_CONTEXT_CLIENT_VERSION;
- attribs[attr++] = SDL_max(_this->gl_config.major_version, 1);
+ attribs[attr++] = SDL_max(major_version, 1);
}
} else {
#ifdef EGL_KHR_create_context
@@ -439,9 +448,9 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
*/
if (SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) {
attribs[attr++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
- attribs[attr++] = _this->gl_config.major_version;
+ attribs[attr++] = major_version;
attribs[attr++] = EGL_CONTEXT_MINOR_VERSION_KHR;
- attribs[attr++] = _this->gl_config.minor_version;
+ attribs[attr++] = minor_version;
/* SDL profile bits match EGL profile bits. */
if (profile_mask != 0 && profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
@@ -465,7 +474,7 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
attribs[attr++] = EGL_NONE;
/* Bind the API */
- if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+ if (profile_es) {
_this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
} else {
_this->egl_data->eglBindAPI(EGL_OPENGL_API);