[gtk/win32-gl-improvements: 18/21] gdkglcontext-win32-wgl.c: Cleanup GL context creation




commit 38c17c1f796a394d0cf559712ac7a78409c4ea8b
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jan 17 18:14:30 2022 +0800

    gdkglcontext-win32-wgl.c: Cleanup GL context creation
    
    Instead of first trying to explicitly ask for a WGL 4.1 context, ask for
    the WGL context version that matches what is reported via
    epoxy_gl_version(), so that we get the maximum WGL version that is
    supported by the graphics drivers, and make sure any WGL contexts that
    are shared with this (initial) WGL context are created likewise.
    
    We can try to do a default-bog-standard 3.2 core WGL context creation
    if the need arises, but let's leave that alone for now.

 gdk/win32/gdkglcontext-win32-wgl.c | 54 ++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 28 deletions(-)
---
diff --git a/gdk/win32/gdkglcontext-win32-wgl.c b/gdk/win32/gdkglcontext-win32-wgl.c
index 41aed57d1f..9a90ccffc6 100644
--- a/gdk/win32/gdkglcontext-win32-wgl.c
+++ b/gdk/win32/gdkglcontext-win32-wgl.c
@@ -430,33 +430,13 @@ create_wgl_context (HDC           hdc,
           goto gl_fail;
         }
 
-      /*
-       * We need a Core GL 4.1 context in order to use the GL support in
-       * the GStreamer media widget backend, but wglCreateContextAttribsARB()
-       * may only give us the GL context version that we ask for here, and
-       * nothing more.  So, if we are asking for a pre-GL 4.1 context,
-       * try to ask for a 4.1 context explicitly first.  If that is not supported,
-       * then we fall back to whatever version that we were asking for (or, even a
-       * legacy context if that fails), at a price of not able to have GL support
-       * for the media GStreamer backend.
-       */
-      if (major < 4 || (major == 4 && minor < 1))
-        hglrc = create_wgl_context_with_attribs (hdc,
-                                                 hglrc_base,
-                                                 share,
-                                                 flags,
-                                                 4,
-                                                 1,
-                                                 is_legacy);
-
-      if (hglrc == NULL)
-        hglrc = create_wgl_context_with_attribs (hdc,
-                                                 hglrc_base,
-                                                 share,
-                                                 flags,
-                                                 major,
-                                                 minor,
-                                                 is_legacy);
+      hglrc = create_wgl_context_with_attribs (hdc,
+                                               hglrc_base,
+                                               share,
+                                               flags,
+                                               major,
+                                               minor,
+                                               is_legacy);
 
       /* return the legacy context we have if it could be setup properly, in case the 3.0+ context creation 
failed */
       if (hglrc == NULL)
@@ -562,10 +542,27 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
   if (!gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, error))
     return 0;
 
-  gdk_gl_context_get_required_version (context, &major, &minor);
   debug_bit = gdk_gl_context_get_debug_enabled (context);
   compat_bit = gdk_gl_context_get_forward_compatible (context);
 
+  /*
+   * We may need a Core GL 4.1+ context in order to use the GL support in
+   * the GStreamer media widget backend (such as on Intel drivers), but
+   * wglCreateContextAttribsARB() may only give us the GL context version
+   * that we ask for here, and nothing more.  So, improve things here by
+   * asking for the GL version that is reported to us via epoxy_gl_version(),
+   * rather than the default GL core 3.2 context.  Save this up in our
+   * GdkGLContext so that subsequent contexts that are shared with this
+   * context are created likewise too.
+   */
+  if (share != NULL)
+    gdk_gl_context_get_required_version (share, &major, &minor);
+  else
+    {
+      major = display_win32->gl_version / 10;
+      minor = display_win32->gl_version % 10;
+    }
+
   if (surface != NULL)
     hdc = GDK_WIN32_SURFACE (surface)->hdc;
   else
@@ -632,6 +629,7 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
 
   /* Ensure that any other context is created with a legacy bit set */
   gdk_gl_context_set_is_legacy (context, legacy_bit);
+  gdk_gl_context_set_required_version (context, major, minor);
 
   return GDK_GL_API_GL;
 }


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