Getting the current GLXFBConfig in GLX

273 Views Asked by At

I can trivially get visuals, visual IDs, etc. when generating an OpenGL context using xlib, but OpenXR requires a GLXFBConfig in order to work. But I can't figure out how to get the GLXFBConfig for the currently active visual. Any ideas?

glXGetVisualFromFBConfig seems to do the opposite, in that it gets me a visual from an GLXFBConfig. But my code reliably finds the correct visual this way. Is there a way to go the other way?

        int attribs[] = { GLX_RGBA,
                GLX_DOUBLEBUFFER,
                GLX_RED_SIZE, 1,
                GLX_GREEN_SIZE, 1,
                GLX_BLUE_SIZE, 1,
                GLX_DEPTH_SIZE, 1,
                None };
        XVisualInfo * vis = glXChooseVisual(CNFGDisplay, screen, attribs);
        CNFGVisual = vis->visual;
        CNFGVisualID = vis->visualid;
        CNFGWinAtt.depth = vis->depth;
        CNFGCtx = glXCreateContext( CNFGDisplay, vis, NULL, True );
1

There are 1 best solutions below

0
Charles Lohr On

I think @genpfault's solution would work, but I decided, instead to just use the glXChooseFBConfig approach instead, so that it just matches since it turns out it's not that hard to actually choose what I want.

int attribs[] = { 
    GLX_RENDER_TYPE, GLX_RGBA_BIT,
    GLX_DOUBLEBUFFER, True,
    GLX_RED_SIZE, 1,
    GLX_GREEN_SIZE, 1,
    GLX_BLUE_SIZE, 1,
    GLX_DEPTH_SIZE, 1,
    None };
int elements = 0;
GLXFBConfig * cfgs = glXChooseFBConfig( CNFGDisplay, CNFGScreen, attribs, &elements );
if( elements == 0 )
{
    fprintf( stderr, "Error: could not get valid GLXFBConfig visual.\n" );
    exit( -1 );
}
CNFGGLXFBConfig = cfgs[0];
XVisualInfo * vis = glXGetVisualFromFBConfig( CNFGDisplay, CNFGGLXFBConfig );
CNFGVisual = vis->visual;
CNFGVisualID = vis->visualid;
CNFGDepth = vis->depth;
CNFGCtx = glXCreateContext( CNFGDisplay, vis, NULL, True );