diff options
author | Benjamin Otte <otte@redhat.com> | 2023-04-25 21:24:04 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2023-04-27 02:13:32 +0200 |
commit | ab2a548479824d3796236c85e5610e964a9689d7 (patch) | |
tree | 0685faf0b8ebb92f048e8f0a2e7a3e07f7e820d1 /gdk | |
parent | 34662fc4b05fa5b43b88a093b5db7a700380387d (diff) | |
download | gtk+-ab2a548479824d3796236c85e5610e964a9689d7.tar.gz |
glx: Make sure highest possible GL version is created
Mirror EGL here.
Diffstat (limited to 'gdk')
-rw-r--r-- | gdk/x11/gdkglcontext-glx.c | 61 |
1 files changed, 42 insertions, 19 deletions
diff --git a/gdk/x11/gdkglcontext-glx.c b/gdk/x11/gdkglcontext-glx.c index 7ee885b831..229373f1e9 100644 --- a/gdk/x11/gdkglcontext-glx.c +++ b/gdk/x11/gdkglcontext-glx.c @@ -477,8 +477,11 @@ gdk_x11_context_create_glx_context (GdkGLContext *context, GdkSurface *surface = gdk_gl_context_get_surface (context); GLXContext ctx; int context_attribs[N_GLX_ATTRS], i = 0, flags = 0; + gsize major_idx, minor_idx; GdkGLVersion min, version; + const GdkGLVersion* supported_versions; gboolean debug_bit, compat_bit; + gsize j; if (!gdk_gl_context_is_api_allowed (context, api, NULL)) return 0; @@ -509,9 +512,9 @@ gdk_x11_context_create_glx_context (GdkGLContext *context, context_attribs[i++] = GLX_CONTEXT_ES2_PROFILE_BIT_EXT; context_attribs[i++] = GLX_CONTEXT_MAJOR_VERSION_ARB; - context_attribs[i++] = gdk_gl_version_get_major (&version); + major_idx = i++; context_attribs[i++] = GLX_CONTEXT_MINOR_VERSION_ARB; - context_attribs[i++] = gdk_gl_version_get_minor (&version); + minor_idx = i++; context_attribs[i++] = GLX_CONTEXT_FLAGS_ARB; context_attribs[i++] = flags; @@ -531,25 +534,44 @@ gdk_x11_context_create_glx_context (GdkGLContext *context, gdk_x11_display_error_trap_push (display); - /* If we don't have access to GLX_ARB_create_context_profile, then - * we have to fall back to the old GLX 1.3 API. - */ - if (legacy && !display_x11->has_glx_create_context) - ctx = glXCreateNewContext (gdk_x11_display_get_xdisplay (display), - display_x11->glx_config, - GLX_RGBA_TYPE, - share_glx != NULL ? share_glx->glx_context : NULL, - TRUE); + supported_versions = gdk_gl_versions_get_for_api (api); + for (j = 0; gdk_gl_version_greater_equal (&supported_versions[j], &version); j++) + { + context_attribs [major_idx] = gdk_gl_version_get_major (&supported_versions[j]); + context_attribs [minor_idx] = gdk_gl_version_get_minor (&supported_versions[j]); - else - ctx = glXCreateContextAttribsARB (gdk_x11_display_get_xdisplay (display), - display_x11->glx_config, - share_glx != NULL ? share_glx->glx_context : NULL, - True, - context_attribs); + /* If we don't have access to GLX_ARB_create_context_profile, then + * we have to fall back to the old GLX 1.3 API. + */ + if (legacy && !display_x11->has_glx_create_context) + ctx = glXCreateNewContext (gdk_x11_display_get_xdisplay (display), + display_x11->glx_config, + GLX_RGBA_TYPE, + share_glx != NULL ? share_glx->glx_context : NULL, + TRUE); - if (gdk_x11_display_error_trap_pop (display) || ctx == NULL) - return 0; + else + ctx = glXCreateContextAttribsARB (gdk_x11_display_get_xdisplay (display), + display_x11->glx_config, + share_glx != NULL ? share_glx->glx_context : NULL, + True, + context_attribs); + + if (ctx) + break; + } + + if (ctx == NULL) + { + gdk_x11_display_error_trap_pop_ignored (display); + return 0; + } + + if (gdk_x11_display_error_trap_pop (display)) + { + glXDestroyContext (dpy, ctx); + return 0; + } GDK_DISPLAY_DEBUG (display, OPENGL, "Realized GLX context[%p], %s, version: %d.%d", @@ -559,6 +581,7 @@ gdk_x11_context_create_glx_context (GdkGLContext *context, display_x11->glx_version % 10); context_glx->glx_context = ctx; + gdk_gl_context_set_version (context, &supported_versions[j]); gdk_gl_context_set_is_legacy (context, legacy); #ifdef HAVE_XDAMAGE |