Final touches to OSMesa OpenGL support on Atari, using loadable libraries. Hope SDL 1.2.8 is out soon.
authorPatrice Mandin <patmandin@gmail.com>
Fri, 26 Nov 2004 16:16:50 +0000
changeset 99112b13601a544
parent 990 8e20c48a9c13
child 992 0324ce32b2d9
Final touches to OSMesa OpenGL support on Atari, using loadable libraries. Hope SDL 1.2.8 is out soon.
configure.in
src/video/ataricommon/SDL_atarigl.c
src/video/ataricommon/SDL_atarigl_c.h
src/video/gem/SDL_gemvideo.c
src/video/xbios/SDL_xbios.c
test/configure.in
     1.1 --- a/configure.in	Fri Nov 26 16:13:24 2004 +0000
     1.2 +++ b/configure.in	Fri Nov 26 16:16:50 2004 +0000
     1.3 @@ -1133,20 +1133,34 @@
     1.4  CheckAtariOSMesa()
     1.5  {
     1.6      if test "x$enable_video" = "xyes" -a "x$enable_video_opengl" = "xyes"; then
     1.7 +        AC_CHECK_HEADER(GL/osmesa.h, have_osmesa_hdr=yes)
     1.8 +        AC_CHECK_LIB(OSMesa, OSMesaCreateContext, have_osmesa_lib=yes, have_osmesa_lib=no, -lm)
     1.9 +
    1.10 +        # Static linking to -lOSMesa
    1.11          AC_PATH_PROG(OSMESA_CONFIG, osmesa-config, no)
    1.12          if test "x$OSMESA_CONFIG" = "xno" -o "x$enable_atari_ldg" = "xno"; then
    1.13 -            AC_CHECK_HEADER(GL/osmesa.h, have_osmesa_hdr=yes)
    1.14 -            AC_CHECK_LIB(OSMesa, OSMesaCreateContext, have_osmesa_lib=yes, have_osmesa_lib=no, -lm)
    1.15 +            # -lOSMesa is really the static library
    1.16              if test "x$have_osmesa_hdr" = "xyes" -a "x$have_osmesa_lib" = "xyes"; then
    1.17      	        CFLAGS="$CFLAGS -DHAVE_OPENGL"
    1.18  		    	SYSTEM_LIBS="$SYSTEM_LIBS -lOSMesa"
    1.19              fi
    1.20          else
    1.21 +            # -lOSMesa is a loader for OSMesa.ldg
    1.22              OSMESA_CFLAGS=`$OSMESA_CONFIG --cflags`
    1.23              OSMESA_LIBS=`$OSMESA_CONFIG --libs`
    1.24 -        	CFLAGS="$CFLAGS -DHAVE_OPENGL $OSMESA_CFLAGS"
    1.25 +            CFLAGS="$CFLAGS -DHAVE_OPENGL $OSMESA_CFLAGS"
    1.26              SYSTEM_LIBS="$SYSTEM_LIBS $OSMESA_LIBS"
    1.27          fi
    1.28 +
    1.29 +        AC_ARG_ENABLE(osmesa-shared,
    1.30 +[  --enable-osmesa-shared  dynamically load OSMesa OpenGL support [default=yes]],
    1.31 +                              , enable_osmesa_shared=yes)
    1.32 +        if test "x$enable_osmesa_shared" = "xyes" -a "x$enable_atari_ldg" = "xyes"; then
    1.33 +            # Dynamic linking
    1.34 +            if test "x$have_osmesa_hdr" = "xyes"; then
    1.35 +                CFLAGS="$CFLAGS -DENABLE_OSMESA_SHARED"
    1.36 +            fi
    1.37 +		fi
    1.38      fi
    1.39  }
    1.40  
     2.1 --- a/src/video/ataricommon/SDL_atarigl.c	Fri Nov 26 16:13:24 2004 +0000
     2.2 +++ b/src/video/ataricommon/SDL_atarigl.c	Fri Nov 26 16:16:50 2004 +0000
     2.3 @@ -24,125 +24,198 @@
     2.4  
     2.5  /*--- Includes ---*/
     2.6  
     2.7 +#include <stdio.h>
     2.8 +#include <stdlib.h>
     2.9 +#include <string.h>
    2.10  #ifdef HAVE_OPENGL
    2.11  #include <GL/osmesa.h>
    2.12  #endif
    2.13  
    2.14 +#include <mint/osbind.h>
    2.15 +
    2.16  #include "SDL_video.h"
    2.17  #include "SDL_error.h"
    2.18  #include "SDL_endian.h"
    2.19  #include "SDL_atarigl_c.h"
    2.20 +#ifdef ENABLE_OSMESA_SHARED
    2.21 +#include "SDL_loadso.h"
    2.22 +#endif
    2.23  
    2.24 -/*--- Variables ---*/
    2.25 +/*--- Defines ---*/
    2.26 +
    2.27 +#define PATH_OSMESA_LDG	"osmesa.ldg"
    2.28 +#define PATH_MESAGL_LDG	"mesa_gl.ldg"
    2.29 +#define PATH_TINYGL_LDG	"tiny_gl.ldg"
    2.30  
    2.31  /*--- Functions prototypes ---*/
    2.32  
    2.33 -static void ConvertNull(SDL_Surface *surface);
    2.34 -static void Convert565To555be(SDL_Surface *surface);
    2.35 -static void Convert565To555le(SDL_Surface *surface);
    2.36 -static void Convert565le(SDL_Surface *surface);
    2.37 -static void ConvertBGRAToABGR(SDL_Surface *surface);
    2.38 +static void SDL_AtariGL_UnloadLibrary(_THIS);
    2.39 +
    2.40 +static void CopyShadowNull(_THIS, SDL_Surface *surface);
    2.41 +static void CopyShadowDirect(_THIS, SDL_Surface *surface);
    2.42 +static void CopyShadow8888To555(_THIS, SDL_Surface *surface);
    2.43 +static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
    2.44 +
    2.45 +static void ConvertNull(_THIS, SDL_Surface *surface);
    2.46 +static void Convert565To555be(_THIS, SDL_Surface *surface);
    2.47 +static void Convert565To555le(_THIS, SDL_Surface *surface);
    2.48 +static void Convert565le(_THIS, SDL_Surface *surface);
    2.49 +static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface);
    2.50 +
    2.51 +static int InitNew(_THIS, SDL_Surface *current);
    2.52 +static int InitOld(_THIS, SDL_Surface *current);
    2.53  
    2.54  /*--- Public functions ---*/
    2.55  
    2.56  int SDL_AtariGL_Init(_THIS, SDL_Surface *current)
    2.57  {
    2.58  #ifdef HAVE_OPENGL
    2.59 -	GLenum osmesa_format;
    2.60 -	SDL_PixelFormat *pixel_format;
    2.61 -	Uint32	redmask;
    2.62 +	if (gl_oldmesa) {
    2.63 +		gl_active = InitOld(this, current);		
    2.64 +	} else {
    2.65 +		gl_active = InitNew(this, current);		
    2.66 +	}
    2.67 +#endif
    2.68  
    2.69 -	SDL_AtariGL_Quit(this);	/* Destroy previous context if exist */
    2.70 -
    2.71 -	/* Init OpenGL context using OSMesa */
    2.72 -	gl_convert = ConvertNull;
    2.73 -
    2.74 -	pixel_format = current->format;
    2.75 -	redmask = pixel_format->Rmask;
    2.76 -	switch (pixel_format->BitsPerPixel) {
    2.77 -		case 15:
    2.78 -			/* 1555, big and little endian, unsupported */
    2.79 -			osmesa_format = OSMESA_RGB_565;
    2.80 -			if (redmask == 31<<10) {
    2.81 -				gl_convert = Convert565To555be;
    2.82 -			} else {
    2.83 -				gl_convert = Convert565To555le;
    2.84 -			}
    2.85 -			break;
    2.86 -		case 16:
    2.87 -			if (redmask == 31<<11) {
    2.88 -				osmesa_format = OSMESA_RGB_565;
    2.89 -			} else {
    2.90 -				/* 565, little endian, unsupported */
    2.91 -				osmesa_format = OSMESA_RGB_565;
    2.92 -				gl_convert = Convert565le;
    2.93 -			}
    2.94 -			break;
    2.95 -		case 24:
    2.96 -			if (redmask == 255<<16) {
    2.97 -				osmesa_format = OSMESA_RGB;
    2.98 -			} else {
    2.99 -				osmesa_format = OSMESA_BGR;
   2.100 -			}
   2.101 -			break;
   2.102 -		case 32:
   2.103 -			if (redmask == 255<<16) {
   2.104 -				osmesa_format = OSMESA_ARGB;
   2.105 -			} else if (redmask == 255<<8) {
   2.106 -				osmesa_format = OSMESA_BGRA;
   2.107 -			} else if (redmask == 255<<24) {
   2.108 -				osmesa_format = OSMESA_RGBA;
   2.109 -			} else {
   2.110 -				/* ABGR format unsupported */
   2.111 -				osmesa_format = OSMESA_BGRA;
   2.112 -				gl_convert = ConvertBGRAToABGR;
   2.113 -			}
   2.114 -			break;
   2.115 -		default:
   2.116 -			osmesa_format = OSMESA_COLOR_INDEX;
   2.117 -			break;
   2.118 -	}
   2.119 -
   2.120 -	gl_ctx = OSMesaCreateContextExt( osmesa_format, this->gl_config.depth_size,
   2.121 -		this->gl_config.stencil_size, this->gl_config.accum_red_size +
   2.122 -		this->gl_config.accum_green_size + this->gl_config.accum_blue_size +
   2.123 -		this->gl_config.accum_alpha_size, NULL );
   2.124 -
   2.125 -	gl_active = (gl_ctx != NULL);
   2.126  	return (gl_active);
   2.127 -#else
   2.128 -	return 0;
   2.129 -#endif
   2.130  }
   2.131  
   2.132  void SDL_AtariGL_Quit(_THIS)
   2.133  {
   2.134  #ifdef HAVE_OPENGL
   2.135 -	/* Shutdown OpenGL context */
   2.136 -	if (gl_ctx) {
   2.137 -		OSMesaDestroyContext(gl_ctx);
   2.138 -		gl_ctx = NULL;
   2.139 +	if (!gl_active) {
   2.140 +		return;
   2.141  	}
   2.142 -#endif
   2.143 +
   2.144 +	if (gl_oldmesa) {
   2.145 +		/* Old mesa implementations */
   2.146 +		if (this->gl_data->OSMesaDestroyLDG) {
   2.147 +			this->gl_data->OSMesaDestroyLDG();
   2.148 +		}
   2.149 +		if (gl_shadow) {
   2.150 +			Mfree(gl_shadow);
   2.151 +			gl_shadow = NULL;
   2.152 +		}
   2.153 +	} else {
   2.154 +		/* New mesa implementation */
   2.155 +		if (gl_ctx) {
   2.156 +			if (this->gl_data->OSMesaDestroyContext) {
   2.157 +				this->gl_data->OSMesaDestroyContext(gl_ctx);
   2.158 +			}
   2.159 +			gl_ctx = NULL;
   2.160 +		}
   2.161 +	}
   2.162 +
   2.163 +	SDL_AtariGL_UnloadLibrary(this);
   2.164 +
   2.165 +#endif /* HAVE_OPENGL */
   2.166  	gl_active = 0;
   2.167  }
   2.168  
   2.169  int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
   2.170  {
   2.171  #ifdef HAVE_OPENGL
   2.172 -	/* Library is always opened */
   2.173 +
   2.174 +#ifdef ENABLE_OSMESA_SHARED
   2.175 +	void *handle;
   2.176 +
   2.177 +	if (gl_active) {
   2.178 +		SDL_SetError("OpenGL context already created");
   2.179 +		return -1;
   2.180 +	}
   2.181 +
   2.182 +	/* Unload previous driver */
   2.183 +	SDL_AtariGL_UnloadLibrary(this);
   2.184 +
   2.185 +	/* Load library given by path */
   2.186 +	handle = SDL_LoadObject(path);
   2.187 +	if (handle == NULL) {
   2.188 +		/* Try to load another one */
   2.189 +		path = getenv("SDL_VIDEO_GL_DRIVER");
   2.190 +		if ( path != NULL ) {
   2.191 +			handle = SDL_LoadObject(path);
   2.192 +		}
   2.193 +
   2.194 +		/* If it does not work, try some other */
   2.195 +		if (handle == NULL) {
   2.196 +			path = PATH_OSMESA_LDG;
   2.197 +			handle = SDL_LoadObject(path);
   2.198 +		}
   2.199 +
   2.200 +		if (handle == NULL) {
   2.201 +			path = PATH_MESAGL_LDG;
   2.202 +			handle = SDL_LoadObject(path);
   2.203 +		}
   2.204 +
   2.205 +		if (handle == NULL) {
   2.206 +			path = PATH_TINYGL_LDG;
   2.207 +			handle = SDL_LoadObject(path);
   2.208 +		}
   2.209 +	}
   2.210 +
   2.211 +	if (handle == NULL) {
   2.212 +		SDL_SetError("Could not load OpenGL library");
   2.213 +		return -1;
   2.214 +	}
   2.215 +
   2.216 +	/* Load functions pointers (osmesa.ldg) */
   2.217 +	this->gl_data->OSMesaCreateContextExt = SDL_LoadFunction(handle, "OSMesaCreateContextExt");
   2.218 +	this->gl_data->OSMesaDestroyContext = SDL_LoadFunction(handle, "OSMesaDestroyContext");
   2.219 +	this->gl_data->OSMesaMakeCurrent = SDL_LoadFunction(handle, "OSMesaMakeCurrent");
   2.220 +	this->gl_data->OSMesaPixelStore = SDL_LoadFunction(handle, "OSMesaPixelStore");
   2.221 +	this->gl_data->OSMesaGetProcAddress = SDL_LoadFunction(handle, "OSMesaGetProcAddress");
   2.222 +	this->gl_data->glGetIntegerv = SDL_LoadFunction(handle, "glGetIntegerv");
   2.223 +
   2.224 +	/* Load old functions pointers (mesa_gl.ldg, tiny_gl.ldg) */
   2.225 +	this->gl_data->OSMesaCreateLDG = SDL_LoadFunction(handle, "OSMesaCreateLDG");
   2.226 +	this->gl_data->OSMesaDestroyLDG = SDL_LoadFunction(handle, "OSMesaDestroyLDG");
   2.227 +
   2.228 +	gl_oldmesa = 0;
   2.229 +
   2.230 +	if ( (this->gl_data->OSMesaCreateContextExt == NULL) || 
   2.231 +	     (this->gl_data->OSMesaDestroyContext == NULL) ||
   2.232 +	     (this->gl_data->OSMesaMakeCurrent == NULL) ||
   2.233 +	     (this->gl_data->OSMesaPixelStore == NULL) ||
   2.234 +	     (this->gl_data->glGetIntegerv == NULL) ||
   2.235 +	     (this->gl_data->OSMesaGetProcAddress == NULL)) {
   2.236 +		/* Hum, maybe old library ? */
   2.237 +		if ( (this->gl_data->OSMesaCreateLDG == NULL) || 
   2.238 +		     (this->gl_data->OSMesaDestroyLDG == NULL)) {
   2.239 +			SDL_SetError("Could not retrieve OpenGL functions");
   2.240 +			return -1;
   2.241 +		} else {
   2.242 +			gl_oldmesa = 1;
   2.243 +		}
   2.244 +	}
   2.245 +
   2.246 +	this->gl_config.dll_handle = handle;
   2.247 +	if ( path ) {
   2.248 +		strncpy(this->gl_config.driver_path, path,
   2.249 +			sizeof(this->gl_config.driver_path)-1);
   2.250 +	} else {
   2.251 +		strcpy(this->gl_config.driver_path, "");
   2.252 +	}
   2.253 +
   2.254 +#endif
   2.255  	this->gl_config.driver_loaded = 1;
   2.256 +
   2.257 +	return 0;
   2.258 +#else
   2.259 +	return -1;
   2.260  #endif
   2.261 -	return 0;
   2.262  }
   2.263  
   2.264  void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc)
   2.265  {
   2.266  	void *func = NULL;
   2.267  #ifdef HAVE_OPENGL
   2.268 -	if (gl_ctx != NULL) {
   2.269 -		func = OSMesaGetProcAddress(proc);
   2.270 +
   2.271 +	if (this->gl_config.dll_handle) {
   2.272 +		func = SDL_LoadFunction(this->gl_config.dll_handle, (void *)proc);
   2.273 +	} else if (this->gl_data->OSMesaGetProcAddress) {
   2.274 +		func = this->gl_data->OSMesaGetProcAddress(proc);
   2.275  	}
   2.276 +
   2.277  #endif
   2.278  	return func;
   2.279  }
   2.280 @@ -153,7 +226,13 @@
   2.281  	GLenum mesa_attrib;
   2.282  	SDL_Surface *surface;
   2.283  
   2.284 -	if (gl_ctx == NULL) {
   2.285 +	if (this->gl_config.dll_handle) {
   2.286 +		if (this->gl_data->glGetIntegerv == NULL) {
   2.287 +			return -1;
   2.288 +		}
   2.289 +	}
   2.290 +
   2.291 +	if (!gl_active) {
   2.292  		return -1;
   2.293  	}
   2.294  
   2.295 @@ -196,7 +275,7 @@
   2.296  			return -1;
   2.297  	}
   2.298  
   2.299 -	glGetIntegerv(mesa_attrib, value);
   2.300 +	this->gl_data->glGetIntegerv(mesa_attrib, value);
   2.301  	return 0;
   2.302  #else
   2.303  	return -1;
   2.304 @@ -209,7 +288,18 @@
   2.305  	SDL_Surface *surface;
   2.306  	GLenum type;
   2.307  
   2.308 -	if (gl_ctx == NULL) {
   2.309 +	if (gl_oldmesa && gl_active) {
   2.310 +		return 0;
   2.311 +	}
   2.312 +
   2.313 +	if (this->gl_config.dll_handle) {
   2.314 +		if ((this->gl_data->OSMesaMakeCurrent == NULL) ||
   2.315 +			(this->gl_data->OSMesaPixelStore == NULL)) {
   2.316 +			return -1;
   2.317 +		}
   2.318 +	}
   2.319 +
   2.320 +	if (!gl_active) {
   2.321  		SDL_SetError("Invalid OpenGL context");
   2.322  		return -1;
   2.323  	}
   2.324 @@ -222,13 +312,13 @@
   2.325  		type = GL_UNSIGNED_BYTE;
   2.326  	}
   2.327  
   2.328 -	if (!OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, surface->h)) {
   2.329 +	if (!(this->gl_data->OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, surface->h))) {
   2.330  		SDL_SetError("Can not make OpenGL context current");
   2.331  		return -1;
   2.332  	}
   2.333  
   2.334  	/* OSMesa draws upside down */
   2.335 -	OSMesaPixelStore(OSMESA_Y_UP, 0);
   2.336 +	this->gl_data->OSMesaPixelStore(OSMESA_Y_UP, 0);
   2.337  
   2.338  	return 0;
   2.339  #else
   2.340 @@ -239,21 +329,296 @@
   2.341  void SDL_AtariGL_SwapBuffers(_THIS)
   2.342  {
   2.343  #ifdef HAVE_OPENGL
   2.344 -	if (gl_ctx == NULL) {
   2.345 -		return;
   2.346 +	if (gl_active) {
   2.347 +		gl_copyshadow(this, this->screen);
   2.348 +		gl_convert(this, this->screen);
   2.349  	}
   2.350 +#endif
   2.351 +}
   2.352  
   2.353 -	gl_convert(this->screen);
   2.354 +void SDL_AtariGL_InitPointers(_THIS)
   2.355 +{
   2.356 +#if defined(HAVE_OPENGL)
   2.357 +	this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
   2.358 +	this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
   2.359 +	this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
   2.360 +	this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
   2.361 +	this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
   2.362 +	this->gl_data->glGetIntegerv = glGetIntegerv;
   2.363  #endif
   2.364  }
   2.365  
   2.366  /*--- Private functions ---*/
   2.367  
   2.368 -static void ConvertNull(SDL_Surface *surface)
   2.369 +static void SDL_AtariGL_UnloadLibrary(_THIS)
   2.370 +{
   2.371 +#if defined(HAVE_OPENGL)
   2.372 +	if (this->gl_config.dll_handle) {
   2.373 +		SDL_UnloadObject(this->gl_config.dll_handle);
   2.374 +		this->gl_config.dll_handle = NULL;
   2.375 +
   2.376 +		/* Restore pointers to static library */
   2.377 +		this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
   2.378 +		this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
   2.379 +		this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
   2.380 +		this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
   2.381 +		this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
   2.382 +		this->gl_data->glGetIntegerv = glGetIntegerv;
   2.383 +
   2.384 +		this->gl_data->OSMesaCreateLDG = NULL;
   2.385 +		this->gl_data->OSMesaDestroyLDG = NULL;
   2.386 +	}
   2.387 +#endif
   2.388 +}
   2.389 +
   2.390 +/*--- Creation of an OpenGL context using new/old functions ---*/
   2.391 +
   2.392 +static int InitNew(_THIS, SDL_Surface *current)
   2.393 +{
   2.394 +	GLenum osmesa_format;
   2.395 +	SDL_PixelFormat *pixel_format;
   2.396 +	Uint32	redmask;
   2.397 +
   2.398 +	if (this->gl_config.dll_handle) {
   2.399 +		if (this->gl_data->OSMesaCreateContextExt == NULL) {
   2.400 +			return 0;
   2.401 +		}
   2.402 +	}
   2.403 +
   2.404 +	/* Init OpenGL context using OSMesa */
   2.405 +	gl_convert = ConvertNull;
   2.406 +	gl_copyshadow = CopyShadowNull;
   2.407 +
   2.408 +	pixel_format = current->format;
   2.409 +	redmask = pixel_format->Rmask;
   2.410 +	switch (pixel_format->BitsPerPixel) {
   2.411 +		case 15:
   2.412 +			/* 1555, big and little endian, unsupported */
   2.413 +			gl_pixelsize = 2;
   2.414 +			osmesa_format = OSMESA_RGB_565;
   2.415 +			if (redmask == 31<<10) {
   2.416 +				gl_convert = Convert565To555be;
   2.417 +			} else {
   2.418 +				gl_convert = Convert565To555le;
   2.419 +			}
   2.420 +			break;
   2.421 +		case 16:
   2.422 +			gl_pixelsize = 2;
   2.423 +			if (redmask == 31<<11) {
   2.424 +				osmesa_format = OSMESA_RGB_565;
   2.425 +			} else {
   2.426 +				/* 565, little endian, unsupported */
   2.427 +				osmesa_format = OSMESA_RGB_565;
   2.428 +				gl_convert = Convert565le;
   2.429 +			}
   2.430 +			break;
   2.431 +		case 24:
   2.432 +			gl_pixelsize = 3;
   2.433 +			if (redmask == 255<<16) {
   2.434 +				osmesa_format = OSMESA_RGB;
   2.435 +			} else {
   2.436 +				osmesa_format = OSMESA_BGR;
   2.437 +			}
   2.438 +			break;
   2.439 +		case 32:
   2.440 +			gl_pixelsize = 4;
   2.441 +			if (redmask == 255<<16) {
   2.442 +				osmesa_format = OSMESA_ARGB;
   2.443 +			} else if (redmask == 255<<8) {
   2.444 +				osmesa_format = OSMESA_BGRA;
   2.445 +			} else if (redmask == 255<<24) {
   2.446 +				osmesa_format = OSMESA_RGBA;
   2.447 +			} else {
   2.448 +				/* ABGR format unsupported */
   2.449 +				osmesa_format = OSMESA_BGRA;
   2.450 +				gl_convert = ConvertBGRAToABGR;
   2.451 +			}
   2.452 +			break;
   2.453 +		default:
   2.454 +			gl_pixelsize = 1;
   2.455 +			osmesa_format = OSMESA_COLOR_INDEX;
   2.456 +			break;
   2.457 +	}
   2.458 +
   2.459 +	gl_ctx = this->gl_data->OSMesaCreateContextExt(
   2.460 +		osmesa_format, this->gl_config.depth_size,
   2.461 +		this->gl_config.stencil_size, this->gl_config.accum_red_size +
   2.462 +		this->gl_config.accum_green_size + this->gl_config.accum_blue_size +
   2.463 +		this->gl_config.accum_alpha_size, NULL );
   2.464 +
   2.465 +	return (gl_ctx != NULL);
   2.466 +}
   2.467 +
   2.468 +static int InitOld(_THIS, SDL_Surface *current)
   2.469 +{
   2.470 +	GLenum osmesa_format;
   2.471 +	SDL_PixelFormat *pixel_format;
   2.472 +	Uint32	redmask;
   2.473 +
   2.474 +	if (this->gl_config.dll_handle) {
   2.475 +		if (this->gl_data->OSMesaCreateLDG == NULL) {
   2.476 +			return 0;
   2.477 +		}
   2.478 +	}
   2.479 +
   2.480 +	/* Init OpenGL context using OSMesa */
   2.481 +	gl_convert = ConvertNull;
   2.482 +	gl_copyshadow = CopyShadowNull;
   2.483 +
   2.484 +	pixel_format = current->format;
   2.485 +	redmask = pixel_format->Rmask;
   2.486 +	switch (pixel_format->BitsPerPixel) {
   2.487 +		case 15:
   2.488 +			/* 15 bits unsupported */
   2.489 +			gl_pixelsize = 2;
   2.490 +			osmesa_format = OSMESA_ARGB;
   2.491 +			if (redmask == 31<<10) {
   2.492 +				gl_copyshadow = CopyShadow8888To555;
   2.493 +			} else {
   2.494 +				gl_copyshadow = CopyShadow8888To565;
   2.495 +				gl_convert = Convert565To555le;
   2.496 +			}
   2.497 +			break;
   2.498 +		case 16:
   2.499 +			/* 16 bits unsupported */
   2.500 +			gl_pixelsize = 2;
   2.501 +			osmesa_format = OSMESA_ARGB;
   2.502 +			gl_copyshadow = CopyShadow8888To565;
   2.503 +			if (redmask != 31<<11) {
   2.504 +				/* 565, little endian, unsupported */
   2.505 +				gl_convert = Convert565le;
   2.506 +			}
   2.507 +			break;
   2.508 +		case 24:
   2.509 +			gl_pixelsize = 3;
   2.510 +			gl_copyshadow = CopyShadowDirect;
   2.511 +			if (redmask == 255<<16) {
   2.512 +				osmesa_format = OSMESA_RGB;
   2.513 +			} else {
   2.514 +				osmesa_format = OSMESA_BGR;
   2.515 +			}
   2.516 +			break;
   2.517 +		case 32:
   2.518 +			gl_pixelsize = 4;
   2.519 +			gl_copyshadow = CopyShadowDirect;
   2.520 +			if (redmask == 255<<16) {
   2.521 +				osmesa_format = OSMESA_ARGB;
   2.522 +			} else if (redmask == 255<<8) {
   2.523 +				osmesa_format = OSMESA_BGRA;
   2.524 +			} else if (redmask == 255<<24) {
   2.525 +				osmesa_format = OSMESA_RGBA;
   2.526 +			} else {
   2.527 +				/* ABGR format unsupported */
   2.528 +				osmesa_format = OSMESA_BGRA;
   2.529 +				gl_convert = ConvertBGRAToABGR;
   2.530 +			}
   2.531 +			break;
   2.532 +		default:
   2.533 +			gl_pixelsize = 1;
   2.534 +			gl_copyshadow = CopyShadowDirect;
   2.535 +			osmesa_format = OSMESA_COLOR_INDEX;
   2.536 +			break;
   2.537 +	}
   2.538 +
   2.539 +	gl_shadow = this->gl_data->OSMesaCreateLDG(
   2.540 +		osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
   2.541 +	);
   2.542 +
   2.543 +	return (gl_shadow != NULL);
   2.544 +}
   2.545 +
   2.546 +/*--- Conversions routines from shadow buffer to the screen ---*/
   2.547 +
   2.548 +static void CopyShadowNull(_THIS, SDL_Surface *surface)
   2.549  {
   2.550  }
   2.551  
   2.552 -static void Convert565To555be(SDL_Surface *surface)
   2.553 +static void CopyShadowDirect(_THIS, SDL_Surface *surface)
   2.554 +{
   2.555 +	int y, srcpitch, dstpitch;
   2.556 +	Uint8 *srcline, *dstline;
   2.557 +
   2.558 +	srcline = gl_shadow;
   2.559 +	srcpitch = surface->w * gl_pixelsize;
   2.560 +	dstline = surface->pixels;
   2.561 +	dstpitch = surface->pitch;
   2.562 +
   2.563 +	for (y=0; y<surface->h; y++) {
   2.564 +		memcpy(dstline, srcline, srcpitch);
   2.565 +
   2.566 +		srcline += srcpitch;
   2.567 +		dstline += dstpitch;
   2.568 +	}
   2.569 +}
   2.570 +
   2.571 +static void CopyShadow8888To555(_THIS, SDL_Surface *surface)
   2.572 +{
   2.573 +	int x,y, srcpitch, dstpitch;
   2.574 +	Uint16 *dstline, *dstcol;
   2.575 +	Uint32 *srcline, *srccol;
   2.576 +
   2.577 +	srcline = (Uint32 *)gl_shadow;
   2.578 +	srcpitch = surface->w;
   2.579 +	dstline = surface->pixels;
   2.580 +	dstpitch = surface->pitch >>1;
   2.581 +
   2.582 +	for (y=0; y<surface->h; y++) {
   2.583 +		srccol = srcline;
   2.584 +		dstcol = dstline;
   2.585 +		for (x=0; x<surface->w; x++) {
   2.586 +			Uint32 srccolor;
   2.587 +			Uint16 dstcolor;
   2.588 +			
   2.589 +			srccolor = *srccol++;
   2.590 +			dstcolor = (srccolor>>9) & (31<<10);
   2.591 +			dstcolor |= (srccolor>>6) & (31<<5);
   2.592 +			dstcolor |= (srccolor>>3) & 31;
   2.593 +			*dstcol++ = dstcolor;
   2.594 +		}
   2.595 +
   2.596 +		srcline += srcpitch;
   2.597 +		dstline += dstpitch;
   2.598 +	}
   2.599 +}
   2.600 +
   2.601 +static void CopyShadow8888To565(_THIS, SDL_Surface *surface)
   2.602 +{
   2.603 +	int x,y, srcpitch, dstpitch;
   2.604 +	Uint16 *dstline, *dstcol;
   2.605 +	Uint32 *srcline, *srccol;
   2.606 +
   2.607 +	srcline = (Uint32 *)gl_shadow;
   2.608 +	srcpitch = surface->w;
   2.609 +	dstline = surface->pixels;
   2.610 +	dstpitch = surface->pitch >>1;
   2.611 +
   2.612 +	for (y=0; y<surface->h; y++) {
   2.613 +		srccol = srcline;
   2.614 +		dstcol = dstline;
   2.615 +
   2.616 +		for (x=0; x<surface->w; x++) {
   2.617 +			Uint32 srccolor;
   2.618 +			Uint16 dstcolor;
   2.619 +			
   2.620 +			srccolor = *srccol++;
   2.621 +			dstcolor = (srccolor>>8) & (31<<11);
   2.622 +			dstcolor |= (srccolor>>5) & (63<<5);
   2.623 +			dstcolor |= (srccolor>>3) & 31;
   2.624 +			*dstcol++ = dstcolor;
   2.625 +		}
   2.626 +
   2.627 +		srcline += srcpitch;
   2.628 +		dstline += dstpitch;
   2.629 +	}
   2.630 +}
   2.631 +
   2.632 +/*--- Conversions routines in the screen ---*/
   2.633 +
   2.634 +static void ConvertNull(_THIS, SDL_Surface *surface)
   2.635 +{
   2.636 +}
   2.637 +
   2.638 +static void Convert565To555be(_THIS, SDL_Surface *surface)
   2.639  {
   2.640  	int x,y, pitch;
   2.641  	unsigned short *line, *pixel;
   2.642 @@ -272,7 +637,7 @@
   2.643  	}
   2.644  }
   2.645  
   2.646 -static void Convert565To555le(SDL_Surface *surface)
   2.647 +static void Convert565To555le(_THIS, SDL_Surface *surface)
   2.648  {
   2.649  	int x,y, pitch;
   2.650  	unsigned short *line, *pixel;
   2.651 @@ -292,7 +657,7 @@
   2.652  	}
   2.653  }
   2.654  
   2.655 -static void Convert565le(SDL_Surface *surface)
   2.656 +static void Convert565le(_THIS, SDL_Surface *surface)
   2.657  {
   2.658  	int x,y, pitch;
   2.659  	unsigned short *line, *pixel;
   2.660 @@ -311,7 +676,7 @@
   2.661  	}
   2.662  }
   2.663  
   2.664 -static void ConvertBGRAToABGR(SDL_Surface *surface)
   2.665 +static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface)
   2.666  {
   2.667  	int x,y, pitch;
   2.668  	unsigned long *line, *pixel;
     3.1 --- a/src/video/ataricommon/SDL_atarigl_c.h	Fri Nov 26 16:13:24 2004 +0000
     3.2 +++ b/src/video/ataricommon/SDL_atarigl_c.h	Fri Nov 26 16:16:50 2004 +0000
     3.3 @@ -33,25 +33,49 @@
     3.4  #define _THIS   SDL_VideoDevice *this
     3.5  
     3.6  struct SDL_PrivateGLData {
     3.7 -	/* to stop switching drivers while we have a valid context */
     3.8 -    int gl_active; 
     3.9 +
    3.10 +    int gl_active; 	/* to stop switching drivers while we have a valid context */
    3.11 +	
    3.12 +	int gl_oldmesa;	/* Old OpenGL support ? */
    3.13 +
    3.14 +	int	gl_pixelsize;	/* for CopyShadow functions */
    3.15 +
    3.16 +	Uint8 *gl_shadow;	/* Shadow buffer for old implementations */
    3.17  
    3.18  	/* for unsupported OSMesa buffer formats */
    3.19 -	void (*ConvertSurface)(SDL_Surface *surface);	
    3.20 +	void (*ConvertSurface)(_THIS, SDL_Surface *surface);	
    3.21  
    3.22 -#ifdef HAVE_OPENGL
    3.23 +	/* to convert the shadow buffer to the screen format */
    3.24 +	void (*CopyShadow)(_THIS, SDL_Surface *surface);	
    3.25 +
    3.26  	OSMesaContext	ctx;
    3.27 -#endif
    3.28 +
    3.29 +	/* osmesa.ldg */
    3.30 +	OSMesaContext (*OSMesaCreateContextExt)( GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, OSMesaContext sharelist);
    3.31 +	void (*OSMesaDestroyContext)( OSMesaContext ctx );
    3.32 +	GLboolean (*OSMesaMakeCurrent)( OSMesaContext ctx, void *buffer, GLenum type, GLsizei width, GLsizei height );
    3.33 +	void (*OSMesaPixelStore)( GLint pname, GLint value );
    3.34 +	void * (*OSMesaGetProcAddress)( const char *funcName );
    3.35 +	void (*glGetIntegerv)( GLenum pname, GLint *value );
    3.36 +
    3.37 +	/* mesa_gl.ldg, tiny_gl.ldg */
    3.38 +	void *(*OSMesaCreateLDG)( long format, long type, long width, long height );
    3.39 +	void (*OSMesaDestroyLDG)(void);
    3.40  };
    3.41  
    3.42 -/* Old variable names */
    3.43 +/* Variable names */
    3.44  #define gl_active	(this->gl_data->gl_active)
    3.45  #define gl_ctx		(this->gl_data->ctx)
    3.46 +#define gl_oldmesa	(this->gl_data->gl_oldmesa)
    3.47 +#define gl_pixelsize	(this->gl_data->gl_pixelsize)
    3.48 +#define gl_shadow	(this->gl_data->gl_shadow)
    3.49  #define gl_convert	(this->gl_data->ConvertSurface)
    3.50 +#define gl_copyshadow	(this->gl_data->CopyShadow)
    3.51  
    3.52  /* OpenGL functions */
    3.53  extern int SDL_AtariGL_Init(_THIS, SDL_Surface *current);
    3.54  extern void SDL_AtariGL_Quit(_THIS);
    3.55 +extern void SDL_AtariGL_InitPointers(_THIS);
    3.56  
    3.57  extern int SDL_AtariGL_LoadLibrary(_THIS, const char *path);
    3.58  extern void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc);
     4.1 --- a/src/video/gem/SDL_gemvideo.c	Fri Nov 26 16:13:24 2004 +0000
     4.2 +++ b/src/video/gem/SDL_gemvideo.c	Fri Nov 26 16:16:50 2004 +0000
     4.3 @@ -313,27 +313,11 @@
     4.4  	if (GEM_version >= 0x0410) {
     4.5  		short ap_gout[4], errorcode;
     4.6  		
     4.7 -#ifdef DEBUG_VIDEO_GEM
     4.8 -		printf("sdl:video:gem: AES %02x.%02x\n", (GEM_version>>8) & 0xff, GEM_version & 0xff);
     4.9 -#endif
    4.10 -
    4.11  		GEM_wfeatures=0;
    4.12  		errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]);
    4.13 -#ifdef DEBUG_VIDEO_GEM
    4.14 -		printf("sdl:video:gem: appl_getinfo() returned 0x%04x\n", errorcode);
    4.15 -#endif
    4.16  
    4.17  		if (errorcode==0) {
    4.18  			GEM_wfeatures=ap_gout[0];			
    4.19 -
    4.20 -#ifdef DEBUG_VIDEO_GEM
    4.21 -			printf("sdl:video:gem: AES wind_*() modes: 0x%04x\n", GEM_wfeatures);
    4.22 -			printf("sdl:video:gem: AES window behaviours: 0x%04x\n", ap_gout[3]);
    4.23 -		} else {
    4.24 -			printf("sdl:video:gem: apgout[]={0x%04x,0x%04x,0x%04x,0x%04x}\n",
    4.25 -				ap_gout[0], ap_gout[1], ap_gout[1], ap_gout[3]
    4.26 -			);
    4.27 -#endif
    4.28  		}
    4.29  	}	
    4.30  
    4.31 @@ -468,8 +452,8 @@
    4.32  
    4.33  	SDL_modelist[1] = NULL;
    4.34  
    4.35 -#ifdef DEBUG_VIDEO_GEM
    4.36 -	printf("sdl:video:gem: VideoInit(): done\n");
    4.37 +#ifdef HAVE_OPENGL
    4.38 +	SDL_AtariGL_InitPointers(this);
    4.39  #endif
    4.40  
    4.41  	/* We're done! */
    4.42 @@ -492,7 +476,9 @@
    4.43  static void GEM_FreeBuffers(_THIS)
    4.44  {
    4.45  #ifdef HAVE_OPENGL
    4.46 -	SDL_AtariGL_Quit(this);
    4.47 +	if (gl_active) {
    4.48 +		SDL_AtariGL_Quit(this);
    4.49 +	}
    4.50  #endif
    4.51  
    4.52  	/* Release buffer */
    4.53 @@ -1290,12 +1276,11 @@
    4.54  
    4.55  static void GEM_GL_SwapBuffers(_THIS)
    4.56  {
    4.57 -	if (gl_ctx == NULL) {
    4.58 -		return;
    4.59 +	if (gl_active) {
    4.60 +		gl_copyshadow(this, this->screen);
    4.61 +		gl_convert(this, this->screen);
    4.62 +		GEM_FlipHWSurface(this, this->screen);
    4.63  	}
    4.64 -
    4.65 -	gl_convert(this->screen);
    4.66 -	GEM_FlipHWSurface(this, this->screen);
    4.67  }
    4.68  
    4.69  #endif
     5.1 --- a/src/video/xbios/SDL_xbios.c	Fri Nov 26 16:13:24 2004 +0000
     5.2 +++ b/src/video/xbios/SDL_xbios.c	Fri Nov 26 16:16:50 2004 +0000
     5.3 @@ -411,6 +411,10 @@
     5.4  	/* Init chunky to planar routine */
     5.5  	SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
     5.6  
     5.7 +#ifdef HAVE_OPENGL
     5.8 +	SDL_AtariGL_InitPointers(this);
     5.9 +#endif
    5.10 +
    5.11  	/* We're done! */
    5.12  	return(0);
    5.13  }
    5.14 @@ -431,7 +435,9 @@
    5.15  	int i;
    5.16  
    5.17  #ifdef HAVE_OPENGL
    5.18 -	SDL_AtariGL_Quit(this);
    5.19 +	if (gl_active) {
    5.20 +		SDL_AtariGL_Quit(this);
    5.21 +	}
    5.22  #endif
    5.23  
    5.24  	for (i=0;i<2;i++) {
    5.25 @@ -876,12 +882,12 @@
    5.26  
    5.27  static void XBIOS_GL_SwapBuffers(_THIS)
    5.28  {
    5.29 -	if (gl_ctx == NULL) {
    5.30 -		return;
    5.31 +	if (gl_active) {
    5.32 +		gl_copyshadow(this, this->screen);
    5.33 +		gl_convert(this, this->screen);
    5.34 +		XBIOS_FlipHWSurface(this, this->screen);
    5.35 +		SDL_AtariGL_MakeCurrent(this);
    5.36  	}
    5.37 -
    5.38 -	XBIOS_FlipHWSurface(this, this->screen);
    5.39 -	SDL_AtariGL_MakeCurrent(this);
    5.40  }
    5.41  
    5.42  #endif
     6.1 --- a/test/configure.in	Fri Nov 26 16:13:24 2004 +0000
     6.2 +++ b/test/configure.in	Fri Nov 26 16:16:50 2004 +0000
     6.3 @@ -28,7 +28,7 @@
     6.4          MATHLIB=""
     6.5          SYS_GL_LIBS="-lGL"
     6.6          ;;
     6.7 -    *-*-darwin* | *-*-mint* )
     6.8 +    *-*-darwin* )
     6.9          MATHLIB=""
    6.10          SYS_GL_LIBS=""
    6.11          ;;
    6.12 @@ -38,6 +38,18 @@
    6.13          fi
    6.14          SYS_GL_LIBS=""
    6.15          ;;
    6.16 +    *-*-mint*)
    6.17 +        MATHLIB=""
    6.18 +        AC_PATH_PROG(OSMESA_CONFIG, osmesa-config, no)
    6.19 +        if test "x$OSMESA_CONFIG" = "xyes"; then
    6.20 +            OSMESA_CFLAGS=`$OSMESA_CONFIG --cflags`
    6.21 +            OSMESA_LIBS=`$OSMESA_CONFIG --libs`
    6.22 +            CFLAGS="$CFLAGS $OSMESA_CFLAGS"
    6.23 +            SYS_GL_LIBS="$OSMESA_LIBS"
    6.24 +        else
    6.25 +            SYS_GL_LIBS="-lOSMesa"
    6.26 +        fi
    6.27 +		;;
    6.28      *)
    6.29          MATHLIB="-lm"
    6.30          AC_PATH_X