[Xcb] Event processing and GLX

Dan Cecile dancecile at gmail.com
Sun Nov 20 10:06:12 PST 2011


I'm starting to experiment with using XCB in a new OpenGL project, and
I'm running into a snag with resizing windows. After finding the
explanation that GLX requires Xlib data structures, I modeled some
code off of the wiki tutorial (http://xcb.freedesktop.org/opengl/).

Opening the window and drawing work properly. When the window size
increases, though, the GLX framebuffer stays at its original size, and
OpenGL cannot draw on the full size of the expanded window.

To simplify the problem, I've modified the "glxdemo" Mesa demo. The
original code, using pure Xlib, can be found in the Mesa Git


I've modified this code very slightly, replacing the Xlib event loop
with an event loop written in XCB. This is enough to trigger the
resizing problem (which does not exist in the original, pure Xlib

Here is the original Xlib event loop:

   static void event_loop( Display *dpy )
      XEvent event;

      while (1) {
         XNextEvent( dpy, &event );

         switch (event.type) {
         case Expose:
            redraw( dpy, event.xany.window );
         case ConfigureNotify:
            resize( event.xconfigure.width, event.xconfigure.height );

And here is the XCB event loop that I tried replacing it with:

   static void event_loop( Display *dpy )
      xcb_connection_t *c;
      xcb_generic_event_t *event;

      XFlush( dpy );

      c = XGetXCBConnection( dpy );

      while (1) {
         event = xcb_wait_for_event( c );

         switch (event->response_type & 0x7F) {
         case XCB_EXPOSE:
            redraw( dpy, ((xcb_expose_event_t *)event)->window );
            resize( ((xcb_configure_notify_event_t *)event)->width,
                    ((xcb_configure_notify_event_t *)event)->height );

         free( event );

The only other change I made was to give XCB ownership of the event
loop immediately after connecting to the X server:

   dpy = XOpenDisplay(NULL);
   XSetEventQueueOwner( dpy, XCBOwnsEventQueue );

My system's OpenGL renderer is "Mesa DRI Intel(R) IGD", using Mesa
7.11.1. My system is running 64-bit Arch Linux, with XCB 1.7, Xlib
1.4.4, and Xorg X Server 1.11.2.

Any feedback on this puzzle would be helpful.

Best regards,
Dan Cecile

More information about the Xcb mailing list