Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
1127 lines (966 loc) · 29 KB

SDL_atarigl.c

File metadata and controls

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