From f43635eae207291bac5e3de1b35f64c3b8629a97 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 17 Dec 2021 09:36:57 -0500 Subject: Explicitly check for supported GLX extensions --- src/x11_gl.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/x11_gl.c b/src/x11_gl.c index 42f4051..80eb448 100644 --- a/src/x11_gl.c +++ b/src/x11_gl.c @@ -1,5 +1,5 @@ /* - Copyright 2012-2020 David Robillard + Copyright 2012-2021 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -28,6 +28,7 @@ #include #include #include +#include typedef struct { GLXFBConfig fb_config; @@ -153,15 +154,19 @@ puglX11GlCreate(PuglView* view) : GLX_CONTEXT_CORE_PROFILE_BIT_ARB), 0}; - PFNGLXCREATECONTEXTATTRIBSARBPROC create_context = - (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( - (const uint8_t*)"glXCreateContextAttribsARB"); + const char* const extensions = + glXQueryExtensionsString(display, view->impl->screen); - PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = - (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( - (const uint8_t*)"glXSwapIntervalEXT"); + // Try to create a modern context + if (!!strstr(extensions, "GLX_ARB_create_context")) { + PFNGLXCREATECONTEXTATTRIBSARBPROC create_context = + (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( + (const uint8_t*)"glXCreateContextAttribsARB"); - surface->ctx = create_context(display, fb_config, 0, True, ctx_attrs); + surface->ctx = create_context(display, fb_config, 0, True, ctx_attrs); + } + + // If that failed, fall back to the legacy API if (!surface->ctx) { surface->ctx = glXCreateNewContext(display, fb_config, GLX_RGBA_TYPE, 0, True); @@ -171,10 +176,18 @@ puglX11GlCreate(PuglView* view) return PUGL_CREATE_CONTEXT_FAILED; } - const int swapInterval = view->hints[PUGL_SWAP_INTERVAL]; - if (glXSwapIntervalEXT && swapInterval != PUGL_DONT_CARE) { + // Set up the swap interval + if (!!strstr(extensions, "GLX_EXT_swap_control")) { + PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = + (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( + (const uint8_t*)"glXSwapIntervalEXT"); + puglX11GlEnter(view, NULL); - glXSwapIntervalEXT(display, impl->win, swapInterval); + + // Set the swap interval if the user requested a specific value + if (view->hints[PUGL_SWAP_INTERVAL] != PUGL_DONT_CARE) { + glXSwapIntervalEXT(display, impl->win, view->hints[PUGL_SWAP_INTERVAL]); + } puglX11GlLeave(view, NULL); } -- cgit v1.2.1