SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context
authorKnut Andre Tidemann <knut.tidemann@gmail.com>
Sat, 28 Jun 2014 12:17:29 -0300
changeset 8962c593cbef6d7d
parent 8961 7dbbee37826b
child 8963 f94215b55583
SDL_egl: allow creation of versioned OpenGL contexts with EGL_KHR_create_context

If the EGL extension EGL_KHR_create_context is available, we can use it to
set the core/compatability profile and the minimum OpenGL version.

Use this if it is available to get the context requested by the GL attributes.
configure
configure.in
include/SDL_egl.h
src/video/SDL_egl.c
     1.1 --- a/configure	Thu Jun 26 12:42:15 2014 -0700
     1.2 +++ b/configure	Sat Jun 28 12:17:29 2014 -0300
     1.3 @@ -21045,6 +21045,7 @@
     1.4  /* end confdefs.h.  */
     1.5  
     1.6           #include <EGL/egl.h>
     1.7 +         #include <EGL/eglext.h>
     1.8  
     1.9  int
    1.10  main ()
     2.1 --- a/configure.in	Thu Jun 26 12:42:15 2014 -0700
     2.2 +++ b/configure.in	Sat Jun 28 12:17:29 2014 -0300
     2.3 @@ -1956,6 +1956,7 @@
     2.4          video_opengl_egl=no
     2.5          AC_TRY_COMPILE([
     2.6           #include <EGL/egl.h>
     2.7 +         #include <EGL/eglext.h>
     2.8          ],[
     2.9          ],[
    2.10          video_opengl_egl=yes
     3.1 --- a/include/SDL_egl.h	Thu Jun 26 12:42:15 2014 -0700
     3.2 +++ b/include/SDL_egl.h	Sat Jun 28 12:17:29 2014 -0300
     3.3 @@ -27,6 +27,7 @@
     3.4  #ifndef _MSC_VER
     3.5  
     3.6  #include <EGL/egl.h>
     3.7 +#include <EGL/eglext.h>
     3.8  
     3.9  #else /* _MSC_VER */
    3.10  
     4.1 --- a/src/video/SDL_egl.c	Thu Jun 26 12:42:15 2014 -0700
     4.2 +++ b/src/video/SDL_egl.c	Sat Jun 28 12:17:29 2014 -0300
     4.3 @@ -69,6 +69,37 @@
     4.4  }
     4.5      
     4.6  /* EGL implementation of SDL OpenGL ES support */
     4.7 +static int SDL_EGL_HasExtension(_THIS, const char *ext)
     4.8 +{
     4.9 +    int i;
    4.10 +    int len = 0;
    4.11 +    int ext_len;
    4.12 +    const char *exts;
    4.13 +    const char *ext_word;
    4.14 +
    4.15 +    ext_len = SDL_strlen(ext);
    4.16 +    exts = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_EXTENSIONS);
    4.17 +
    4.18 +    if(exts) {
    4.19 +        ext_word = exts;
    4.20 +
    4.21 +        for(i = 0; exts[i] != 0; i++) {
    4.22 +            if(exts[i] == ' ') {
    4.23 +                if(ext_len == len && !SDL_strncmp(ext_word, ext, len)) {
    4.24 +                    return 1;
    4.25 +                }
    4.26 +
    4.27 +                len = 0;
    4.28 +                ext_word = &exts[i + 1];
    4.29 +            }
    4.30 +            else {
    4.31 +                len++;
    4.32 +            }
    4.33 +        }
    4.34 +    }
    4.35 +
    4.36 +    return 0;
    4.37 +}
    4.38  
    4.39  void *
    4.40  SDL_EGL_GetProcAddress(_THIS, const char *proc)
    4.41 @@ -226,6 +257,7 @@
    4.42      LOAD_FUNC(eglWaitNative);
    4.43      LOAD_FUNC(eglWaitGL);
    4.44      LOAD_FUNC(eglBindAPI);
    4.45 +    LOAD_FUNC(eglQueryString);
    4.46      
    4.47  #if !defined(__WINRT__)
    4.48      _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
    4.49 @@ -365,6 +397,10 @@
    4.50      EGLint context_attrib_list[] = {
    4.51          EGL_CONTEXT_CLIENT_VERSION,
    4.52          1,
    4.53 +        EGL_NONE,
    4.54 +        EGL_NONE,
    4.55 +        EGL_NONE,
    4.56 +        EGL_NONE,
    4.57          EGL_NONE
    4.58      };
    4.59      
    4.60 @@ -392,9 +428,29 @@
    4.61      }
    4.62      else {
    4.63          _this->egl_data->eglBindAPI(EGL_OPENGL_API);
    4.64 +        if(SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) {
    4.65 +            context_attrib_list[0] = EGL_CONTEXT_MAJOR_VERSION_KHR;
    4.66 +            context_attrib_list[1] = _this->gl_config.major_version;
    4.67 +            context_attrib_list[2] = EGL_CONTEXT_MINOR_VERSION_KHR;
    4.68 +            context_attrib_list[3] = _this->gl_config.minor_version;
    4.69 +            context_attrib_list[4] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
    4.70 +            switch(_this->gl_config.profile_mask) {
    4.71 +            case SDL_GL_CONTEXT_PROFILE_COMPATIBILITY:
    4.72 +                context_attrib_list[5] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
    4.73 +                break;
    4.74 +
    4.75 +            case SDL_GL_CONTEXT_PROFILE_CORE:
    4.76 +            default:
    4.77 +                context_attrib_list[5] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
    4.78 +                break;
    4.79 +            }
    4.80 +        }
    4.81 +        else {
    4.82 +            context_attrib_list[0] = EGL_NONE;
    4.83 +        }
    4.84          egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
    4.85                                            _this->egl_data->egl_config,
    4.86 -                                          share_context, NULL);
    4.87 +                                          share_context, context_attrib_list);
    4.88      }
    4.89      
    4.90      if (egl_context == EGL_NO_CONTEXT) {