changeset 1000:fbeac9312843

TinyGL only support RGB24 color buffer
author Patrice Mandin <patmandin@gmail.com>
date Tue, 30 Nov 2004 16:14:05 +0000
parents 8be85fa59cf3
children 70bfe658442c
files src/video/ataricommon/SDL_atarigl.c
diffstat 1 files changed, 295 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/ataricommon/SDL_atarigl.c	Tue Nov 30 15:21:29 2004 +0000
+++ b/src/video/ataricommon/SDL_atarigl.c	Tue Nov 30 16:14:05 2004 +0000
@@ -47,12 +47,22 @@
 #define PATH_MESAGL_LDG	"mesa_gl.ldg"
 #define PATH_TINYGL_LDG	"tiny_gl.ldg"
 
+#define VDI_RGB	0xf
+
 /*--- Functions prototypes ---*/
 
 static void SDL_AtariGL_UnloadLibrary(_THIS);
 
+#ifdef HAVE_OPENGL
 static void CopyShadowNull(_THIS, SDL_Surface *surface);
 static void CopyShadowDirect(_THIS, SDL_Surface *surface);
+static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface);
+static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface);
+static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface);
+static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface);
+static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface);
+static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface);
+static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface);
 static void CopyShadow8888To555(_THIS, SDL_Surface *surface);
 static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
 
@@ -64,6 +74,7 @@
 
 static int InitNew(_THIS, SDL_Surface *current);
 static int InitOld(_THIS, SDL_Surface *current);
+#endif
 
 /*--- Public functions ---*/
 
@@ -396,6 +407,7 @@
 
 /*--- Creation of an OpenGL context using new/old functions ---*/
 
+#ifdef HAVE_OPENGL
 static int InitNew(_THIS, SDL_Surface *current)
 {
 	GLenum osmesa_format;
@@ -502,12 +514,13 @@
 	return (gl_ctx != NULL);
 }
 
