[gtk: 1/2] gdkglcontext-wayland: Fallback to GLES 2.0 after legacy failed




commit aced6030eed169f9c5df2fe9748cb10d8f4cd2cb
Author: Emmanuel Gil Peyrot <linkmauve linkmauve fr>
Date:   Sun Mar 21 20:02:08 2021 +0000

    gdkglcontext-wayland: Fallback to GLES 2.0 after legacy failed
    
    This lets the NGL backend be selected instead of the Cairo backend on
    devices which expose both GL and GLES, but have better support of GLES.
    
    Tested on a PinePhone.

 gdk/wayland/gdkglcontext-wayland.c | 46 +++++++++++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 6 deletions(-)
---
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index 1667117e7f..9e2572f5be 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -126,14 +126,48 @@ gdk_wayland_gl_context_realize (GdkGLContext *context,
                                                   : EGL_NO_CONTEXT,
                           context_attribs);
 
+  /* If context creation failed without the ES bit, let's try again with it */
+  if (ctx == NULL)
+    {
+      i = 0;
+      context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
+      context_attribs[i++] = 2;
+      context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
+      context_attribs[i++] = 0;
+      context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
+      context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
+      context_attribs[i++] = EGL_NONE;
+      g_assert (i < N_EGL_ATTRS);
+
+      eglBindAPI (EGL_OPENGL_ES_API);
+
+      legacy_bit = FALSE;
+      use_es = TRUE;
+
+      GDK_DISPLAY_NOTE (display, OPENGL,
+                g_message ("eglCreateContext failed, switching to OpenGL ES"));
+      ctx = eglCreateContext (display_wayland->egl_display,
+                              context_wayland->egl_config,
+                              share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context
+                                 : shared_data_context != NULL ? GDK_WAYLAND_GL_CONTEXT 
(shared_data_context)->egl_context
+                                    : EGL_NO_CONTEXT,
+                              context_attribs);
+    }
+
   /* If context creation failed without the legacy bit, let's try again with it */
-  if (ctx == NULL && !legacy_bit)
+  if (ctx == NULL)
     {
-      /* Ensure that re-ordering does not break the offsets */
-      g_assert (context_attribs[0] == EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR);
-      context_attribs[1] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
-      context_attribs[3] = 3;
-      context_attribs[5] = 0;
+      i = 0;
+      context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
+      context_attribs[i++] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
+      context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
+      context_attribs[i++] = 3;
+      context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
+      context_attribs[i++] = 0;
+      context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
+      context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
+      context_attribs[i++] = EGL_NONE;
+      g_assert (i < N_EGL_ATTRS);
 
       eglBindAPI (EGL_OPENGL_API);
 


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