[gtk/win32-check-shader-support] GDK-Win32: Reject GL context if shaders aren't supported




commit 4c048106b06b172d9355949bd46f069933184ef5
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Aug 17 15:13:38 2021 +0800

    GDK-Win32: Reject GL context if shaders aren't supported
    
    When we initialize OpenGL, check whether we have OpenGL or OpenGL/ES 2.0 or
    later; if not, check whether we have the 'GL_ARB_shader_objects' extension,
    since we must be able to support shaders if using OpenGL for GTK.
    
    If we don't support shaders, as some Windows graphics drivers do not support
    OpenGL adequately, notably older Intel drivers, reject and destroy the GL/GLES
    context that we created, and so fallback to the Cairo GSK renderer, so that
    things continue to run, albeit with an expected warning message that the GL
    context cannot be realized.
    
    Also, when we could not make the created dummy WGL context current during
    initialization, make sure that we destroy the dummy WGL context as well.
    
    Fixes issue #4165.

 gdk/win32/gdkglcontext-win32-egl.c | 18 +++++++++++++++++-
 gdk/win32/gdkglcontext-win32-wgl.c | 19 +++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)
---
diff --git a/gdk/win32/gdkglcontext-win32-egl.c b/gdk/win32/gdkglcontext-win32-egl.c
index 9d2df6b499..338f81ff70 100644
--- a/gdk/win32/gdkglcontext-win32-egl.c
+++ b/gdk/win32/gdkglcontext-win32-egl.c
@@ -277,7 +277,23 @@ gdk_win32_display_init_egl (GdkDisplay  *display,
   display_win32->egl_disp = egl_disp;
   display_win32->egl_version = epoxy_egl_version (egl_disp);
 
-  eglBindAPI(EGL_OPENGL_ES_API);
+  eglBindAPI (EGL_OPENGL_ES_API);
+
+  /* We must have OpenGL/ES 2.0 or later, or have the GL_ARB_shader_objects extension */
+  if (display_win32->egl_version < 20)
+    {
+      if (!epoxy_has_egl_extension (egl_disp, "GL_ARB_shader_objects"))
+        {
+          eglTerminate (egl_disp);
+          egl_disp = EGL_NO_DISPLAY;
+
+          g_set_error_literal (error, GDK_GL_ERROR,
+                               GDK_GL_ERROR_NOT_AVAILABLE,
+                               _("No GL implementation is available"));
+
+          return FALSE;
+        }
+    }
 
   display_win32->hasEglSurfacelessContext =
     epoxy_has_egl_extension (egl_disp, "EGL_KHR_surfaceless_context");
diff --git a/gdk/win32/gdkglcontext-win32-wgl.c b/gdk/win32/gdkglcontext-win32-wgl.c
index 4b000f4792..cf7935a462 100644
--- a/gdk/win32/gdkglcontext-win32-wgl.c
+++ b/gdk/win32/gdkglcontext-win32-wgl.c
@@ -278,6 +278,9 @@ gdk_win32_display_init_wgl (GdkDisplay  *display,
   if (best_idx == 0 ||
      !wglMakeCurrent (hdc, display_win32->dummy_context_wgl.hglrc))
     {
+      if (display_win32->dummy_context_wgl.hglrc != NULL)
+        wglDeleteContext (display_win32->dummy_context_wgl.hglrc);
+
       g_set_error_literal (error, GDK_GL_ERROR,
                            GDK_GL_ERROR_NOT_AVAILABLE,
                            _("No GL implementation is available"));
@@ -288,6 +291,22 @@ gdk_win32_display_init_wgl (GdkDisplay  *display,
   display_win32->wgl_pixel_format = best_idx;
   display_win32->gl_version = epoxy_gl_version ();
 
+  /* We must have OpenGL/WGL 2.0 or later, or have the GL_ARB_shader_objects extension */
+  if (display_win32->gl_version < 20)
+    {
+      if (!epoxy_has_wgl_extension (hdc, "GL_ARB_shader_objects"))
+        {
+          wglMakeCurrent (NULL, NULL);
+          wglDeleteContext (display_win32->dummy_context_wgl.hglrc);
+
+          g_set_error_literal (error, GDK_GL_ERROR,
+                               GDK_GL_ERROR_NOT_AVAILABLE,
+                               _("No GL implementation is available"));
+
+          return FALSE;
+        }
+    }
+
   display_win32->hasWglARBCreateContext =
     epoxy_has_wgl_extension (hdc, "WGL_ARB_create_context");
   display_win32->hasWglEXTSwapControl =


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