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 9637adf81fe554b9
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
     1.1 --- a/src/video/SDL_egl.c	Tue May 26 16:42:36 2015 -0400
     1.2 +++ b/src/video/SDL_egl.c	Tue May 26 19:34:56 2015 -0300
     1.3 @@ -414,6 +414,9 @@
     1.4  
     1.5      EGLContext egl_context, share_context = EGL_NO_CONTEXT;
     1.6      EGLint profile_mask = _this->gl_config.profile_mask;
     1.7 +    EGLint major_version = _this->gl_config.major_version;
     1.8 +    EGLint minor_version = _this->gl_config.minor_version;
     1.9 +    SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
    1.10  
    1.11      if (!_this->egl_data) {
    1.12          /* The EGL library wasn't loaded, SDL_GetError() should have info */
    1.13 @@ -425,12 +428,18 @@
    1.14      }
    1.15  
    1.16      /* Set the context version and other attributes. */
    1.17 -    if (_this->gl_config.major_version < 3 && _this->gl_config.flags == 0 &&
    1.18 -        (profile_mask == 0 || profile_mask == SDL_GL_CONTEXT_PROFILE_ES)) {
    1.19 -        /* Create a context without using EGL_KHR_create_context attribs. */
    1.20 -        if (profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
    1.21 +    if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
    1.22 +        _this->gl_config.flags == 0 &&
    1.23 +        (profile_mask == 0 || profile_es)) {
    1.24 +        /* Create a context without using EGL_KHR_create_context attribs.
    1.25 +         * When creating a GLES context without EGL_KHR_create_context we can
    1.26 +         * only specify the major version. When creating a desktop GL context
    1.27 +         * we can't specify any version, so we only try in that case when the
    1.28 +         * version is less than 3.0 (matches SDL's GLX/WGL behavior.)
    1.29 +         */
    1.30 +        if (profile_es) {
    1.31              attribs[attr++] = EGL_CONTEXT_CLIENT_VERSION;
    1.32 -            attribs[attr++] = SDL_max(_this->gl_config.major_version, 1);
    1.33 +            attribs[attr++] = SDL_max(major_version, 1);
    1.34          }
    1.35      } else {
    1.36  #ifdef EGL_KHR_create_context
    1.37 @@ -439,9 +448,9 @@
    1.38           */
    1.39          if (SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) {
    1.40              attribs[attr++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
    1.41 -            attribs[attr++] = _this->gl_config.major_version;
    1.42 +            attribs[attr++] = major_version;
    1.43              attribs[attr++] = EGL_CONTEXT_MINOR_VERSION_KHR;
    1.44 -            attribs[attr++] = _this->gl_config.minor_version;
    1.45 +            attribs[attr++] = minor_version;
    1.46  
    1.47              /* SDL profile bits match EGL profile bits. */
    1.48              if (profile_mask != 0 && profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
    1.49 @@ -465,7 +474,7 @@
    1.50      attribs[attr++] = EGL_NONE;
    1.51  
    1.52      /* Bind the API */
    1.53 -    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
    1.54 +    if (profile_es) {
    1.55          _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
    1.56      } else {
    1.57          _this->egl_data->eglBindAPI(EGL_OPENGL_API);