Skip to content

Commit

Permalink
Check for Mesa rather than GLX > 1.2 when determining glXQueryDrawabl…
Browse files Browse the repository at this point in the history
…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 06e19e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions overlay_gl/init_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion overlay_gl/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ typedef struct _Context {
unsigned int uiMappedLength;

bool bValid;
bool bGlx;
bool bMesa;

GLuint uiProgram;

Expand Down

0 comments on commit 06e19e6

Please sign in to comment.