# HG changeset patch # User Patrice Mandin # Date 1101831245 0 # Node ID fbeac93128430f5fc225cc24858e82900a0ed928 # Parent 8be85fa59cf3ce18657a81697398873840557c22 TinyGL only support RGB24 color buffer diff -r 8be85fa59cf3 -r fbeac9312843 src/video/ataricommon/SDL_atarigl.c --- 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; yh; y++) { + srccol = srcline; + dstcol = dstline; + for (x=0; xw; 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; yh; y++) { + srccol = srcline; + dstcol = dstline; + + for (x=0; xw; 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; yh; y++) { + srccol = srcline; + dstcol = dstline; + + for (x=0; xw; 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; yh; y++) { + srccol = srcline; + dstcol = dstline; + + for (x=0; xw; 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; yh; y++) { + srccol = srcline; + dstcol = dstline; + + for (x=0; xw; 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; yh; y++) { + srccol = srcline; + dstcol = dstline; + + for (x=0; xw; 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; yh; y++) { + srccol = srcline; + dstcol = dstline; + + for (x=0; xw; 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 */