src/video/ataricommon/SDL_atarigl.c
author Sam Lantinga
Tue, 07 Feb 2006 09:29:18 +0000
changeset 1338 604d73db6802
parent 1336 3692456e7b0f
child 1358 c71e05b4dc2e
permissions -rw-r--r--
Removed uses of stdlib.h and string.h
patmandin@989
     1
/*
patmandin@989
     2
    SDL - Simple DirectMedia Layer
patmandin@989
     3
    Copyright (C) 1997-2004 Sam Lantinga
patmandin@989
     4
patmandin@989
     5
    This library is free software; you can redistribute it and/or
patmandin@989
     6
    modify it under the terms of the GNU Library General Public
patmandin@989
     7
    License as published by the Free Software Foundation; either
patmandin@989
     8
    version 2 of the License, or (at your option) any later version.
patmandin@989
     9
patmandin@989
    10
    This library is distributed in the hope that it will be useful,
patmandin@989
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
patmandin@989
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
patmandin@989
    13
    Library General Public License for more details.
patmandin@989
    14
patmandin@989
    15
    You should have received a copy of the GNU Library General Public
patmandin@989
    16
    License along with this library; if not, write to the Free
patmandin@989
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
patmandin@989
    18
patmandin@989
    19
    Sam Lantinga
patmandin@989
    20
    slouken@libsdl.org
patmandin@989
    21
*/
patmandin@989
    22
patmandin@989
    23
/* Atari OSMesa.ldg implementation of SDL OpenGL support */
patmandin@989
    24
patmandin@989
    25
/*--- Includes ---*/
patmandin@989
    26
patmandin@989
    27
#ifdef HAVE_OPENGL
patmandin@989
    28
#include <GL/osmesa.h>
patmandin@989
    29
#endif
patmandin@989
    30
patmandin@991
    31
#include <mint/osbind.h>
patmandin@991
    32
slouken@1338
    33
#include "SDL_stdlib.h"
slouken@1338
    34
#include "SDL_string.h"
patmandin@989
    35
#include "SDL_video.h"
patmandin@989
    36
#include "SDL_error.h"
patmandin@989
    37
#include "SDL_endian.h"
patmandin@989
    38
#include "SDL_atarigl_c.h"
patmandin@991
    39
#ifdef ENABLE_OSMESA_SHARED
patmandin@991
    40
#include "SDL_loadso.h"
patmandin@991
    41
#endif
patmandin@989
    42
patmandin@991
    43
/*--- Defines ---*/
patmandin@991
    44
patmandin@991
    45
#define PATH_OSMESA_LDG	"osmesa.ldg"
patmandin@991
    46
#define PATH_MESAGL_LDG	"mesa_gl.ldg"
patmandin@991
    47
#define PATH_TINYGL_LDG	"tiny_gl.ldg"
patmandin@989
    48
patmandin@1000
    49
#define VDI_RGB	0xf
patmandin@1000
    50
patmandin@989
    51
/*--- Functions prototypes ---*/
patmandin@989
    52
patmandin@991
    53
static void SDL_AtariGL_UnloadLibrary(_THIS);
patmandin@991
    54
patmandin@1000
    55
#ifdef HAVE_OPENGL
patmandin@991
    56
static void CopyShadowNull(_THIS, SDL_Surface *surface);
patmandin@991
    57
static void CopyShadowDirect(_THIS, SDL_Surface *surface);
patmandin@1000
    58
static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface);
patmandin@1000
    59
static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface);
patmandin@1000
    60
static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface);
patmandin@1000
    61
static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface);
patmandin@1000
    62
static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface);
patmandin@1000
    63
static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface);
patmandin@1000
    64
static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface);
patmandin@991
    65
static void CopyShadow8888To555(_THIS, SDL_Surface *surface);
patmandin@991
    66
static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
patmandin@991
    67
patmandin@991
    68
static void ConvertNull(_THIS, SDL_Surface *surface);
patmandin@991
    69
static void Convert565To555be(_THIS, SDL_Surface *surface);
patmandin@991
    70
static void Convert565To555le(_THIS, SDL_Surface *surface);
patmandin@991
    71
static void Convert565le(_THIS, SDL_Surface *surface);
patmandin@991
    72
static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface);
patmandin@991
    73
patmandin@991
    74
static int InitNew(_THIS, SDL_Surface *current);
patmandin@991
    75
static int InitOld(_THIS, SDL_Surface *current);
patmandin@1000
    76
#endif
patmandin@989
    77
patmandin@989
    78
/*--- Public functions ---*/
patmandin@989
    79
patmandin@989
    80
int SDL_AtariGL_Init(_THIS, SDL_Surface *current)
patmandin@989
    81
{
patmandin@989
    82
#ifdef HAVE_OPENGL
patmandin@991
    83
	if (gl_oldmesa) {
patmandin@991
    84
		gl_active = InitOld(this, current);		
patmandin@991
    85
	} else {
patmandin@991
    86
		gl_active = InitNew(this, current);		
patmandin@991
    87
	}
patmandin@991
    88
#endif
patmandin@989
    89
patmandin@989
    90
	return (gl_active);
patmandin@989
    91
}
patmandin@989
    92
patmandin@992
    93
void SDL_AtariGL_Quit(_THIS, SDL_bool unload)
patmandin@989
    94
{
patmandin@989
    95
#ifdef HAVE_OPENGL
patmandin@991
    96
	if (gl_oldmesa) {
patmandin@991
    97
		/* Old mesa implementations */
patmandin@991
    98
		if (this->gl_data->OSMesaDestroyLDG) {
patmandin@991
    99
			this->gl_data->OSMesaDestroyLDG();
patmandin@991
   100
		}
patmandin@991
   101
		if (gl_shadow) {
patmandin@991
   102
			Mfree(gl_shadow);
patmandin@991
   103
			gl_shadow = NULL;
patmandin@991
   104
		}
patmandin@991
   105
	} else {
patmandin@991
   106
		/* New mesa implementation */
patmandin@991
   107
		if (gl_ctx) {
patmandin@991
   108
			if (this->gl_data->OSMesaDestroyContext) {
patmandin@991
   109
				this->gl_data->OSMesaDestroyContext(gl_ctx);
patmandin@991
   110
			}
patmandin@991
   111
			gl_ctx = NULL;
patmandin@991
   112
		}
patmandin@991
   113
	}
patmandin@991
   114
patmandin@992
   115
	if (unload) {
patmandin@992
   116
		SDL_AtariGL_UnloadLibrary(this);
patmandin@992
   117
	}
patmandin@991
   118
patmandin@991
   119
#endif /* HAVE_OPENGL */
patmandin@989
   120
	gl_active = 0;
patmandin@989
   121
}
patmandin@989
   122
patmandin@989
   123
