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 352:f0df7a6d4703
prev335:fb890e1814c0
next370:3131ba1440fc
author nkeynes
date Sun Feb 11 10:09:32 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Bug 27: Implement opengl framebuffer objects
Rewrite much of the final video output stage. Now uses generic "render
buffers", implemented on GL using framebuffer objects + textures.
file annotate diff log raw
1.1 --- a/src/drivers/video_x11.c Sat Jan 27 12:03:53 2007 +0000
1.2 +++ b/src/drivers/video_x11.c Sun Feb 11 10:09:32 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: video_x11.c,v 1.11 2007-01-27 12:03:53 nkeynes Exp $
1.6 + * $Id: video_x11.c,v 1.12 2007-02-11 10:09:32 nkeynes Exp $
1.7 *
1.8 * Shared functions for all X11-based display drivers.
1.9 *
1.10 @@ -21,30 +21,46 @@
1.11 #include "dream.h"
1.12 #include "drivers/video_x11.h"
1.13
1.14 +extern uint32_t video_width, video_height;
1.15 +
1.16 /**
1.17 * General X11 parameters. The front-end driver is expected to set this up
1.18 - * by calling video_x11_set_display after initializing itself.
1.19 + * by calling video_glx_init after initializing itself.
1.20 */
1.21 -Display *video_x11_display = NULL;
1.22 -Screen *video_x11_screen = NULL;
1.23 -Window video_x11_window = 0;
1.24 -extern uint32_t video_width, video_height;
1.25 +static Display *video_x11_display = NULL;
1.26 +static Screen *video_x11_screen = NULL;
1.27 +static Window video_x11_window = 0;
1.28 +
1.29 /**
1.30 * GLX parameters.
1.31 */
1.32 -GLXContext glx_context;
1.33 -Window glx_window;
1.34 -gboolean glx_open = FALSE;
1.35 +static GLXContext glx_context;
1.36 +static Window glx_window;
1.37 +static XSetWindowAttributes win_attrs;
1.38
1.39 -void video_x11_set_display( Display *display, Screen *screen, Window window )
1.40 +gboolean video_glx_init( Display *display, Screen *screen, Window window,
1.41 + int width, int height, display_driver_t driver )
1.42 {
1.43 video_x11_display = display;
1.44 video_x11_screen = screen;
1.45 video_x11_window = window;
1.46 +
1.47 + if( !video_glx_create_window(width,height) ) {
1.48 + return FALSE;
1.49 + }
1.50 +
1.51 + if( gl_fbo_is_supported() ) {
1.52 + gl_fbo_init(driver);
1.53 + return TRUE;
1.54 + } else {
1.55 + /* Pbuffers? */
1.56 + ERROR( "Framebuffer objects not supported (required in this version)" );
1.57 + video_glx_shutdown();
1.58 + return FALSE;
1.59 + }
1.60 }
1.61
1.62 -
1.63 -gboolean video_glx_create_window( int x, int y, int width, int height )
1.64 +gboolean video_glx_create_window( int width, int height )
1.65 {
1.66 int major, minor;
1.67 const char *glxExts, *glxServer;
1.68 @@ -56,7 +72,6 @@
1.69 GLX_DOUBLEBUFFER,
1.70 None };
1.71 int screen = XScreenNumberOfScreen(video_x11_screen);
1.72 - XSetWindowAttributes win_attrs;
1.73 XVisualInfo *visual;
1.74
1.75 if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
1.76 @@ -68,11 +83,6 @@
1.77 return FALSE;
1.78 }
1.79
1.80 - glxExts = glXQueryExtensionsString( video_x11_display, screen );
1.81 - glxServer = glXQueryServerString( video_x11_display, screen, GLX_VENDOR );
1.82 - INFO( "GLX version %d.%d, %s. Supported exts: %s", major, minor,
1.83 - glxServer, glxExts );
1.84 -
1.85 /* Find ourselves a nice visual */
1.86 visual = glXChooseVisual( video_x11_display,
1.87 screen,
1.88 @@ -100,7 +110,7 @@
1.89 RootWindowOfScreen(video_x11_screen),
1.90 visual->visual, AllocNone );
1.91 glx_window = XCreateWindow( video_x11_display, video_x11_window,
1.92 - x, y, width, height, 0, visual->depth,
1.93 + 0, 0, width, height, 0, visual->depth,
1.94 InputOutput, visual->visual,
1.95 CWColormap | CWEventMask,
1.96 &win_attrs );
1.97 @@ -123,11 +133,15 @@
1.98 glXDestroyContext( video_x11_display, glx_context );
1.99 return FALSE;
1.100 }
1.101 -
1.102 - hasRequiredGLExtensions();
1.103 - glx_open = TRUE;
1.104 return TRUE;
1.105 }
1.106 +void video_glx_shutdown()
1.107 +{
1.108 + XDestroyWindow( video_x11_display, glx_window );
1.109 + XFreeColormap( video_x11_display, win_attrs.colormap );
1.110 + glXDestroyContext( video_x11_display, glx_context );
1.111 +}
1.112 +
1.113
1.114 int video_glx_load_font( const gchar *font_name )
1.115 {
1.116 @@ -142,61 +156,8 @@
1.117 }
1.118
1.119
1.120 -
1.121 -gboolean video_glx_set_render_format( int x, int y, int width, int height )
1.122 -{
1.123 - if( glx_open )
1.124 - return TRUE;
1.125 - return video_glx_create_window( x, y, width, height );
1.126 -}
1.127 -
1.128 -gboolean video_glx_display_frame( video_buffer_t frame )
1.129 -{
1.130 - GLenum type = colour_formats[frame->colour_format].type;
1.131 - GLenum format = colour_formats[frame->colour_format].format;
1.132 - int bpp = colour_formats[frame->colour_format].bpp;
1.133 -
1.134 - glDrawBuffer( GL_FRONT );
1.135 - glViewport( 0, 0, video_width, video_height );
1.136 - glMatrixMode(GL_PROJECTION);
1.137 - glLoadIdentity();
1.138 - glOrtho( 0, frame->hres, frame->vres, 0, 0, -65535 );
1.139 - glMatrixMode(GL_MODELVIEW);
1.140 - glLoadIdentity();
1.141 - glRasterPos2i( 0, 0 );
1.142 - glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
1.143 - float scale = 480.0 / frame->vres;
1.144 - glPixelZoom( 1.0f, -scale );
1.145 - int rowstride = (frame->rowstride / bpp) - frame->hres;
1.146 - glPixelStorei( GL_PACK_ROW_LENGTH, rowstride );
1.147 - glDrawPixels( frame->hres, frame->vres, format, type,
1.148 - frame->data );
1.149 - glPopClientAttrib();
1.150 - glFlush();
1.151 - return TRUE;
1.152 -}
1.153 -
1.154 -gboolean video_glx_blank( int width, int height, uint32_t colour )
1.155 -{
1.156 - glDrawBuffer( GL_FRONT );
1.157 - glViewport( 0, 0, width, height );
1.158 - glMatrixMode( GL_PROJECTION );
1.159 - glLoadIdentity();
1.160 - glOrtho( 0, width, height, 0, 0, -65535 );
1.161 - glMatrixMode(GL_MODELVIEW);
1.162 - glLoadIdentity();
1.163 - glColor3b( (colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF );
1.164 - glRecti(0,0, width, height );
1.165 - glFlush();
1.166 - return TRUE;
1.167 -}
1.168 -
1.169 void video_glx_swap_buffers( void )
1.170 {
1.171 glXSwapBuffers( video_x11_display, glx_window );
1.172 }
1.173
1.174 -void video_glx_create_pixmap( int width, int height )
1.175 -{
1.176 -
1.177 -}
.