[GLX] Ärger mit glXMakeContextCurrent bei mehrere Fenstern



  • Hallo!

    Ich versuche gerade mit GLX in zwei Fenstern zu rendern. Für beide Fenster erstelle ich separate GLX Kontexte und aktiviere nacheinander beide Fenster mit glXMakeContextCurrent, um darin zu rendern. Soweit funktioniert alles. Wenn ich danach aber wieder in das erste Fenster rendern möchte, bekomme ich die folgende Fehlermeldung:

    X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
      Major opcode of failed request:  136 (DRI2)
      Minor opcode of failed request:  3 (DRI2CreateDrawable)
      Resource id in failed request:  0x2c00006
      Serial number of failed request:  39
      Current serial number in output stream:  41
    

    Was mache ich falsch?

    Hier der dazugehörige Sourcecode. Er basiert auf glXIntro.

    #include <stdio.h>
    #include <stdlib.h>
    #include <GL/gl.h>
    #include <GL/glx.h>
    #include <unistd.h>
    
    int singleBufferAttributess[] = {
        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
        GLX_RENDER_TYPE,   GLX_RGBA_BIT,
        GLX_RED_SIZE,      1,   /* Request a single buffered color buffer */
        GLX_GREEN_SIZE,    1,   /* with the maximum number of color bits  */
        GLX_BLUE_SIZE,     1,   /* for each component                     */
        None
    };
    
    int doubleBufferAttributes[] = {
        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
        GLX_RENDER_TYPE,   GLX_RGBA_BIT,
        GLX_DOUBLEBUFFER,  True,  /* Request a double-buffered color buffer with */
        GLX_RED_SIZE,      1,     /* the maximum number of bits per component    */
        GLX_GREEN_SIZE,    1, 
        GLX_BLUE_SIZE,     1,
        None
    };
    
    static Bool WaitForNotify( Display *dpy, XEvent *event, XPointer arg ) {
        return (event->type == MapNotify) && (event->xmap.window == (Window) arg);
    }
    int main( int argc, char *argv[] )
    {
        Display              *dpy;
        Window                xWin;
        Window                xWin2;
        XEvent                event;
        XVisualInfo          *vInfo;
        XSetWindowAttributes  swa;
        GLXFBConfig          *fbConfigs;
        GLXContext            context;
        GLXContext            context2;
        GLXWindow             glxWin;
        GLXWindow             glxWin2;
        int                   swaMask;
        int                   numReturned;
        int                   swapFlag = True;
    
        /* Open a connection to the X server */
        dpy = XOpenDisplay( NULL );
        if ( dpy == NULL ) {
            printf( "Unable to open a connection to the X server\n" );
            exit( EXIT_FAILURE );
        }
    
        /* Request a suitable framebuffer configuration - try for a double 
        ** buffered configuration first */
        fbConfigs = glXChooseFBConfig( dpy, DefaultScreen(dpy),
                                       doubleBufferAttributes, &numReturned );
    
        if ( fbConfigs == NULL ) {  /* no double buffered configs available */
          fbConfigs = glXChooseFBConfig( dpy, DefaultScreen(dpy),
                                         singleBufferAttributess, &numReturned );
          swapFlag = False;
        }
    
        /* Create an X colormap and window with a visual matching the first
        ** returned framebuffer config */
        vInfo = glXGetVisualFromFBConfig( dpy, fbConfigs[0] );
    
        swa.border_pixel = 0;
        swa.event_mask = StructureNotifyMask;
        swa.colormap = XCreateColormap( dpy, RootWindow(dpy, vInfo->screen),
                                        vInfo->visual, AllocNone );
    
        swaMask = CWBorderPixel | CWColormap | CWEventMask;
    
        xWin = XCreateWindow( dpy, RootWindow(dpy, vInfo->screen), 0, 0, 256, 256,
                              0, vInfo->depth, InputOutput, vInfo->visual,
                              swaMask, &swa );
    
        xWin2 = XCreateWindow( dpy, RootWindow(dpy, vInfo->screen), 0, 0, 256, 256,
                               0, vInfo->depth, InputOutput, vInfo->visual,
                               swaMask, &swa );
    
        /* Create a GLX context for OpenGL rendering */
        context = glXCreateNewContext( dpy, fbConfigs[0], GLX_RGBA_TYPE,
    				 NULL, True );
    
        context2 = glXCreateNewContext( dpy, fbConfigs[0], GLX_RGBA_TYPE,
    	 	   		  NULL, True );
    
        /* Create a GLX window to associate the frame buffer configuration
        ** with the created X window */
        glxWin = glXCreateWindow( dpy, fbConfigs[0], xWin, NULL );
        glxWin2 = glXCreateWindow( dpy, fbConfigs[0], xWin2, NULL );
    
        /* Map the window to the screen, and wait for it to appear */
        XMapWindow( dpy, xWin );
        XIfEvent( dpy, &event, WaitForNotify, (XPointer) xWin );
    
        XMapWindow( dpy, xWin2 );
        XIfEvent( dpy, &event, WaitForNotify, (XPointer) xWin2 );
    
        /* Bind the GLX context to the Window */
        glXMakeContextCurrent( dpy, glxWin, glxWin, context );
    
        /* OpenGL rendering ... */
        glClearColor( 1.0, 0.0, 0.0, 1.0 );
        glClear( GL_COLOR_BUFFER_BIT );
    
        glFlush();
    
        if ( swapFlag )
            glXSwapBuffers( dpy, glxWin );
    
        /* Bind the GLX context to the Window */
        glXMakeContextCurrent( dpy, glxWin2, glxWin2, context2 );
    
        /* OpenGL rendering ... */
        glClearColor( 0.0, 0.0, 1.0, 1.0 );
        glClear( GL_COLOR_BUFFER_BIT );
    
        glFlush();
    
        if ( swapFlag )
            glXSwapBuffers( dpy, glxWin2 );
    
        /* Bind the GLX context to the Window */
        glXMakeContextCurrent( dpy, glxWin, glxWin, context ); // KABOOM
    
        sleep( 10 );
        exit( EXIT_SUCCESS );
    }
    


  • Okay, ich hab' mir den Sourcecode von freeglut angeschaut und es selber raus bekommen. ^^
    Offenbar muss man die Sache mit glXCreateWindow weglassen und statt dessen das X window verwenden. :3

    glXMakeContextCurrent( dpy, xWin, xWin, context );
    
    glXSwapBuffers( dpy, xWin );
    

    Dann frage ich mich allerdings wozu glXCreateWindow gut sein soll. ;3


Anmelden zum Antworten