src/video/ataricommon/SDL_atarigl.c
changeset 1000 fbeac9312843
parent 995 22fc5f45bbb7
child 1002 13aa96c76e86
     1.1 --- a/src/video/ataricommon/SDL_atarigl.c	Tue Nov 30 15:21:29 2004 +0000
     1.2 +++ b/src/video/ataricommon/SDL_atarigl.c	Tue Nov 30 16:14:05 2004 +0000
     1.3 @@ -47,12 +47,22 @@
     1.4  #define PATH_MESAGL_LDG	"mesa_gl.ldg"
     1.5  #define PATH_TINYGL_LDG	"tiny_gl.ldg"
     1.6  
     1.7 +#define VDI_RGB	0xf
     1.8 +
     1.9  /*--- Functions prototypes ---*/
    1.10  
    1.11  static void SDL_AtariGL_UnloadLibrary(_THIS);
    1.12  
    1.13 +#ifdef HAVE_OPENGL
    1.14  static void CopyShadowNull(_THIS, SDL_Surface *surface);
    1.15  static void CopyShadowDirect(_THIS, SDL_Surface *surface);
    1.16 +static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface);
    1.17 +static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface);
    1.18 +static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface);
    1.19 +static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface);
    1.20 +static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface);
    1.21 +static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface);
    1.22 +static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface);
    1.23  static void CopyShadow8888To555(_THIS, SDL_Surface *surface);
    1.24  static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
    1.25  
    1.26 @@ -64,6 +74,7 @@
    1.27  
    1.28  static int InitNew(_THIS, SDL_Surface *current);
    1.29  static int InitOld(_THIS, SDL_Surface *current);
    1.30 +#endif
    1.31  
    1.32  /*--- Public functions ---*/
    1.33  
    1.34 @@ -396,6 +407,7 @@
    1.35  
    1.36  /*--- Creation of an OpenGL context using new/old functions ---*/
    1.37  
    1.38 +#ifdef HAVE_OPENGL
    1.39  static int InitNew(_THIS, SDL_Surface *current)
    1.40  {
    1.41  	GLenum osmesa_format;
    1.42 @@ -502,12 +514,13 @@
    1.43  	return (gl_ctx != NULL);
    1.44  }
    1.45  
    1.46 +
    1.47  static int InitOld(_THIS, SDL_Surface *current)
    1.48  {
    1.49  	GLenum osmesa_format;
    1.50  	SDL_PixelFormat *pixel_format;
    1.51  	Uint32	redmask;
    1.52 -	int recreatecontext;
    1.53 +	int recreatecontext, tinygl_present;
    1.54  
    1.55  	if (this->gl_config.dll_handle) {
    1.56  		if (this->gl_data->OSMesaCreateLDG == NULL) {
    1.57 @@ -515,6 +528,14 @@
    1.58  		}
    1.59  	}
    1.60  
    1.61 +	/* TinyGL only supports VDI_RGB (OSMESA_RGB) */
    1.62 +	tinygl_present=0;
    1.63 +	if (this->gl_config.dll_handle) {
    1.64 +		if (this->gl_data->glFinish == NULL) {
    1.65 +			tinygl_present=1;
    1.66 +		}
    1.67 +	}
    1.68 +
    1.69  	/* Init OpenGL context using OSMesa */
    1.70  	gl_convert = ConvertNull;
    1.71  	gl_copyshadow = CopyShadowNull;
    1.72 @@ -525,49 +546,92 @@
    1.73  		case 15:
    1.74  			/* 15 bits unsupported */
    1.75  			gl_pixelsize = 2;
    1.76 -			osmesa_format = OSMESA_ARGB;
    1.77 -			if (redmask == 31<<10) {
    1.78 -				gl_copyshadow = CopyShadow8888To555;
    1.79 +			if (tinygl_present) {
    1.80 +				osmesa_format = VDI_RGB;
    1.81 +				if (redmask == 31<<10) {
    1.82 +					gl_copyshadow = CopyShadowRGBTo555;
    1.83 +				} else {
    1.84 +					gl_copyshadow = CopyShadowRGBTo565;
    1.85 +					gl_convert = Convert565To555le;
    1.86 +				}
    1.87  			} else {
    1.88 -				gl_copyshadow = CopyShadow8888To565;
    1.89 -				gl_convert = Convert565To555le;
    1.90 +				osmesa_format = OSMESA_ARGB;
    1.91 +				if (redmask == 31<<10) {
    1.92 +					gl_copyshadow = CopyShadow8888To555;
    1.93 +				} else {
    1.94 +					gl_copyshadow = CopyShadow8888To565;
    1.95 +					gl_convert = Convert565To555le;
    1.96 +				}
    1.97  			}
    1.98  			break;
    1.99  		case 16:
   1.100  			/* 16 bits unsupported */
   1.101  			gl_pixelsize = 2;
   1.102 -			osmesa_format = OSMESA_ARGB;
   1.103 -			gl_copyshadow = CopyShadow8888To565;
   1.104 -			if (redmask != 31<<11) {
   1.105 -				/* 565, little endian, unsupported */
   1.106 -				gl_convert = Convert565le;
   1.107 +			if (tinygl_present) {
   1.108 +				osmesa_format = VDI_RGB;
   1.109 +				gl_copyshadow = CopyShadowRGBTo565;
   1.110 +				if (redmask != 31<<11) {
   1.111 +					/* 565, little endian, unsupported */
   1.112 +					gl_convert = Convert565le;
   1.113 +				}
   1.114 +			} else {
   1.115 +				osmesa_format = OSMESA_ARGB;
   1.116 +				gl_copyshadow = CopyShadow8888To565;
   1.117 +				if (redmask != 31<<11) {
   1.118 +					/* 565, little endian, unsupported */
   1.119 +					gl_convert = Convert565le;
   1.120 +				}
   1.121  			}
   1.122  			break;
   1.123  		case 24:
   1.124  			gl_pixelsize = 3;
   1.125 -			gl_copyshadow = CopyShadowDirect;
   1.126 -			if (redmask == 255<<16) {
   1.127 -				osmesa_format = OSMESA_RGB;
   1.128 +			if (tinygl_present) {
   1.129 +				osmesa_format = VDI_RGB;
   1.130 +				gl_copyshadow = CopyShadowDirect;
   1.131 +				if (redmask != 255<<16) {
   1.132 +					gl_copyshadow = CopyShadowRGBSwap;
   1.133 +				}
   1.134  			} else {
   1.135 -				osmesa_format = OSMESA_BGR;
   1.136 +				gl_copyshadow = CopyShadowDirect;
   1.137 +				if (redmask == 255<<16) {
   1.138 +					osmesa_format = OSMESA_RGB;
   1.139 +				} else {
   1.140 +					osmesa_format = OSMESA_BGR;
   1.141 +				}
   1.142  			}
   1.143  			break;
   1.144  		case 32:
   1.145  			gl_pixelsize = 4;
   1.146 -			gl_copyshadow = CopyShadowDirect;
   1.147 -			if (redmask == 255<<16) {
   1.148 -				osmesa_format = OSMESA_ARGB;
   1.149 -			} else if (redmask == 255<<8) {
   1.150 -				osmesa_format = OSMESA_BGRA;
   1.151 -			} else if (redmask == 255<<24) {
   1.152 -				osmesa_format = OSMESA_RGBA;
   1.153 +			if (tinygl_present) {
   1.154 +				osmesa_format = VDI_RGB;
   1.155 +				gl_copyshadow = CopyShadowRGBToARGB;
   1.156 +				if (redmask == 255) {
   1.157 +					gl_convert = CopyShadowRGBToABGR;
   1.158 +				} else if (redmask == 255<<8) {
   1.159 +					gl_convert = CopyShadowRGBToBGRA;
   1.160 +				} else if (redmask == 255<<24) {
   1.161 +					gl_convert = CopyShadowRGBToRGBA;
   1.162 +				}
   1.163  			} else {
   1.164 -				/* ABGR format unsupported */
   1.165 -				osmesa_format = OSMESA_BGRA;
   1.166 -				gl_convert = ConvertBGRAToABGR;
   1.167 +				gl_copyshadow = CopyShadowDirect;
   1.168 +				if (redmask == 255<<16) {
   1.169 +					osmesa_format = OSMESA_ARGB;
   1.170 +				} else if (redmask == 255<<8) {
   1.171 +					osmesa_format = OSMESA_BGRA;
   1.172 +				} else if (redmask == 255<<24) {
   1.173 +					osmesa_format = OSMESA_RGBA;
   1.174 +				} else {
   1.175 +					/* ABGR format unsupported */
   1.176 +					osmesa_format = OSMESA_BGRA;
   1.177 +					gl_convert = ConvertBGRAToABGR;
   1.178 +				}
   1.179  			}
   1.180  			break;
   1.181  		default:
   1.182 +			if (tinygl_present) {
   1.183 +				SDL_AtariGL_Quit(this, SDL_FALSE);
   1.184 +				return 0;
   1.185 +			}
   1.186  			gl_pixelsize = 1;
   1.187  			gl_copyshadow = CopyShadowDirect;
   1.188  			osmesa_format = OSMESA_COLOR_INDEX;
   1.189 @@ -627,6 +691,210 @@
   1.190  	}
   1.191  }
   1.192  
   1.193 +static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface)
   1.194 +{
   1.195 +	int x,y, srcpitch, dstpitch;
   1.196 +	Uint16 *dstline, *dstcol;
   1.197 +	Uint8 *srcline, *srccol;
   1.198 +
   1.199 +	srcline = (Uint8 *)gl_shadow;
   1.200 +	srcpitch = surface->w *3;
   1.201 +	dstline = surface->pixels;
   1.202 +	dstpitch = surface->pitch >>1;
   1.203 +
   1.204 +	for (y=0; y<surface->h; y++) {
   1.205 +		srccol = srcline;
   1.206 +		dstcol = dstline;
   1.207 +		for (x=0; x<surface->w; x++) {
   1.208 +			Uint16 dstcolor;
   1.209 +			
   1.210 +			dstcolor = ((*srccol++)>>9) & (31<<10);
   1.211 +			dstcolor |= ((*srccol++)>>6) & (31<<5);
   1.212 +			dstcolor |= ((*srccol++)>>3) & 31;
   1.213 +			*dstcol++ = dstcolor;
   1.214 +		}
   1.215 +
   1.216 +		srcline += srcpitch;
   1.217 +		dstline += dstpitch;
   1.218 +	}
   1.219 +}
   1.220 +
   1.221 +static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface)
   1.222 +{
   1.223 +	int x,y, srcpitch, dstpitch;
   1.224 +	Uint16 *dstline, *dstcol;
   1.225 +	Uint8 *srcline, *srccol;
   1.226 +
   1.227 +	srcline = (Uint8 *)gl_shadow;
   1.228 +	srcpitch = surface->w *3;
   1.229 +	dstline = surface->pixels;
   1.230 +	dstpitch = surface->pitch >>1;
   1.231 +
   1.232 +	for (y=0; y<surface->h; y++) {
   1.233 +		srccol = srcline;
   1.234 +		dstcol = dstline;
   1.235 +
   1.236 +		for (x=0; x<surface->w; x++) {
   1.237 +			Uint16 dstcolor;
   1.238 +			
   1.239 +			dstcolor = ((*srccol++)>>8) & (31<<11);
   1.240 +			dstcolor |= ((*srccol++)>>5) & (63<<5);
   1.241 +			dstcolor |= ((*srccol++)>>3) & 31;
   1.242 +			*dstcol++ = dstcolor;
   1.243 +		}
   1.244 +
   1.245 +		srcline += srcpitch;
   1.246 +		dstline += dstpitch;
   1.247 +	}
   1.248 +}
   1.249 +
   1.250 +static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface)
   1.251 +{
   1.252 +	int x,y, srcpitch, dstpitch;
   1.253 +	Uint8 *dstline, *dstcol;
   1.254 +	Uint8 *srcline, *srccol;
   1.255 +
   1.256 +	srcline = (Uint8 *)gl_shadow;
   1.257 +	srcpitch = surface->w *3;
   1.258 +	dstline = surface->pixels;
   1.259 +	dstpitch = surface->pitch;
   1.260 +
   1.261 +	for (y=0; y<surface->h; y++) {
   1.262 +		srccol = srcline;
   1.263 +		dstcol = dstline;
   1.264 +
   1.265 +		for (x=0; x<surface->w; x++) {
   1.266 +			*dstcol++ = srccol[2];
   1.267 +			*dstcol++ = srccol[1];
   1.268 +			*dstcol++ = srccol[0];
   1.269 +			srccol += 3;
   1.270 +		}
   1.271 +
   1.272 +		srcline += srcpitch;
   1.273 +		dstline += dstpitch;
   1.274 +	}
   1.275 +}
   1.276 +
   1.277 +static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface)
   1.278 +{
   1.279 +	int x,y, srcpitch, dstpitch;
   1.280 +	Uint32 *dstline, *dstcol;
   1.281 +	Uint8 *srcline, *srccol;
   1.282 +
   1.283 +	srcline = (Uint8 *)gl_shadow;
   1.284 +	srcpitch = surface->w *3;
   1.285 +	dstline = surface->pixels;
   1.286 +	dstpitch = surface->pitch >>2;
   1.287 +
   1.288 +	for (y=0; y<surface->h; y++) {
   1.289 +		srccol = srcline;
   1.290 +		dstcol = dstline;
   1.291 +
   1.292 +		for (x=0; x<surface->w; x++) {
   1.293 +			Uint32	dstcolor;
   1.294 +
   1.295 +			dstcolor = (*srccol++)<<16;
   1.296 +			dstcolor |= (*srccol++)<<8;
   1.297 +			dstcolor |= *srccol++;
   1.298 +
   1.299 +			*dstcol++ = dstcolor;
   1.300 +		}
   1.301 +
   1.302 +		srcline += srcpitch;
   1.303 +		dstline += dstpitch;
   1.304 +	}
   1.305 +}
   1.306 +
   1.307 +static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface)
   1.308 +{
   1.309 +	int x,y, srcpitch, dstpitch;
   1.310 +	Uint32 *dstline, *dstcol;
   1.311 +	Uint8 *srcline, *srccol;
   1.312 +
   1.313 +	srcline = (Uint8 *)gl_shadow;
   1.314 +	srcpitch = surface->w *3;
   1.315 +	dstline = surface->pixels;
   1.316 +	dstpitch = surface->pitch >>2;
   1.317 +
   1.318 +	for (y=0; y<surface->h; y++) {
   1.319 +		srccol = srcline;
   1.320 +		dstcol = dstline;
   1.321 +
   1.322 +		for (x=0; x<surface->w; x++) {
   1.323 +			Uint32	dstcolor;
   1.324 +
   1.325 +			dstcolor = *srccol++;
   1.326 +			dstcolor |= (*srccol++)<<8;
   1.327 +			dstcolor |= (*srccol++)<<16;
   1.328 +
   1.329 +			*dstcol++ = dstcolor;
   1.330 +		}
   1.331 +
   1.332 +		srcline += srcpitch;
   1.333 +		dstline += dstpitch;
   1.334 +	}
   1.335 +}
   1.336 +
   1.337 +static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface)
   1.338 +{
   1.339 +	int x,y, srcpitch, dstpitch;
   1.340 +	Uint32 *dstline, *dstcol;
   1.341 +	Uint8 *srcline, *srccol;
   1.342 +
   1.343 +	srcline = (Uint8 *)gl_shadow;
   1.344 +	srcpitch = surface->w *3;
   1.345 +	dstline = surface->pixels;
   1.346 +	dstpitch = surface->pitch >>2;
   1.347 +
   1.348 +	for (y=0; y<surface->h; y++) {
   1.349 +		srccol = srcline;
   1.350 +		dstcol = dstline;
   1.351 +
   1.352 +		for (x=0; x<surface->w; x++) {
   1.353 +			Uint32	dstcolor;
   1.354 +
   1.355 +			dstcolor = (*srccol++)<<8;
   1.356 +			dstcolor |= (*srccol++)<<16;
   1.357 +			dstcolor |= (*srccol++)<<24;
   1.358 +
   1.359 +			*dstcol++ = dstcolor;
   1.360 +		}
   1.361 +
   1.362 +		srcline += srcpitch;
   1.363 +		dstline += dstpitch;
   1.364 +	}
   1.365 +}
   1.366 +
   1.367 +static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface)
   1.368 +{
   1.369 +	int x,y, srcpitch, dstpitch;
   1.370 +	Uint32 *dstline, *dstcol;
   1.371 +	Uint8 *srcline, *srccol;
   1.372 +
   1.373 +	srcline = (Uint8 *)gl_shadow;
   1.374 +	srcpitch = surface->w *3;
   1.375 +	dstline = surface->pixels;
   1.376 +	dstpitch = surface->pitch >>2;
   1.377 +
   1.378 +	for (y=0; y<surface->h; y++) {
   1.379 +		srccol = srcline;
   1.380 +		dstcol = dstline;
   1.381 +
   1.382 +		for (x=0; x<surface->w; x++) {
   1.383 +			Uint32	dstcolor;
   1.384 +
   1.385 +			dstcolor = (*srccol++)<<24;
   1.386 +			dstcolor |= (*srccol++)<<16;
   1.387 +			dstcolor |= (*srccol++)<<8;
   1.388 +
   1.389 +			*dstcol++ = dstcolor;
   1.390 +		}
   1.391 +
   1.392 +		srcline += srcpitch;
   1.393 +		dstline += dstpitch;
   1.394 +	}
   1.395 +}
   1.396 +
   1.397  static void CopyShadow8888To555(_THIS, SDL_Surface *surface)
   1.398  {
   1.399  	int x,y, srcpitch, dstpitch;
   1.400 @@ -770,3 +1038,5 @@
   1.401  		line += pitch;
   1.402  	}
   1.403  }
   1.404 +
   1.405 +#endif /* HAVE_OPENGL */