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