Skip to content
Permalink
Browse files

Check for Mesa rather than GLX > 1.2 when determining glXQueryDrawabl…

…e GLX_WIDTH/GLX_HEIGHT availability.

You cannot query for GLX_WIDTH and GLX_HEIGHT using glXQueryDrawable in Mesa.
It simply fails with an error, and crashes the program:

    X Error of failed request:  GLXBadDrawable
      Major opcode of failed request:  156 (GLX)
      Minor opcode of failed request:  29 (X_GLXGetDrawableAttributes)
      Serial number of failed request:  41
      Current serial number in output stream:  41

The old check to only allow using glXQueryDrawable using GLX > 1.2
presumably worked for older Mesa versions, but now, Mesa advertises
GLX > 1.2.

That makes the overlay practically unusable when using Mesa.

This commit changes the code path to detect Mesa instead of GLX > 1.2,
and makes the overlay work correctly on Mesa once again.
  • Loading branch information...
mkrautz committed Jun 5, 2015
1 parent 859da4d commit 06e19e6fb191afa794f8018b67252940bc097fdd
Showing with 14 additions and 8 deletions.
  1. +13 −7 overlay_gl/init_unix.c
  2. +1 −1 overlay_gl/overlay.c
@@ -80,31 +80,37 @@ void glXSwapBuffers(Display * dpy, GLXDrawable draw) {
c->dpy = dpy;
c->draw = draw;

c->bGlx = false;
c->bMesa = false;
c->bValid = false;

int major, minor;
if (glXQueryVersion(dpy, &major, &minor)) {
ods("GLX version %d.%d", major, minor);
c->bValid = true;
if ((major > 1) || (major==1 && minor >= 3)) {
c->bGlx = true;
}

const char *version = (const char *) glGetString(GL_VERSION);
if (version) {
ods("GL version string: %s", version);
if (strstr(version, "Mesa") != NULL) {
c->bMesa = true;
}
}

contexts = c;
newContext(c);
}

if (c->bValid) {
GLuint width, height;
if (c->bGlx) {
glXQueryDrawable(dpy, draw, GLX_WIDTH, (unsigned int *) &width);
glXQueryDrawable(dpy, draw, GLX_HEIGHT, (unsigned int *) &height);
} else {
if (c->bMesa) {
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
width = viewport[2];
height = viewport[3];
} else {
glXQueryDrawable(dpy, draw, GLX_WIDTH, (unsigned int *) &width);
glXQueryDrawable(dpy, draw, GLX_HEIGHT, (unsigned int *) &height);
}

drawContext(c, width, height);
@@ -108,7 +108,7 @@ typedef struct _Context {
unsigned int uiMappedLength;

bool bValid;
bool bGlx;
bool bMesa;

GLuint uiProgram;

0 comments on commit 06e19e6

Please sign in to comment.
You can’t perform that action at this time.