From a77e8a11f2416e6cfe9e69f70a8dba4463e94d4c Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Sat, 4 Dec 2004 20:53:58 +0000 Subject: [PATCH] Some Atari OpenGL implementations draw upside down --- src/video/ataricommon/SDL_atarigl.c | 46 +++++++++++++++++++++++++++ src/video/ataricommon/SDL_atarigl_c.h | 17 ++++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/video/ataricommon/SDL_atarigl.c b/src/video/ataricommon/SDL_atarigl.c index 7a1da2f8e..fb8b56885 100644 --- a/src/video/ataricommon/SDL_atarigl.c +++ b/src/video/ataricommon/SDL_atarigl.c @@ -425,6 +425,7 @@ static int InitNew(_THIS, SDL_Surface *current) /* Init OpenGL context using OSMesa */ gl_convert = ConvertNull; gl_copyshadow = CopyShadowNull; + gl_upsidedown = SDL_FALSE; pixel_format = current->format; redmask = pixel_format->Rmask; @@ -539,6 +540,7 @@ static int InitOld(_THIS, SDL_Surface *current) /* Init OpenGL context using OSMesa */ gl_convert = ConvertNull; gl_copyshadow = CopyShadowNull; + gl_upsidedown = SDL_FALSE; pixel_format = current->format; redmask = pixel_format->Rmask; @@ -556,6 +558,7 @@ static int InitOld(_THIS, SDL_Surface *current) } } else { gl_pixelsize = 4; + gl_upsidedown = SDL_TRUE; osmesa_format = OSMESA_ARGB; if (redmask == 31<<10) { gl_copyshadow = CopyShadow8888To555; @@ -577,6 +580,7 @@ static int InitOld(_THIS, SDL_Surface *current) } } else { gl_pixelsize = 4; + gl_upsidedown = SDL_TRUE; osmesa_format = OSMESA_ARGB; gl_copyshadow = CopyShadow8888To565; if (redmask != 31<<11) { @@ -595,6 +599,7 @@ static int InitOld(_THIS, SDL_Surface *current) } } else { gl_copyshadow = CopyShadowDirect; + gl_upsidedown = SDL_TRUE; if (redmask == 255<<16) { osmesa_format = OSMESA_RGB; } else { @@ -616,6 +621,7 @@ static int InitOld(_THIS, SDL_Surface *current) } } else { gl_pixelsize = 4; + gl_upsidedown = SDL_TRUE; gl_copyshadow = CopyShadowDirect; if (redmask == 255<<16) { osmesa_format = OSMESA_ARGB; @@ -685,6 +691,10 @@ static void CopyShadowDirect(_THIS, SDL_Surface *surface) srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { memcpy(dstline, srcline, srcpitch); @@ -704,6 +714,10 @@ static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface) srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>1; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; @@ -732,6 +746,10 @@ static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface) srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>1; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; @@ -761,6 +779,10 @@ static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface) srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; @@ -788,6 +810,10 @@ static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface) srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>2; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; @@ -818,6 +844,10 @@ static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface) srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>2; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; @@ -848,6 +878,10 @@ static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface) srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>2; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; @@ -878,6 +912,10 @@ static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface) srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>2; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; @@ -908,6 +946,10 @@ static void CopyShadow8888To555(_THIS, SDL_Surface *surface) srcpitch = (surface->w * gl_pixelsize) >>2; dstline = surface->pixels; dstpitch = surface->pitch >>1; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; @@ -938,6 +980,10 @@ static void CopyShadow8888To565(_THIS, SDL_Surface *surface) srcpitch = (surface->w * gl_pixelsize) >> 2; dstline = surface->pixels; dstpitch = surface->pitch >>1; + if (gl_upsidedown) { + srcline += (surface->h-1)*srcpitch; + srcpitch = -srcpitch; + } for (y=0; yh; y++) { srccol = srcline; diff --git a/src/video/ataricommon/SDL_atarigl_c.h b/src/video/ataricommon/SDL_atarigl_c.h index 664765b4e..18ca7ec5b 100644 --- a/src/video/ataricommon/SDL_atarigl_c.h +++ b/src/video/ataricommon/SDL_atarigl_c.h @@ -40,6 +40,8 @@ struct SDL_PrivateGLData { int gl_pixelsize; /* for CopyShadow functions */ + SDL_bool gl_upsidedown; /* Some implementations draw upside down */ + Uint8 *gl_shadow; /* Shadow buffer for old implementations */ /* for unsupported OSMesa buffer formats */ @@ -75,19 +77,20 @@ struct SDL_PrivateGLData { }; /* Variable names */ -#define gl_active (this->gl_data->gl_active) -#define gl_ctx (this->gl_data->ctx) -#define gl_oldmesa (this->gl_data->gl_oldmesa) +#define gl_active (this->gl_data->gl_active) +#define gl_ctx (this->gl_data->ctx) +#define gl_oldmesa (this->gl_data->gl_oldmesa) #define gl_pixelsize (this->gl_data->gl_pixelsize) -#define gl_shadow (this->gl_data->gl_shadow) -#define gl_convert (this->gl_data->ConvertSurface) +#define gl_upsidedown (this->gl_data->gl_upsidedown) +#define gl_shadow (this->gl_data->gl_shadow) +#define gl_convert (this->gl_data->ConvertSurface) #define gl_copyshadow (this->gl_data->CopyShadow) #define gl_curformat (this->gl_data->format) #define gl_curdepth (this->gl_data->depth) #define gl_curstencil (this->gl_data->stencil) #define gl_curaccum (this->gl_data->accum) -#define gl_curwidth (this->gl_data->width) -#define gl_curheight (this->gl_data->height) +#define gl_curwidth (this->gl_data->width) +#define gl_curheight (this->gl_data->height) /* OpenGL functions */ extern int SDL_AtariGL_Init(_THIS, SDL_Surface *current);