int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
patmandin@989
   124
{
patmandin@989
   125
#ifdef HAVE_OPENGL
patmandin@991
   126
patmandin@991
   127
#ifdef ENABLE_OSMESA_SHARED
patmandin@991
   128
	void *handle;
patmandin@995
   129
	SDL_bool cancel_load;
patmandin@991
   130
patmandin@991
   131
	if (gl_active) {
patmandin@991
   132
		SDL_SetError("OpenGL context already created");
patmandin@991
   133
		return -1;
patmandin@991
   134
	}
patmandin@991
   135
patmandin@1239
   136
	/* Unload previous driver */
patmandin@1239
   137
	SDL_AtariGL_UnloadLibrary(this);
patmandin@991
   138
patmandin@991
   139
	/* Load library given by path */
patmandin@1239
   140
	handle = SDL_LoadObject(path);
patmandin@991
   141
	if (handle == NULL) {
patmandin@991
   142
		/* Try to load another one */
slouken@1336
   143
		path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
patmandin@991
   144
		if ( path != NULL ) {
patmandin@991
   145
			handle = SDL_LoadObject(path);
patmandin@991
   146
		}
patmandin@991
   147
patmandin@991
   148
		/* If it does not work, try some other */
patmandin@991
   149
		if (handle == NULL) {
patmandin@991
   150
			path = PATH_OSMESA_LDG;
patmandin@991
   151
			handle = SDL_LoadObject(path);
patmandin@991
   152
		}
patmandin@991
   153
patmandin@991
   154
		if (handle == NULL) {
patmandin@991
   155
			path = PATH_MESAGL_LDG;
patmandin@991
   156
			handle = SDL_LoadObject(path);
patmandin@991
   157
		}
patmandin@991
   158
patmandin@991
   159
		if (handle == NULL) {
patmandin@991
   160
			path = PATH_TINYGL_LDG;
patmandin@991
   161
			handle = SDL_LoadObject(path);
patmandin@991
   162
		}
patmandin@991
   163
	}
patmandin@991
   164
patmandin@991
   165
	if (handle == NULL) {
patmandin@991
   166
		SDL_SetError("Could not load OpenGL library");
patmandin@991
   167
		return -1;
patmandin@991
   168
	}
patmandin@991
   169
patmandin@993
   170
	this->gl_data->glGetIntegerv = SDL_LoadFunction(handle, "glGetIntegerv");
patmandin@993
   171
	this->gl_data->glFinish = SDL_LoadFunction(handle, "glFinish");
patmandin@995
   172
	this->gl_data->glFlush = SDL_LoadFunction(handle, "glFlush");
patmandin@993
   173
patmandin@995
   174
	cancel_load = SDL_FALSE;
patmandin@995
   175
	if (this->gl_data->glGetIntegerv == NULL) {
patmandin@995
   176
		cancel_load = SDL_TRUE;
patmandin@995
   177
	} else {
patmandin@995
   178
		/* We need either glFinish (OSMesa) or glFlush (TinyGL) */
patmandin@995
   179
		if ((this->gl_data->glFinish == NULL) &&
patmandin@995
   180
			(this->gl_data->glFlush == NULL)) {
patmandin@995
   181
				cancel_load = SDL_TRUE;
patmandin@995
   182
		}
patmandin@995
   183
	}
patmandin@995
   184
	if (cancel_load) {
patmandin@993
   185
		SDL_SetError("Could not retrieve OpenGL functions");
patmandin@993
   186
		SDL_UnloadObject(handle);
patmandin@993
   187
		/* Restore pointers to static library */
patmandin@993
   188
		SDL_AtariGL_InitPointers(this);
patmandin@993
   189
		return -1;
patmandin@993
   190
	}
patmandin@993
   191
patmandin@991
   192
	/* Load functions pointers (osmesa.ldg) */
patmandin@991
   193
	this->gl_data->OSMesaCreateContextExt = SDL_LoadFunction(handle, "OSMesaCreateContextExt");
patmandin@991
   194
	this->gl_data->OSMesaDestroyContext = SDL_LoadFunction(handle, "OSMesaDestroyContext");
patmandin@991
   195
	this->gl_data->OSMesaMakeCurrent = SDL_LoadFunction(handle, "OSMesaMakeCurrent");
patmandin@991
   196
	this->gl_data->OSMesaPixelStore = SDL_LoadFunction(handle, "OSMesaPixelStore");
patmandin@991
   197
	this->gl_data->OSMesaGetProcAddress = SDL_LoadFunction(handle, "OSMesaGetProcAddress");
patmandin@991
   198
patmandin@991
   199
	/* Load old functions pointers (mesa_gl.ldg, tiny_gl.ldg) */
patmandin@991
   200
	this->gl_data->OSMesaCreateLDG = SDL_LoadFunction(handle, "OSMesaCreateLDG");
patmandin@991
   201
	this->gl_data->OSMesaDestroyLDG = SDL_LoadFunction(handle, "OSMesaDestroyLDG");
patmandin@991
   202
patmandin@991
   203
	gl_oldmesa = 0;
patmandin@991
   204
patmandin@991
   205
	if ( (this->gl_data->OSMesaCreateContextExt == NULL) || 
patmandin@991
   206
	     (this->gl_data->OSMesaDestroyContext == NULL) ||
patmandin@991
   207
	     (this->gl_data->OSMesaMakeCurrent == NULL) ||
patmandin@991
   208
	     (this->gl_data->OSMesaPixelStore == NULL) ||
patmandin@991
   209
	     (this->gl_data->OSMesaGetProcAddress == NULL)) {
patmandin@991
   210
		/* Hum, maybe old library ? */
patmandin@991
   211
		if ( (this->gl_data->OSMesaCreateLDG == NULL) || 
patmandin@991
   212
		     (this->gl_data->OSMesaDestroyLDG == NULL)) {
patmandin@993
   213
			SDL_SetError("Could not retrieve OSMesa functions");
patmandin@993
   214
			SDL_UnloadObject(handle);
patmandin@993
   215
			/* Restore pointers to static library */
patmandin@993
   216
			SDL_AtariGL_InitPointers(this);
patmandin@991
   217
			return -1;
patmandin@991
   218
		} else {
patmandin@991
   219
			gl_oldmesa = 1;
patmandin@991
   220
		}
patmandin@991
   221
	}
patmandin@991
   222
patmandin@991
   223
	this->gl_config.dll_handle = handle;
patmandin@991
   224
	if ( path ) {
slouken@1336
   225
		SDL_strncpy(this->gl_config.driver_path, path,
patmandin@991
   226
			sizeof(this->gl_config.driver_path)-1);
patmandin@991
   227
	} else {
slouken@1336
   228
		SDL_strcpy(this->gl_config.driver_path, "");
patmandin@991
   229
	}
patmandin@991
   230
patmandin@991
   231
#endif
patmandin@989
   232
	this->gl_config.driver_loaded = 1;
patmandin@991
   233
patmandin@991
   234
	return 0;
patmandin@991
   235
#else
patmandin@991
   236
	return -1;
patmandin@989
   237
#endif
patmandin@989
   238
}
patmandin@989
   239
patmandin@989
   240
void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc)
patmandin@989
   241
{
patmandin@989
   242
	void *func = NULL;
patmandin@989
   243
#ifdef HAVE_OPENGL
patmandin@991
   244
patmandin@991
   245
	if (this->gl_config.dll_handle) {
patmandin@991
   246
		func = SDL_LoadFunction(this->gl_config.dll_handle, (void *)proc);
patmandin@991
   247
	} else if (this->gl_data->OSMesaGetProcAddress) {
patmandin@991
   248
		func = this->gl_data->OSMesaGetProcAddress(proc);
patmandin@989
   249
	}
patmandin@991
   250
patmandin@989
   251
#endif
patmandin@989
   252
	return func;
patmandin@989
   253
}
patmandin@989
   254
patmandin@989
   255
