aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-12-17 09:36:57 -0500
committerDavid Robillard <d@drobilla.net>2021-12-17 09:36:57 -0500
commitf43635eae207291bac5e3de1b35f64c3b8629a97 (patch)
tree7edc9ef38bb8e8eb338e750f7cd40670c3e70741 /src
parent0fb812f37e89591d40269cd64ec8f199a0f2c04e (diff)
downloadpugl-f43635eae207291bac5e3de1b35f64c3b8629a97.tar.gz
pugl-f43635eae207291bac5e3de1b35f64c3b8629a97.tar.bz2
pugl-f43635eae207291bac5e3de1b35f64c3b8629a97.zip
Explicitly check for supported GLX extensions
Diffstat (limited to 'src')
-rw-r--r--src/x11_gl.c35
1 files changed, 24 insertions, 11 deletions
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 <d@drobilla.net>
+ Copyright 2012-2021 David Robillard <d@drobilla.net>
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 <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
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);
}