2 * $Id: gl_glx.c,v 1.2 2006-02-15 12:39:13 nkeynes Exp $
4 * GLX framebuffer support. Note depends on an X11 video driver
5 * (ie video_gtk) to maintain the X11 side of things.
7 * Copyright (c) 2005 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
24 #include "drivers/video_x11.h"
26 GLXContext glx_context;
28 gboolean glx_open = FALSE;
30 gboolean gl_glx_create_window( uint32_t width, uint32_t height )
33 const char *glxExts, *glxServer;
34 int visual_attrs[] = { GLX_RGBA, GLX_RED_SIZE, 4,
41 int screen = XScreenNumberOfScreen(video_x11_screen);
42 XSetWindowAttributes win_attrs;
45 if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
46 ERROR( "X Display lacks the GLX nature" );
49 if( major < 1 || minor < 2 ) {
50 ERROR( "X display supports GLX %d.%d, but we need at least 1.2", major, minor );
54 glxExts = glXQueryExtensionsString( video_x11_display, screen );
55 glxServer = glXQueryServerString( video_x11_display, screen, GLX_VENDOR );
56 INFO( "GLX version %d.%d, %s. Supported exts: %s", major, minor,
59 /* Find ourselves a nice visual */
60 visual = glXChooseVisual( video_x11_display,
63 if( visual == NULL ) {
64 ERROR( "Unable to obtain a compatible visual" );
68 /* And a matching gl context */
69 glx_context = glXCreateContext( video_x11_display, visual, None, True );
70 if( glx_context == NULL ) {
71 ERROR( "Unable to obtain a GLX Context. Possibly your system is broken in some small, undefineable way" );
76 /* Ok, all good so far. Unfortunately the visual we need to use will
77 * almost certainly be different from the one our frame is using. Which
78 * means we have to jump through the following hoops to create a
79 * child window with the appropriate settings.
81 win_attrs.event_mask = 0;
82 win_attrs.colormap = XCreateColormap( video_x11_display,
83 RootWindowOfScreen(video_x11_screen),
84 visual->visual, AllocNone );
85 glx_window = XCreateWindow( video_x11_display, video_x11_window,
86 0, 0, width, height, 0, visual->depth,
87 InputOutput, visual->visual,
88 CWColormap | CWEventMask,
90 if( glx_window == None ) {
91 /* Hrm. Aww, no window? */
92 ERROR( "Unable to create GLX window" );
93 glXDestroyContext( video_x11_display, glx_context );
94 if( win_attrs.colormap )
95 XFreeColormap( video_x11_display, win_attrs.colormap );
98 XMapRaised( video_x11_display, glx_window );
100 /* And finally set the window to be the active drawing area */
101 if( glXMakeCurrent( video_x11_display, glx_window, glx_context ) == False ) {
102 /* Oh you have _GOT_ to be kidding me */
103 ERROR( "Unable to prepare GLX window for drawing" );
104 XDestroyWindow( video_x11_display, glx_window );
105 XFreeColormap( video_x11_display, win_attrs.colormap );
106 glXDestroyContext( video_x11_display, glx_context );
116 gboolean gl_glx_set_output_format( uint32_t width, uint32_t height,
120 int screen = XScreenNumberOfScreen(video_x11_screen);
121 int buffer_attrs[] = { GLX_PBUFFER_WIDTH, width,
122 GLX_PBUFFER_HEIGHT, height,
123 GLX_PRESERVED_CONTENTS, True,
126 if( !gl_glx_create_window( width, height ) )
132 gboolean gl_glx_swap_frame( )
.