Commit 63a94a14 authored by Patrice Mandin's avatar Patrice Mandin

TinyGL only support RGB24 color buffer

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401001
parent 268aaf60
...@@ -47,12 +47,22 @@ ...@@ -47,12 +47,22 @@
#define PATH_MESAGL_LDG "mesa_gl.ldg" #define PATH_MESAGL_LDG "mesa_gl.ldg"
#define PATH_TINYGL_LDG "tiny_gl.ldg" #define PATH_TINYGL_LDG "tiny_gl.ldg"
#define VDI_RGB 0xf
/*--- Functions prototypes ---*/ /*--- Functions prototypes ---*/
static void SDL_AtariGL_UnloadLibrary(_THIS); static void SDL_AtariGL_UnloadLibrary(_THIS);
#ifdef HAVE_OPENGL
static void CopyShadowNull(_THIS, SDL_Surface *surface); static void CopyShadowNull(_THIS, SDL_Surface *surface);
static void CopyShadowDirect(_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 CopyShadow8888To555(_THIS, SDL_Surface *surface);
static void CopyShadow8888To565(_THIS, SDL_Surface *surface); static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
...@@ -64,6 +74,7 @@ static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface); ...@@ -64,6 +74,7 @@ static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface);
static int InitNew(_THIS, SDL_Surface *current); static int InitNew(_THIS, SDL_Surface *current);
static int InitOld(_THIS, SDL_Surface *current); static int InitOld(_THIS, SDL_Surface *current);
#endif
/*--- Public functions ---*/ /*--- Public functions ---*/
...@@ -396,6 +407,7 @@ static void SDL_AtariGL_UnloadLibrary(_THIS) ...@@ -396,6 +407,7 @@ static void SDL_AtariGL_UnloadLibrary(_THIS)
/*--- Creation of an OpenGL context using new/old functions ---*/ /*--- Creation of an OpenGL context using new/old functions ---*/
#ifdef HAVE_OPENGL
static int InitNew(_THIS, SDL_Surface *current) static int InitNew(_THIS, SDL_Surface *current)
{ {
GLenum osmesa_format; GLenum osmesa_format;
...@@ -502,12 +514,13 @@ static int InitNew(_THIS, SDL_Surface *current) ...@@ -502,12 +514,13 @@ static int InitNew(_THIS, SDL_Surface *current)
return (gl_ctx != NULL); return (gl_ctx != NULL);
} }
static int InitOld(_THIS, SDL_Surface *current) static int InitOld(_THIS, SDL_Surface *current)
{ {
GLenum osmesa_format; GLenum osmesa_format;
SDL_PixelFormat *pixel_format; SDL_PixelFormat *pixel_format;
Uint32 redmask; Uint32 redmask;
int recreatecontext; int recreatecontext, tinygl_present;
if (this->gl_config.dll_handle) { if (this->gl_config.dll_handle) {
if (this->gl_data->OSMesaCreateLDG == NULL) { if (this->gl_data->OSMesaCreateLDG == NULL) {
...@@ -515,6 +528,14 @@ static int InitOld(_THIS, SDL_Surface *current) ...@@ -515,6 +528,14 @@ static int InitOld(_THIS, SDL_Surface *current)
} }
} }
/* 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 */ /* Init OpenGL context using OSMesa */
gl_convert = ConvertNull; gl_convert = ConvertNull;
gl_copyshadow = CopyShadowNull; gl_copyshadow = CopyShadowNull;
...@@ -525,49 +546,92 @@ static int InitOld(_THIS, SDL_Surface *current) ...@@ -525,49 +546,92 @@ static int InitOld(_THIS, SDL_Surface *current)
case 15: case 15:
/* 15 bits unsupported */ /* 15 bits unsupported */
gl_pixelsize = 2; gl_pixelsize = 2;
osmesa_format = OSMESA_ARGB; if (tinygl_present) {
if (redmask == 31<<10) { osmesa_format = VDI_RGB;
gl_copyshadow = CopyShadow8888To555; if (redmask == 31<<10) {
gl_copyshadow = CopyShadowRGBTo555;
} else {
gl_copyshadow = CopyShadowRGBTo565;
gl_convert = Convert565To555le;
}
} else { } else {
gl_copyshadow = CopyShadow8888To565; osmesa_format = OSMESA_ARGB;
gl_convert = Convert565To555le; if (redmask == 31<<10) {
gl_copyshadow = CopyShadow8888To555;
} else {
gl_copyshadow = CopyShadow8888To565;
gl_convert = Convert565To555le;
}
} }
break; break;
case 16: case 16:
/* 16 bits unsupported */ /* 16 bits unsupported */
gl_pixelsize = 2; gl_pixelsize = 2;
osmesa_format = OSMESA_ARGB; if (tinygl_present) {
gl_copyshadow = CopyShadow8888To565; osmesa_format = VDI_RGB;
if (redmask != 31<<11) { gl_copyshadow = CopyShadowRGBTo565;
/* 565, little endian, unsupported */ if (redmask != 31<<11) {
gl_convert = Convert565le; /* 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; break;
case 24: case 24:
gl_pixelsize = 3; gl_pixelsize = 3;
gl_copyshadow = CopyShadowDirect; if (tinygl_present) {
if (redmask == 255<<16) { osmesa_format = VDI_RGB;
osmesa_format = OSMESA_RGB; gl_copyshadow = CopyShadowDirect;
if (redmask != 255<<16) {
gl_copyshadow = CopyShadowRGBSwap;
}
} else { } else {
osmesa_format = OSMESA_BGR; gl_copyshadow = CopyShadowDirect;
if (redmask == 255<<16) {
osmesa_format = OSMESA_RGB;
} else {
osmesa_format = OSMESA_BGR;
}
} }
break; break;
case 32: case 32:
gl_pixelsize = 4; gl_pixelsize = 4;
gl_copyshadow = CopyShadowDirect; if (tinygl_present) {
if (redmask == 255<<16) { osmesa_format = VDI_RGB;
osmesa_format = OSMESA_ARGB; gl_copyshadow = CopyShadowRGBToARGB;
} else if (redmask == 255<<8) { if (redmask == 255) {
osmesa_format = OSMESA_BGRA; gl_convert = CopyShadowRGBToABGR;
} else if (redmask == 255<<24) { } else if (redmask == 255<<8) {
osmesa_format = OSMESA_RGBA; gl_convert = CopyShadowRGBToBGRA;
} else if (redmask == 255<<24) {
gl_convert = CopyShadowRGBToRGBA;
}
} else { } else {
/* ABGR format unsupported */ gl_copyshadow = CopyShadowDirect;
osmesa_format = OSMESA_BGRA; if (redmask == 255<<16) {
gl_convert = ConvertBGRAToABGR; 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; break;
default: default:
if (tinygl_present) {
SDL_AtariGL_Quit(this, SDL_FALSE);
return 0;
}
gl_pixelsize = 1; gl_pixelsize = 1;
gl_copyshadow = CopyShadowDirect; gl_copyshadow = CopyShadowDirect;
osmesa_format = OSMESA_COLOR_INDEX; osmesa_format = OSMESA_COLOR_INDEX;
...@@ -627,6 +691,210 @@ static void CopyShadowDirect(_THIS, SDL_Surface *surface) ...@@ -627,6 +691,210 @@ static void CopyShadowDirect(_THIS, SDL_Surface *surface)
} }
} }
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) static void CopyShadow8888To555(_THIS, SDL_Surface *surface)
{ {
int x,y, srcpitch, dstpitch; int x,y, srcpitch, dstpitch;
...@@ -770,3 +1038,5 @@ static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface) ...@@ -770,3 +1038,5 @@ static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface)
line += pitch; line += pitch;
} }
} }
#endif /* HAVE_OPENGL */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment