src/video/SDL_egl.c
changeset 8962 c593cbef6d7d
parent 8872 5a6375d96834
child 8964 d9ac759bb62a
     1.1 --- a/src/video/SDL_egl.c	Thu Jun 26 12:42:15 2014 -0700
     1.2 +++ b/src/video/SDL_egl.c	Sat Jun 28 12:17:29 2014 -0300
     1.3 @@ -69,6 +69,37 @@
     1.4  }
     1.5      
     1.6  /* EGL implementation of SDL OpenGL ES support */
     1.7 +static int SDL_EGL_HasExtension(_THIS, const char *ext)
     1.8 +{
     1.9 +    int i;
    1.10 +    int len = 0;
    1.11 +    int ext_len;
    1.12 +    const char *exts;
    1.13 +    const char *ext_word;
    1.14 +
    1.15 +    ext_len = SDL_strlen(ext);
    1.16 +    exts = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_EXTENSIONS);
    1.17 +
    1.18 +    if(exts) {
    1.19 +        ext_word = exts;
    1.20 +
    1.21 +        for(i = 0; exts[i] != 0; i++) {
    1.22 +            if(exts[i] == ' ') {
    1.23 +                if(ext_len == len && !SDL_strncmp(ext_word, ext, len)) {
    1.24 +                    return 1;
    1.25 +                }
    1.26 +
    1.27 +                len = 0;
    1.28 +                ext_word = &exts[i + 1];
    1.29 +            }
    1.30 +            else {
    1.31 +                len++;
    1.32 +            }
    1.33 +        }
    1.34 +    }
    1.35 +
    1.36 +    return 0;
    1.37 +}
    1.38  
    1.39  void *
    1.40  SDL_EGL_GetProcAddress(_THIS, const char *proc)
    1.41 @@ -226,6 +257,7 @@
    1.42      LOAD_FUNC(eglWaitNative);
    1.43      LOAD_FUNC(eglWaitGL);
    1.44      LOAD_FUNC(eglBindAPI);
    1.45 +    LOAD_FUNC(eglQueryString);
    1.46      
    1.47  #if !defined(__WINRT__)
    1.48      _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
    1.49 @@ -365,6 +397,10 @@
    1.50      EGLint context_attrib_list[] = {
    1.51          EGL_CONTEXT_CLIENT_VERSION,
    1.52          1,
    1.53 +        EGL_NONE,
    1.54 +        EGL_NONE,
    1.55 +        EGL_NONE,
    1.56 +        EGL_NONE,
    1.57          EGL_NONE
    1.58      };
    1.59      
    1.60 @@ -392,9 +428,29 @@
    1.61      }
    1.62      else {
    1.63          _this->egl_data->eglBindAPI(EGL_OPENGL_API);
    1.64 +        if(SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) {
    1.65 +            context_attrib_list[0] = EGL_CONTEXT_MAJOR_VERSION_KHR;
    1.66 +            context_attrib_list[1] = _this->gl_config.major_version;
    1.67 +            context_attrib_list[2] = EGL_CONTEXT_MINOR_VERSION_KHR;
    1.68 +            context_attrib_list[3] = _this->gl_config.minor_version;
    1.69 +            context_attrib_list[4] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
    1.70 +            switch(_this->gl_config.profile_mask) {
    1.71 +            case SDL_GL_CONTEXT_PROFILE_COMPATIBILITY:
    1.72 +                context_attrib_list[5] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
    1.73 +                break;
    1.74 +
    1.75 +            case SDL_GL_CONTEXT_PROFILE_CORE:
    1.76 +            default:
    1.77 +                context_attrib_list[5] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
    1.78 +                break;
    1.79 +            }
    1.80 +        }
    1.81 +        else {
    1.82 +            context_attrib_list[0] = EGL_NONE;
    1.83 +        }
    1.84          egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
    1.85                                            _this->egl_data->egl_config,
    1.86 -                                          share_context, NULL);
    1.87 +                                          share_context, context_attrib_list);
    1.88      }
    1.89      
    1.90      if (egl_context == EGL_NO_CONTEXT) {