Search
lxdream.org :: lxdream/src/drivers/gl_glx.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/gl_glx.c
changeset 96:3ec45b6525ba
prev94:8d80d9c7cc7d
author nkeynes
date Wed Feb 15 12:39:13 2006 +0000 (18 years ago)
permissions -rw-r--r--
last change More GLX work in progress
view annotate diff log raw
     1 /**
     2  * $Id: gl_glx.c,v 1.2 2006-02-15 12:39:13 nkeynes Exp $
     3  *
     4  * GLX framebuffer support. Note depends on an X11 video driver 
     5  * (ie video_gtk) to maintain the X11 side of things.
     6  *
     7  * Copyright (c) 2005 Nathan Keynes.
     8  *
     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.
    13  *
    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.
    18  */
    20 #include "dream.h"
    21 #include <X11/Xlib.h>
    22 #include <GL/glx.h>
    23 #include "video.h"
    24 #include "drivers/video_x11.h"
    26 GLXContext glx_context;
    27 Window glx_window;
    28 gboolean glx_open = FALSE;
    30 gboolean gl_glx_create_window( uint32_t width, uint32_t height )
    31 {
    32     int major, minor;
    33     const char *glxExts, *glxServer;
    34     int visual_attrs[] = { GLX_RGBA, GLX_RED_SIZE, 4, 
    35 			   GLX_GREEN_SIZE, 4, 
    36 			   GLX_BLUE_SIZE, 4,
    37 			   GLX_ALPHA_SIZE, 4,
    38 			   GLX_DEPTH_SIZE, 16,
    39 			   GLX_DOUBLEBUFFER, 
    40 			   None };
    41     int screen = XScreenNumberOfScreen(video_x11_screen);
    42     XSetWindowAttributes win_attrs;
    43     XVisualInfo *visual;
    45     if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
    46 	ERROR( "X Display lacks the GLX nature" );
    47 	return FALSE;
    48     }
    49     if( major < 1 || minor < 2 ) {
    50 	ERROR( "X display supports GLX %d.%d, but we need at least 1.2", major, minor );
    51 	return FALSE;
    52     }
    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,
    57 	  glxServer, glxExts );
    59     /* Find ourselves a nice visual */
    60     visual = glXChooseVisual( video_x11_display, 
    61 			      screen,
    62 			      visual_attrs );
    63     if( visual == NULL ) {
    64 	ERROR( "Unable to obtain a compatible visual" );
    65 	return FALSE;
    66     }
    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" );
    72 	return FALSE;
    73     }
    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.
    80      */
    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, 
    89 				&win_attrs );
    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 );
    96 	return FALSE;
    97     }
    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 );
   107 	return FALSE;
   108     }
   110     glx_open = TRUE;
   111     return TRUE;
   112 }
   116 gboolean gl_glx_set_output_format( uint32_t width, uint32_t height,
   117 				   int colour_format )
   118 {
   119     GLXFBConfig config;
   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,
   124 			   None };
   125     if( !glx_open ) {
   126 	if( !gl_glx_create_window( width, height ) )
   127 	    return FALSE;
   128     }
   129     return TRUE;
   130 }
   132 gboolean gl_glx_swap_frame( )
   133 {
   134     return FALSE;
   135 }
.