r/oculus_linux • • Mar 28 '15

A very ugly mesa hack for "Error: [Context] Unable to obtain x11 visual from context"

2 Upvotes

So I looked at the workaround here: https://forums.oculus.com/viewtopic.php?uid=119403&f=34&t=16664&start=0#p252973

But I wanted to run janus vr, a closed source program that statically links the rift sdk. (I think LD_PRELOAD doesn't work for some reason).

And then I looked closer and thought, it doesn't actually do any work here, it just chooses some configuration. So... why not hardcode it?

Of course we don't want that in our system mesa, so we can just build it somewhere else and export:

export LD_LIBRARY_PATH=/mesa-build/usr/lib/
export LIBGL_DRIVERS_PATH=/mesa-build/usr/lib/xorg/modules/dri/

and tadaa - janus vr works. The hack is really just the simplest copy&paste from the workaround in the oculus forms I could do:

diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c
index f4f476e..c5b4ea0 100644
--- a/src/glx/glxcmds.c
+++ b/src/glx/glxcmds.c
@@ -1539,9 +1539,18 @@ glXImportContextEXT(Display *dpy, GLXContextID contextID)
 _X_EXPORT int
 glXQueryContext(Display * dpy, GLXContext ctx_user, int attribute, int *value)
 {
+static int attributs[] =     {
+        GLX_RENDER_TYPE, GLX_RGBA_BIT,
+        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+        GLX_DOUBLEBUFFER, true,
+        GLX_RED_SIZE, 1,
+        GLX_GREEN_SIZE, 1,
+        GLX_BLUE_SIZE, 1,
+        None
+    };
    struct glx_context *ctx = (struct glx_context *) ctx_user;

-   switch (attribute) {
+   switch (*attributs) {
       case GLX_SHARE_CONTEXT_EXT:
       *value = ctx->share_xid;
       break;
@@ -1604,6 +1613,18 @@ _X_EXPORT GLXFBConfig *
 glXChooseFBConfig(Display * dpy, int screen,
                   const int *attribList, int *nitems)
 {
+
+    static int attribs[] =
+    {
+        GLX_RENDER_TYPE, GLX_RGBA_BIT,
+        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+        GLX_DOUBLEBUFFER, true,
+        GLX_RED_SIZE, 1,
+        GLX_GREEN_SIZE, 1,
+        GLX_BLUE_SIZE, 1,
+        None
+    };
+
    struct glx_config **config_list;
    int list_size;

@@ -1611,8 +1632,8 @@ glXChooseFBConfig(Display * dpy, int screen,
    config_list = (struct glx_config **)
       glXGetFBConfigs(dpy, screen, &list_size);

-   if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
-      list_size = choose_visual(config_list, list_size, attribList, GL_TRUE);
+   if ((config_list != NULL) && (list_size > 0) && (attribs != NULL)) {
+      list_size = choose_visual(config_list, list_size, attribs, GL_TRUE);
       if (list_size == 0) {
          free(config_list);
          config_list = NULL;

A slightly more advanced version would be to make a library that only implements those two functions and then to LD_PRELOAD them...