int SDL_AtariGL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
patmandin@989
   256
{
patmandin@989
   257
#ifdef HAVE_OPENGL
patmandin@989
   258
	GLenum mesa_attrib;
patmandin@989
   259
	SDL_Surface *surface;
patmandin@989
   260
patmandin@991
   261
	if (!gl_active) {
patmandin@989
   262
		return -1;
patmandin@989
   263
	}
patmandin@989
   264
patmandin@989
   265
	switch(attrib) {
patmandin@989
   266
		case SDL_GL_RED_SIZE:
patmandin@989
   267
			mesa_attrib = GL_RED_BITS;
patmandin@989
   268
			break;
patmandin@989
   269
		case SDL_GL_GREEN_SIZE:
patmandin@989
   270
			mesa_attrib = GL_GREEN_BITS;
patmandin@989
   271
			break;
patmandin@989
   272
		case SDL_GL_BLUE_SIZE:
patmandin@989
   273
			mesa_attrib = GL_BLUE_BITS;
patmandin@989
   274
			break;
patmandin@989
   275
		case SDL_GL_ALPHA_SIZE:
patmandin@989
   276
			mesa_attrib = GL_ALPHA_BITS;
patmandin@989
   277
			break;
patmandin@989
   278
		case SDL_GL_DOUBLEBUFFER:
patmandin@989
   279
			surface = this->screen;
patmandin@989
   280
			*value = ((surface->flags & SDL_DOUBLEBUF)==SDL_DOUBLEBUF);
patmandin@989
   281
			return 0;
patmandin@989
   282
		case SDL_GL_DEPTH_SIZE:
patmandin@989
   283
			mesa_attrib = GL_DEPTH_BITS;
patmandin@989
   284
			break;
patmandin@989
   285
		case SDL_GL_STENCIL_SIZE:
patmandin@989
   286
			mesa_attrib = GL_STENCIL_BITS;
patmandin@989
   287
			break;
patmandin@989
   288
		case SDL_GL_ACCUM_RED_SIZE:
patmandin@989
   289
			mesa_attrib = GL_ACCUM_RED_BITS;
patmandin@989
   290
			break;
patmandin@989
   291
		case SDL_GL_ACCUM_GREEN_SIZE:
patmandin@989
   292
			mesa_attrib = GL_ACCUM_GREEN_BITS;
patmandin@989
   293
			break;
patmandin@989
   294
		case SDL_GL_ACCUM_BLUE_SIZE:
patmandin@989
   295
			mesa_attrib = GL_ACCUM_BLUE_BITS;
patmandin@989
   296
			break;
patmandin@989
   297
		case SDL_GL_ACCUM_ALPHA_SIZE:
patmandin@989
   298
			mesa_attrib = GL_ACCUM_ALPHA_BITS;
patmandin@989
   299
			break;
patmandin@989
   300
		default :
patmandin@989
   301
			return -1;
patmandin@989
   302
	}
patmandin@989
   303
patmandin@991
   304
	this->gl_data->glGetIntegerv(mesa_attrib, value);
patmandin@989
   305
	return 0;
patmandin@989
   306
#else
patmandin@989
   307
	return -1;
patmandin@989
   308
#endif
patmandin@989
   309
}
patmandin@989
   310
patmandin@989
   311
int SDL_AtariGL_MakeCurrent(_THIS)
patmandin@989
   312
{
patmandin@989
   313
#ifdef HAVE_OPENGL
patmandin@989
   314
	SDL_Surface *surface;
patmandin@989
   315
	GLenum type;
patmandin@989
   316
patmandin@991
   317
	if (gl_oldmesa && gl_active) {
patmandin@991
   318
		return 0;
patmandin@991
   319
	}
patmandin@991
   320
patmandin@991
   321
	if (this->gl_config.dll_handle) {
patmandin@991
   322
		if ((this->gl_data->OSMesaMakeCurrent == NULL) ||
patmandin@991
   323
			(this->gl_data->OSMesaPixelStore == NULL)) {
patmandin@991
   324
			return -1;
patmandin@991
   325
		}
patmandin@991
   326
	}
patmandin@991
   327
patmandin@991
   328
	if (!gl_active) {
patmandin@989
   329
		SDL_SetError("Invalid OpenGL context");
patmandin@989
   330
		return -1;
patmandin@989
   331
	}
patmandin@989
   332
patmandin@989
   333
	surface = this->screen;
patmandin@989
   334
	
patmandin@989
   335
	if ((surface->format->BitsPerPixel == 15) || (surface->format->BitsPerPixel == 16)) {
patmandin@989
   336
		type = GL_UNSIGNED_SHORT_5_6_5;
patmandin@989
   337
	} else {
patmandin@989
   338
		type = GL_UNSIGNED_BYTE;
patmandin@989
   339
	}
patmandin@989
   340
patmandin@991
   341
	if (!(this->gl_data->OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, surface->h))) {
patmandin@989
   342
		SDL_SetError("Can not make OpenGL context current");
patmandin@989
   343
		return -1;
patmandin@989
   344
	}
patmandin@989
   345
patmandin@989
   346
	/* OSMesa draws upside down */
patmandin@991
   347
	this->gl_data->OSMesaPixelStore(OSMESA_Y_UP, 0);
patmandin@989
   348
patmandin@989
   349
	return 0;
patmandin@989
   350
#else
patmandin@989
   351
	return -1;
patmandin@989
   352
#endif
patmandin@989
   353
}
patmandin@989
   354
patmandin@989
   355
void SDL_AtariGL_SwapBuffers(_THIS)
patmandin@989
   356
{
patmandin@989
   357
#ifdef HAVE_OPENGL
patmandin@991
   358
	if (gl_active) {
patmandin@993
   359
		if (this->gl_config.dll_handle) {
patmandin@993
   360
			if (this->gl_data->glFinish) {
patmandin@993
   361
				this->gl_data->glFinish();
patmandin@995
   362
			} else if (this->gl_data->glFlush) {
patmandin@995
   363
				this->gl_data->glFlush();
patmandin@993
   364
			}
patmandin@993
   365
		} else {
patmandin@993
   366
			this->gl_data->glFinish();
patmandin@993
   367
		}
patmandin@991
   368
		gl_copyshadow(this, this->screen);
patmandin@991
   369
		gl_convert(this, this->screen);
patmandin@989
   370
	}
patmandin@991
   371
#endif
patmandin@991
   372
}
patmandin@989
   373
patmandin@991
   374
void SDL_AtariGL_InitPointers(_THIS)
patmandin@991
   375
{
patmandin@991
   376
#if defined(HAVE_OPENGL)
patmandin@991
   377
	this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
patmandin@991
   378
	this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
patmandin@991
   379
	this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
patmandin@991
   380
	this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
patmandin@991
   381
	this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
patmandin@993
   382
patmandin@991
   383
	this->gl_data->glGetIntegerv = glGetIntegerv;
patmandin@993
   384
	this->gl_data->glFinish = glFinish;
patmandin@995
   385
	this->gl_data->glFlush = glFlush;
patmandin@993
   386
patmandin@993
   387
	this->gl_data->OSMesaCreateLDG = NULL;
patmandin@993
   388
	this->gl_data->OSMesaDestroyLDG = NULL;
patmandin@989
   389
#endif
patmandin@989
   390
}
patmandin@989
   391
patmandin@989
   392
/*--- Private functions ---*/
patmandin@989
   393
patmandin@991
   394
static void SDL_AtariGL_UnloadLibrary(_THIS)
patmandin@991
   395
{
patmandin@991
   396
#if defined(HAVE_OPENGL)
patmandin@991
   397
	if (this->gl_config.dll_handle) {
patmandin@991
   398
		SDL_UnloadObject(this->gl_config.dll_handle);
patmandin@991
   399
		this->gl_config.dll_handle = NULL;
patmandin@991
   400
patmandin@991
   401
		/* Restore pointers to static library */
patmandin@993
   402
		SDL_AtariGL_InitPointers(this);
patmandin@991
   403
	}
patmandin@991
   404
#endif
patmandin@991
   405
}
patmandin@991
   406
