VIGS: Try harder to get OpenGL 3.2 core context 25/17025/1
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Sat, 1 Mar 2014 09:38:41 +0000 (13:38 +0400)
committerStanislav Vorobiov <s.vorobiov@samsung.com>
Sat, 1 Mar 2014 11:13:13 +0000 (15:13 +0400)
Querying for just OpenGL 3.1 isn't enough,
the implementation MAY return OpenGL 3.x where x > 1,
but it's not guaranteed. Thus, we must try to create
another context explicitly specifying OpenGL 3.2 core,
if that fails then we know for sure that OpenGL 3.2 core
isn't supported

Change-Id: I8625c65ed8f4781a94e03fff86ac737e514b0c69

hw/yagl/yagl_drivers/egl_glx/yagl_egl_glx.c
hw/yagl/yagl_drivers/egl_wgl/yagl_egl_wgl.c

index 5a031257671327bc36c9171f5c7b78a3bc6f31e0..e73af917264083cd09110c497d6345eaffccf1d8 100644 (file)
@@ -140,7 +140,7 @@ static bool yagl_egl_glx_get_gl_version(struct yagl_egl_glx *egl_glx,
         GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
         None
     };
-    int ctx_attribs[] =
+    int ctx_attribs_3_1[] =
     {
         GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
         GLX_CONTEXT_MINOR_VERSION_ARB, 1,
@@ -148,6 +148,14 @@ static bool yagl_egl_glx_get_gl_version(struct yagl_egl_glx *egl_glx,
         GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
         None
     };
+    int ctx_attribs_3_2[] =
+    {
+        GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+        GLX_CONTEXT_MINOR_VERSION_ARB, 2,
+        GLX_RENDER_TYPE, GLX_RGBA_TYPE,
+        GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
+        None
+    };
     int surface_attribs[] = {
         GLX_PBUFFER_WIDTH, 1,
         GLX_PBUFFER_HEIGHT, 1,
@@ -164,7 +172,6 @@ static bool yagl_egl_glx_get_gl_version(struct yagl_egl_glx *egl_glx,
     const GLubyte *(GLAPIENTRY *GetStringi)(GLenum, GLuint) = NULL;
     void (GLAPIENTRY *GetIntegerv)(GLenum, GLint*) = NULL;
     GLint i, num_extensions = 0;
-    GLint major = 0, minor = 0;
 
     YAGL_EGL_GLX_ENTER(yagl_egl_glx_get_gl_version, NULL);
 
@@ -208,7 +215,7 @@ static bool yagl_egl_glx_get_gl_version(struct yagl_egl_glx *egl_glx,
                                               configs[0],
                                               NULL,
                                               True,
-                                              ctx_attribs);
+                                              ctx_attribs_3_1);
 
     if (!ctx) {
         YAGL_LOG_INFO("glXCreateContextAttribsARB failed, using OpenGL 2.1");
@@ -267,19 +274,23 @@ static bool yagl_egl_glx_get_gl_version(struct yagl_egl_glx *egl_glx,
      * able to patch shaders and run them with GLSL 1.50.
      */
 
-    GetIntegerv(GL_MAJOR_VERSION, &major);
-    GetIntegerv(GL_MINOR_VERSION, &minor);
+    egl_glx->glXMakeContextCurrent(egl_glx->global_dpy, 0, 0, NULL);
+    egl_glx->glXDestroyContext(egl_glx->global_dpy, ctx);
+
+    ctx = egl_glx->glXCreateContextAttribsARB(egl_glx->global_dpy,
+                                              configs[0],
+                                              NULL,
+                                              True,
+                                              ctx_attribs_3_2);
 
-    if ((major > 3) ||
-        ((major == 3) && (minor >= 2))) {
+    if (ctx) {
         YAGL_LOG_INFO("GL_ARB_ES3_compatibility not supported, using OpenGL 3.2");
         *version = yagl_gl_3_2;
-        res = true;
-        goto out;
+    } else {
+        YAGL_LOG_INFO("GL_ARB_ES3_compatibility not supported, OpenGL 3.2 not supported, using OpenGL 3.1");
+        *version = yagl_gl_3_1;
     }
 
-    YAGL_LOG_INFO("GL_ARB_ES3_compatibility not supported, OpenGL 3.2 not supported, using OpenGL 3.1");
-    *version = yagl_gl_3_1;
     res = true;
 
 out:
@@ -583,7 +594,7 @@ static EGLContext yagl_egl_glx_context_create(struct yagl_egl_driver *driver,
 {
     struct yagl_egl_glx *egl_glx = (struct yagl_egl_glx*)driver;
     GLXContext ctx;
-    int attribs[] =
+    int attribs_3_1[] =
     {
         GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
         GLX_CONTEXT_MINOR_VERSION_ARB, 1,
@@ -591,6 +602,14 @@ static EGLContext yagl_egl_glx_context_create(struct yagl_egl_driver *driver,
         GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
         None
     };
+    int attribs_3_2[] =
+    {
+        GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+        GLX_CONTEXT_MINOR_VERSION_ARB, 2,
+        GLX_RENDER_TYPE, GLX_RGBA_TYPE,
+        GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
+        None
+    };
 
     YAGL_EGL_GLX_ENTER(yagl_egl_glx_context_create,
                        "dpy = %p, share_context = %p, version = %d",
@@ -605,7 +624,8 @@ static EGLContext yagl_egl_glx_context_create(struct yagl_egl_driver *driver,
                                                       NULL
                                                     : (GLXContext)share_context),
                                                   True,
-                                                  attribs);
+                                                  ((egl_glx->base.gl_version >= yagl_gl_3_2) ?
+                                                   attribs_3_2 : attribs_3_1));
     } else {
         ctx = egl_glx->glXCreateNewContext(dpy,
                                            (GLXFBConfig)cfg->driver_data,
index f6d673eb9050fd66dc671bfa4ffc682463a4d538..ba178d2b13492e8ad861dd6e856233b8c1f0daf2 100644 (file)
@@ -144,13 +144,20 @@ static bool yagl_egl_wgl_get_gl_version(YaglEglWglDriver *egl_wgl,
         WGL_STENCIL_BITS_ARB, 8,
         0,
     };
-    int ctx_attribs[] =
+    int ctx_attribs_3_1[] =
     {
         WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
         WGL_CONTEXT_MINOR_VERSION_ARB, 1,
         WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
         0
     };
+    int ctx_attribs_3_2[] =
+    {
+        WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
+        WGL_CONTEXT_MINOR_VERSION_ARB, 2,
+        WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
+        0
+    };
     int pbuff_attribs[] =
     {
         WGL_PBUFFER_LARGEST_ARB, FALSE,
@@ -165,13 +172,12 @@ static bool yagl_egl_wgl_get_gl_version(YaglEglWglDriver *egl_wgl,
     int config_id = 0;
     UINT n = 0;
     PIXELFORMATDESCRIPTOR pix_fmt;
-    HGLRC ctx;
+    HGLRC ctx = NULL;
     HPBUFFERARB pbuffer;
     HDC pbuffer_dc;
     const GLubyte *(GLAPIENTRY *GetStringi)(GLenum, GLuint) = NULL;
     void (GLAPIENTRY *GetIntegerv)(GLenum, GLint*) = NULL;
     GLint i, num_extensions = 0;
-    GLint major = 0, minor = 0;
 
     YAGL_EGL_WGL_ENTER(yagl_egl_wgl_get_gl_version, NULL);
 
@@ -240,7 +246,7 @@ static bool yagl_egl_wgl_get_gl_version(YaglEglWglDriver *egl_wgl,
 
     ctx = egl_wgl->wglCreateContextAttribsARB(dc,
                                               NULL,
-                                              ctx_attribs);
+                                              ctx_attribs_3_1);
 
     if (!ctx) {
         YAGL_LOG_INFO("wglCreateContextAttribsARB failed, using OpenGL 2.1");
@@ -304,19 +310,21 @@ static bool yagl_egl_wgl_get_gl_version(YaglEglWglDriver *egl_wgl,
      * able to patch shaders and run them with GLSL 1.50.
      */
 
-    GetIntegerv(GL_MAJOR_VERSION, &major);
-    GetIntegerv(GL_MINOR_VERSION, &minor);
+    egl_wgl->wglMakeCurrent(NULL, NULL);
+    egl_wgl->wglDeleteContext(ctx);
+
+    ctx = egl_wgl->wglCreateContextAttribsARB(dc,
+                                              NULL,
+                                              ctx_attribs_3_2);
 
-    if ((major > 3) ||
-        ((major == 3) && (minor >= 2))) {
+    if (ctx) {
         YAGL_LOG_INFO("GL_ARB_ES3_compatibility not supported, using OpenGL 3.2");
         *version = yagl_gl_3_2;
-        res = true;
-        goto out7;
+    } else {
+        YAGL_LOG_INFO("GL_ARB_ES3_compatibility not supported, OpenGL 3.2 not supported, using OpenGL 3.1");
+        *version = yagl_gl_3_1;
     }
 
-    YAGL_LOG_INFO("GL_ARB_ES3_compatibility not supported, OpenGL 3.2 not supported, using OpenGL 3.1");
-    *version = yagl_gl_3_1;
     res = true;
 
 out7:
@@ -326,7 +334,9 @@ out6:
 out5:
     egl_wgl->wglDestroyPbufferARB(pbuffer);
 out4:
-    egl_wgl->wglDeleteContext(ctx);
+    if (ctx) {
+        egl_wgl->wglDeleteContext(ctx);
+    }
 out3:
     ReleaseDC(win, dc);
 out2:
@@ -723,13 +733,20 @@ static EGLContext yagl_egl_wgl_context_create(struct yagl_egl_driver *driver,
 {
     YaglEglWglDriver *egl_wgl = (YaglEglWglDriver *)(driver);
     YaglEglWglDpy *dpy = (YaglEglWglDpy *)egl_dpy;
-    int attribs[] =
+    int attribs_3_1[] =
     {
         WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
         WGL_CONTEXT_MINOR_VERSION_ARB, 1,
         WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
         0
     };
+    int attribs_3_2[] =
+    {
+        WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
+        WGL_CONTEXT_MINOR_VERSION_ARB, 2,
+        WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
+        0
+    };
     HGLRC egl_wgl_ctx;
     HDC dc;
 
@@ -746,7 +763,8 @@ static EGLContext yagl_egl_wgl_context_create(struct yagl_egl_driver *driver,
     if ((egl_wgl->base.gl_version > yagl_gl_2) && (version != 1)) {
         egl_wgl_ctx = egl_wgl->wglCreateContextAttribsARB(dc,
                                                           share_context,
-                                                          attribs);
+                                                          ((egl_wgl->base.gl_version >= yagl_gl_3_2) ?
+                                                           attribs_3_2 : attribs_3_1));
     } else {
         egl_wgl_ctx = egl_wgl->wglCreateContext(dc);
     }