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