patmandin@991
   407
/*--- Creation of an OpenGL context using new/old functions ---*/
patmandin@991
   408
patmandin@1000
   409
#ifdef HAVE_OPENGL
patmandin@991
   410
static int InitNew(_THIS, SDL_Surface *current)
patmandin@991
   411
{
patmandin@991
   412
	GLenum osmesa_format;
patmandin@991
   413
	SDL_PixelFormat *pixel_format;
patmandin@991
   414
	Uint32	redmask;
patmandin@992
   415
	int recreatecontext;
patmandin@992
   416
	GLint newaccumsize;
patmandin@991
   417
patmandin@991
   418
	if (this->gl_config.dll_handle) {
patmandin@991
   419
		if (this->gl_data->OSMesaCreateContextExt == NULL) {
patmandin@991
   420
			return 0;
patmandin@991
   421
		}
patmandin@991
   422
	}
patmandin@991
   423
patmandin@991
   424
	/* Init OpenGL context using OSMesa */
patmandin@991
   425
	gl_convert = ConvertNull;
patmandin@991
   426
	gl_copyshadow = CopyShadowNull;
patmandin@1005
   427
	gl_upsidedown = SDL_FALSE;
patmandin@991
   428
patmandin@991
   429
	pixel_format = current->format;
patmandin@991
   430
	redmask = pixel_format->Rmask;
patmandin@991
   431
	switch (pixel_format->BitsPerPixel) {
patmandin@991
   432
		case 15:
patmandin@991
   433
			/* 1555, big and little endian, unsupported */
patmandin@991
   434
			gl_pixelsize = 2;
patmandin@991
   435
			osmesa_format = OSMESA_RGB_565;
patmandin@991
   436
			if (redmask == 31<<10) {
patmandin@991
   437
				gl_convert = Convert565To555be;
patmandin@991
   438
			} else {
patmandin@991
   439
				gl_convert = Convert565To555le;
patmandin@991
   440
			}
patmandin@991
   441
			break;
patmandin@991
   442
		case 16:
patmandin@991
   443
			gl_pixelsize = 2;
patmandin@991
   444
			if (redmask == 31<<11) {
patmandin@991
   445
				osmesa_format = OSMESA_RGB_565;
patmandin@991
   446
			} else {
patmandin@991
   447
				/* 565, little endian, unsupported */
patmandin@991
   448
				osmesa_format = OSMESA_RGB_565;
patmandin@991
   449
				gl_convert = Convert565le;
patmandin@991
   450
			}
patmandin@991
   451
			break;
patmandin@991
   452
		case 24:
patmandin@991
   453
			gl_pixelsize = 3;
patmandin@991
   454
			if (redmask == 255<<16) {
patmandin@991
   455
				osmesa_format = OSMESA_RGB;
patmandin@991
   456
			} else {
patmandin@991
   457
				osmesa_format = OSMESA_BGR;
patmandin@991
   458
			}
patmandin@991
   459
			break;
patmandin@991
   460
		case 32:
patmandin@991
   461
			gl_pixelsize = 4;
patmandin@991
   462
			if (redmask == 255<<16) {
patmandin@991
   463
				osmesa_format = OSMESA_ARGB;
patmandin@991
   464
			} else if (redmask == 255<<8) {
patmandin@991
   465
				osmesa_format = OSMESA_BGRA;
patmandin@991
   466
			} else if (redmask == 255<<24) {
patmandin@991
   467
				osmesa_format = OSMESA_RGBA;
patmandin@991
   468
			} else {
patmandin@991
   469
				/* ABGR format unsupported */
patmandin@991
   470
				osmesa_format = OSMESA_BGRA;
patmandin@991
   471
				gl_convert = ConvertBGRAToABGR;
patmandin@991
   472
			}
patmandin@991
   473
			break;
patmandin@991
   474
		default:
patmandin@991
   475
			gl_pixelsize = 1;
patmandin@991
   476
			osmesa_format = OSMESA_COLOR_INDEX;
patmandin@991
   477
			break;
patmandin@991
   478
	}
patmandin@991
   479
patmandin@992
   480
	/* Try to keep current context if possible */
patmandin@992
   481
	newaccumsize =
patmandin@992
   482
		this->gl_config.accum_red_size +
patmandin@992
   483
		this->gl_config.accum_green_size +
patmandin@992
   484
		this->gl_config.accum_blue_size +
patmandin@992
   485
		this->gl_config.accum_alpha_size;
patmandin@992
   486
	recreatecontext=1;
patmandin@992
   487
	if (gl_ctx &&
patmandin@992
   488
		(gl_curformat == osmesa_format) &&
patmandin@992
   489
		(gl_curdepth == this->gl_config.depth_size) &&
patmandin@992
   490
		(gl_curstencil == this->gl_config.stencil_size) &&
patmandin@992
   491
		(gl_curaccum == newaccumsize)) {
patmandin@992
   492
		recreatecontext = 0;
patmandin@992
   493
	}
patmandin@992
   494
	if (recreatecontext) {
patmandin@992
   495
		SDL_AtariGL_Quit(this, SDL_FALSE);
patmandin@992
   496
patmandin@992
   497
		gl_ctx = this->gl_data->OSMesaCreateContextExt(
patmandin@992
   498
			osmesa_format, this->gl_config.depth_size,
patmandin@992
   499
			this->gl_config.stencil_size, newaccumsize, NULL );
patmandin@992
   500
patmandin@992
   501
		if (gl_ctx) {
patmandin@992
   502
			gl_curformat = osmesa_format;
patmandin@992
   503
			gl_curdepth = this->gl_config.depth_size;
patmandin@992
   504
			gl_curstencil = this->gl_config.stencil_size;
patmandin@992
   505
			gl_curaccum = newaccumsize;
patmandin@992
   506
		} else {
patmandin@992
   507
			gl_curformat = 0;
patmandin@992
   508
			gl_curdepth = 0;
patmandin@992
   509
			gl_curstencil = 0;
patmandin@992
   510
			gl_curaccum = 0;
patmandin@992
   511
		}
patmandin@992
   512
	}
patmandin@991
   513
patmandin@991
   514
	return (gl_ctx != NULL);
patmandin@991
   515
}
patmandin@991
   516
patmandin@1000
   517
patmandin@991
   518
