Search
lxdream.org :: lxdream/src/drivers/video_x11.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_x11.c
changeset 442:c0dcf22c8e08
prev439:f0c7928c5914
next478:57f73576c974
author nkeynes
date Sat Oct 13 04:00:23 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Cleanup window creation - not used now anyway
file annotate diff log raw
1.1 --- a/src/drivers/video_x11.c Thu Oct 11 11:09:10 2007 +0000
1.2 +++ b/src/drivers/video_x11.c Sat Oct 13 04:00:23 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: video_x11.c,v 1.17 2007-10-11 11:09:10 nkeynes Exp $
1.6 + * $Id: video_x11.c,v 1.18 2007-10-13 04:00:23 nkeynes Exp $
1.7 *
1.8 * Shared functions for all X11-based display drivers.
1.9 *
1.10 @@ -47,9 +47,9 @@
1.11 {
1.12 video_x11_display = display;
1.13 video_x11_screen = screen;
1.14 - video_x11_window = window;
1.15 + glx_window = video_x11_window = window;
1.16
1.17 - if( !video_glx_create_window(width,height) ) {
1.18 + if( !video_glx_init_context(glx_window) ) {
1.19 return FALSE;
1.20 }
1.21
1.22 @@ -75,9 +75,12 @@
1.23 }
1.24 }
1.25
1.26 -gboolean video_glx_create_window( int width, int height )
1.27 +/**
1.28 + * Create a new window with a custom visual - not used at the moment,
1.29 + * but retained for future reference.
1.30 + */
1.31 +gboolean video_x11_create_window( int width, int height )
1.32 {
1.33 - int major, minor;
1.34 int visual_attrs[] = { GLX_RGBA, GLX_RED_SIZE, 4,
1.35 GLX_GREEN_SIZE, 4,
1.36 GLX_BLUE_SIZE, 4,
1.37 @@ -87,44 +90,12 @@
1.38 None };
1.39 int screen = XScreenNumberOfScreen(video_x11_screen);
1.40 XVisualInfo *visual;
1.41 + /* Find ourselves a nice visual */
1.42 + visual = glXChooseVisual( video_x11_display,
1.43 + screen,
1.44 + visual_attrs );
1.45
1.46 - if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
1.47 - ERROR( "X Display lacks the GLX nature" );
1.48 - return FALSE;
1.49 - }
1.50 - if( major < 1 || minor < 2 ) {
1.51 - ERROR( "X display supports GLX %d.%d, but we need at least 1.2", major, minor );
1.52 - return FALSE;
1.53 - }
1.54 -
1.55 - XVisualInfo query;
1.56 - int query_items = 1;
1.57 - query.visualid = XVisualIDFromVisual(DefaultVisual(video_x11_display, screen));
1.58 - visual = XGetVisualInfo(video_x11_display, VisualIDMask, &query, &query_items );
1.59 -
1.60 -
1.61 - /* Find ourselves a nice visual */
1.62 - //visual = glXChooseVisual( video_x11_display,
1.63 - // screen,
1.64 - // visual_attrs );
1.65 - if( visual == NULL ) {
1.66 - ERROR( "Unable to obtain a compatible visual" );
1.67 - return FALSE;
1.68 - }
1.69 -
1.70 - /* And a matching gl context */
1.71 - glx_context = glXCreateContext( video_x11_display, visual, None, True );
1.72 - if( glx_context == NULL ) {
1.73 - ERROR( "Unable to obtain a GLX Context. Possibly your system is broken in some small, undefineable way" );
1.74 - return FALSE;
1.75 - }
1.76 - #if 0
1.77 -
1.78 - /* Ok, all good so far. Unfortunately the visual we need to use will
1.79 - * almost certainly be different from the one our frame is using. Which
1.80 - * means we have to jump through the following hoops to create a
1.81 - * child window with the appropriate settings.
1.82 - */
1.83 + /* Create a child window with the visual in question */
1.84 win_attrs.event_mask = 0;
1.85 win_attrs.colormap = XCreateColormap( video_x11_display,
1.86 RootWindowOfScreen(video_x11_screen),
1.87 @@ -137,28 +108,64 @@
1.88 if( glx_window == None ) {
1.89 /* Hrm. Aww, no window? */
1.90 ERROR( "Unable to create GLX window" );
1.91 - glXDestroyContext( video_x11_display, gtl_context );
1.92 if( win_attrs.colormap )
1.93 XFreeColormap( video_x11_display, win_attrs.colormap );
1.94 + XFree(visual);
1.95 return FALSE;
1.96 }
1.97 XMapRaised( video_x11_display, glx_window );
1.98 - #endif
1.99
1.100 - glx_window = video_x11_window;
1.101 + XFree(visual);
1.102 + return TRUE;
1.103 +}
1.104
1.105 - /* And finally set the window to be the active drawing area */
1.106 - if( glXMakeCurrent( video_x11_display, glx_window, glx_context ) == False ) {
1.107 - /* Ok you have _GOT_ to be kidding me */
1.108 - ERROR( "Unable to prepare GLX window for drawing" );
1.109 - XDestroyWindow( video_x11_display, glx_window );
1.110 - XFreeColormap( video_x11_display, win_attrs.colormap );
1.111 - glXDestroyContext( video_x11_display, glx_context );
1.112 +gboolean video_glx_init_context( Window window )
1.113 +{
1.114 + XWindowAttributes attr;
1.115 + XVisualInfo *visual;
1.116 + XVisualInfo query;
1.117 + int query_items = 1;
1.118 +
1.119 + XGetWindowAttributes(video_x11_display, window, &attr);
1.120 +
1.121 + query.visualid = XVisualIDFromVisual(attr.visual);
1.122 + visual = XGetVisualInfo(video_x11_display, VisualIDMask, &query, &query_items );
1.123 + if( visual == NULL ) {
1.124 + ERROR( "Unable to obtain a compatible visual" );
1.125 return FALSE;
1.126 }
1.127 +
1.128 + int major, minor;
1.129 + if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
1.130 + ERROR( "X Display lacks the GLX nature" );
1.131 + XFree(visual);
1.132 + return FALSE;
1.133 + }
1.134 + if( major < 1 || minor < 2 ) {
1.135 + ERROR( "X display supports GLX %d.%d, but we need at least 1.2", major, minor );
1.136 + XFree(visual);
1.137 + return FALSE;
1.138 + }
1.139 +
1.140 + /* And a matching gl context */
1.141 + glx_context = glXCreateContext( video_x11_display, visual, None, True );
1.142 + if( glx_context == NULL ) {
1.143 + ERROR( "Unable to obtain a GLX Context. Possibly your system is broken in some small, undefineable way" );
1.144 + XFree(visual);
1.145 + return FALSE;
1.146 + }
1.147 +
1.148 + if( glXMakeCurrent( video_x11_display, window, glx_context ) == False ) {
1.149 + ERROR( "Unable to prepare GLX context for drawing" );
1.150 + glXDestroyContext( video_x11_display, glx_context );
1.151 + XFree(visual);
1.152 + return FALSE;
1.153 + }
1.154 + XFree(visual);
1.155 return TRUE;
1.156 }
1.157
1.158 +
1.159 void video_glx_shutdown()
1.160 {
1.161 if( glsl_loaded ) {
.