Add support for OpenGL on Atari using OSMesa, the offscreen rendering driver from Mesa
authorPatrice Mandin <patmandin@gmail.com>
Wed, 17 Nov 2004 23:13:15 +0000
changeset 9783b1ba22f5a28
parent 977 9c55b00f8251
child 979 c9d1ade1fb0b
Add support for OpenGL on Atari using OSMesa, the offscreen rendering driver from Mesa
README.MiNT
configure.in
src/video/xbios/SDL_xbios.c
src/video/xbios/SDL_xbios.h
test/configure.in
     1.1 --- a/README.MiNT	Mon Nov 15 23:34:56 2004 +0000
     1.2 +++ b/README.MiNT	Wed Nov 17 23:13:15 2004 +0000
     1.3 @@ -53,13 +53,14 @@
     1.4  Threads (Multitasking OS only via GNU pth library)
     1.5  Shared object loader (using LDG library from http://ldg.atari.org/)
     1.6  Audio CD (MetaDOS)
     1.7 +OpenGL (using Mesa offscreen rendering driver)
     1.8  
     1.9  - Driver combinations:
    1.10 -Video   Kbd     Mouse   Timer   Joysticks Joypads
    1.11 -xbios   ikbd    ikbd    vbl(2)  ikbd      hardware
    1.12 -xbios   gemdos  xbios   vbl(2)  xbios     hardware
    1.13 -xbios   bios    xbios   vbl(2)  xbios     hardware
    1.14 -gem     gem     gem(1)  vbl(2)  xbios     hardware
    1.15 +Video   Kbd     Mouse   Timer   Joysticks Joypads	OpenGL
    1.16 +xbios   ikbd    ikbd    vbl(2)  ikbd      hardware	OSMesa
    1.17 +xbios   gemdos  xbios   vbl(2)  xbios     hardware	OSMesa
    1.18 +xbios   bios    xbios   vbl(2)  xbios     hardware	OSMesa
    1.19 +gem     gem     gem(1)  vbl(2)  xbios     hardware	no
    1.20  
    1.21  (1) GEM does not report relative mouse motion, so xbios mouse driver is used
    1.22  to report this type event.
     2.1 --- a/configure.in	Mon Nov 15 23:34:56 2004 +0000
     2.2 +++ b/configure.in	Wed Nov 17 23:13:15 2004 +0000
     2.3 @@ -1129,6 +1129,19 @@
     2.4      fi
     2.5  }
     2.6  
     2.7 +dnl Check for Mesa offscreen rendering
     2.8 +CheckOSMesa()
     2.9 +{
    2.10 +    if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
    2.11 +        AC_CHECK_HEADER(GL/osmesa.h, have_osmesa_hdr=yes)
    2.12 +        AC_CHECK_LIB(OSMesa, OSMesaCreateContext, have_osmesa_lib=yes, have_osmesa_lib=no, -lm)
    2.13 +        if test x$have_osmesa_hdr = xyes -a x$have_osmesa_lib = xyes; then
    2.14 +    	    CFLAGS="$CFLAGS -DHAVE_OPENGL"
    2.15 +			SYSTEM_LIBS="$SYSTEM_LIBS -lOSMesa"
    2.16 +        fi
    2.17 +    fi
    2.18 +}
    2.19 +
    2.20  dnl See if we can use the new unified event interface in Linux 2.4
    2.21  CheckInputEvents()
    2.22  {
    2.23 @@ -2572,6 +2585,7 @@
    2.24          CheckAtariAudio
    2.25          CheckAtariLdg
    2.26          CheckPTH
    2.27 +		CheckOSMesa
    2.28          # Set up files for the audio library
    2.29          if test x$enable_threads = xyes -a x$enable_pth = xyes; then
    2.30              if test x$enable_audio = xyes; then
     3.1 --- a/src/video/xbios/SDL_xbios.c	Mon Nov 15 23:34:56 2004 +0000
     3.2 +++ b/src/video/xbios/SDL_xbios.c	Wed Nov 17 23:13:15 2004 +0000
     3.3 @@ -37,6 +37,10 @@
     3.4  #include <sys/stat.h>
     3.5  #include <unistd.h>
     3.6  
     3.7 +#ifdef HAVE_OPENGL
     3.8 +#include <GL/osmesa.h>
     3.9 +#endif
    3.10 +
    3.11  /* Mint includes */
    3.12  #include <mint/cookie.h>
    3.13  #include <mint/osbind.h>
    3.14 @@ -74,6 +78,15 @@
    3.15  static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface);
    3.16  static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
    3.17  
    3.18 +#ifdef HAVE_OPENGL
    3.19 +/* OpenGL functions */
    3.20 +static int XBIOS_GL_LoadLibrary(_THIS, const char *path);
    3.21 +static void *XBIOS_GL_GetProcAddress(_THIS, const char *proc);
    3.22 +static int XBIOS_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
    3.23 +static int XBIOS_GL_MakeCurrent(_THIS);
    3.24 +static void XBIOS_GL_SwapBuffers(_THIS);
    3.25 +#endif
    3.26 +
    3.27  /* List of video modes */
    3.28  
    3.29  /* ST modes */
    3.30 @@ -93,21 +106,21 @@
    3.31  static int xbiosnummodes_f30rvb=16;
    3.32  static xbiosmode_t xbiosmodelist_f30rvb[]={
    3.33  	{BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE},
    3.34 +	{BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE},
    3.35 +	{BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE},
    3.36 +	{BPS16|VERTFLAG,320,400,16,SDL_FALSE},
    3.37  	{BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE},
    3.38 -	{BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE},
    3.39 +	{BPS16|OVERSCAN,384,240,16,SDL_FALSE},
    3.40  	{BPS16|COL80,640,200,16,SDL_FALSE},
    3.41 -	{BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE},
    3.42 -	{BPS16|OVERSCAN,384,240,16,SDL_FALSE},
    3.43 -	{BPS16|VERTFLAG,320,400,16,SDL_FALSE},
    3.44  	{BPS16,320,200,16,SDL_FALSE},
    3.45  
    3.46  	{BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE},
    3.47 +	{BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE},
    3.48 +	{BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE},
    3.49 +	{BPS8|VERTFLAG,320,400,8,SDL_FALSE},
    3.50  	{BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE},
    3.51 -	{BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE},
    3.52 +	{BPS8|OVERSCAN,384,240,8,SDL_FALSE},
    3.53  	{BPS8|COL80,640,200,8,SDL_FALSE},
    3.54 -	{BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE},
    3.55 -	{BPS8|OVERSCAN,384,240,8,SDL_FALSE},
    3.56 -	{BPS8|VERTFLAG,320,400,8,SDL_FALSE},
    3.57  	{BPS8,320,200,8,SDL_FALSE}
    3.58  };
    3.59  
    3.60 @@ -118,8 +131,8 @@
    3.61  	{BPS16|VERTFLAG,320,240,16,SDL_FALSE},
    3.62  
    3.63  	{BPS8|COL80,640,480,8,SDL_FALSE},	
    3.64 +	{BPS8,320,480,8,SDL_FALSE},
    3.65  	{BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE},
    3.66 -	{BPS8,320,480,8,SDL_FALSE},
    3.67  	{BPS8|VERTFLAG,320,240,8,SDL_FALSE}
    3.68  };
    3.69  
    3.70 @@ -206,6 +219,15 @@
    3.71  	device->FlipHWSurface = XBIOS_FlipHWSurface;
    3.72  	device->FreeHWSurface = XBIOS_FreeHWSurface;
    3.73  
    3.74 +#ifdef HAVE_OPENGL
    3.75 +	/* OpenGL functions */
    3.76 +	device->GL_LoadLibrary = XBIOS_GL_LoadLibrary;
    3.77 +	device->GL_GetProcAddress = XBIOS_GL_GetProcAddress;
    3.78 +	device->GL_GetAttribute = XBIOS_GL_GetAttribute;
    3.79 +	device->GL_MakeCurrent = XBIOS_GL_MakeCurrent;
    3.80 +	device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
    3.81 +#endif
    3.82 +
    3.83  	/* Events */
    3.84  	device->InitOSKeymap = Atari_InitOSKeymap;
    3.85  	device->PumpEvents = Atari_PumpEvents;
    3.86 @@ -393,6 +415,10 @@
    3.87  	/* Init chunky to planar routine */
    3.88  	SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
    3.89  
    3.90 +#ifdef HAVE_OPENGL
    3.91 +	this->gl_config.driver_loaded = 1;
    3.92 +#endif
    3.93 +
    3.94  	/* We're done! */
    3.95  	return(0);
    3.96  }
    3.97 @@ -412,6 +438,14 @@
    3.98  {
    3.99  	int i;
   3.100  
   3.101 +#ifdef HAVE_OPENGL
   3.102 +	/* Shutdown OpenGL context */
   3.103 +	if (XBIOS_ctx) {
   3.104 +		OSMesaDestroyContext(XBIOS_ctx);
   3.105 +		XBIOS_ctx = NULL;
   3.106 +	}
   3.107 +#endif
   3.108 +
   3.109  	for (i=0;i<2;i++) {
   3.110  		if (XBIOS_screensmem[i]!=NULL) {
   3.111  			Mfree(XBIOS_screensmem[i]);
   3.112 @@ -503,6 +537,14 @@
   3.113  
   3.114  	XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL);
   3.115  
   3.116 +#ifdef HAVE_OPENGL
   3.117 +	if (flags & SDL_OPENGL) {
   3.118 +		if (this->gl_config.double_buffer) {
   3.119 +			flags |= SDL_DOUBLEBUF;
   3.120 +		}
   3.121 +	}
   3.122 +#endif
   3.123 +
   3.124  	/* Double buffer ? */
   3.125  	if (flags & SDL_DOUBLEBUF) {
   3.126  		XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM);
   3.127 @@ -525,7 +567,6 @@
   3.128  		return(NULL);
   3.129  	}
   3.130  
   3.131 -	current->flags = modeflags;
   3.132  	current->w = XBIOS_width = width;
   3.133  	current->h = XBIOS_height = height;
   3.134  	current->pitch = (width * new_depth)>>3;
   3.135 @@ -540,6 +581,33 @@
   3.136  
   3.137  	XBIOS_fbnum = 0;
   3.138  
   3.139 +#ifdef HAVE_OPENGL
   3.140 +	if (flags & SDL_OPENGL) {
   3.141 +		GLenum format;
   3.142 +
   3.143 +		/* Init OpenGL context using OSMesa */
   3.144 +		if (new_depth == 8) {
   3.145 +			format = OSMESA_COLOR_INDEX;
   3.146 +		} else {
   3.147 +			format = OSMESA_RGB_565;
   3.148 +		}
   3.149 +
   3.150 +		XBIOS_ctx = OSMesaCreateContextExt( format, this->gl_config.depth_size,
   3.151 +			this->gl_config.stencil_size, this->gl_config.accum_red_size +
   3.152 +			this->gl_config.accum_green_size + this->gl_config.accum_blue_size +
   3.153 +			this->gl_config.accum_alpha_size, NULL );
   3.154 +		if (!XBIOS_ctx) {
   3.155 +			XBIOS_FreeBuffers(this);
   3.156 +			SDL_SetError("OSMesaCreateContext failed");
   3.157 +			return(NULL);
   3.158 +		}
   3.159 +
   3.160 +		modeflags |= SDL_OPENGL;
   3.161 +	}
   3.162 +#endif
   3.163 +
   3.164 +	current->flags = modeflags;
   3.165 +
   3.166  	/* Now set the video mode */
   3.167  #ifndef DEBUG_VIDEO_XBIOS
   3.168  	Setscreen(-1,XBIOS_screens[0],-1);
   3.169 @@ -698,13 +766,6 @@
   3.170  		destscr += destx;
   3.171  
   3.172  		/* Convert chunky to planar screen */
   3.173 -#ifdef DEBUG_VIDEO_XBIOS
   3.174 -		printf("C2p:\n");
   3.175 -		printf(" Source: Adr=0x%08x, Pitch=%d\n", surface->pixels, surface->pitch);
   3.176 -		printf(" Dest: Adr=0x%08x, Pitch=%d\n", destscr, XBIOS_pitch);
   3.177 -		printf(" Size: %dx%d, dblline=%d\n", surface->w, surface->h, XBIOS_doubleline);
   3.178 -		fflush(stdout);
   3.179 -#endif
   3.180  		SDL_Atari_C2pConvert(
   3.181  			surface->pixels,
   3.182  			destscr,
   3.183 @@ -835,3 +896,113 @@
   3.184  
   3.185  	this->screen->pixels = NULL;	
   3.186  }
   3.187 +
   3.188 +#ifdef HAVE_OPENGL
   3.189 +
   3.190 +/* OpenGL functions */
   3.191 +static int XBIOS_GL_LoadLibrary(_THIS, const char *path)
   3.192 +{
   3.193 +	/* Library is always opened */
   3.194 +	this->gl_config.driver_loaded = 1;
   3.195 +
   3.196 +	return 0;
   3.197 +}
   3.198 +
   3.199 +static void *XBIOS_GL_GetProcAddress(_THIS, const char *proc)
   3.200 +{
   3.201 +	void *func = NULL;
   3.202 +
   3.203 +	if (XBIOS_ctx != NULL) {
   3.204 +		func = OSMesaGetProcAddress(proc);
   3.205 +	}
   3.206 +
   3.207 +	return func;
   3.208 +}
   3.209 +
   3.210 +static int XBIOS_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
   3.211 +{
   3.212 +	GLenum mesa_attrib;
   3.213 +	SDL_Surface *surface;
   3.214 +
   3.215 +	if (XBIOS_ctx == NULL) {
   3.216 +		return -1;
   3.217 +	}
   3.218 +
   3.219 +	switch(attrib) {
   3.220 +		case SDL_GL_RED_SIZE:
   3.221 +			mesa_attrib = GL_RED_BITS;
   3.222 +			break;
   3.223 +		case SDL_GL_GREEN_SIZE:
   3.224 +			mesa_attrib = GL_GREEN_BITS;
   3.225 +			break;
   3.226 +		case SDL_GL_BLUE_SIZE:
   3.227 +			mesa_attrib = GL_BLUE_BITS;
   3.228 +			break;
   3.229 +		case SDL_GL_ALPHA_SIZE:
   3.230 +			mesa_attrib = GL_ALPHA_BITS;
   3.231 +			break;
   3.232 +		case SDL_GL_DOUBLEBUFFER:
   3.233 +			surface = this->screen;
   3.234 +			*value = ((surface->flags & SDL_DOUBLEBUF)==SDL_DOUBLEBUF);
   3.235 +			return 0;
   3.236 +		case SDL_GL_DEPTH_SIZE:
   3.237 +			mesa_attrib = GL_DEPTH_BITS;
   3.238 +			break;
   3.239 +		case SDL_GL_STENCIL_SIZE:
   3.240 +			mesa_attrib = GL_STENCIL_BITS;
   3.241 +			break;
   3.242 +		case SDL_GL_ACCUM_RED_SIZE:
   3.243 +			mesa_attrib = GL_ACCUM_RED_BITS;
   3.244 +			break;
   3.245 +		case SDL_GL_ACCUM_GREEN_SIZE:
   3.246 +			mesa_attrib = GL_ACCUM_GREEN_BITS;
   3.247 +			break;
   3.248 +		case SDL_GL_ACCUM_BLUE_SIZE:
   3.249 +			mesa_attrib = GL_ACCUM_BLUE_BITS;
   3.250 +			break;
   3.251 +		case SDL_GL_ACCUM_ALPHA_SIZE:
   3.252 +			mesa_attrib = GL_ACCUM_ALPHA_BITS;
   3.253 +			break;
   3.254 +		default :
   3.255 +			return -1;
   3.256 +	}
   3.257 +
   3.258 +	glGetIntegerv(mesa_attrib, value);
   3.259 +	return 0;
   3.260 +}
   3.261 +
   3.262 +static int XBIOS_GL_MakeCurrent(_THIS)
   3.263 +{
   3.264 +	SDL_Surface *surface;
   3.265 +	GLenum type;
   3.266 +
   3.267 +	if (XBIOS_ctx == NULL) {
   3.268 +		return -1;
   3.269 +	}
   3.270 +
   3.271 +	surface = this->screen;
   3.272 +	if ((surface->format->BitsPerPixel) == 8) {
   3.273 +		type = GL_UNSIGNED_BYTE;
   3.274 +	} else {
   3.275 +		type = GL_UNSIGNED_SHORT_5_6_5;
   3.276 +	}
   3.277 +
   3.278 +	if (!OSMesaMakeCurrent(XBIOS_ctx, surface->pixels, type, surface->w, surface->h)) {
   3.279 +		SDL_SetError("Can not make OpenGL context current");
   3.280 +		return -1;
   3.281 +	}
   3.282 +
   3.283 +	return 0;
   3.284 +}
   3.285 +
   3.286 +static void XBIOS_GL_SwapBuffers(_THIS)
   3.287 +{
   3.288 +	if (XBIOS_ctx == NULL) {
   3.289 +		return;
   3.290 +	}
   3.291 +
   3.292 +	XBIOS_FlipHWSurface(this, this->screen);
   3.293 +	XBIOS_GL_MakeCurrent(this);
   3.294 +}
   3.295 +
   3.296 +#endif
     4.1 --- a/src/video/xbios/SDL_xbios.h	Mon Nov 15 23:34:56 2004 +0000
     4.2 +++ b/src/video/xbios/SDL_xbios.h	Wed Nov 17 23:13:15 2004 +0000
     4.3 @@ -28,6 +28,10 @@
     4.4  #ifndef _SDL_xbios_h
     4.5  #define _SDL_xbios_h
     4.6  
     4.7 +#ifdef HAVE_OPENGL
     4.8 +#include <GL/osmesa.h>
     4.9 +#endif
    4.10 +
    4.11  #include "SDL_types.h"
    4.12  #include "SDL_sysvideo.h"
    4.13  
    4.14 @@ -69,6 +73,9 @@
    4.15  	int frame_number;		/* Number of frame for double buffer */
    4.16  	int pitch;				/* Destination line width for C2P */
    4.17  	int width, height;		/* Screen size for centered C2P */
    4.18 +#ifdef HAVE_OPENGL
    4.19 +	OSMesaContext ctx;		/* OpenGL OSMesa context */
    4.20 +#endif
    4.21  
    4.22  	SDL_Rect *SDL_modelist[NUM_MODELISTS][SDL_NUMMODES+1];
    4.23  	xbiosmode_t *videomodes[NUM_MODELISTS][SDL_NUMMODES+1];
    4.24 @@ -123,5 +130,8 @@
    4.25  #define XBIOS_pitch			(this->hidden->pitch)
    4.26  #define XBIOS_width			(this->hidden->width)
    4.27  #define XBIOS_height		(this->hidden->height)
    4.28 +#ifdef HAVE_OPENGL
    4.29 +#define XBIOS_ctx			(this->hidden->ctx)
    4.30 +#endif
    4.31  
    4.32  #endif /* _SDL_xbios_h */
     5.1 --- a/test/configure.in	Mon Nov 15 23:34:56 2004 +0000
     5.2 +++ b/test/configure.in	Wed Nov 17 23:13:15 2004 +0000
     5.3 @@ -5,8 +5,7 @@
     5.4  SDL_VERSION=1.2.7
     5.5  
     5.6  dnl Detect the canonical host and target build environment
     5.7 -AC_CANONICAL_HOST
     5.8 -AC_CANONICAL_TARGET
     5.9 +AC_CANONICAL_SYSTEM
    5.10  
    5.11  dnl Setup for automake
    5.12  AM_INIT_AUTOMAKE(SDL_tests, $SDL_VERSION)
    5.13 @@ -36,9 +35,13 @@
    5.14      *-*-aix*)
    5.15          if test x$ac_cv_prog_gcc = xyes; then
    5.16              CFLAGS="-mthreads"
    5.17 -	fi
    5.18 +        fi
    5.19          SYS_GL_LIBS=""
    5.20          ;;
    5.21 +    *-*-mint*)
    5.22 +        MATHLIB="-lm"
    5.23 +        SYS_GL_LIBS="-lOSMesa"
    5.24 +        ;;
    5.25      *)
    5.26          MATHLIB="-lm"
    5.27          AC_PATH_X