src/video/ataricommon/SDL_atarigl.c
changeset 991 12b13601a544
parent 989 475166d13b44
child 992 0324ce32b2d9
     1.1 --- a/src/video/ataricommon/SDL_atarigl.c	Fri Nov 26 16:13:24 2004 +0000
     1.2 +++ b/src/video/ataricommon/SDL_atarigl.c	Fri Nov 26 16:16:50 2004 +0000
     1.3 @@ -24,125 +24,198 @@
     1.4  
     1.5  /*--- Includes ---*/
     1.6  
     1.7 +#include <stdio.h>
     1.8 +#include <stdlib.h>
     1.9 +#include <string.h>
    1.10  #ifdef HAVE_OPENGL
    1.11  #include <GL/osmesa.h>
    1.12  #endif
    1.13  
    1.14 +#include <mint/osbind.h>
    1.15 +
    1.16  #include "SDL_video.h"
    1.17  #include "SDL_error.h"
    1.18  #include "SDL_endian.h"
    1.19  #include "SDL_atarigl_c.h"
    1.20 +#ifdef ENABLE_OSMESA_SHARED
    1.21 +#include "SDL_loadso.h"
    1.22 +#endif
    1.23  
    1.24 -/*--- Variables ---*/
    1.25 +/*--- Defines ---*/
    1.26 +
    1.27 +#define PATH_OSMESA_LDG	"osmesa.ldg"
    1.28 +#define PATH_MESAGL_LDG	"mesa_gl.ldg"
    1.29 +#define PATH_TINYGL_LDG	"tiny_gl.ldg"
    1.30  
    1.31  /*--- Functions prototypes ---*/
    1.32  
    1.33 -static void ConvertNull(SDL_Surface *surface);
    1.34 -static void Convert565To555be(SDL_Surface *surface);
    1.35 -static void Convert565To555le(SDL_Surface *surface);
    1.36 -static void Convert565le(SDL_Surface *surface);
    1.37 -static void ConvertBGRAToABGR(SDL_Surface *surface);
    1.38 +static void SDL_AtariGL_UnloadLibrary(_THIS);
    1.39 +
    1.40 +static void CopyShadowNull(_THIS, SDL_Surface *surface);
    1.41 +static void CopyShadowDirect(_THIS, SDL_Surface *surface);
    1.42 +static void CopyShadow8888To555(_THIS, SDL_Surface *surface);
    1.43 +static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
    1.44 +
    1.45 +static void ConvertNull(_THIS, SDL_Surface *surface);
    1.46 +static void Convert565To555be(_THIS, SDL_Surface *surface);
    1.47 +static void Convert565To555le(_THIS, SDL_Surface *surface);
    1.48 +static void Convert565le(_THIS, SDL_Surface *surface);
    1.49 +static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface);
    1.50 +
    1.51 +static int InitNew(_THIS, SDL_Surface *current);
    1.52 +static int InitOld(_THIS, SDL_Surface *current);
    1.53  
    1.54  /*--- Public functions ---*/
    1.55  
    1.56  int SDL_AtariGL_Init(_THIS, SDL_Surface *current)
    1.57  {
    1.58  #ifdef HAVE_OPENGL
    1.59 -	GLenum osmesa_format;
    1.60 -	SDL_PixelFormat *pixel_format;
    1.61 -	Uint32	redmask;
    1.62 -
    1.63 -	SDL_AtariGL_Quit(this);	/* Destroy previous context if exist */
    1.64 -
    1.65 -	/* Init OpenGL context using OSMesa */
    1.66 -	gl_convert = ConvertNull;
    1.67 +	if (gl_oldmesa) {
    1.68 +		gl_active = InitOld(this, current);		
    1.69 +	} else {
    1.70 +		gl_active = InitNew(this, current);		
    1.71 +	}
    1.72 +#endif
    1.73  
    1.74 -	pixel_format = current->format;
    1.75 -	redmask = pixel_format->Rmask;
    1.76 -	switch (pixel_format->BitsPerPixel) {
    1.77 -		case 15:
    1.78 -			/* 1555, big and little endian, unsupported */
    1.79 -			osmesa_format = OSMESA_RGB_565;
    1.80 -			if (redmask == 31<<10) {
    1.81 -				gl_convert = Convert565To555be;
    1.82 -			} else {
    1.83 -				gl_convert = Convert565To555le;
    1.84 -			}
    1.85 -			break;
    1.86 -		case 16:
    1.87 -			if (redmask == 31<<11) {
    1.88 -				osmesa_format = OSMESA_RGB_565;
    1.89 -			} else {
    1.90 -				/* 565, little endian, unsupported */
    1.91 -				osmesa_format = OSMESA_RGB_565;
    1.92 -				gl_convert = Convert565le;
    1.93 -			}
    1.94 -			break;
    1.95 -		case 24:
    1.96 -			if (redmask == 255<<16) {
    1.97 -				osmesa_format = OSMESA_RGB;
    1.98 -			} else {
    1.99 -				osmesa_format = OSMESA_BGR;
   1.100 -			}
   1.101 -			break;
   1.102 -		case 32:
   1.103 -			if (redmask == 255<<16) {
   1.104 -				osmesa_format = OSMESA_ARGB;
   1.105 -			} else if (redmask == 255<<8) {
   1.106 -				osmesa_format = OSMESA_BGRA;
   1.107 -			} else if (redmask == 255<<24) {
   1.108 -				osmesa_format = OSMESA_RGBA;
   1.109 -			} else {
   1.110 -				/* ABGR format unsupported */
   1.111 -				osmesa_format = OSMESA_BGRA;
   1.112 -				gl_convert = ConvertBGRAToABGR;
   1.113 -			}
   1.114 -			break;
   1.115 -		default:
   1.116 -			osmesa_format = OSMESA_COLOR_INDEX;
   1.117 -			break;
   1.118 -	}
   1.119 -
   1.120 -	gl_ctx = OSMesaCreateContextExt( osmesa_format, this->gl_config.depth_size,
   1.121 -		this->gl_config.stencil_size, this->gl_config.accum_red_size +
   1.122 -		this->gl_config.accum_green_size + this->gl_config.accum_blue_size +
   1.123 -		this->gl_config.accum_alpha_size, NULL );
   1.124 -
   1.125 -	gl_active = (gl_ctx != NULL);
   1.126  	return (gl_active);
   1.127 -#else
   1.128 -	return 0;
   1.129 -#endif
   1.130  }
   1.131  
   1.132  void SDL_AtariGL_Quit(_THIS)
   1.133  {
   1.134  #ifdef HAVE_OPENGL
   1.135 -	/* Shutdown OpenGL context */
   1.136 -	if (gl_ctx) {
   1.137 -		OSMesaDestroyContext(gl_ctx);
   1.138 -		gl_ctx = NULL;
   1.139 +	if (!gl_active) {
   1.140 +		return;
   1.141  	}
   1.142 -#endif
   1.143 +
   1.144 +	if (gl_oldmesa) {
   1.145 +		/* Old mesa implementations */
   1.146 +		if (this->gl_data->OSMesaDestroyLDG) {
   1.147 +			this->gl_data->OSMesaDestroyLDG();
   1.148 +		}
   1.149 +		if (gl_shadow) {
   1.150 +			Mfree(gl_shadow);
   1.151 +			gl_shadow = NULL;
   1.152 +		}
   1.153 +	} else {
   1.154 +		/* New mesa implementation */
   1.155 +		if (gl_ctx) {
   1.156 +			if (this->gl_data->OSMesaDestroyContext) {
   1.157 +				this->gl_data->OSMesaDestroyContext(gl_ctx);
   1.158 +			}
   1.159 +			gl_ctx = NULL;
   1.160 +		}
   1.161 +	}
   1.162 +
   1.163 +	SDL_AtariGL_UnloadLibrary(this);
   1.164 +
   1.165 +#endif /* HAVE_OPENGL */
   1.166  	gl_active = 0;
   1.167  }
   1.168  
   1.169  int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
   1.170  {
   1.171  #ifdef HAVE_OPENGL
   1.172 -	/* Library is always opened */
   1.173 +
   1.174 +#ifdef ENABLE_OSMESA_SHARED
   1.175 +	void *handle;
   1.176 +
   1.177 +	if (gl_active) {
   1.178 +		SDL_SetError("OpenGL context already created");
   1.179 +		return -1;
   1.180 +	}
   1.181 +
   1.182 +	/* Unload previous driver */
   1.183 +	SDL_AtariGL_UnloadLibrary(this);
   1.184 +
   1.185 +	/* Load library given by path */
   1.186 +	handle = SDL_LoadObject(path);
   1.187 +	if (handle == NULL) {
   1.188 +		/* Try to load another one */
   1.189 +		path = getenv("SDL_VIDEO_GL_DRIVER");
   1.190 +		if ( path != NULL ) {
   1.191 +			handle = SDL_LoadObject(path);
   1.192 +		}
   1.193 +
   1.194 +		/* If it does not work, try some other */
   1.195 +		if (handle == NULL) {
   1.196 +			path = PATH_OSMESA_LDG;
   1.197 +			handle = SDL_LoadObject(path);
   1.198 +		}
   1.199 +
   1.200 +		if (handle == NULL) {
   1.201 +			path = PATH_MESAGL_LDG;
   1.202 +			handle = SDL_LoadObject(path);
   1.203 +		}
   1.204 +
   1.205 +		if (handle == NULL) {
   1.206 +			path = PATH_TINYGL_LDG;
   1.207 +			handle = SDL_LoadObject(path);
   1.208 +		}
   1.209 +	}
   1.210 +
   1.211 +	if (handle == NULL) {
   1.212 +		SDL_SetError("Could not load OpenGL library");
   1.213 +		return -1;
   1.214 +	}
   1.215 +
   1.216 +	/* Load functions pointers (osmesa.ldg) */
   1.217 +	this->gl_data->OSMesaCreateContextExt = SDL_LoadFunction(handle, "OSMesaCreateContextExt");
   1.218 +	this->gl_data->OSMesaDestroyContext = SDL_LoadFunction(handle, "OSMesaDestroyContext");
   1.219 +	this->gl_data->OSMesaMakeCurrent = SDL_LoadFunction(handle, "OSMesaMakeCurrent");
   1.220 +	this->gl_data->OSMesaPixelStore = SDL_LoadFunction(handle, "OSMesaPixelStore");
   1.221 +	this->gl_data->OSMesaGetProcAddress = SDL_LoadFunction(handle, "OSMesaGetProcAddress");
   1.222 +	this->gl_data->glGetIntegerv = SDL_LoadFunction(handle, "glGetIntegerv");
   1.223 +
   1.224 +	/* Load old functions pointers (mesa_gl.ldg, tiny_gl.ldg) */
   1.225 +	this->gl_data->OSMesaCreateLDG = SDL_LoadFunction(handle, "OSMesaCreateLDG");
   1.226 +	this->gl_data->OSMesaDestroyLDG = SDL_LoadFunction(handle, "OSMesaDestroyLDG");
   1.227 +
   1.228 +	gl_oldmesa = 0;
   1.229 +
   1.230 +	if ( (this->gl_data->OSMesaCreateContextExt == NULL) || 
   1.231 +	     (this->gl_data->OSMesaDestroyContext == NULL) ||
   1.232 +	     (this->gl_data->OSMesaMakeCurrent == NULL) ||
   1.233 +	     (this->gl_data->OSMesaPixelStore == NULL) ||
   1.234 +	     (this->gl_data->glGetIntegerv == NULL) ||
   1.235 +	     (this->gl_data->OSMesaGetProcAddress == NULL)) {
   1.236 +		/* Hum, maybe old library ? */
   1.237 +		if ( (this->gl_data->OSMesaCreateLDG == NULL) || 
   1.238 +		     (this->gl_data->OSMesaDestroyLDG == NULL)) {
   1.239 +			SDL_SetError("Could not retrieve OpenGL functions");
   1.240 +			return -1;
   1.241 +		} else {
   1.242 +			gl_oldmesa = 1;
   1.243 +		}
   1.244 +	}
   1.245 +
   1.246 +	this->gl_config.dll_handle = handle;
   1.247 +	if ( path ) {
   1.248 +		strncpy(this->gl_config.driver_path, path,
   1.249 +			sizeof(this->gl_config.driver_path)-1);
   1.250 +	} else {
   1.251 +		strcpy(this->gl_config.driver_path, "");
   1.252 +	}
   1.253 +
   1.254 +#endif
   1.255  	this->gl_config.driver_loaded = 1;
   1.256 +
   1.257 +	return 0;
   1.258 +#else
   1.259 +	return -1;
   1.260  #endif
   1.261 -	return 0;
   1.262  }
   1.263  
   1.264  void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc)
   1.265  {
   1.266  	void *func = NULL;
   1.267  #ifdef HAVE_OPENGL
   1.268 -	if (gl_ctx != NULL) {
   1.269 -		func = OSMesaGetProcAddress(proc);
   1.270 +
   1.271 +	if (this->gl_config.dll_handle) {
   1.272 +		func = SDL_LoadFunction(this->gl_config.dll_handle, (void *)proc);
   1.273 +	} else if (this->gl_data->OSMesaGetProcAddress) {
   1.274 +		func = this->gl_data->OSMesaGetProcAddress(proc);
   1.275  	}
   1.276 +
   1.277  #endif
   1.278  	return func;
   1.279  }
   1.280 @@ -153,7 +226,13 @@
   1.281  	GLenum mesa_attrib;
   1.282  	SDL_Surface *surface;
   1.283  
   1.284 -	if (gl_ctx == NULL) {
   1.285 +	if (this->gl_config.dll_handle) {
   1.286 +		if (this->gl_data->glGetIntegerv == NULL) {
   1.287 +			return -1;
   1.288 +		}
   1.289 +	}
   1.290 +
   1.291 +	if (!gl_active) {
   1.292  		return -1;
   1.293  	}
   1.294  
   1.295 @@ -196,7 +275,7 @@
   1.296  			return -1;
   1.297  	}
   1.298  
   1.299 -	glGetIntegerv(mesa_attrib, value);
   1.300 +	this->gl_data->glGetIntegerv(mesa_attrib, value);
   1.301  	return 0;
   1.302  #else
   1.303  	return -1;
   1.304 @@ -209,7 +288,18 @@
   1.305  	SDL_Surface *surface;
   1.306  	GLenum type;
   1.307  
   1.308 -	if (gl_ctx == NULL) {
   1.309 +	if (gl_oldmesa && gl_active) {
   1.310 +		return 0;
   1.311 +	}
   1.312 +
   1.313 +	if (this->gl_config.dll_handle) {
   1.314 +		if ((this->gl_data->OSMesaMakeCurrent == NULL) ||
   1.315 +			(this->gl_data->OSMesaPixelStore == NULL)) {
   1.316 +			return -1;
   1.317 +		}
   1.318 +	}
   1.319 +
   1.320 +	if (!gl_active) {
   1.321  		SDL_SetError("Invalid OpenGL context");
   1.322  		return -1;
   1.323  	}
   1.324 @@ -222,13 +312,13 @@
   1.325  		type = GL_UNSIGNED_BYTE;
   1.326  	}
   1.327  
   1.328 -	if (!OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, surface->h)) {
   1.329 +	if (!(this->gl_data->OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, surface->h))) {
   1.330  		SDL_SetError("Can not make OpenGL context current");
   1.331  		return -1;
   1.332  	}
   1.333  
   1.334  	/* OSMesa draws upside down */
   1.335 -	OSMesaPixelStore(OSMESA_Y_UP, 0);
   1.336 +	this->gl_data->OSMesaPixelStore(OSMESA_Y_UP, 0);
   1.337  
   1.338  	return 0;
   1.339  #else
   1.340 @@ -239,21 +329,296 @@
   1.341  void SDL_AtariGL_SwapBuffers(_THIS)
   1.342  {
   1.343  #ifdef HAVE_OPENGL
   1.344 -	if (gl_ctx == NULL) {
   1.345 -		return;
   1.346 +	if (gl_active) {
   1.347 +		gl_copyshadow(this, this->screen);
   1.348 +		gl_convert(this, this->screen);
   1.349  	}
   1.350 +#endif
   1.351 +}
   1.352  
   1.353 -	gl_convert(this->screen);
   1.354 +void SDL_AtariGL_InitPointers(_THIS)
   1.355 +{
   1.356 +#if defined(HAVE_OPENGL)
   1.357 +	this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
   1.358 +	this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
   1.359 +	this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
   1.360 +	this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
   1.361 +	this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
   1.362 +	this->gl_data->glGetIntegerv = glGetIntegerv;
   1.363  #endif
   1.364  }
   1.365  
   1.366  /*--- Private functions ---*/
   1.367  
   1.368 -static void ConvertNull(SDL_Surface *surface)
   1.369 +static void SDL_AtariGL_UnloadLibrary(_THIS)
   1.370 +{
   1.371 +#if defined(HAVE_OPENGL)
   1.372 +	if (this->gl_config.dll_handle) {
   1.373 +		SDL_UnloadObject(this->gl_config.dll_handle);
   1.374 +		this->gl_config.dll_handle = NULL;
   1.375 +
   1.376 +		/* Restore pointers to static library */
   1.377 +		this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
   1.378 +		this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
   1.379 +		this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
   1.380 +		this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
   1.381 +		this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
   1.382 +		this->gl_data->glGetIntegerv = glGetIntegerv;
   1.383 +
   1.384 +		this->gl_data->OSMesaCreateLDG = NULL;
   1.385 +		this->gl_data->OSMesaDestroyLDG = NULL;
   1.386 +	}
   1.387 +#endif
   1.388 +}
   1.389 +
   1.390 +/*--- Creation of an OpenGL context using new/old functions ---*/
   1.391 +
   1.392 +static int InitNew(_THIS, SDL_Surface *current)
   1.393 +{
   1.394 +	GLenum osmesa_format;
   1.395 +	SDL_PixelFormat *pixel_format;
   1.396 +	Uint32	redmask;
   1.397 +
   1.398 +	if (this->gl_config.dll_handle) {
   1.399 +		if (this->gl_data->OSMesaCreateContextExt == NULL) {
   1.400 +			return 0;
   1.401 +		}
   1.402 +	}
   1.403 +
   1.404 +	/* Init OpenGL context using OSMesa */
   1.405 +	gl_convert = ConvertNull;
   1.406 +	gl_copyshadow = CopyShadowNull;
   1.407 +
   1.408 +	pixel_format = current->format;
   1.409 +	redmask = pixel_format->Rmask;
   1.410 +	switch (pixel_format->BitsPerPixel) {
   1.411 +		case 15:
   1.412 +			/* 1555, big and little endian, unsupported */
   1.413 +			gl_pixelsize = 2;
   1.414 +			osmesa_format = OSMESA_RGB_565;
   1.415 +			if (redmask == 31<<10) {
   1.416 +				gl_convert = Convert565To555be;
   1.417 +			} else {
   1.418 +				gl_convert = Convert565To555le;
   1.419 +			}
   1.420 +			break;
   1.421 +		case 16:
   1.422 +			gl_pixelsize = 2;
   1.423 +			if (redmask == 31<<11) {
   1.424 +				osmesa_format = OSMESA_RGB_565;
   1.425 +			} else {
   1.426 +				/* 565, little endian, unsupported */
   1.427 +				osmesa_format = OSMESA_RGB_565;
   1.428 +				gl_convert = Convert565le;
   1.429 +			}
   1.430 +			break;
   1.431 +		case 24:
   1.432 +			gl_pixelsize = 3;
   1.433 +			if (redmask == 255<<16) {
   1.434 +				osmesa_format = OSMESA_RGB;
   1.435 +			} else {
   1.436 +				osmesa_format = OSMESA_BGR;
   1.437 +			}
   1.438 +			break;
   1.439 +		case 32:
   1.440 +			gl_pixelsize = 4;
   1.441 +			if (redmask == 255<<16) {
   1.442 +				osmesa_format = OSMESA_ARGB;
   1.443 +			} else if (redmask == 255<<8) {
   1.444 +				osmesa_format = OSMESA_BGRA;
   1.445 +			} else if (redmask == 255<<24) {
   1.446 +				osmesa_format = OSMESA_RGBA;
   1.447 +			} else {
   1.448 +				/* ABGR format unsupported */
   1.449 +				osmesa_format = OSMESA_BGRA;
   1.450 +				gl_convert = ConvertBGRAToABGR;
   1.451 +			}
   1.452 +			break;
   1.453 +		default:
   1.454 +			gl_pixelsize = 1;
   1.455 +			osmesa_format = OSMESA_COLOR_INDEX;
   1.456 +			break;
   1.457 +	}
   1.458 +
   1.459 +	gl_ctx = this->gl_data->OSMesaCreateContextExt(
   1.460 +		osmesa_format, this->gl_config.depth_size,
   1.461 +		this->gl_config.stencil_size, this->gl_config.accum_red_size +
   1.462 +		this->gl_config.accum_green_size + this->gl_config.accum_blue_size +
   1.463 +		this->gl_config.accum_alpha_size, NULL );
   1.464 +
   1.465 +	return (gl_ctx != NULL);
   1.466 +}
   1.467 +
   1.468 +static int InitOld(_THIS, SDL_Surface *current)
   1.469 +{
   1.470 +	GLenum osmesa_format;
   1.471 +	SDL_PixelFormat *pixel_format;
   1.472 +	Uint32	redmask;
   1.473 +
   1.474 +	if (this->gl_config.dll_handle) {
   1.475 +		if (this->gl_data->OSMesaCreateLDG == NULL) {
   1.476 +			return 0;
   1.477 +		}
   1.478 +	}
   1.479 +
   1.480 +	/* Init OpenGL context using OSMesa */
   1.481 +	gl_convert = ConvertNull;
   1.482 +	gl_copyshadow = CopyShadowNull;
   1.483 +
   1.484 +	pixel_format = current->format;
   1.485 +	redmask = pixel_format->Rmask;
   1.486 +	switch (pixel_format->BitsPerPixel) {
   1.487 +		case 15:
   1.488 +			/* 15 bits unsupported */
   1.489 +			gl_pixelsize = 2;
   1.490 +			osmesa_format = OSMESA_ARGB;
   1.491 +			if (redmask == 31<<10) {
   1.492 +				gl_copyshadow = CopyShadow8888To555;
   1.493 +			} else {
   1.494 +				gl_copyshadow = CopyShadow8888To565;
   1.495 +				gl_convert = Convert565To555le;
   1.496 +			}
   1.497 +			break;
   1.498 +		case 16:
   1.499 +			/* 16 bits unsupported */
   1.500 +			gl_pixelsize = 2;
   1.501 +			osmesa_format = OSMESA_ARGB;
   1.502 +			gl_copyshadow = CopyShadow8888To565;
   1.503 +			if (redmask != 31<<11) {
   1.504 +				/* 565, little endian, unsupported */
   1.505 +				gl_convert = Convert565le;
   1.506 +			}
   1.507 +			break;
   1.508 +		case 24:
   1.509 +			gl_pixelsize = 3;
   1.510 +			gl_copyshadow = CopyShadowDirect;
   1.511 +			if (redmask == 255<<16) {
   1.512 +				osmesa_format = OSMESA_RGB;
   1.513 +			} else {
   1.514 +				osmesa_format = OSMESA_BGR;
   1.515 +			}
   1.516 +			break;
   1.517 +		case 32:
   1.518 +			gl_pixelsize = 4;
   1.519 +			gl_copyshadow = CopyShadowDirect;
   1.520 +			if (redmask == 255<<16) {
   1.521 +				osmesa_format = OSMESA_ARGB;
   1.522 +			} else if (redmask == 255<<8) {
   1.523 +				osmesa_format = OSMESA_BGRA;
   1.524 +			} else if (redmask == 255<<24) {
   1.525 +				osmesa_format = OSMESA_RGBA;
   1.526 +			} else {
   1.527 +				/* ABGR format unsupported */
   1.528 +				osmesa_format = OSMESA_BGRA;
   1.529 +				gl_convert = ConvertBGRAToABGR;
   1.530 +			}
   1.531 +			break;
   1.532 +		default:
   1.533 +			gl_pixelsize = 1;
   1.534 +			gl_copyshadow = CopyShadowDirect;
   1.535 +			osmesa_format = OSMESA_COLOR_INDEX;
   1.536 +			break;
   1.537 +	}
   1.538 +
   1.539 +	gl_shadow = this->gl_data->OSMesaCreateLDG(
   1.540 +		osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
   1.541 +	);
   1.542 +
   1.543 +	return (gl_shadow != NULL);
   1.544 +}
   1.545 +
   1.546 +/*--- Conversions routines from shadow buffer to the screen ---*/
   1.547 +
   1.548 +static void CopyShadowNull(_THIS, SDL_Surface *surface)
   1.549  {
   1.550  }
   1.551  
   1.552 -static void Convert565To555be(SDL_Surface *surface)
   1.553 +static void CopyShadowDirect(_THIS, SDL_Surface *surface)
   1.554 +{
   1.555 +	int y, srcpitch, dstpitch;
   1.556 +	Uint8 *srcline, *dstline;
   1.557 +
   1.558 +	srcline = gl_shadow;
   1.559 +	srcpitch = surface->w * gl_pixelsize;
   1.560 +	dstline = surface->pixels;
   1.561 +	dstpitch = surface->pitch;
   1.562 +
   1.563 +	for (y=0; y<surface->h; y++) {
   1.564 +		memcpy(dstline, srcline, srcpitch);
   1.565 +
   1.566 +		srcline += srcpitch;
   1.567 +		dstline += dstpitch;
   1.568 +	}
   1.569 +}
   1.570 +
   1.571 +static void CopyShadow8888To555(_THIS, SDL_Surface *surface)
   1.572 +{
   1.573 +	int x,y, srcpitch, dstpitch;
   1.574 +	Uint16 *dstline, *dstcol;
   1.575 +	Uint32 *srcline, *srccol;
   1.576 +
   1.577 +	srcline = (Uint32 *)gl_shadow;
   1.578 +	srcpitch = surface->w;
   1.579 +	dstline = surface->pixels;
   1.580 +	dstpitch = surface->pitch >>1;
   1.581 +
   1.582 +	for (y=0; y<surface->h; y++) {
   1.583 +		srccol = srcline;
   1.584 +		dstcol = dstline;
   1.585 +		for (x=0; x<surface->w; x++) {
   1.586 +			Uint32 srccolor;
   1.587 +			Uint16 dstcolor;
   1.588 +			
   1.589 +			srccolor = *srccol++;
   1.590 +			dstcolor = (srccolor>>9) & (31<<10);
   1.591 +			dstcolor |= (srccolor>>6) & (31<<5);
   1.592 +			dstcolor |= (srccolor>>3) & 31;
   1.593 +			*dstcol++ = dstcolor;
   1.594 +		}
   1.595 +
   1.596 +		srcline += srcpitch;
   1.597 +		dstline += dstpitch;
   1.598 +	}
   1.599 +}
   1.600 +
   1.601 +static void CopyShadow8888To565(_THIS, SDL_Surface *surface)
   1.602 +{
   1.603 +	int x,y, srcpitch, dstpitch;
   1.604 +	Uint16 *dstline, *dstcol;
   1.605 +	Uint32 *srcline, *srccol;
   1.606 +
   1.607 +	srcline = (Uint32 *)gl_shadow;
   1.608 +	srcpitch = surface->w;
   1.609 +	dstline = surface->pixels;
   1.610 +	dstpitch = surface->pitch >>1;
   1.611 +
   1.612 +	for (y=0; y<surface->h; y++) {
   1.613 +		srccol = srcline;
   1.614 +		dstcol = dstline;
   1.615 +
   1.616 +		for (x=0; x<surface->w; x++) {
   1.617 +			Uint32 srccolor;
   1.618 +			Uint16 dstcolor;
   1.619 +			
   1.620 +			srccolor = *srccol++;
   1.621 +			dstcolor = (srccolor>>8) & (31<<11);
   1.622 +			dstcolor |= (srccolor>>5) & (63<<5);
   1.623 +			dstcolor |= (srccolor>>3) & 31;
   1.624 +			*dstcol++ = dstcolor;
   1.625 +		}
   1.626 +
   1.627 +		srcline += srcpitch;
   1.628 +		dstline += dstpitch;
   1.629 +	}
   1.630 +}
   1.631 +
   1.632 +/*--- Conversions routines in the screen ---*/
   1.633 +
   1.634 +static void ConvertNull(_THIS, SDL_Surface *surface)
   1.635 +{
   1.636 +}
   1.637 +
   1.638 +static void Convert565To555be(_THIS, SDL_Surface *surface)
   1.639  {
   1.640  	int x,y, pitch;
   1.641  	unsigned short *line, *pixel;
   1.642 @@ -272,7 +637,7 @@
   1.643  	}
   1.644  }
   1.645  
   1.646 -static void Convert565To555le(SDL_Surface *surface)
   1.647 +static void Convert565To555le(_THIS, SDL_Surface *surface)
   1.648  {
   1.649  	int x,y, pitch;
   1.650  	unsigned short *line, *pixel;
   1.651 @@ -292,7 +657,7 @@
   1.652  	}
   1.653  }
   1.654  
   1.655 -static void Convert565le(SDL_Surface *surface)
   1.656 +static void Convert565le(_THIS, SDL_Surface *surface)
   1.657  {
   1.658  	int x,y, pitch;
   1.659  	unsigned short *line, *pixel;
   1.660 @@ -311,7 +676,7 @@
   1.661  	}
   1.662  }
   1.663  
   1.664 -static void ConvertBGRAToABGR(SDL_Surface *surface)
   1.665 +static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface)
   1.666  {
   1.667  	int x,y, pitch;
   1.668  	unsigned long *line, *pixel;