Search
lxdream.org :: lxdream :: r545:fdcdcd8b9fd1
lxdream 0.9.1
released Jun 29
Download Now
changeset545:fdcdcd8b9fd1
parent544:3c3a4bd77178
child546:7d01e597a066
authornkeynes
dateThu Nov 29 09:28:28 2007 +0000 (12 years ago)
Refactor GLX support and implement pbuffer rendering support
src/Makefile.am
src/Makefile.in
src/drivers/gl_common.c
src/drivers/gl_common.h
src/drivers/gl_fbo.c
src/drivers/video_glx.c
src/drivers/video_glx.h
src/drivers/video_gtk.c
src/drivers/video_x11.c
src/drivers/video_x11.h
src/gtkui/main_win.c
src/gui.h
src/pvr2/pvr2.c
src/pvr2/pvr2.h
1.1 --- a/src/Makefile.am Thu Nov 22 11:13:57 2007 +0000
1.2 +++ b/src/Makefile.am Thu Nov 29 09:28:28 2007 +0000
1.3 @@ -54,7 +54,7 @@
1.4 gtkui/mmio_win.c gtkui/debug_win.c gtkui/dump_win.c \
1.5 gtkui/ctrl_dlg.c gtkui/path_dlg.c gtkui/gdrom_menu.c \
1.6 drivers/video_gtk.c drivers/video_gtk.h \
1.7 - drivers/video_x11.c drivers/video_x11.h
1.8 + drivers/video_glx.c drivers/video_glx.h
1.9 endif
1.10
1.11 if CDROM_LINUX
2.1 --- a/src/Makefile.in Thu Nov 22 11:13:57 2007 +0000
2.2 +++ b/src/Makefile.in Thu Nov 29 09:28:28 2007 +0000
2.3 @@ -47,7 +47,7 @@
2.4 @GUI_GTK_TRUE@ gtkui/mmio_win.c gtkui/debug_win.c gtkui/dump_win.c \
2.5 @GUI_GTK_TRUE@ gtkui/ctrl_dlg.c gtkui/path_dlg.c gtkui/gdrom_menu.c \
2.6 @GUI_GTK_TRUE@ drivers/video_gtk.c drivers/video_gtk.h \
2.7 -@GUI_GTK_TRUE@ drivers/video_x11.c drivers/video_x11.h
2.8 +@GUI_GTK_TRUE@ drivers/video_glx.c drivers/video_glx.h
2.9
2.10 @CDROM_LINUX_TRUE@am__append_3 = drivers/cd_linux.c
2.11 @CDROM_LINUX_FALSE@am__append_4 = drivers/cd_none.c
2.12 @@ -287,8 +287,8 @@
2.13 gtkui/gtkui.c gtkui/gtkui.h gtkui/main_win.c gtkui/gtkcb.c \
2.14 gtkui/mmio_win.c gtkui/debug_win.c gtkui/dump_win.c \
2.15 gtkui/ctrl_dlg.c gtkui/path_dlg.c gtkui/gdrom_menu.c \
2.16 - drivers/video_gtk.c drivers/video_gtk.h drivers/video_x11.c \
2.17 - drivers/video_x11.h drivers/cd_linux.c drivers/cd_none.c \
2.18 + drivers/video_gtk.c drivers/video_gtk.h drivers/video_glx.c \
2.19 + drivers/video_glx.h drivers/cd_linux.c drivers/cd_none.c \
2.20 drivers/audio_esd.c
2.21 @BUILD_SH4X86_TRUE@am__objects_1 = sh4x86.$(OBJEXT) sh4trans.$(OBJEXT) \
2.22 @BUILD_SH4X86_TRUE@ x86dasm.$(OBJEXT) i386-dis.$(OBJEXT) \
2.23 @@ -298,7 +298,7 @@
2.24 @GUI_GTK_TRUE@ debug_win.$(OBJEXT) dump_win.$(OBJEXT) \
2.25 @GUI_GTK_TRUE@ ctrl_dlg.$(OBJEXT) path_dlg.$(OBJEXT) \
2.26 @GUI_GTK_TRUE@ gdrom_menu.$(OBJEXT) video_gtk.$(OBJEXT) \
2.27 -@GUI_GTK_TRUE@ video_x11.$(OBJEXT)
2.28 +@GUI_GTK_TRUE@ video_glx.$(OBJEXT)
2.29 @CDROM_LINUX_TRUE@am__objects_3 = cd_linux.$(OBJEXT)
2.30 @CDROM_LINUX_FALSE@am__objects_4 = cd_none.$(OBJEXT)
2.31 @AUDIO_ESOUND_TRUE@am__objects_5 = audio_esd.$(OBJEXT)
2.32 @@ -377,8 +377,8 @@
2.33 @AMDEP_TRUE@ ./$(DEPDIR)/syscall.Po ./$(DEPDIR)/tacore.Po \
2.34 @AMDEP_TRUE@ ./$(DEPDIR)/testsh4x86.Po ./$(DEPDIR)/testxlt.Po \
2.35 @AMDEP_TRUE@ ./$(DEPDIR)/texcache.Po ./$(DEPDIR)/timer.Po \
2.36 -@AMDEP_TRUE@ ./$(DEPDIR)/util.Po ./$(DEPDIR)/video_gtk.Po \
2.37 -@AMDEP_TRUE@ ./$(DEPDIR)/video_null.Po ./$(DEPDIR)/video_x11.Po \
2.38 +@AMDEP_TRUE@ ./$(DEPDIR)/util.Po ./$(DEPDIR)/video_glx.Po \
2.39 +@AMDEP_TRUE@ ./$(DEPDIR)/video_gtk.Po ./$(DEPDIR)/video_null.Po \
2.40 @AMDEP_TRUE@ ./$(DEPDIR)/watch.Po ./$(DEPDIR)/x86dasm.Po \
2.41 @AMDEP_TRUE@ ./$(DEPDIR)/xltcache.Po ./$(DEPDIR)/yuv.Po
2.42 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
2.43 @@ -529,9 +529,9 @@
2.44 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texcache.Po@am__quote@
2.45 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Po@am__quote@
2.46 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@
2.47 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/video_glx.Po@am__quote@
2.48 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/video_gtk.Po@am__quote@
2.49 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/video_null.Po@am__quote@
2.50 -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/video_x11.Po@am__quote@
2.51 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/watch.Po@am__quote@
2.52 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/x86dasm.Po@am__quote@
2.53 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xltcache.Po@am__quote@
2.54 @@ -1879,27 +1879,27 @@
2.55 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.56 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o video_gtk.obj `if test -f 'drivers/video_gtk.c'; then $(CYGPATH_W) 'drivers/video_gtk.c'; else $(CYGPATH_W) '$(srcdir)/drivers/video_gtk.c'; fi`
2.57
2.58 -video_x11.o: drivers/video_x11.c
2.59 -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT video_x11.o -MD -MP -MF "$(DEPDIR)/video_x11.Tpo" \
2.60 -@am__fastdepCC_TRUE@ -c -o video_x11.o `test -f 'drivers/video_x11.c' || echo '$(srcdir)/'`drivers/video_x11.c; \
2.61 -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/video_x11.Tpo" "$(DEPDIR)/video_x11.Po"; \
2.62 -@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/video_x11.Tpo"; exit 1; \
2.63 +video_glx.o: drivers/video_glx.c
2.64 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT video_glx.o -MD -MP -MF "$(DEPDIR)/video_glx.Tpo" \
2.65 +@am__fastdepCC_TRUE@ -c -o video_glx.o `test -f 'drivers/video_glx.c' || echo '$(srcdir)/'`drivers/video_glx.c; \
2.66 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/video_glx.Tpo" "$(DEPDIR)/video_glx.Po"; \
2.67 +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/video_glx.Tpo"; exit 1; \
2.68 @am__fastdepCC_TRUE@ fi
2.69 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/video_x11.c' object='video_x11.o' libtool=no @AMDEPBACKSLASH@
2.70 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/video_x11.Po' tmpdepfile='$(DEPDIR)/video_x11.TPo' @AMDEPBACKSLASH@
2.71 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/video_glx.c' object='video_glx.o' libtool=no @AMDEPBACKSLASH@
2.72 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/video_glx.Po' tmpdepfile='$(DEPDIR)/video_glx.TPo' @AMDEPBACKSLASH@
2.73 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.74 -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o video_x11.o `test -f 'drivers/video_x11.c' || echo '$(srcdir)/'`drivers/video_x11.c
2.75 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o video_glx.o `test -f 'drivers/video_glx.c' || echo '$(srcdir)/'`drivers/video_glx.c
2.76
2.77 -video_x11.obj: drivers/video_x11.c
2.78 -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT video_x11.obj -MD -MP -MF "$(DEPDIR)/video_x11.Tpo" \
2.79 -@am__fastdepCC_TRUE@ -c -o video_x11.obj `if test -f 'drivers/video_x11.c'; then $(CYGPATH_W) 'drivers/video_x11.c'; else $(CYGPATH_W) '$(srcdir)/drivers/video_x11.c'; fi`; \
2.80 -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/video_x11.Tpo" "$(DEPDIR)/video_x11.Po"; \
2.81 -@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/video_x11.Tpo"; exit 1; \
2.82 +video_glx.obj: drivers/video_glx.c
2.83 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT video_glx.obj -MD -MP -MF "$(DEPDIR)/video_glx.Tpo" \
2.84 +@am__fastdepCC_TRUE@ -c -o video_glx.obj `if test -f 'drivers/video_glx.c'; then $(CYGPATH_W) 'drivers/video_glx.c'; else $(CYGPATH_W) '$(srcdir)/drivers/video_glx.c'; fi`; \
2.85 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/video_glx.Tpo" "$(DEPDIR)/video_glx.Po"; \
2.86 +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/video_glx.Tpo"; exit 1; \
2.87 @am__fastdepCC_TRUE@ fi
2.88 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/video_x11.c' object='video_x11.obj' libtool=no @AMDEPBACKSLASH@
2.89 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/video_x11.Po' tmpdepfile='$(DEPDIR)/video_x11.TPo' @AMDEPBACKSLASH@
2.90 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/video_glx.c' object='video_glx.obj' libtool=no @AMDEPBACKSLASH@
2.91 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/video_glx.Po' tmpdepfile='$(DEPDIR)/video_glx.TPo' @AMDEPBACKSLASH@
2.92 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.93 -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o video_x11.obj `if test -f 'drivers/video_x11.c'; then $(CYGPATH_W) 'drivers/video_x11.c'; else $(CYGPATH_W) '$(srcdir)/drivers/video_x11.c'; fi`
2.94 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o video_glx.obj `if test -f 'drivers/video_glx.c'; then $(CYGPATH_W) 'drivers/video_glx.c'; else $(CYGPATH_W) '$(srcdir)/drivers/video_glx.c'; fi`
2.95
2.96 cd_linux.o: drivers/cd_linux.c
2.97 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cd_linux.o -MD -MP -MF "$(DEPDIR)/cd_linux.Tpo" \
3.1 --- a/src/drivers/gl_common.c Thu Nov 22 11:13:57 2007 +0000
3.2 +++ b/src/drivers/gl_common.c Thu Nov 29 09:28:28 2007 +0000
3.3 @@ -23,7 +23,6 @@
3.4 #include "drivers/gl_common.h"
3.5
3.6 extern uint32_t video_width, video_height;
3.7 -static uint32_t frame_colour = 0;
3.8
3.9 char *required_extensions[] = { "GL_EXT_framebuffer_object", NULL };
3.10
3.11 @@ -74,18 +73,12 @@
3.12 return isOK;
3.13 }
3.14
3.15 -void gl_display_render_buffer( render_buffer_t buffer )
3.16 +/**
3.17 + * Reset the gl state to simple orthographic projection with
3.18 + * texturing, alpha/depth/scissor/cull tests disabled.
3.19 + */
3.20 +void gl_reset_state()
3.21 {
3.22 - float top, bottom;
3.23 - if( buffer->inverted ) {
3.24 - top = ((float)buffer->height) - 0.5;
3.25 - bottom = 0.5;
3.26 - } else {
3.27 - top = 0.5;
3.28 - bottom = ((float)buffer->height) - 0.5;
3.29 - }
3.30 -
3.31 - /* Reset display parameters */
3.32 glViewport( 0, 0, video_width, video_height );
3.33 glMatrixMode(GL_PROJECTION);
3.34 glLoadIdentity();
3.35 @@ -97,8 +90,28 @@
3.36 glDisable( GL_DEPTH_TEST );
3.37 glDisable( GL_SCISSOR_TEST );
3.38 glDisable( GL_CULL_FACE );
3.39 - glColor3f( 0,0,0 );
3.40 -
3.41 + glDrawBuffer( GL_FRONT );
3.42 +}
3.43 +
3.44 +void gl_display_render_buffer( render_buffer_t buffer )
3.45 +{
3.46 + gl_texture_window( buffer->width, buffer->height, buffer->buf_id, buffer->inverted );
3.47 +}
3.48 +
3.49 +void gl_texture_window( int width, int height, int tex_id, gboolean inverted )
3.50 +{
3.51 + float top, bottom;
3.52 + if( inverted ) {
3.53 + top = ((float)height) - 0.5;
3.54 + bottom = 0.5;
3.55 + } else {
3.56 + top = 0.5;
3.57 + bottom = ((float)height) - 0.5;
3.58 + }
3.59 +
3.60 + /* Reset display parameters */
3.61 + gl_reset_state();
3.62 + glColor3f( 0,0,0 );
3.63
3.64 int x1=0,y1=0,x2=video_width,y2=video_height;
3.65
3.66 @@ -136,7 +149,7 @@
3.67
3.68 /* Render the textured rectangle */
3.69 glEnable( GL_TEXTURE_RECTANGLE_ARB );
3.70 - glBindTexture( GL_TEXTURE_RECTANGLE_ARB, buffer->buf_id );
3.71 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, tex_id );
3.72 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
3.73 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3.74 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3.75 @@ -145,9 +158,9 @@
3.76 glBegin( GL_QUADS );
3.77 glTexCoord2f( 0.5, top );
3.78 glVertex2f( x1, y1 );
3.79 - glTexCoord2f( ((float)buffer->width)-0.5, top );
3.80 + glTexCoord2f( ((float)width)-0.5, top );
3.81 glVertex2f( x2, y1 );
3.82 - glTexCoord2f( ((float)buffer->width)-0.5, bottom );
3.83 + glTexCoord2f( ((float)width)-0.5, bottom );
3.84 glVertex2f( x2, y2 );
3.85 glTexCoord2f( 0.5, bottom );
3.86 glVertex2f( x1, y2 );
3.87 @@ -156,7 +169,7 @@
3.88 glFlush();
3.89 }
3.90
3.91 -gboolean gl_load_frame_buffer( frame_buffer_t frame, render_buffer_t render )
3.92 +gboolean gl_load_frame_buffer( frame_buffer_t frame, int tex_id )
3.93 {
3.94 GLenum type = colour_formats[frame->colour_format].type;
3.95 GLenum format = colour_formats[frame->colour_format].format;
3.96 @@ -164,7 +177,7 @@
3.97 int rowstride = (frame->rowstride / bpp) - frame->width;
3.98
3.99 glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
3.100 - glBindTexture( GL_TEXTURE_RECTANGLE_ARB, render->buf_id );
3.101 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, tex_id );
3.102 glTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, 0,0,
3.103 frame->width, frame->height, format, type, frame->data );
3.104 return TRUE;
3.105 @@ -172,29 +185,13 @@
3.106
3.107 gboolean gl_display_blank( uint32_t colour )
3.108 {
3.109 - glViewport( 0, 0, video_width, video_height );
3.110 - glMatrixMode( GL_PROJECTION );
3.111 - glLoadIdentity();
3.112 - glOrtho( 0, video_width, video_height, 0, 0, -65535 );
3.113 - glMatrixMode(GL_MODELVIEW);
3.114 - glLoadIdentity();
3.115 - glColor3b( (colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF );
3.116 + gl_reset_state();
3.117 + glColor3ub( (colour >> 16) & 0xFF, (colour >> 8) & 0xFF, colour & 0xFF );
3.118 glRecti(0,0, video_width, video_height );
3.119 glFlush();
3.120 - frame_colour = colour;
3.121 return TRUE;
3.122 }
3.123
3.124 -void gl_redisplay_last()
3.125 -{
3.126 - render_buffer_t buffer = pvr2_get_front_buffer();
3.127 - if( buffer == NULL ) {
3.128 - gl_display_blank( frame_colour );
3.129 - } else {
3.130 - gl_display_render_buffer( buffer );
3.131 - }
3.132 -}
3.133 -
3.134 /**
3.135 * Generic GL read_render_buffer. This function assumes that the caller
3.136 * has already set the appropriate glReadBuffer(); in other words, unless
4.1 --- a/src/drivers/gl_common.h Thu Nov 22 11:13:57 2007 +0000
4.2 +++ b/src/drivers/gl_common.h Thu Nov 29 09:28:28 2007 +0000
4.3 @@ -31,9 +31,9 @@
4.4 gboolean hasRequiredGLExtensions();
4.5
4.6 /**
4.7 - * Generic GL routine to draw the given frame buffer into a render buffer
4.8 + * Generic GL routine to draw the given frame buffer into a texture
4.9 */
4.10 -gboolean gl_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer );
4.11 +gboolean gl_load_frame_buffer( frame_buffer_t frame, int tex_id );
4.12
4.13 /**
4.14 * Generic GL routine to blank the display view with the specified colour.
4.15 @@ -46,6 +46,11 @@
4.16 void gl_display_render_buffer( render_buffer_t buffer );
4.17
4.18 /**
4.19 + * Write a rectangular texture (GL_TEXTURE_RECTANGLE_ARB) to the display frame
4.20 + */
4.21 +void gl_texture_window( int width, int height, int tex_id, gboolean inverted );
4.22 +
4.23 +/**
4.24 * Redisplay the last frame.
4.25 */
4.26 void gl_redisplay_last();
5.1 --- a/src/drivers/gl_fbo.c Thu Nov 22 11:13:57 2007 +0000
5.2 +++ b/src/drivers/gl_fbo.c Thu Nov 29 09:28:28 2007 +0000
5.3 @@ -27,7 +27,6 @@
5.4 #include <stdlib.h>
5.5 #include "lxdream.h"
5.6 #include "display.h"
5.7 -#include "drivers/video_x11.h"
5.8 #include "drivers/gl_common.h"
5.9
5.10 #define MAX_FRAMEBUFFERS 2
5.11 @@ -259,7 +258,7 @@
5.12 {
5.13 glFinish();
5.14 gl_fbo_detach();
5.15 - gl_load_frame_buffer( frame, buffer );
5.16 + gl_load_frame_buffer( frame, buffer->buf_id );
5.17 }
5.18
5.19 static gboolean gl_fbo_display_blank( uint32_t colour )
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/src/drivers/video_glx.c Thu Nov 29 09:28:28 2007 +0000
6.3 @@ -0,0 +1,343 @@
6.4 +/**
6.5 + * $Id: video_x11.c,v 1.20 2007-10-31 12:05:23 nkeynes Exp $
6.6 + *
6.7 + * Shared functions for all X11-based display drivers.
6.8 + *
6.9 + * Copyright (c) 2005 Nathan Keynes.
6.10 + *
6.11 + * This program is free software; you can redistribute it and/or modify
6.12 + * it under the terms of the GNU General Public License as published by
6.13 + * the Free Software Foundation; either version 2 of the License, or
6.14 + * (at your option) any later version.
6.15 + *
6.16 + * This program is distributed in the hope that it will be useful,
6.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.19 + * GNU General Public License for more details.
6.20 + */
6.21 +
6.22 +#include <X11/Xlib.h>
6.23 +#include <GL/glx.h>
6.24 +#include <GL/gl.h>
6.25 +#include "dream.h"
6.26 +#include "pvr2/pvr2.h"
6.27 +#include "drivers/video_glx.h"
6.28 +#include "drivers/gl_common.h"
6.29 +
6.30 +/**
6.31 + * General X11 parameters. The front-end driver is expected to set this up
6.32 + * by calling video_glx_init after initializing itself.
6.33 + */
6.34 +Display *video_x11_display = NULL;
6.35 +Window video_x11_window = 0;
6.36 +static gboolean glsl_loaded = FALSE;
6.37 +
6.38 +static int glx_version = 100;
6.39 +static XVisualInfo *glx_visual;
6.40 +static GLXFBConfig glx_fbconfig;
6.41 +static GLXContext glx_context = NULL;
6.42 +static gboolean glx_is_initialized = FALSE;
6.43 +static gboolean glx_fbconfig_supported = FALSE;
6.44 +static gboolean glx_pbuffer_supported = FALSE;
6.45 +static int glx_pbuffer_texture = 0;
6.46 +
6.47 +/* Prototypes for pbuffer support methods */
6.48 +static void glx_pbuffer_init( display_driver_t driver );
6.49 +static render_buffer_t glx_pbuffer_create_render_buffer( uint32_t width, uint32_t height );
6.50 +static void glx_pbuffer_destroy_render_buffer( render_buffer_t buffer );
6.51 +static gboolean glx_pbuffer_set_render_target( render_buffer_t buffer );
6.52 +static gboolean glx_pbuffer_display_render_buffer( render_buffer_t buffer );
6.53 +static void glx_pbuffer_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer );
6.54 +static gboolean glx_pbuffer_display_blank( uint32_t colour );
6.55 +static gboolean glx_pbuffer_read_render_buffer( unsigned char *target, render_buffer_t buffer, int rowstride, int format );
6.56 +
6.57 +/**
6.58 + * Test if a specific extension is supported. From opengl.org
6.59 + * @param extension extension name to check for
6.60 + * @return TRUE if supported, otherwise FALSE.
6.61 + */
6.62 +gboolean isServerGLXExtensionSupported( Display *display, int screen,
6.63 + const char *extension )
6.64 +{
6.65 + const char *extensions = NULL;
6.66 + const char *start;
6.67 + char *where, *terminator;
6.68 +
6.69 + /* Extension names should not have spaces. */
6.70 + where = strchr(extension, ' ');
6.71 + if (where || *extension == '\0')
6.72 + return 0;
6.73 + extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
6.74 + start = extensions;
6.75 + for (;;) {
6.76 + where = strstr((const char *) start, extension);
6.77 + if (!where)
6.78 + break;
6.79 + terminator = where + strlen(extension);
6.80 + if (where == start || *(where - 1) == ' ')
6.81 + if (*terminator == ' ' || *terminator == '\0')
6.82 + return TRUE;
6.83 + start = terminator;
6.84 + }
6.85 + return FALSE;
6.86 +}
6.87 +
6.88 +gboolean video_glx_init( Display *display, int screen )
6.89 +{
6.90 + int major, minor;
6.91 +
6.92 + if( glx_is_initialized ) {
6.93 + return TRUE;
6.94 + }
6.95 +
6.96 + Bool result = glXQueryVersion( display, &major, &minor );
6.97 + if( result != False ) {
6.98 + glx_version = (major*100) + minor;
6.99 + }
6.100 +
6.101 + glx_fbconfig_supported = (glx_version >= 103 ||
6.102 + isServerGLXExtensionSupported(display, screen,
6.103 + "GLX_SGIX_fbconfig") );
6.104 + glx_pbuffer_supported = (glx_version >= 103 ||
6.105 + isServerGLXExtensionSupported(display, screen,
6.106 + "GLX_SGIX_pbuffer") );
6.107 +
6.108 + if( glx_fbconfig_supported ) {
6.109 + int nelem;
6.110 + int fb_attribs[] = { GLX_DRAWABLE_TYPE,
6.111 + GLX_PBUFFER_BIT|GLX_WINDOW_BIT,
6.112 + GLX_RENDER_TYPE, GLX_RGBA_BIT,
6.113 + GLX_DEPTH_SIZE, 24, 0 };
6.114 + GLXFBConfig *configs = glXChooseFBConfig( display, screen,
6.115 + fb_attribs, &nelem );
6.116 +
6.117 + if( configs == NULL || nelem == 0 ) {
6.118 + /* Didn't work. Fallback to 1.2 methods */
6.119 + glx_fbconfig_supported = FALSE;
6.120 + glx_pbuffer_supported = FALSE;
6.121 + } else {
6.122 + glx_fbconfig = configs[0];
6.123 + glx_visual = glXGetVisualFromFBConfig(display, glx_fbconfig);
6.124 + XFree(configs);
6.125 + }
6.126 + }
6.127 +
6.128 + if( !glx_fbconfig_supported ) {
6.129 + int attribs[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, 0 };
6.130 + glx_visual = glXChooseVisual( display, screen, attribs );
6.131 + }
6.132 + glx_is_initialized = TRUE;
6.133 + return TRUE;
6.134 +}
6.135 +
6.136 +gboolean video_glx_init_context( Display *display, Window window )
6.137 +{
6.138 + if( glx_fbconfig_supported ) {
6.139 + glx_context = glXCreateNewContext( display, glx_fbconfig,
6.140 + GLX_RGBA_TYPE, NULL, True );
6.141 + if( glx_context == NULL ) {
6.142 + ERROR( "Unable to create a GLX Context.");
6.143 + return FALSE;
6.144 + }
6.145 +
6.146 + if( glXMakeContextCurrent( display, window, window,
6.147 + glx_context ) == False ) {
6.148 + ERROR( "Unable to prepare GLX context for drawing" );
6.149 + glXDestroyContext( display, glx_context );
6.150 + return FALSE;
6.151 + }
6.152 + } else {
6.153 + glx_context = glXCreateContext( display, glx_visual, None, True );
6.154 + if( glx_context == NULL ) {
6.155 + ERROR( "Unable to create a GLX Context.");
6.156 + return FALSE;
6.157 + }
6.158 +
6.159 + if( glXMakeCurrent( display, window, glx_context ) == False ) {
6.160 + ERROR( "Unable to prepare GLX context for drawing" );
6.161 + glXDestroyContext( display, glx_context );
6.162 + return FALSE;
6.163 + }
6.164 + }
6.165 +
6.166 + if( !glXIsDirect(display, glx_context) ) {
6.167 + WARN( "Not using direct rendering - this is likely to be slow" );
6.168 + }
6.169 +
6.170 + texcache_gl_init();
6.171 + video_x11_display = display;
6.172 + video_x11_window = window;
6.173 +
6.174 + return TRUE;
6.175 +}
6.176 +
6.177 +gboolean video_glx_init_driver( display_driver_t driver )
6.178 +{
6.179 + if( gl_fbo_is_supported() ) { // First preference
6.180 + gl_fbo_init(driver);
6.181 + } else if( glx_pbuffer_supported ) {
6.182 + glx_pbuffer_init(driver);
6.183 + } else {
6.184 + ERROR( "Unable to create render buffers (requires either EXT_framebuffer_object or GLX 1.3+)" );
6.185 + video_glx_shutdown();
6.186 + return FALSE;
6.187 + }
6.188 + return TRUE;
6.189 +}
6.190 +
6.191 +
6.192 +void video_glx_shutdown()
6.193 +{
6.194 + // texcache_gl_shutdown();
6.195 + glx_is_initialized = FALSE;
6.196 + if( glx_context != NULL ) {
6.197 + glXDestroyContext( video_x11_display, glx_context );
6.198 + glx_context = NULL;
6.199 + }
6.200 + if( glx_visual != NULL ) {
6.201 + XFree(glx_visual);
6.202 + glx_visual = NULL;
6.203 + }
6.204 +}
6.205 +
6.206 +
6.207 +XVisualInfo *video_glx_get_visual()
6.208 +{
6.209 + return glx_visual;
6.210 +}
6.211 +
6.212 +
6.213 +int video_glx_load_font( const gchar *font_name )
6.214 +{
6.215 + int lists;
6.216 + XFontStruct *font = XLoadQueryFont(video_x11_display, font_name );
6.217 + if (font == NULL)
6.218 + return -1;
6.219 +
6.220 + lists = glGenLists(96);
6.221 + glXUseXFont(font->fid, 32, 96, lists);
6.222 + XFreeFont(video_x11_display, font);
6.223 + return lists;
6.224 +}
6.225 +
6.226 +
6.227 +void video_glx_swap_buffers( void )
6.228 +{
6.229 + glXSwapBuffers( video_x11_display, video_x11_window );
6.230 +}
6.231 +
6.232 +void video_glx_make_window_current( void )
6.233 +{
6.234 + glXMakeCurrent( video_x11_display, video_x11_window, glx_context );
6.235 +}
6.236 +
6.237 +
6.238 +// Pbuffer support
6.239 +
6.240 +/**
6.241 + * Construct the initial frame buffers and allocate ids for everything.
6.242 + * The render handling driver methods are set to the fbo versions.
6.243 + */
6.244 +static void glx_pbuffer_init( display_driver_t driver )
6.245 +{
6.246 + glGenTextures( 1, &glx_pbuffer_texture );
6.247 + driver->create_render_buffer = glx_pbuffer_create_render_buffer;
6.248 + driver->destroy_render_buffer = glx_pbuffer_destroy_render_buffer;
6.249 + driver->set_render_target = glx_pbuffer_set_render_target;
6.250 + driver->display_render_buffer = glx_pbuffer_display_render_buffer;
6.251 + driver->load_frame_buffer = glx_pbuffer_load_frame_buffer;
6.252 + driver->display_blank = glx_pbuffer_display_blank;
6.253 + driver->read_render_buffer = glx_pbuffer_read_render_buffer;
6.254 +}
6.255 +
6.256 +void glx_pbuffer_shutdown()
6.257 +{
6.258 + glDeleteTextures( 1, &glx_pbuffer_texture );
6.259 +}
6.260 +
6.261 +static render_buffer_t glx_pbuffer_create_render_buffer( uint32_t width, uint32_t height )
6.262 +{
6.263 + int attribs[] = { GLX_PBUFFER_WIDTH, width, GLX_PBUFFER_HEIGHT, height,
6.264 + GLX_PRESERVED_CONTENTS, True, 0 };
6.265 + GLXPbuffer pb = glXCreatePbuffer( video_x11_display, glx_fbconfig, attribs );
6.266 + if( pb == (GLXPbuffer)NULL ) {
6.267 + ERROR( "Unable to create pbuffer" );
6.268 + return NULL;
6.269 + }
6.270 + render_buffer_t buffer = calloc( sizeof(struct render_buffer), 1 );
6.271 + buffer->width = width;
6.272 + buffer->height = height;
6.273 + buffer->buf_id = pb;
6.274 + return buffer;
6.275 +}
6.276 +
6.277 +static void glx_pbuffer_destroy_render_buffer( render_buffer_t buffer )
6.278 +{
6.279 + glXDestroyPbuffer( video_x11_display, (GLXPbuffer)buffer->buf_id );
6.280 + buffer->buf_id = 0;
6.281 + free( buffer );
6.282 +}
6.283 +
6.284 +static gboolean glx_pbuffer_set_render_target( render_buffer_t buffer )
6.285 +{
6.286 + glFinish();
6.287 + if( glXMakeContextCurrent( video_x11_display, (GLXPbuffer)buffer->buf_id, (GLXPbuffer)buffer->buf_id, glx_context ) == False ) {
6.288 + ERROR( "Make context current (pbuffer) failed!" );
6.289 + }
6.290 + /* setup the gl context */
6.291 + glViewport( 0, 0, buffer->width, buffer->height );
6.292 + glDrawBuffer(GL_FRONT);
6.293 +
6.294 + return TRUE;
6.295 +}
6.296 +
6.297 +/**
6.298 + * Render the texture holding the given buffer to the front window
6.299 + * buffer.
6.300 + */
6.301 +static gboolean glx_pbuffer_display_render_buffer( render_buffer_t buffer )
6.302 +{
6.303 + glFinish();
6.304 + glReadBuffer( GL_FRONT );
6.305 + glDrawBuffer( GL_FRONT );
6.306 + glXMakeContextCurrent( video_x11_display, (GLXPbuffer)buffer->buf_id, (GLXPbuffer)buffer->buf_id, glx_context );
6.307 + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, glx_pbuffer_texture );
6.308 + glCopyTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, 0, 0, buffer->width, buffer->height, 0 );
6.309 + video_glx_make_window_current();
6.310 + gl_texture_window( buffer->width, buffer->height, glx_pbuffer_texture, buffer->inverted );
6.311 + return TRUE;
6.312 +}
6.313 +
6.314 +static void glx_pbuffer_load_frame_buffer( frame_buffer_t frame, render_buffer_t buffer )
6.315 +{
6.316 + glFinish();
6.317 + glXMakeContextCurrent( video_x11_display, (GLXPbuffer)buffer->buf_id, (GLXPbuffer)buffer->buf_id, glx_context );
6.318 + GLenum type = colour_formats[frame->colour_format].type;
6.319 + GLenum format = colour_formats[frame->colour_format].format;
6.320 + int bpp = colour_formats[frame->colour_format].bpp;
6.321 + int rowstride = (frame->rowstride / bpp) - frame->width;
6.322 +
6.323 + gl_reset_state();
6.324 + glPixelStorei( GL_UNPACK_ROW_LENGTH, rowstride );
6.325 + glRasterPos2f(0.375, frame->height-0.375);
6.326 + glPixelZoom( 1.0, 1.0 );
6.327 + glDrawPixels( frame->width, frame->height, format, type, frame->data );
6.328 + glFlush();
6.329 +}
6.330 +
6.331 +static gboolean glx_pbuffer_display_blank( uint32_t colour )
6.332 +{
6.333 + glFinish();
6.334 + video_glx_make_window_current();
6.335 + return gl_display_blank( colour );
6.336 +}
6.337 +
6.338 +static gboolean glx_pbuffer_read_render_buffer( unsigned char *target, render_buffer_t buffer,
6.339 + int rowstride, int format )
6.340 +{
6.341 + glXMakeCurrent( video_x11_display, (GLXDrawable)buffer->buf_id, glx_context );
6.342 + glReadBuffer( GL_FRONT );
6.343 + return gl_read_render_buffer( target, buffer, rowstride, format );
6.344 +}
6.345 +
6.346 +
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/src/drivers/video_glx.h Thu Nov 29 09:28:28 2007 +0000
7.3 @@ -0,0 +1,55 @@
7.4 +/**
7.5 + * $Id: video_glx.h,v 1.5 2007-09-08 04:05:35 nkeynes Exp $
7.6 + *
7.7 + * Parent for all glx-based display drivers.
7.8 + *
7.9 + * Copyright (c) 2005 Nathan Keynes.
7.10 + *
7.11 + * This program is free software; you can redistribute it and/or modify
7.12 + * it under the terms of the GNU General Public License as published by
7.13 + * the Free Software Foundation; either version 2 of the License, or
7.14 + * (at your option) any later version.
7.15 + *
7.16 + * This program is distributed in the hope that it will be useful,
7.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.19 + * GNU General Public License for more details.
7.20 + */
7.21 +
7.22 +#ifndef video_glx_driver_H
7.23 +#define video_glx_driver_H
7.24 +
7.25 +#include "X11/Xlib.h"
7.26 +#include "display.h"
7.27 +
7.28 +/**
7.29 + * Initialize GLX support. Detect capabilities, visuals, etc.
7.30 + * Must be called before any other GLX functions
7.31 + */
7.32 +gboolean video_glx_init( Display *display, int screen );
7.33 +
7.34 +/**
7.35 + * Return the prefered visual to be used for the GL window.
7.36 + * (Not using this for the render window may cause init context
7.37 + * to fail).
7.38 + */
7.39 +XVisualInfo *video_glx_get_visual();
7.40 +
7.41 +/**
7.42 + * Initialize the GLX context and bind to the specified window.
7.43 + * (which should have been created with the visual returned above).
7.44 + */
7.45 +gboolean video_glx_init_context( Display *display, Window window );
7.46 +
7.47 +/**
7.48 + * Initialize the display driver by setting the appropriate methods
7.49 + * for GLX support
7.50 + */
7.51 +gboolean video_glx_init_driver( display_driver_t driver );
7.52 +
7.53 +/**
7.54 + * Shutdown GLX support and release all resources.
7.55 + */
7.56 +void video_glx_shutdown();
7.57 +
7.58 +#endif
8.1 --- a/src/drivers/video_gtk.c Thu Nov 22 11:13:57 2007 +0000
8.2 +++ b/src/drivers/video_gtk.c Thu Nov 29 09:28:28 2007 +0000
8.3 @@ -22,7 +22,7 @@
8.4 #include <stdint.h>
8.5 #include "dream.h"
8.6 #include "display.h"
8.7 -#include "drivers/video_x11.h"
8.8 +#include "drivers/video_glx.h"
8.9 #include "drivers/gl_common.h"
8.10 #include "gtkui/gtkui.h"
8.11
8.12 @@ -80,8 +80,12 @@
8.13
8.14 gboolean video_gtk_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data )
8.15 {
8.16 - gl_fbo_detach();
8.17 - gl_redisplay_last();
8.18 + render_buffer_t buffer = pvr2_get_front_buffer();
8.19 + if( buffer == NULL ) {
8.20 + display_gtk_driver.display_blank(pvr2_get_border_colour());
8.21 + } else {
8.22 + display_gtk_driver.display_render_buffer(buffer);
8.23 + }
8.24 return TRUE;
8.25 }
8.26
8.27 @@ -89,13 +93,13 @@
8.28 {
8.29 video_width = event->width;
8.30 video_height = event->height;
8.31 - gl_fbo_detach();
8.32 - gl_redisplay_last();
8.33 + video_gtk_expose_callback(widget, NULL, data);
8.34 return TRUE;
8.35 }
8.36
8.37 gboolean video_gtk_init()
8.38 {
8.39 +
8.40 video_win = gtk_gui_get_renderarea();
8.41 if( video_win == NULL ) {
8.42 return FALSE;
8.43 @@ -115,17 +119,16 @@
8.44 gtk_widget_set_double_buffered( video_win, FALSE );
8.45 video_width = video_win->allocation.width;
8.46 video_height = video_win->allocation.height;
8.47 - return video_glx_init( gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win))),
8.48 - gdk_x11_screen_get_xscreen( gtk_widget_get_screen(GTK_WIDGET(video_win))),
8.49 - GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ),
8.50 - video_width, video_height, &display_gtk_driver );
8.51 + Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win)));
8.52 + Window window = GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window );
8.53 + video_glx_init_context( display, window );
8.54 + video_glx_init_driver( &display_gtk_driver );
8.55 }
8.56
8.57 void video_gtk_shutdown()
8.58 {
8.59 if( video_win != NULL ) {
8.60 video_glx_shutdown();
8.61 - gtk_widget_destroy( GTK_WIDGET(video_win) );
8.62 }
8.63
8.64 }
9.1 --- a/src/drivers/video_x11.c Thu Nov 22 11:13:57 2007 +0000
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,212 +0,0 @@
9.4 -/**
9.5 - * $Id: video_x11.c,v 1.20 2007-10-31 12:05:23 nkeynes Exp $
9.6 - *
9.7 - * Shared functions for all X11-based display drivers.
9.8 - *
9.9 - * Copyright (c) 2005 Nathan Keynes.
9.10 - *
9.11 - * This program is free software; you can redistribute it and/or modify
9.12 - * it under the terms of the GNU General Public License as published by
9.13 - * the Free Software Foundation; either version 2 of the License, or
9.14 - * (at your option) any later version.
9.15 - *
9.16 - * This program is distributed in the hope that it will be useful,
9.17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
9.18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.19 - * GNU General Public License for more details.
9.20 - */
9.21 -
9.22 -#include <X11/Xlib.h>
9.23 -#include <GL/glx.h>
9.24 -#include "dream.h"
9.25 -#include "pvr2/pvr2.h"
9.26 -#include "drivers/video_x11.h"
9.27 -#include "drivers/gl_common.h"
9.28 -
9.29 -extern uint32_t video_width, video_height;
9.30 -
9.31 -/**
9.32 - * General X11 parameters. The front-end driver is expected to set this up
9.33 - * by calling video_glx_init after initializing itself.
9.34 - */
9.35 -static Display *video_x11_display = NULL;
9.36 -static Screen *video_x11_screen = NULL;
9.37 -static Window video_x11_window = 0;
9.38 -static gboolean glsl_loaded = FALSE;
9.39 -
9.40 -/**
9.41 - * GLX parameters.
9.42 - */
9.43 -static GLXContext glx_context;
9.44 -static Window glx_window;
9.45 -static XSetWindowAttributes win_attrs;
9.46 -
9.47 -gboolean video_glx_create_window( int width, int height );
9.48 -gboolean video_glx_init_context( Window window );
9.49 -
9.50 -gboolean video_glx_init( Display *display, Screen *screen, Window window,
9.51 - int width, int height, display_driver_t driver )
9.52 -{
9.53 - video_x11_display = display;
9.54 - video_x11_screen = screen;
9.55 - glx_window = video_x11_window = window;
9.56 -
9.57 - if( !video_glx_init_context(glx_window) ) {
9.58 - return FALSE;
9.59 - }
9.60 -
9.61 - if( !glXIsDirect(video_x11_display, glx_context) ) {
9.62 - WARN( "Not using direct rendering - this is likely to be slow" );
9.63 - }
9.64 -
9.65 - if( gl_fbo_is_supported() ) {
9.66 - gl_fbo_init(driver);
9.67 -
9.68 -#ifdef USE_GLSL
9.69 - if( glsl_is_supported() ) {
9.70 - glsl_loaded = glsl_load_shaders( glsl_vertex_shader_src, glsl_fragment_shader_src );
9.71 - if( !glsl_loaded ) {
9.72 - WARN( "Shaders failed to load" );
9.73 - }
9.74 - } else {
9.75 - WARN( "Shaders not supported" );
9.76 - }
9.77 -#endif
9.78 - return TRUE;
9.79 - } else {
9.80 - /* Pbuffers? */
9.81 - ERROR( "Framebuffer objects not supported (required in this version)" );
9.82 - video_glx_shutdown();
9.83 - return FALSE;
9.84 - }
9.85 -}
9.86 -
9.87 -/**
9.88 - * Create a new window with a custom visual - not used at the moment,
9.89 - * but retained for future reference.
9.90 - */
9.91 -gboolean video_x11_create_window( int width, int height )
9.92 -{
9.93 - int visual_attrs[] = { GLX_RGBA, GLX_RED_SIZE, 4,
9.94 - GLX_GREEN_SIZE, 4,
9.95 - GLX_BLUE_SIZE, 4,
9.96 - GLX_ALPHA_SIZE, 4,
9.97 - GLX_DEPTH_SIZE, 24,
9.98 - GLX_DOUBLEBUFFER,
9.99 - None };
9.100 - int screen = XScreenNumberOfScreen(video_x11_screen);
9.101 - XVisualInfo *visual;
9.102 - /* Find ourselves a nice visual */
9.103 - visual = glXChooseVisual( video_x11_display,
9.104 - screen,
9.105 - visual_attrs );
9.106 -
9.107 - /* Create a child window with the visual in question */
9.108 - win_attrs.event_mask = 0;
9.109 - win_attrs.colormap = XCreateColormap( video_x11_display,
9.110 - RootWindowOfScreen(video_x11_screen),
9.111 - visual->visual, AllocNone );
9.112 - glx_window = XCreateWindow( video_x11_display, video_x11_window,
9.113 - 0, 0, width, height, 0, visual->depth,
9.114 - InputOutput, visual->visual,
9.115 - CWColormap | CWEventMask,
9.116 - &win_attrs );
9.117 - if( glx_window == None ) {
9.118 - /* Hrm. Aww, no window? */
9.119 - ERROR( "Unable to create GLX window" );
9.120 - if( win_attrs.colormap )
9.121 - XFreeColormap( video_x11_display, win_attrs.colormap );
9.122 - XFree(visual);
9.123 - return FALSE;
9.124 - }
9.125 - XMapRaised( video_x11_display, glx_window );
9.126 -
9.127 - XFree(visual);
9.128 - return TRUE;
9.129 -}
9.130 -
9.131 -gboolean video_glx_init_context( Window window )
9.132 -{
9.133 - XWindowAttributes attr;
9.134 - XVisualInfo *visual;
9.135 - XVisualInfo query;
9.136 - int query_items = 1;
9.137 -
9.138 - XGetWindowAttributes(video_x11_display, window, &attr);
9.139 -
9.140 - query.visualid = XVisualIDFromVisual(attr.visual);
9.141 - visual = XGetVisualInfo(video_x11_display, VisualIDMask, &query, &query_items );
9.142 - if( visual == NULL ) {
9.143 - ERROR( "Unable to obtain a compatible visual" );
9.144 - return FALSE;
9.145 - }
9.146 -
9.147 - int major, minor;
9.148 - if( glXQueryVersion( video_x11_display, &major, &minor ) == False ) {
9.149 - ERROR( "X Display lacks the GLX nature" );
9.150 - XFree(visual);
9.151 - return FALSE;
9.152 - }
9.153 - if( major < 1 || minor < 2 ) {
9.154 - ERROR( "X display supports GLX %d.%d, but we need at least 1.2", major, minor );
9.155 - XFree(visual);
9.156 - return FALSE;
9.157 - }
9.158 -
9.159 - /* And a matching gl context */
9.160 - glx_context = glXCreateContext( video_x11_display, visual, None, True );
9.161 - if( glx_context == NULL ) {
9.162 - ERROR( "Unable to obtain a GLX Context. Possibly your system is broken in some small, undefineable way" );
9.163 - XFree(visual);
9.164 - return FALSE;
9.165 - }
9.166 -
9.167 - if( glXMakeCurrent( video_x11_display, window, glx_context ) == False ) {
9.168 - ERROR( "Unable to prepare GLX context for drawing" );
9.169 - glXDestroyContext( video_x11_display, glx_context );
9.170 - XFree(visual);
9.171 - return FALSE;
9.172 - }
9.173 - XFree(visual);
9.174 -
9.175 - texcache_gl_init();
9.176 - return TRUE;
9.177 -}
9.178 -
9.179 -
9.180 -void video_glx_shutdown()
9.181 -{
9.182 - if( glsl_loaded ) {
9.183 - glsl_unload_shaders();
9.184 - }
9.185 - if( glx_window != None ) {
9.186 - XDestroyWindow( video_x11_display, glx_window );
9.187 - XFreeColormap( video_x11_display, win_attrs.colormap );
9.188 - glx_window = None;
9.189 - }
9.190 - if( glx_context != NULL ) {
9.191 - glXDestroyContext( video_x11_display, glx_context );
9.192 - glx_context = NULL;
9.193 - }
9.194 -}
9.195 -
9.196 -
9.197 -int video_glx_load_font( const gchar *font_name )
9.198 -{
9.199 - int lists;
9.200 - XFontStruct *font = XLoadQueryFont(video_x11_display, font_name );
9.201 - if (font == NULL)
9.202 - return -1;
9.203 -
9.204 - lists = glGenLists(96);
9.205 - glXUseXFont(font->fid, 32, 96, lists);
9.206 - XFreeFont(video_x11_display, font);
9.207 - return lists;
9.208 -}
9.209 -
9.210 -
9.211 -void video_glx_swap_buffers( void )
9.212 -{
9.213 - glXSwapBuffers( video_x11_display, glx_window );
9.214 -}
9.215 -
10.1 --- a/src/drivers/video_x11.h Thu Nov 22 11:13:57 2007 +0000
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,28 +0,0 @@
10.4 -/**
10.5 - * $Id: video_x11.h,v 1.5 2007-09-08 04:05:35 nkeynes Exp $
10.6 - *
10.7 - * Parent for all X11 display drivers.
10.8 - *
10.9 - * Copyright (c) 2005 Nathan Keynes.
10.10 - *
10.11 - * This program is free software; you can redistribute it and/or modify
10.12 - * it under the terms of the GNU General Public License as published by
10.13 - * the Free Software Foundation; either version 2 of the License, or
10.14 - * (at your option) any later version.
10.15 - *
10.16 - * This program is distributed in the hope that it will be useful,
10.17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.19 - * GNU General Public License for more details.
10.20 - */
10.21 -
10.22 -#ifndef video_x11_driver_H
10.23 -#define video_x11_driver_H
10.24 -
10.25 -#include "X11/Xlib.h"
10.26 -#include "display.h"
10.27 -
10.28 -gboolean video_glx_init( Display *display, Screen *screen, Window window,
10.29 - int width, int height, display_driver_t driver );
10.30 -void video_glx_shutdown();
10.31 -#endif
11.1 --- a/src/gtkui/main_win.c Thu Nov 22 11:13:57 2007 +0000
11.2 +++ b/src/gtkui/main_win.c Thu Nov 29 09:28:28 2007 +0000
11.3 @@ -26,9 +26,12 @@
11.4 #include <stdlib.h>
11.5
11.6 #include <gtk/gtk.h>
11.7 +#include <gdk/gdkx.h>
11.8 +#include <X11/Xutil.h>
11.9
11.10 #include "dream.h"
11.11 #include "gtkui/gtkui.h"
11.12 +#include "drivers/video_glx.h"
11.13
11.14
11.15 struct main_window_info {
11.16 @@ -87,8 +90,17 @@
11.17 gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
11.18
11.19 gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
11.20 +
11.21 + Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(win->window));
11.22 + Screen *screen = gdk_x11_screen_get_xscreen( gtk_widget_get_screen(win->window));
11.23 + int screen_no = XScreenNumberOfScreen(screen);
11.24 + video_glx_init(display, screen_no);
11.25
11.26 + XVisualInfo *visual = video_glx_get_visual();
11.27 + GdkVisual *gdkvis = gdk_x11_screen_lookup_visual( gtk_widget_get_screen(win->window), visual->visualid );
11.28 + GdkColormap *colormap = gdk_colormap_new( gdkvis, FALSE );
11.29 win->video = gtk_drawing_area_new();
11.30 + gtk_widget_set_colormap( win->video, colormap );
11.31 GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
11.32 gtk_widget_set_size_request( win->video, 640, 480 );
11.33 frame = gtk_frame_new(NULL);
12.1 --- a/src/gui.h Thu Nov 22 11:13:57 2007 +0000
12.2 +++ b/src/gui.h Thu Nov 29 09:28:28 2007 +0000
12.3 @@ -49,6 +49,11 @@
12.4 typedef enum { IO_IDE, IO_NETWORK } io_activity_type;
12.5
12.6 /**
12.7 + * Notify the GUI of state changes (eg binary was loaded and PC changed)
12.8 + */
12.9 +void gui_update_state();
12.10 +
12.11 +/**
12.12 * Notify the GUI of I/O activity.
12.13 * @param activity the type of IO activity being reported.
12.14 * @param active TRUE if the I/O device is becoming active, FALSE if inactive.
13.1 --- a/src/pvr2/pvr2.c Thu Nov 22 11:13:57 2007 +0000
13.2 +++ b/src/pvr2/pvr2.c Thu Nov 29 09:28:28 2007 +0000
13.3 @@ -90,6 +90,7 @@
13.4 static render_buffer_t render_buffers[MAX_RENDER_BUFFERS];
13.5 static int render_buffer_count = 0;
13.6 static render_buffer_t displayed_render_buffer = NULL;
13.7 +static uint32_t displayed_border_colour = 0;
13.8
13.9 /**
13.10 * Event handler for the hpos callback
13.11 @@ -140,6 +141,7 @@
13.12 }
13.13 render_buffer_count = 0;
13.14 displayed_render_buffer = NULL;
13.15 + displayed_border_colour = 0;
13.16 }
13.17
13.18 static void pvr2_reset( void )
13.19 @@ -333,6 +335,11 @@
13.20 return displayed_render_buffer;
13.21 }
13.22
13.23 +uint32_t pvr2_get_border_colour()
13.24 +{
13.25 + return displayed_border_colour;
13.26 +}
13.27 +
13.28 gboolean pvr2_save_next_scene( const gchar *filename )
13.29 {
13.30 if( pvr2_state.save_next_render_filename != NULL ) {
13.31 @@ -359,13 +366,14 @@
13.32 return; /* can't really do anything much */
13.33 } else if( !bEnabled ) {
13.34 /* Output disabled == black */
13.35 + displayed_render_buffer = NULL;
13.36 + displayed_border_colour = 0;
13.37 display_driver->display_blank( 0 );
13.38 - displayed_render_buffer = NULL;
13.39 } else if( MMIO_READ( PVR2, DISP_CFG2 ) & 0x08 ) {
13.40 /* Enabled but blanked - border colour */
13.41 - uint32_t colour = MMIO_READ( PVR2, DISP_BORDER );
13.42 - display_driver->display_blank( colour );
13.43 + displayed_border_colour = MMIO_READ( PVR2, DISP_BORDER );
13.44 displayed_render_buffer = NULL;
13.45 + display_driver->display_blank( displayed_border_colour );
13.46 } else {
13.47 /* Real output - determine dimensions etc */
13.48 struct frame_buffer fbuf;
14.1 --- a/src/pvr2/pvr2.h Thu Nov 22 11:13:57 2007 +0000
14.2 +++ b/src/pvr2/pvr2.h Thu Nov 29 09:28:28 2007 +0000
14.3 @@ -66,6 +66,7 @@
14.4 void pvr2_set_base_address( uint32_t );
14.5 int pvr2_get_frame_count( void );
14.6 render_buffer_t pvr2_get_front_buffer();
14.7 +uint32_t pvr2_get_border_colour();
14.8 gboolean pvr2_save_next_scene( const gchar *filename );
14.9
14.10 #define PVR2_CMD_END_OF_LIST 0x00
.