static int InitOld(_THIS, SDL_Surface *current)
patmandin@991
   519
{
patmandin@991
   520
	GLenum osmesa_format;
patmandin@991
   521
	SDL_PixelFormat *pixel_format;
patmandin@991
   522
	Uint32	redmask;
patmandin@1000
   523
	int recreatecontext, tinygl_present;
patmandin@991
   524
patmandin@991
   525
	if (this->gl_config.dll_handle) {
patmandin@991
   526
		if (this->gl_data->OSMesaCreateLDG == NULL) {
patmandin@991
   527
			return 0;
patmandin@991
   528
		}
patmandin@991
   529
	}
patmandin@991
   530
patmandin@1000
   531
	/* TinyGL only supports VDI_RGB (OSMESA_RGB) */
patmandin@1000
   532
	tinygl_present=0;
patmandin@1000
   533
	if (this->gl_config.dll_handle) {
patmandin@1000
   534
		if (this->gl_data->glFinish == NULL) {
patmandin@1000
   535
			tinygl_present=1;
patmandin@1000
   536
		}
patmandin@1000
   537
	}
patmandin@1000
   538
patmandin@991
   539
	/* Init OpenGL context using OSMesa */
patmandin@991
   540
	gl_convert = ConvertNull;
patmandin@991
   541
	gl_copyshadow = CopyShadowNull;
patmandin@1005
   542
	gl_upsidedown = SDL_FALSE;
patmandin@991
   543
patmandin@991
   544
	pixel_format = current->format;
patmandin@991
   545
	redmask = pixel_format->Rmask;
patmandin@991
   546
	switch (pixel_format->BitsPerPixel) {
patmandin@991
   547
		case 15:
patmandin@991
   548
			/* 15 bits unsupported */
patmandin@1000
   549
			if (tinygl_present) {
patmandin@1002
   550
				gl_pixelsize = 3;
patmandin@1000
   551
				osmesa_format = VDI_RGB;
patmandin@1000
   552
				if (redmask == 31<<10) {
patmandin@1000
   553
					gl_copyshadow = CopyShadowRGBTo555;
patmandin@1000
   554
				} else {
patmandin@1000
   555
					gl_copyshadow = CopyShadowRGBTo565;
patmandin@1000
   556
					gl_convert = Convert565To555le;
patmandin@1000
   557
				}
patmandin@991
   558
			} else {
patmandin@1002
   559
				gl_pixelsize = 4;
patmandin@1005
   560
				gl_upsidedown = SDL_TRUE;
patmandin@1000
   561
				osmesa_format = OSMESA_ARGB;
patmandin@1000
   562
				if (redmask == 31<<10) {
patmandin@1000
   563
					gl_copyshadow = CopyShadow8888To555;
patmandin@1000
   564
				} else {
patmandin@1000
   565
					gl_copyshadow = CopyShadow8888To565;
patmandin@1000
   566
					gl_convert = Convert565To555le;
patmandin@1000
   567
				}
patmandin@991
   568
			}
patmandin@991
   569
			break;
patmandin@991
   570
		case 16:
patmandin@991
   571
			/* 16 bits unsupported */
patmandin@1000
   572
			if (tinygl_present) {
patmandin@1002
   573
				gl_pixelsize = 3;
patmandin@1000
   574
				osmesa_format = VDI_RGB;
patmandin@1000
   575
				gl_copyshadow = CopyShadowRGBTo565;
patmandin@1000
   576
				if (redmask != 31<<11) {
patmandin@1000
   577
					/* 565, little endian, unsupported */
patmandin@1000
   578
					gl_convert = Convert565le;
patmandin@1000
   579
				}
patmandin@1000
   580
			} else {
patmandin@1002
   581
				gl_pixelsize = 4;
patmandin@1005
   582
				gl_upsidedown = SDL_TRUE;
patmandin@1000
   583
				osmesa_format = OSMESA_ARGB;
patmandin@1000
   584
				gl_copyshadow = CopyShadow8888To565;
patmandin@1000
   585
				if (redmask != 31<<11) {
patmandin@1000
   586
					/* 565, little endian, unsupported */
patmandin@1000
   587
					gl_convert = Convert565le;
patmandin@1000
   588
				}
patmandin@991
   589
			}
patmandin@991
   590
			break;
patmandin@991
   591
		case 24:
patmandin@991
   592
			gl_pixelsize = 3;
patmandin@1000
   593
			if (tinygl_present) {
patmandin@1000
   594
				osmesa_format = VDI_RGB;
patmandin@1000
   595
				gl_copyshadow = CopyShadowDirect;
patmandin@1000
   596
				if (redmask != 255<<16) {
patmandin@1000
   597
					gl_copyshadow = CopyShadowRGBSwap;
patmandin@1000
   598
				}
patmandin@991
   599
			} else {
patmandin@1000
   600
				gl_copyshadow = CopyShadowDirect;
patmandin@1005
   601
				gl_upsidedown = SDL_TRUE;
patmandin@1000
   602
				if (redmask == 255<<16) {
patmandin@1000
   603
					osmesa_format = OSMESA_RGB;
patmandin@1000
   604
				} else {
patmandin@1000
   605
					osmesa_format = OSMESA_BGR;
patmandin@1000
   606
				}
patmandin@991
   607
			}
patmandin@991
   608
			break;
patmandin@991
   609
		case 32:
patmandin@1000
   610
			if (tinygl_present) {
patmandin@1002
   611
				gl_pixelsize = 3;
patmandin@1000
   612
				osmesa_format = VDI_RGB;
patmandin@1000
   613
				gl_copyshadow = CopyShadowRGBToARGB;
patmandin@1000
   614
				if (redmask == 255) {
patmandin@1000
   615
					gl_convert = CopyShadowRGBToABGR;
patmandin@1000
   616
				} else if (redmask == 255<<8) {
patmandin@1000
   617
					gl_convert = CopyShadowRGBToBGRA;
patmandin@1000
   618
				} else if (redmask == 255<<24) {
patmandin@1000
   619
					gl_convert = CopyShadowRGBToRGBA;
patmandin@1000
   620
				}
patmandin@991
   621
			} else {
patmandin@1002
   622
				gl_pixelsize = 4;
patmandin@1005
   623
				gl_upsidedown = SDL_TRUE;
patmandin@1000
   624
				gl_copyshadow = CopyShadowDirect;
patmandin@1000
   625
				if (redmask == 255<<16) {
patmandin@1000
   626
					osmesa_format = OSMESA_ARGB;
patmandin@1000
   627
				} else if (redmask == 255<<8) {
patmandin@1000
   628
					osmesa_format = OSMESA_BGRA;
patmandin@1000
   629
				} else if (redmask == 255<<24) {
patmandin@1000
   630
					osmesa_format = OSMESA_RGBA;
patmandin@1000
   631
				} else {
patmandin@1000
   632
					/* ABGR format unsupported */
patmandin@1000
   633
					osmesa_format = OSMESA_BGRA;
patmandin@1000
   634
					gl_convert = ConvertBGRAToABGR;
patmandin@1000
   635
				}
patmandin@991
   636
			}
patmandin@991
   637
			break;
patmandin@991
   638
		default:
patmandin@1000
   639
			if (tinygl_present) {
patmandin@1000
   640
				SDL_AtariGL_Quit(this, SDL_FALSE);
patmandin@1000
   641
				return 0;
patmandin@1000
   642
			}
patmandin@991
   643
			gl_pixelsize = 1;
patmandin@991
   644
			gl_copyshadow = CopyShadowDirect;
patmandin@991
   645
			osmesa_format = OSMESA_COLOR_INDEX;
patmandin@991
   646
			break;
patmandin@991
   647
	}
patmandin@991
   648
patmandin@992
   649
	/* Try to keep current context if possible */
patmandin@992
   650
	recreatecontext=1;
patmandin@992
   651
	if (gl_shadow &&
patmandin@992
   652
		(gl_curformat == osmesa_format) &&
patmandin@992
   653
		(gl_curwidth == current->w) &&
patmandin@992
   654
		(gl_curheight == current->h)) {
patmandin@992
   655
		recreatecontext = 0;
patmandin@992
   656
	}
patmandin@992
   657
	if (recreatecontext) {
patmandin@992
   658
		SDL_AtariGL_Quit(this, SDL_FALSE);
patmandin@992
   659
patmandin@992
   660
		gl_shadow = this->gl_data->OSMesaCreateLDG(
patmandin@992
   661
			osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
patmandin@992
   662
		);
patmandin@992
   663
patmandin@992
   664
		if (gl_shadow) {
patmandin@992
   665
			gl_curformat = osmesa_format;
patmandin@992
   666
			gl_curwidth = current->w;
patmandin@992
   667
			gl_curheight = current->h;
patmandin@992
   668
		} else {
patmandin@992
   669
			gl_curformat = 0;
patmandin@992
   670
			gl_curwidth = 0;
patmandin@992
   671
			gl_curheight = 0;
patmandin@992
   672
		}
patmandin@992
   673
	}
patmandin@991
   674
patmandin@991
   675
	return (gl_shadow != NULL);
patmandin@991
   676
}
patmandin@991
   677
