GDK-Win32: Reject WGL context if shaders aren't supported
authorChun-wei Fan <fanchunwei@src.gnome.org>
Tue, 17 Aug 2021 07:13:38 +0000 (15:13 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Tue, 17 Aug 2021 08:25:09 +0000 (16:25 +0800)
When we initialize OpenGL, check whether we have OpenGL  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
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
gdk/win32/gdkglcontext-win32-wgl.c

index 9d2df6b49937d4a7f293c133a444cb48c9a4b1cd..cfc4417a9a3bd11985d7c450205d72e7960d9493 100644 (file)
@@ -277,7 +277,7 @@ 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);
 
   display_win32->hasEglSurfacelessContext =
     epoxy_has_egl_extension (egl_disp, "EGL_KHR_surfaceless_context");
index 4b000f4792c6a1acd76f78a1d4043956a1304049..3d05fb8907d97286f31e44e3bea521262f46da65 100644 (file)
@@ -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_gl_extension ("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 =