+
 static int InitOld(_THIS, SDL_Surface *current)
 {
 	GLenum osmesa_format;
 	SDL_PixelFormat *pixel_format;
 	Uint32	redmask;
-	int recreatecontext;
+	int recreatecontext, tinygl_present;
 
 	if (this->gl_config.dll_handle) {
 		if (this->gl_data->OSMesaCreateLDG == NULL) {
@@ -515,6 +528,14 @@
 		}
 	}
 
+	/* TinyGL only supports VDI_RGB (OSMESA_RGB) */
+	tinygl_present=0;
+	if (this->gl_config.dll_handle) {
+		if (this->gl_data->glFinish == NULL) {
+			tinygl_present=1;
+		}
+	}
+
 	/* Init OpenGL context using OSMesa */
 	gl_convert = ConvertNull;
 	gl_copyshadow = CopyShadowNull;
@@ -525,49 +546,92 @@
 		case 15:
 			/* 15 bits unsupported */
 			gl_pixelsize = 2;
-			osmesa_format = OSMESA_ARGB;
-			if (redmask == 31<<10) {
-				gl_copyshadow = CopyShadow8888To555;
+			if (tinygl_present) {
+				osmesa_format = VDI_RGB;
+				if (redmask == 31<<10) {
+					gl_copyshadow = CopyShadowRGBTo555;
+				} else {
+					gl_copyshadow = CopyShadowRGBTo565;
+					gl_convert = Convert565To555le;
+				}
 			} else {
-				gl_copyshadow = CopyShadow8888To565;
-				gl_convert = Convert565To555le;
+				osmesa_format = OSMESA_ARGB;
+				if (redmask == 31<<10) {
+					gl_copyshadow = CopyShadow8888To555;
+				} else {
+					gl_copyshadow = CopyShadow8888To565;
+					gl_convert = Convert565To555le;
+				}
 			}
 			break;
 		case 16:
 			/* 16 bits unsupported */
 			gl_pixelsize = 2;
-			osmesa_format = OSMESA_ARGB;
-			gl_copyshadow = CopyShadow8888To565;
-			if (redmask != 31<<11) {
-				/* 565, little endian, unsupported */
-				gl_convert = Convert565le;
+			if (tinygl_present) {
+				osmesa_format = VDI_RGB;
+				gl_copyshadow = CopyShadowRGBTo565;
+				if (redmask != 31<<11) {
+					/* 565, little endian, unsupported */
+					gl_convert = Convert565le;
+				}
+			} else {
+				osmesa_format = OSMESA_ARGB;
+				gl_copyshadow = CopyShadow8888To565;
+				if (redmask != 31<<11) {
+					/* 565, little endian, unsupported */
+					gl_convert = Convert565le;
+				}
 			}
 			break;
 		case 24:
 			gl_pixelsize = 3;
-			gl_copyshadow = CopyShadowDirect;
-			if (redmask == 255<<16) {
-				osmesa_format = OSMESA_RGB;
+			if (tinygl_present) {
+				osmesa_format = VDI_RGB;
+				gl_copyshadow = CopyShadowDirect;
+				if (redmask != 255<<16) {
+					gl_copyshadow = CopyShadowRGBSwap;
+				}
 			} else {
-				osmesa_format = OSMESA_BGR;
+				gl_copyshadow = CopyShadowDirect;
+				if (redmask == 255<<16) {
+					osmesa_format = OSMESA_RGB;
+				} else {
+					osmesa_format = OSMESA_BGR;
+				}
 			}
 			break;
 		case 32:
 			gl_pixelsize = 4;
-			gl_copyshadow = CopyShadowDirect;
-			if (redmask == 255<<16) {
-				osmesa_format = OSMESA_ARGB;
-			} else if (redmask == 255<<8) {
-				osmesa_format = OSMESA_BGRA;
-			} else if (redmask == 255<<24) {
-				osmesa_format = OSMESA_RGBA;
+			if (tinygl_present) {
+				osmesa_format = VDI_RGB;
+				gl_copyshadow = CopyShadowRGBToARGB;
+				if (redmask == 255) {
+					gl_convert = CopyShadowRGBToABGR;
+				} else if (redmask == 255<<8) {
+					gl_convert = CopyShadowRGBToBGRA;
+				} else if (redmask == 255<<24) {
+					gl_convert = CopyShadowRGBToRGBA;
+				}
 			} else {
-				/* ABGR format unsupported */
-				osmesa_format = OSMESA_BGRA;
-				gl_convert = ConvertBGRAToABGR;
+				gl_copyshadow = CopyShadowDirect;
+				if (redmask == 255<<16) {
+					osmesa_format = OSMESA_ARGB;
+				} else if (redmask == 255<<8) {
+					osmesa_format = OSMESA_BGRA;
+				} else if (redmask == 255<<24) {
+					osmesa_format = OSMESA_RGBA;
+				} else {
+					/* ABGR format unsupported */
+					osmesa_format = OSMESA_BGRA;
+					gl_convert = ConvertBGRAToABGR;
+				}
 			}
 			break;
 		default:
+			if (tinygl_present) {
+				SDL_AtariGL_Quit(this, SDL_FALSE);
+				return 0;
+			}
 			gl_pixelsize = 1;
 			gl_copyshadow = CopyShadowDirect;
 			osmesa_format = OSMESA_COLOR_INDEX;
@@ -627,6 +691,210 @@
 	}
 }
 
+static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface)
+{
+	int x,y, srcpitch, dstpitch;
+	Uint16 *dstline, *dstcol;
+	Uint8 *srcline, *srccol;
+
+	srcline = (Uint8 *)gl_shadow;
+	srcpitch = surface->w *3;
+	dstline = surface->pixels;
+	dstpitch = surface->pitch >>1;
+
+	for (y=0; y<surface->h; y++) {
+		srccol = srcline;
+		dstcol = dstline;
+		for (x=0; x<surface->w; x++) {
+			Uint16 dstcolor;
+			
+			dstcolor = ((*srccol++)>>9) & (31<<10);
+			dstcolor |= ((*srccol++)>>6) & (31<<5);
+			dstcolor |= ((*srccol++)>>3) & 31;
+			*dstcol++ = dstcolor;
+		}
+
+		srcline += srcpitch;
+		dstline += dstpitch;
+	}
+}
+
+static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface)
+{
+	int x,y, srcpitch, dstpitch;
+	Uint16 *dstline, *dstcol;
+	Uint8 *srcline, *srccol;
+
+	srcline = (Uint8 *)gl_shadow;
+	srcpitch = surface->w *3;
+	dstline = surface->pixels;
+	dstpitch = surface->pitch >>1;
+
+	for (y=0; y<surface->h; y++) {
+		srccol = srcline;
+		dstcol = dstline;
+
+		for (x=0; x<surface->w; x++) {
+			Uint16 dstcolor;
+			
+			dstcolor = ((*srccol++)>>8) & (31<<11);
+			dstcolor |= ((*srccol++)>>5) & (63<<5);
+			dstcolor |= ((*srccol++)>>3) & 31;
+			*dstcol++ = dstcolor;
+		}
+
+		srcline += srcpitch;
+		dstline += dstpitch;
+	}
+}
+
+static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface)
+{
+	int x,y, srcpitch, dstpitch;
+	Uint8 *dstline, *dstcol;
+	Uint8 *srcline, *srccol;
+
+	srcline = (Uint8 *)gl_shadow;
+	srcpitch = surface->w *3;
+	dstline = surface->pixels;
+	dstpitch = surface->pitch;
+
+	for (y=0; y<surface->h; y++) {
+		srccol = srcline;
+		dstcol = dstline;
+
+		for (x=0; x<surface->w; x++) {
+			*dstcol++ = srccol[2];
+			*dstcol++ = srccol[1];
+			*dstcol++ = srccol[0];
+			srccol += 3;
+		}
+
+		srcline += srcpitch;
+		dstline += dstpitch;
+	}
+}
+
+static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface)
+{
+	int x,y, srcpitch, dstpitch;
+	Uint32 *dstline, *dstcol;
+	Uint8 *srcline, *srccol;
+
+	srcline = (Uint8 *)gl_shadow;
+	srcpitch = surface->w *3;
+	dstline = surface->pixels;
+	dstpitch = surface->pitch >>2;
+
+	for (y=0; y<surface->h; y++) {
+		srccol = srcline;
+		dstcol = dstline;
+
+		for (x=0; x<surface->w; x++) {
+			Uint32	dstcolor;
+
+			dstcolor = (*srccol++)<<16;
+			dstcolor |= (*srccol++)<<8;
+			dstcolor |= *srccol++;
+
+			*dstcol++ = dstcolor;
+		}
+
+		srcline += srcpitch;
+		dstline += dstpitch;
+	}
+}
+
+static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface)
+{
+	int x,y, srcpitch, dstpitch;
+	Uint32 *dstline, *dstcol;
+	Uint8 *srcline, *srccol;
+
+	srcline = (Uint8 *)gl_shadow;
+	srcpitch = surface->w *3;
+	dstline = surface->pixels;
+	dstpitch = surface->pitch >>2;
+
+	for (y=0; y<surface->h; y++) {
+		srccol = srcline;
+		dstcol = dstline;
+
+		for (x=0; x<surface->w; x++) {
+			Uint32	dstcolor;
+
+			dstcolor = *srccol++;
+			dstcolor |= (*srccol++)<<8;
+			dstcolor |= (*srccol++)<<16;
+
+			*dstcol++ = dstcolor;
+		}
+
+		srcline += srcpitch;
+		dstline += dstpitch;
+	}
+}
+
+static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface)
+{
+	int x,y, srcpitch, dstpitch;
+	Uint32 *dstline, *dstcol;
+	Uint8 *srcline, *srccol;
+
+	srcline = (Uint8 *)gl_shadow;
+	srcpitch = surface->w *3;
+	dstline = surface->pixels;
+	dstpitch = surface->pitch >>2;
+
+	for (y=0; y<surface->h; y++) {
+		srccol = srcline;
+		dstcol = dstline;
+
+		for (x=0; x<surface->w; x++) {
+			Uint32	dstcolor;
+
+			dstcolor = (*srccol++)<<8;
+			dstcolor |= (*srccol++)<<16;
+			dstcolor |= (*srccol++)<<24;
+
+			*dstcol++ = dstcolor;
+		}
+
+		srcline += srcpitch;
+		dstline += dstpitch;
+	}
+}
+
+static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface)
+{
+	int x,y, srcpitch, dstpitch;
+	Uint32 *dstline, *dstcol;
+	Uint8 *srcline, *srccol;
+
+	srcline = (Uint8 *)gl_shadow;
+	srcpitch = surface->w *3;
+	dstline = surface->pixels;
+	dstpitch = surface->pitch >>2;
+
+	for (y=0; y<surface->h; y++) {
+		srccol = srcline;
+		dstcol = dstline;
+
+		for (x=0; x<surface->w; x++) {
+			Uint32	dstcolor;
+
+			dstcolor = (*srccol++)<<24;
+			dstcolor |= (*srccol++)<<16;
+			dstcolor |= (*srccol++)<<8;
+
+			*dstcol++ = dstcolor;
+		}
+
+		srcline += srcpitch;
+		dstline += dstpitch;
+	}
+}
+
 static void CopyShadow8888To555(_THIS, SDL_Surface *surface)
 {
 	int x,y, srcpitch, dstpitch;
@@ -770,3 +1038,5 @@
 		line += pitch;
 	}
 }
+
+#endif /* HAVE_OPENGL */