patmandin@991
   678
/*--- Conversions routines from shadow buffer to the screen ---*/
patmandin@991
   679
patmandin@991
   680
static void CopyShadowNull(_THIS, SDL_Surface *surface)
patmandin@989
   681
{
patmandin@989
   682
}
patmandin@989
   683
patmandin@991
   684
static void CopyShadowDirect(_THIS, SDL_Surface *surface)
patmandin@991
   685
{
patmandin@991
   686
	int y, srcpitch, dstpitch;
patmandin@991
   687
	Uint8 *srcline, *dstline;
patmandin@991
   688
patmandin@991
   689
	srcline = gl_shadow;
patmandin@991
   690
	srcpitch = surface->w * gl_pixelsize;
patmandin@991
   691
	dstline = surface->pixels;
patmandin@991
   692
	dstpitch = surface->pitch;
patmandin@1005
   693
	if (gl_upsidedown) {
patmandin@1005
   694
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   695
		srcpitch = -srcpitch;
patmandin@1005
   696
	}
patmandin@991
   697
patmandin@991
   698
	for (y=0; y<surface->h; y++) {
slouken@1336
   699
		SDL_memcpy(dstline, srcline, srcpitch);
patmandin@991
   700
patmandin@991
   701
		srcline += srcpitch;
patmandin@991
   702
		dstline += dstpitch;
patmandin@991
   703
	}
patmandin@991
   704
}
patmandin@991
   705
patmandin@1000
   706
static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface)
patmandin@1000
   707
{
patmandin@1000
   708
	int x,y, srcpitch, dstpitch;
patmandin@1000
   709
	Uint16 *dstline, *dstcol;
patmandin@1000
   710
	Uint8 *srcline, *srccol;
patmandin@1000
   711
patmandin@1000
   712
	srcline = (Uint8 *)gl_shadow;
patmandin@1002
   713
	srcpitch = surface->w * gl_pixelsize;
patmandin@1000
   714
	dstline = surface->pixels;
patmandin@1000
   715
	dstpitch = surface->pitch >>1;
patmandin@1005
   716
	if (gl_upsidedown) {
patmandin@1005
   717
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   718
		srcpitch = -srcpitch;
patmandin@1005
   719
	}
patmandin@1000
   720
patmandin@1000
   721
	for (y=0; y<surface->h; y++) {
patmandin@1000
   722
		srccol = srcline;
patmandin@1000
   723
		dstcol = dstline;
patmandin@1000
   724
		for (x=0; x<surface->w; x++) {
patmandin@1000
   725
			Uint16 dstcolor;
patmandin@1000
   726
			
patmandin@1003
   727
			dstcolor = ((*srccol++)<<7) & (31<<10);
patmandin@1003
   728
			dstcolor |= ((*srccol++)<<2) & (31<<5);
patmandin@1000
   729
			dstcolor |= ((*srccol++)>>3) & 31;
patmandin@1000
   730
			*dstcol++ = dstcolor;
patmandin@1000
   731
		}
patmandin@1000
   732
patmandin@1000
   733
		srcline += srcpitch;
patmandin@1000
   734
		dstline += dstpitch;
patmandin@1000
   735
	}
patmandin@1000
   736
}
patmandin@1000
   737
patmandin@1000
   738
static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface)
patmandin@1000
   739
{
patmandin@1000
   740
	int x,y, srcpitch, dstpitch;
patmandin@1000
   741
	Uint16 *dstline, *dstcol;
patmandin@1000
   742
	Uint8 *srcline, *srccol;
patmandin@1000
   743
patmandin@1000
   744
	srcline = (Uint8 *)gl_shadow;
patmandin@1002
   745
	srcpitch = surface->w * gl_pixelsize;
patmandin@1000
   746
	dstline = surface->pixels;
patmandin@1000
   747
	dstpitch = surface->pitch >>1;
patmandin@1005
   748
	if (gl_upsidedown) {
patmandin@1005
   749
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   750
		srcpitch = -srcpitch;
patmandin@1005
   751
	}
patmandin@1000
   752
patmandin@1000
   753
	for (y=0; y<surface->h; y++) {
patmandin@1000
   754
		srccol = srcline;
patmandin@1000
   755
		dstcol = dstline;
patmandin@1000
   756
patmandin@1000
   757
		for (x=0; x<surface->w; x++) {
patmandin@1000
   758
			Uint16 dstcolor;
patmandin@1000
   759
			
patmandin@1003
   760
			dstcolor = ((*srccol++)<<8) & (31<<11);
patmandin@1003
   761
			dstcolor |= ((*srccol++)<<3) & (63<<5);
patmandin@1000
   762
			dstcolor |= ((*srccol++)>>3) & 31;
patmandin@1000
   763
			*dstcol++ = dstcolor;
patmandin@1000
   764
		}
patmandin@1000
   765
patmandin@1000
   766
		srcline += srcpitch;
patmandin@1000
   767
		dstline += dstpitch;
patmandin@1000
   768
	}
patmandin@1000
   769
}
patmandin@1000
   770
patmandin@1000
   771
static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface)
patmandin@1000
   772
{
patmandin@1000
   773
	int x,y, srcpitch, dstpitch;
patmandin@1000
   774
	Uint8 *dstline, *dstcol;
patmandin@1000
   775
	Uint8 *srcline, *srccol;
patmandin@1000
   776
patmandin@1000
   777
	srcline = (Uint8 *)gl_shadow;
patmandin@1002
   778
	srcpitch = surface->w * gl_pixelsize;
patmandin@1000
   779
	dstline = surface->pixels;
patmandin@1000
   780
	dstpitch = surface->pitch;
patmandin@1005
   781
	if (gl_upsidedown) {
patmandin@1005
   782
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   783
		srcpitch = -srcpitch;
patmandin@1005
   784
	}
patmandin@1000
   785
patmandin@1000
   786
	for (y=0; y<surface->h; y++) {
patmandin@1000
   787
		srccol = srcline;
patmandin@1000
   788
		dstcol = dstline;
patmandin@1000
   789
patmandin@1000
   790
		for (x=0; x<surface->w; x++) {
patmandin@1000
   791
			*dstcol++ = srccol[2];
patmandin@1000
   792
			*dstcol++ = srccol[1];
patmandin@1000
   793
			*dstcol++ = srccol[0];
patmandin@1000
   794
			srccol += 3;
patmandin@1000
   795
		}
patmandin@1000
   796
patmandin@1000
   797
		srcline += srcpitch;
patmandin@1000
   798
		dstline += dstpitch;
patmandin@1000
   799
	}
patmandin@1000
   800
}
patmandin@1000
   801
patmandin@1000
   802
