EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension.
authorAlex Szpakowski <slime73@gmail.com>
Tue, 26 May 2015 19:34:56 -0300
changeset 9637 adf81fe554b9
parent 9636 ac8cd6c6d966
child 9638 a30b6998c1d8
EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension. Fixes bugzilla #2994.
src/video/SDL_egl.c
--- a/src/video/SDL_egl.c	Tue May 26 16:42:36 2015 -0400
+++ b/src/video/SDL_egl.c	Tue May 26 19:34:56 2015 -0300
@@ -414,6 +414,9 @@
 
     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 @@
     }
 
     /* 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 @@
          */
         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 @@
     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);