Search
lxdream.org :: lxdream :: r96:3ec45b6525ba
lxdream 0.9.1
released Jun 29
Download Now
changeset96:3ec45b6525ba
parent95:7c0dac698ea2
child97:437d00238f74
authornkeynes
dateWed Feb 15 12:39:13 2006 +0000 (14 years ago)
More GLX work in progress
src/drivers/gl_glx.c
1.1 --- a/src/drivers/gl_glx.c Wed Feb 15 12:38:50 2006 +0000
1.2 +++ b/src/drivers/gl_glx.c Wed Feb 15 12:39:13 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gl_glx.c,v 1.1 2006-02-05 04:05:27 nkeynes Exp $
1.6 + * $Id: gl_glx.c,v 1.2 2006-02-15 12:39:13 nkeynes Exp $
1.7 *
1.8 * GLX framebuffer support. Note depends on an X11 video driver
1.9 * (ie video_gtk) to maintain the X11 side of things.
1.10 @@ -23,18 +23,31 @@
1.11 #include "video.h"
1.12 #include "drivers/video_x11.h"
1.13
1.14 -gboolean gl_glx_init( )
1.15 +GLXContext glx_context;
1.16 +Window glx_window;
1.17 +gboolean glx_open = FALSE;
1.18 +
1.19 +gboolean gl_glx_create_window( uint32_t width, uint32_t height )
1.20 {
1.21 int major, minor;
1.22 const char *glxExts, *glxServer;
1.23 + int visual_attrs[] = { GLX_RGBA, GLX_RED_SIZE, 4,
1.24 + GLX_GREEN_SIZE, 4,
1.25 + GLX_BLUE_SIZE, 4,
1.26 + GLX_ALPHA_SIZE, 4,
1.27 + GLX_DEPTH_SIZE, 16,
1.28 + GLX_DOUBLEBUFFER,
1.29 + None };
1.30 int screen = XScreenNumberOfScreen(video_x11_screen);
1.31 + XSetWindowAttributes win_attrs;
1.32 + XVisualInfo *visual;
1.33
1.34 if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
1.35 ERROR( "X Display lacks the GLX nature" );
1.36 return FALSE;
1.37 }
1.38 - if( major < 1 || minor < 1 ) {
1.39 - ERROR( "GLX version %d.%d is not supported", major, minor );
1.40 + if( major < 1 || minor < 2 ) {
1.41 + ERROR( "X display supports GLX %d.%d, but we need at least 1.2", major, minor );
1.42 return FALSE;
1.43 }
1.44
1.45 @@ -42,12 +55,78 @@
1.46 glxServer = glXQueryServerString( video_x11_display, screen, GLX_VENDOR );
1.47 INFO( "GLX version %d.%d, %s. Supported exts: %s", major, minor,
1.48 glxServer, glxExts );
1.49 +
1.50 + /* Find ourselves a nice visual */
1.51 + visual = glXChooseVisual( video_x11_display,
1.52 + screen,
1.53 + visual_attrs );
1.54 + if( visual == NULL ) {
1.55 + ERROR( "Unable to obtain a compatible visual" );
1.56 + return FALSE;
1.57 + }
1.58 +
1.59 + /* And a matching gl context */
1.60 + glx_context = glXCreateContext( video_x11_display, visual, None, True );
1.61 + if( glx_context == NULL ) {
1.62 + ERROR( "Unable to obtain a GLX Context. Possibly your system is broken in some small, undefineable way" );
1.63 + return FALSE;
1.64 + }
1.65 +
1.66 +
1.67 + /* Ok, all good so far. Unfortunately the visual we need to use will
1.68 + * almost certainly be different from the one our frame is using. Which
1.69 + * means we have to jump through the following hoops to create a
1.70 + * child window with the appropriate settings.
1.71 + */
1.72 + win_attrs.event_mask = 0;
1.73 + win_attrs.colormap = XCreateColormap( video_x11_display,
1.74 + RootWindowOfScreen(video_x11_screen),
1.75 + visual->visual, AllocNone );
1.76 + glx_window = XCreateWindow( video_x11_display, video_x11_window,
1.77 + 0, 0, width, height, 0, visual->depth,
1.78 + InputOutput, visual->visual,
1.79 + CWColormap | CWEventMask,
1.80 + &win_attrs );
1.81 + if( glx_window == None ) {
1.82 + /* Hrm. Aww, no window? */
1.83 + ERROR( "Unable to create GLX window" );
1.84 + glXDestroyContext( video_x11_display, glx_context );
1.85 + if( win_attrs.colormap )
1.86 + XFreeColormap( video_x11_display, win_attrs.colormap );
1.87 + return FALSE;
1.88 + }
1.89 + XMapRaised( video_x11_display, glx_window );
1.90 +
1.91 + /* And finally set the window to be the active drawing area */
1.92 + if( glXMakeCurrent( video_x11_display, glx_window, glx_context ) == False ) {
1.93 + /* Oh you have _GOT_ to be kidding me */
1.94 + ERROR( "Unable to prepare GLX window for drawing" );
1.95 + XDestroyWindow( video_x11_display, glx_window );
1.96 + XFreeColormap( video_x11_display, win_attrs.colormap );
1.97 + glXDestroyContext( video_x11_display, glx_context );
1.98 + return FALSE;
1.99 + }
1.100 +
1.101 + glx_open = TRUE;
1.102 + return TRUE;
1.103 }
1.104
1.105 -gboolean gl_glx_start_frame( uint32_t width, uint32_t height,
1.106 - int colour_format )
1.107 +
1.108 +
1.109 +gboolean gl_glx_set_output_format( uint32_t width, uint32_t height,
1.110 + int colour_format )
1.111 {
1.112 - return FALSE;
1.113 + GLXFBConfig config;
1.114 + int screen = XScreenNumberOfScreen(video_x11_screen);
1.115 + int buffer_attrs[] = { GLX_PBUFFER_WIDTH, width,
1.116 + GLX_PBUFFER_HEIGHT, height,
1.117 + GLX_PRESERVED_CONTENTS, True,
1.118 + None };
1.119 + if( !glx_open ) {
1.120 + if( !gl_glx_create_window( width, height ) )
1.121 + return FALSE;
1.122 + }
1.123 + return TRUE;
1.124 }
1.125
1.126 gboolean gl_glx_swap_frame( )
.