static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface)
patmandin@1000
   803
{
patmandin@1000
   804
	int x,y, srcpitch, dstpitch;
patmandin@1000
   805
	Uint32 *dstline, *dstcol;
patmandin@1000
   806
	Uint8 *srcline, *srccol;
patmandin@1000
   807
patmandin@1000
   808
	srcline = (Uint8 *)gl_shadow;
patmandin@1002
   809
	srcpitch = surface->w * gl_pixelsize;
patmandin@1000
   810
	dstline = surface->pixels;
patmandin@1000
   811
	dstpitch = surface->pitch >>2;
patmandin@1005
   812
	if (gl_upsidedown) {
patmandin@1005
   813
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   814
		srcpitch = -srcpitch;
patmandin@1005
   815
	}
patmandin@1000
   816
patmandin@1000
   817
	for (y=0; y<surface->h; y++) {
patmandin@1000
   818
		srccol = srcline;
patmandin@1000
   819
		dstcol = dstline;
patmandin@1000
   820
patmandin@1000
   821
		for (x=0; x<surface->w; x++) {
patmandin@1000
   822
			Uint32	dstcolor;
patmandin@1000
   823
patmandin@1000
   824
			dstcolor = (*srccol++)<<16;
patmandin@1000
   825
			dstcolor |= (*srccol++)<<8;
patmandin@1000
   826
			dstcolor |= *srccol++;
patmandin@1000
   827
patmandin@1000
   828
			*dstcol++ = dstcolor;
patmandin@1000
   829
		}
patmandin@1000
   830
patmandin@1000
   831
		srcline += srcpitch;
patmandin@1000
   832
		dstline += dstpitch;
patmandin@1000
   833
	}
patmandin@1000
   834
}
patmandin@1000
   835
patmandin@1000
   836
static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface)
patmandin@1000
   837
{
patmandin@1000
   838
	int x,y, srcpitch, dstpitch;
patmandin@1000
   839
	Uint32 *dstline, *dstcol;
patmandin@1000
   840
	Uint8 *srcline, *srccol;
patmandin@1000
   841
patmandin@1000
   842
	srcline = (Uint8 *)gl_shadow;
patmandin@1002
   843
	srcpitch = surface->w * gl_pixelsize;
patmandin@1000
   844
	dstline = surface->pixels;
patmandin@1000
   845
	dstpitch = surface->pitch >>2;
patmandin@1005
   846
	if (gl_upsidedown) {
patmandin@1005
   847
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   848
		srcpitch = -srcpitch;
patmandin@1005
   849
	}
patmandin@1000
   850
patmandin@1000
   851
	for (y=0; y<surface->h; y++) {
patmandin@1000
   852
		srccol = srcline;
patmandin@1000
   853
		dstcol = dstline;
patmandin@1000
   854
patmandin@1000
   855
		for (x=0; x<surface->w; x++) {
patmandin@1000
   856
			Uint32	dstcolor;
patmandin@1000
   857
patmandin@1000
   858
			dstcolor = *srccol++;
patmandin@1000
   859
			dstcolor |= (*srccol++)<<8;
patmandin@1000
   860
			dstcolor |= (*srccol++)<<16;
patmandin@1000
   861
patmandin@1000
   862
			*dstcol++ = dstcolor;
patmandin@1000
   863
		}
patmandin@1000
   864
patmandin@1000
   865
		srcline += srcpitch;
patmandin@1000
   866
		dstline += dstpitch;
patmandin@1000
   867
	}
patmandin@1000
   868
}
patmandin@1000
   869
patmandin@1000
   870
static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface)
patmandin@1000
   871
{
patmandin@1000
   872
	int x,y, srcpitch, dstpitch;
patmandin@1000
   873
	Uint32 *dstline, *dstcol;
patmandin@1000
   874
	Uint8 *srcline, *srccol;
patmandin@1000
   875
patmandin@1000
   876
	srcline = (Uint8 *)gl_shadow;
patmandin@1002
   877
	srcpitch = surface->w * gl_pixelsize;
patmandin@1000
   878
	dstline = surface->pixels;
patmandin@1000
   879
	dstpitch = surface->pitch >>2;
patmandin@1005
   880
	if (gl_upsidedown) {
patmandin@1005
   881
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   882
		srcpitch = -srcpitch;
patmandin@1005
   883
	}
patmandin@1000
   884
patmandin@1000
   885
	for (y=0; y<surface->h; y++) {
patmandin@1000
   886
		srccol = srcline;
patmandin@1000
   887
		dstcol = dstline;
patmandin@1000
   888
patmandin@1000
   889
		for (x=0; x<surface->w; x++) {
patmandin@1000
   890
			Uint32	dstcolor;
patmandin@1000
   891
patmandin@1000
   892
			dstcolor = (*srccol++)<<8;
patmandin@1000
   893
			dstcolor |= (*srccol++)<<16;
patmandin@1000
   894
			dstcolor |= (*srccol++)<<24;
patmandin@1000
   895
patmandin@1000
   896
			*dstcol++ = dstcolor;
patmandin@1000
   897
		}
patmandin@1000
   898
patmandin@1000
   899
		srcline += srcpitch;
patmandin@1000
   900
		dstline += dstpitch;
patmandin@1000
   901
	}
patmandin@1000
   902
}
patmandin@1000
   903
patmandin@1000
   904
static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface)
patmandin@1000
   905
{
patmandin@1000
   906
	int x,y, srcpitch, dstpitch;
patmandin@1000
   907
	Uint32 *dstline, *dstcol;
patmandin@1000
   908
	Uint8 *srcline, *srccol;
patmandin@1000
   909
patmandin@1000
   910
	srcline = (Uint8 *)gl_shadow;
patmandin@1002
   911
	srcpitch = surface->w * gl_pixelsize;
patmandin@1000
   912
	dstline = surface->pixels;
patmandin@1000
   913
	dstpitch = surface->pitch >>2;
patmandin@1005
   914
	if (gl_upsidedown) {
patmandin@1005
   915
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   916
		srcpitch = -srcpitch;
patmandin@1005
   917
	}
patmandin@1000
   918
patmandin@1000
   919
	for (y=0; y<surface->h; y++) {
patmandin@1000
   920
		srccol = srcline;
patmandin@1000
   921
		dstcol = dstline;
patmandin@1000
   922
patmandin@1000
   923
		for (x=0; x<surface->w; x++) {
patmandin@1000
   924
			Uint32	dstcolor;
patmandin@1000
   925
patmandin@1000
   926
			dstcolor = (*srccol++)<<24;
patmandin@1000
   927
			dstcolor |= (*srccol++)<<16;
patmandin@1000
   928
			dstcolor |= (*srccol++)<<8;
patmandin@1000
   929
patmandin@1000
   930
			*dstcol++ = dstcolor;
patmandin@1000
   931
		}
patmandin@1000
   932
patmandin@1000
   933
		srcline += srcpitch;
patmandin@1000
   934
		dstline += dstpitch;
patmandin@1000
   935
	}
patmandin@1000
   936
}
patmandin@1000
   937
patmandin@991
   938
