From f218ba381a350d4d1a230e015836646cc2baff87 Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 8 Aug 2019 20:48:49 +0100 Subject: [PATCH] Avoid passing GLX_SAMPLE* to glXChooseVisual if num_samples is zero I think glXChooseVisual will return an error if GLX_SAMPLE* is present even if we set it to False/0, so we might never get a context on old hardware. --- gl-natives/src/main/c/jaggl.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/gl-natives/src/main/c/jaggl.c b/gl-natives/src/main/c/jaggl.c index 7a01f46..f4758bb 100644 --- a/gl-natives/src/main/c/jaggl.c +++ b/gl-natives/src/main/c/jaggl.c @@ -533,6 +533,7 @@ JNIEXPORT jboolean JNICALL Java_jaggl_context_choosePixelFormat1(JNIEnv *env, jc for (int i = 0; i < 2; i++) { bool double_buffered = i == 0; + int attribs[] = { GLX_RGBA, GLX_RED_SIZE, @@ -545,13 +546,26 @@ JNIEXPORT jboolean JNICALL Java_jaggl_context_choosePixelFormat1(JNIEnv *env, jc alpha_bits, GLX_DEPTH_SIZE, 24, - GLX_SAMPLE_BUFFERS, - num_samples ? True : False, - GLX_SAMPLES, - num_samples, - double_buffered ? GLX_DOUBLEBUFFER : None, + None, /* for GLX_DOUBLEBUFFER */ + None, /* for GLX_SAMPLE_BUFFERS */ + None, /* for True */ + None, /* for GLX_SAMPLES */ + None, /* for num_samples */ None }; + + int j = 11; + if (double_buffered) { + attribs[j++] = GLX_DOUBLEBUFFER; + } + + if (num_samples) { + attribs[j++] = GLX_SAMPLE_BUFFERS; + attribs[j++] = True; + attribs[j++] = GLX_SAMPLES; + attribs[j++] = num_samples; + } + jaggl_visual_info = glXChooseVisual(jaggl_display, DefaultScreen(jaggl_display), attribs); if (jaggl_visual_info) { jaggl_double_buffered = double_buffered;