[gtk/wip/otte/gl-hdr: 14/18] glcontext: Handle failure of eglBindAPI()




commit 3ca84c4357b38f364f96d812d57713d9f332fc99
Author: Benjamin Otte <otte redhat com>
Date:   Wed Oct 6 02:36:59 2021 +0200

    glcontext: Handle failure of eglBindAPI()
    
    We don't want to be sure if we have GL or GLES.

 gdk/gdkglcontext.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 0fea1e7614..527ef62773 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -384,10 +384,8 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
       if (forward_bit)
         flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
 
-      if (!use_es)
+      if (!use_es && eglBindAPI (EGL_OPENGL_API))
         {
-          eglBindAPI (EGL_OPENGL_API);
-
           /* We want a core profile, unless in legacy mode */
           context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
           context_attribs[i++] = legacy_bit
@@ -400,16 +398,20 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
           context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR;
           context_attribs[i++] = legacy_bit ? 0 : minor;
         }
-      else
+      else if (eglBindAPI (EGL_OPENGL_ES_API))
         {
-          eglBindAPI (EGL_OPENGL_ES_API);
-
           context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
           if (major == 3)
             context_attribs[i++] = 3;
           else
             context_attribs[i++] = 2;
         }
+      else
+        {
+          g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
+                               _("The EGL implementation supports neither OpenGL nor GLES"));
+          return FALSE;
+        }
 
       /* Specify the flags */
       context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
@@ -433,7 +435,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
                               context_attribs);
 
       /* If context creation failed without the ES bit, let's try again with it */
-      if (ctx == NULL)
+      if (ctx == NULL && eglBindAPI (EGL_OPENGL_ES_API))
         {
           i = 0;
           context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
@@ -445,8 +447,6 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
           context_attribs[i++] = EGL_NONE;
           g_assert (i < N_EGL_ATTRS);
 
-          eglBindAPI (EGL_OPENGL_ES_API);
-
           legacy_bit = FALSE;
           use_es = TRUE;
 
@@ -460,7 +460,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
         }
 
       /* If context creation failed without the legacy bit, let's try again with it */
-      if (ctx == NULL)
+      if (ctx == NULL && eglBindAPI (EGL_OPENGL_API))
         {
           i = 0;
           context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
@@ -474,8 +474,6 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
           context_attribs[i++] = EGL_NONE;
           g_assert (i < N_EGL_ATTRS);
 
-          eglBindAPI (EGL_OPENGL_API);
-
           legacy_bit = TRUE;
           use_es = FALSE;
 
@@ -510,7 +508,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
 #endif
 
   g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
-                       "The current backend does not support OpenGL");
+                       _("The current backend does not support OpenGL"));
   return FALSE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]