static void CopyShadow8888To555(_THIS, SDL_Surface *surface)
patmandin@991
   939
{
patmandin@991
   940
	int x,y, srcpitch, dstpitch;
patmandin@991
   941
	Uint16 *dstline, *dstcol;
patmandin@991
   942
	Uint32 *srcline, *srccol;
patmandin@991
   943
patmandin@991
   944
	srcline = (Uint32 *)gl_shadow;
patmandin@1002
   945
	srcpitch = (surface->w * gl_pixelsize) >>2;
patmandin@991
   946
	dstline = surface->pixels;
patmandin@991
   947
	dstpitch = surface->pitch >>1;
patmandin@1005
   948
	if (gl_upsidedown) {
patmandin@1005
   949
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   950
		srcpitch = -srcpitch;
patmandin@1005
   951
	}
patmandin@991
   952
patmandin@991
   953
	for (y=0; y<surface->h; y++) {
patmandin@991
   954
		srccol = srcline;
patmandin@991
   955
		dstcol = dstline;
patmandin@991
   956
		for (x=0; x<surface->w; x++) {
patmandin@991
   957
			Uint32 srccolor;
patmandin@991
   958
			Uint16 dstcolor;
patmandin@991
   959
			
patmandin@991
   960
			srccolor = *srccol++;
patmandin@991
   961
			dstcolor = (srccolor>>9) & (31<<10);
patmandin@991
   962
			dstcolor |= (srccolor>>6) & (31<<5);
patmandin@991
   963
			dstcolor |= (srccolor>>3) & 31;
patmandin@991
   964
			*dstcol++ = dstcolor;
patmandin@991
   965
		}
patmandin@991
   966
patmandin@991
   967
		srcline += srcpitch;
patmandin@991
   968
		dstline += dstpitch;
patmandin@991
   969
	}
patmandin@991
   970
}
patmandin@991
   971
patmandin@991
   972
static void CopyShadow8888To565(_THIS, SDL_Surface *surface)
patmandin@991
   973
{
patmandin@991
   974
	int x,y, srcpitch, dstpitch;
patmandin@991
   975
	Uint16 *dstline, *dstcol;
patmandin@991
   976
	Uint32 *srcline, *srccol;
patmandin@991
   977
patmandin@991
   978
	srcline = (Uint32 *)gl_shadow;
patmandin@1002
   979
	srcpitch = (surface->w * gl_pixelsize) >> 2;
patmandin@991
   980
	dstline = surface->pixels;
patmandin@991
   981
	dstpitch = surface->pitch >>1;
patmandin@1005
   982
	if (gl_upsidedown) {
patmandin@1005
   983
		srcline += (surface->h-1)*srcpitch;
patmandin@1005
   984
		srcpitch = -srcpitch;
patmandin@1005
   985
	}
patmandin@991
   986
patmandin@991
   987
	for (y=0; y<surface->h; y++) {
patmandin@991
   988
		srccol = srcline;
patmandin@991
   989
		dstcol = dstline;
patmandin@991
   990
patmandin@991
   991
		for (x=0; x<surface->w; x++) {
patmandin@991
   992
			Uint32 srccolor;
patmandin@991
   993
			Uint16 dstcolor;
patmandin@991
   994
			
patmandin@991
   995
			srccolor = *srccol++;
patmandin@991
   996
			dstcolor = (srccolor>>8) & (31<<11);
patmandin@991
   997
			dstcolor |= (srccolor>>5) & (63<<5);
patmandin@991
   998
			dstcolor |= (srccolor>>3) & 31;
patmandin@991
   999
			*dstcol++ = dstcolor;
patmandin@991
  1000
		}
patmandin@991
  1001
patmandin@991
  1002
		srcline += srcpitch;
patmandin@991
  1003
		dstline += dstpitch;
patmandin@991
  1004
	}
patmandin@991
  1005
}
patmandin@991
  1006
patmandin@991
  1007
/*--- Conversions routines in the screen ---*/
patmandin@991
  1008
patmandin@991
  1009
static void ConvertNull(_THIS, SDL_Surface *surface)
patmandin@991
  1010
{
patmandin@991
  1011
}
patmandin@991
  1012
patmandin@991
  1013
static void Convert565To555be(_THIS, SDL_Surface *surface)
patmandin@989
  1014
{
patmandin@989
  1015
	int x,y, pitch;
patmandin@989
  1016
	unsigned short *line, *pixel;
patmandin@989
  1017
patmandin@989
  1018
	line = surface->pixels;
patmandin@989
  1019
	pitch = surface->pitch >> 1;
patmandin@989
  1020
	for (y=0; y<surface->h; y++) {
patmandin@989
  1021
		pixel = line;
patmandin@989
  1022
		for (x=0; x<surface->w; x++) {
patmandin@989
  1023
			unsigned short color = *pixel;
patmandin@989
  1024
patmandin@989
  1025
			*pixel++ = (color & 0x1f)|((color>>1) & 0xffe0);
patmandin@989
  1026
		}
patmandin@989
  1027
patmandin@989
  1028
		line += pitch;
patmandin@989
  1029
	}
patmandin@989
  1030
}
patmandin@989
  1031
patmandin@991
  1032
static void Convert565To555le(_THIS, SDL_Surface *surface)
patmandin@989
  1033
{
patmandin@989
  1034
	int x,y, pitch;
patmandin@989
  1035
	unsigned short *line, *pixel;
patmandin@989
  1036
patmandin@989
  1037
	line = surface->pixels;
patmandin@989
  1038
	pitch = surface->pitch >>1;
patmandin@989
  1039
	for (y=0; y<surface->h; y++) {
patmandin@989
  1040
		pixel = line;
patmandin@989
  1041
		for (x=0; x<surface->w; x++) {
patmandin@989
  1042
			unsigned short color = *pixel;
patmandin@989
  1043
patmandin@989
  1044
			color = (color & 0x1f)|((color>>1) & 0xffe0);
patmandin@989
  1045
			*pixel++ = SDL_Swap16(color);
patmandin@989
  1046
		}
patmandin@989
  1047
patmandin@989
  1048
		line += pitch;
patmandin@989
  1049
	}
patmandin@989
  1050
}
patmandin@989
  1051
patmandin@991
  1052
static void Convert565le(_THIS, SDL_Surface *surface)
patmandin@989
  1053
{
patmandin@989
  1054
	int x,y, pitch;
patmandin@989
  1055
	unsigned short *line, *pixel;
patmandin@989
  1056
patmandin@989
  1057
	line = surface->pixels;
patmandin@989
  1058
	pitch = surface->pitch >>1;
patmandin@989
  1059
	for (y=0; y<surface->h; y++) {
patmandin@989
  1060
		pixel = line;
patmandin@989
  1061
		for (x=0; x<surface->w; x++) {
patmandin@989
  1062
			unsigned short color = *pixel;
patmandin@989
  1063
patmandin@989
  1064
			*pixel++ = SDL_Swap16(color);
patmandin@989
  1065
		}
patmandin@989
  1066
patmandin@989
  1067
		line += pitch;
patmandin@989
  1068
	}
patmandin@989
  1069
}
patmandin@989
  1070
patmandin@991
  1071
static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface)
patmandin@989
  1072
{
patmandin@989
  1073
	int x,y, pitch;
patmandin@989
  1074
	unsigned long *line, *pixel;
patmandin@989
  1075
patmandin@989
  1076
	line = surface->pixels;
patmandin@989
  1077
	pitch = surface->pitch >>2;
patmandin@989
  1078
	for (y=0; y<surface->h; y++) {
patmandin@989
  1079
		pixel = line;
patmandin@989
  1080
		for (x=0; x<surface->w; x++) {
patmandin@989
  1081
			unsigned long color = *pixel;
patmandin@989
  1082
patmandin@989
  1083
			*pixel++ = (color<<24)|(color>>8);
patmandin@989
  1084
		}
patmandin@989
  1085
patmandin@989
  1086
		line += pitch;
patmandin@989
  1087
	}
patmandin@989
  1088
}
patmandin@1000
  1089
patmandin@1000
  1090
#endif /* HAVE_OPENGL */