This patch to openscad works around the problem:

  
https://salsa.debian.org/knielsen-guest/openscad/commit/7225800b534a36e5ad84c56c274889b8d0edc0ce

It uses Xrender to query visuals returned from glXChooseFBConfig(), and
filter out those with alphaMask=0.

With this patch, all openscad tests are passing with mesa 19.3.1-2.

However, I'm unsure if this is the correct approach? It does not seem right
that querying Xrender would be required just to specify GLX_ALPHA_SIZE to
glXChooseFBConfig(). Maybe there is a simpler fix for openscad, or possibly
this is a bug in mesa that should be fixed?

 - Kristian.

commit 7225800b534a36e5ad84c56c274889b8d0edc0ce (HEAD -> newstuffs, salsa/newstuffs)
Author: Kristian Nielsen <kniel...@knielsen-hq.org>
Date:   Tue Dec 24 11:05:45 2019 +0100

    Add a patch to work-around test failures against latest mesa

diff --git a/debian/changelog b/debian/changelog
index 9ca95cd5..7fe6f8ad 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,8 +2,9 @@ openscad (2019.05-4) unstable; urgency=medium
 
   * Make openscad-testrun default to run tests in parallel.
   * Limit --parallel build based on available memory (Closes: #945162)
+  * Work-around "BadMatch" error with mesa >= 19.3 (Closes: 947196)
 
- -- Kristian Nielsen <kniel...@knielsen-hq.org>  Sat, 07 Dec 2019 11:12:30 +0100
+ -- Kristian Nielsen <kniel...@knielsen-hq.org>  Tue, 24 Dec 2019 10:29:22 +0100
 
 openscad (2019.05-3) unstable; urgency=medium
 
diff --git a/debian/control b/debian/control
index b8299716..96ab274e 100644
--- a/debian/control
+++ b/debian/control
@@ -27,6 +27,7 @@ Build-Depends:
 # workaround for https://github.com/openscad/openscad/issues/1543
     libqt5opengl5-dev,
     libglew-dev (>= 1.5.4) | libglew1.6-dev | libglew1.5-dev (>= 1.5.4),
+    libxrender-dev,
     libgmp-dev | libgmp10-dev | libgmp3-dev,
     libmpfr-dev,
     python3:any,
diff --git a/debian/patches/Prefer-FBConfig-with-alpha-support-for-GLX-off-screen-con.patch b/debian/patches/Prefer-FBConfig-with-alpha-support-for-GLX-off-screen-con.patch
new file mode 100644
index 00000000..1364dcba
--- /dev/null
+++ b/debian/patches/Prefer-FBConfig-with-alpha-support-for-GLX-off-screen-con.patch
@@ -0,0 +1,84 @@
+From: Kristian Nielsen <kniel...@knielsen-hq.org>
+Date: Tue, 24 Dec 2019 10:22:05 +0100
+Subject: Prefer FBConfig with alpha support for GLX off-screen context
+
+This is to work-around a problem seen with mesa >= 19.3 (Debian
+bug#947196). When GLX_ALPHA_SIZE>0 is passed to glXChooseFBConfig(),
+the first configurations returned result in a BadMatch error in
+glXSwapBuffers(). Picking the first returned configuration with
+alphaMask > 0 (as reported by Xrender) avoids the failure.
+---
+ features/glew.prf          |  2 +-
+ src/OffscreenContextGLX.cc | 25 ++++++++++++++++++++++---
+ 2 files changed, 23 insertions(+), 4 deletions(-)
+
+diff --git a/features/glew.prf b/features/glew.prf
+index d4c83bd..1c3b4c4 100644
+--- a/features/glew.prf
++++ b/features/glew.prf
+@@ -7,7 +7,7 @@ GLEW_DIR = $$(GLEWDIR)
+   QMAKE_LIBDIR += $$GLEW_DIR/lib64
+ }
+ 
+-unix:LIBS += -lGLEW
++unix:LIBS += -lGLEW -lXrender
+ mingw-cross-env*: {
+    {
+     CONFIG += link_pkgconfig
+diff --git a/src/OffscreenContextGLX.cc b/src/OffscreenContextGLX.cc
+index 1f29155..933c4c8 100644
+--- a/src/OffscreenContextGLX.cc
++++ b/src/OffscreenContextGLX.cc
+@@ -43,6 +43,7 @@ OffscreenContext.mm (Mac OSX version)
+ 
+ #include <GL/gl.h>
+ #include <GL/glx.h>
++#include <X11/extensions/Xrender.h>
+ 
+ #include <assert.h>
+ #include <sstream>
+@@ -145,7 +146,25 @@ bool create_glx_dummy_window(OffscreenContext &ctx)
+ 		return false;
+ 	}
+ 
+-	auto visinfo = glXGetVisualFromFBConfig( dpy, fbconfigs[0] );
++	auto fbconfig = fbconfigs[0];
++	auto visinfo = glXGetVisualFromFBConfig( dpy, fbconfig );
++	// If Xrender is available, use it to prefer an fbconfig with alpha.
++	// This is to work-around a problem seen with mesa >= 19.3, where
++	// the configs without alpha-support cause a BadMatch failure in
++	// glXSwapBuffers() (Debian bug#947196).
++	int event_basep, error_basep;
++	if (XRenderQueryExtension(dpy, &event_basep, &error_basep)) {
++	  for (int i = 0; i < num_returned; i++) {
++	    auto v = glXGetVisualFromFBConfig(dpy, fbconfigs[i]);
++	    auto pf = XRenderFindVisualFormat(dpy, v->visual);
++	    if (pf && pf->direct.alphaMask > 0) {
++	      visinfo = v;
++	      fbconfig = fbconfigs[i];
++	      break;
++	    }
++	  }
++	}
++
+ 	if (visinfo == nullptr) {
+ 		std::cerr << "glXGetVisualFromFBConfig failed\n";
+ 		XFree(fbconfigs);
+@@ -183,7 +202,7 @@ bool create_glx_dummy_window(OffscreenContext &ctx)
+ 	// Most programs would call XMapWindow here. But we don't, to keep the window hidden
+ 	// XMapWindow( dpy, xWin );
+ 
+-	auto context = glXCreateNewContext(dpy, fbconfigs[0], GLX_RGBA_TYPE, nullptr, true);
++	auto context = glXCreateNewContext(dpy, fbconfig, GLX_RGBA_TYPE, nullptr, true);
+ 	if (context == nullptr) {
+ 		std::cerr << "glXCreateNewContext failed\n";
+ 		XDestroyWindow(dpy, xWin);
+@@ -192,7 +211,7 @@ bool create_glx_dummy_window(OffscreenContext &ctx)
+ 		return false;
+ 	}
+ 
+-	//GLXWindow glxWin = glXCreateWindow( dpy, fbconfigs[0], xWin, nullptr );
++	//GLXWindow glxWin = glXCreateWindow( dpy, fbconfig, xWin, nullptr );
+ 
+ 	if (!glXMakeContextCurrent( dpy, xWin, xWin, context )) {
+ 		//if (!glXMakeContextCurrent( dpy, glxWin, glxWin, context )) {
diff --git a/debian/patches/series b/debian/patches/series
index f3a93ea0..3eabd748 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -10,3 +10,4 @@ Work-around-for-race-in-Xvfb-with-many-parallel-X-connect.patch
 Work-around-Mesa-llvmpipe-bug-on-MIPS-which-causes-crashe.patch
 Switch-to-std-c-14-for-CGAL5-compatibility.patch
 Use-CGAL-in-header-only-mode-which-is-required-in-CGAL-5.patch
+Prefer-FBConfig-with-alpha-support-for-GLX-off-screen-con.patch

Reply via email to