// Test the legacy GLX server and client together in the Vinix guest. module main #include #include #include #flag -lGL #flag -lX11 @[typedef] struct C.XVisualInfo { depth i32 } fn C.XOpenDisplay(&char) voidptr fn C.XDefaultScreen(voidptr) i32 fn C.XRootWindow(voidptr, i32) u64 fn C.XCreatePixmap(voidptr, u64, u32, u32, u32) u64 fn C.XFreePixmap(voidptr, u64) i32 fn C.XFree(voidptr) i32 fn C.XCloseDisplay(voidptr) i32 fn C.glXChooseVisual(voidptr, i32, &i32) &C.XVisualInfo fn C.glXCreateGLXPixmap(voidptr, &C.XVisualInfo, u64) u64 fn C.glXDestroyGLXPixmap(voidptr, u64) fn C.glXCreateContext(voidptr, &C.XVisualInfo, voidptr, i32) voidptr fn C.glXMakeCurrent(voidptr, u64, voidptr) i32 fn C.glXIsDirect(voidptr, voidptr) i32 fn C.glXDestroyContext(voidptr, voidptr) fn C.glClearColor(f32, f32, f32, f32) fn C.glClear(u32) fn C.glReadBuffer(u32) fn C.glReadPixels(i32, i32, i32, i32, u32, u32, voidptr) fn C.glGetError() u32 fn main() { eprintln('GLX probe: open display') display := C.XOpenDisplay(unsafe { nil }) assert display != unsafe { nil } defer { C.XCloseDisplay(display) } screen := C.XDefaultScreen(display) mut attributes := [i32(C.GLX_RGBA), C.GLX_RED_SIZE, 8, C.GLX_GREEN_SIZE, 8, C.GLX_BLUE_SIZE, 8, 0]! eprintln('GLX probe: select a visual') visual := C.glXChooseVisual(display, screen, &attributes[0]) assert visual != unsafe { nil } defer { C.XFree(visual) } pixmap := C.XCreatePixmap(display, C.XRootWindow(display, screen), 1, 1, u32(visual.depth)) assert pixmap != 0 defer { C.XFreePixmap(display, pixmap) } drawable := C.glXCreateGLXPixmap(display, visual, pixmap) assert drawable != 0 defer { C.glXDestroyGLXPixmap(display, drawable) } eprintln('GLX probe: create indirect context') context := C.glXCreateContext(display, visual, unsafe { nil }, C.False) assert context != unsafe { nil } defer { C.glXDestroyContext(display, context) } assert C.glXIsDirect(display, context) == C.False eprintln('GLX probe: bind indirect context') assert C.glXMakeCurrent(display, drawable, context) != C.False defer { C.glXMakeCurrent(display, 0, unsafe { nil }) } C.glClearColor(0, 1, 0, 1) C.glClear(C.GL_COLOR_BUFFER_BIT) C.glReadBuffer(C.GL_FRONT) mut pixel := [4]u8{} eprintln('GLX probe: read pixels') C.glReadPixels(0, 0, 1, 1, C.GL_RGBA, C.GL_UNSIGNED_BYTE, &pixel[0]) assert C.glGetError() == C.GL_NO_ERROR assert pixel[0] == 0 && pixel[1] == 255 && pixel[2] == 0 println('Indirect GLX rendered a green pixel in Xvfb.') }