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

Latest commit

 

History

History
2465 lines (2161 loc) · 68.4 KB

SDL_glsdl.c

File metadata and controls

2465 lines (2161 loc) · 68.4 KB
 
May 1, 2006
May 1, 2006
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/*
* glSDL "SDL-over-OpenGL" video driver implemented by
* David Olofson <david@olofson.net> and
* Stephane Marchesin <stephane.marchesin@wanadoo.fr>
*/
#include <math.h>
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "SDL_glsdl.h"
#undef DEBUG_GLSDL
#undef DEBUG_GLSDL_CHOP
#define FAKE_MAXTEXSIZE 256
#undef GLSDL_GRAPHICAL_DEBUG
/* Initialization/Query functions */
/* Hardware surface functions */
May 29, 2006
May 29, 2006
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
static int glSDL_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color * colors);
static int glSDL_AllocHWSurface(_THIS, SDL_Surface * surface);
static int glSDL_LockHWSurface(_THIS, SDL_Surface * surface);
static int glSDL_FlipHWSurface(_THIS, SDL_Surface * surface);
static void glSDL_UnlockHWSurface(_THIS, SDL_Surface * surface);
static void glSDL_FreeHWSurface(_THIS, SDL_Surface * surface);
static int glSDL_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect,
Uint32 color);
static int glSDL_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst);
static int glSDL_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key);
static int glSDL_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha);
static int glSDL_VideoInit(_THIS, SDL_PixelFormat * vformat);
static SDL_Rect **glSDL_ListModes(_THIS, SDL_PixelFormat * format,
Uint32 flags);
static void glSDL_VideoQuit(_THIS);
static void glSDL_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
static SDL_Surface *glSDL_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp,
Uint32 flags);
May 1, 2006
May 1, 2006
68
69
70
71
72
73
74
75
76
77
78
79
80
#define IS_GLSDL_SURFACE(s) ((s) && glSDL_GetTexInfo(s))
#define LOGIC_W(s) ( IS_GLSDL_SURFACE(this,s) ? TEXINFO(s)->lw : (s)->w )
#define LOGIC_H(s) ( IS_GLSDL_SURFACE(this,s) ? TEXINFO(s)->lh : (s)->h )
#define GLSDL_NOTEX (~0)
/*
* Special version for glSDL, which ignores the fake SDL_HWSURFACE
* flags, so we don't have SDL calling us back whenever we want to
* do some internal blitting...
*/
May 28, 2006
May 28, 2006
81
static void
May 29, 2006
May 29, 2006
82
83
glSDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
May 1, 2006
May 1, 2006
84
{
May 28, 2006
May 28, 2006
85
86
87
88
89
90
91
92
93
SDL_BlitInfo info;
if (srcrect)
if (!srcrect->w || !srcrect->h)
return;
/* Check to make sure the blit mapping is valid */
if ((src->map->dst != dst) ||
(src->map->dst->format_version != src->map->format_version))
May 29, 2006
May 29, 2006
94
if (SDL_MapSurface(src, dst) < 0)
May 28, 2006
May 28, 2006
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
return;
/* Set up the blit information */
if (srcrect) {
info.s_pixels = (Uint8 *) src->pixels +
(Uint16) srcrect->y * src->pitch +
(Uint16) srcrect->x * src->format->BytesPerPixel;
info.s_width = srcrect->w;
info.s_height = srcrect->h;
} else {
info.s_pixels = (Uint8 *) src->pixels;
info.s_width = src->w;
info.s_height = src->h;
}
info.s_skip = src->pitch - info.s_width * src->format->BytesPerPixel;
if (dstrect) {
info.d_pixels = (Uint8 *) dst->pixels +
(Uint16) dstrect->y * dst->pitch +
(Uint16) dstrect->x * dst->format->BytesPerPixel;
/*
* NOTE: SDL_SoftBlit() uses the 'dstrect' for this!
* This version is more like SDL_BlitSurface().
*/
info.d_width = srcrect->w;
info.d_height = srcrect->h;
} else {
info.d_pixels = (Uint8 *) dst->pixels;
info.d_width = dst->w;
info.d_height = dst->h;
}
info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel;
info.aux_data = src->map->sw_data->aux_data;
info.src = src->format;
info.table = src->map->table;
info.dst = dst->format;
May 29, 2006
May 29, 2006
131
src->map->sw_data->blit(&info);
May 1, 2006
May 1, 2006
132
133
134
135
136
137
138
139
}
/*
* Another special version. Doesn't lock/unlock, and doesn't mess
* with flags and stuff. It just converts the surface, period.
* Does not convert into palletized formats.
*/
May 28, 2006
May 28, 2006
140
static SDL_Surface *
May 29, 2006
May 29, 2006
141
142
glSDL_ConvertSurface(SDL_Surface * surface,
SDL_PixelFormat * format, Uint32 flags)
May 1, 2006
May 1, 2006
143
{
May 28, 2006
May 28, 2006
144
145
146
147
148
149
150
SDL_Surface *convert;
Uint32 colorkey = 0;
Uint8 alpha = 0;
Uint32 surface_flags;
SDL_Rect bounds;
/* Create a new surface with the desired format */
May 29, 2006
May 29, 2006
151
152
153
154
155
convert = SDL_CreateRGBSurface(flags,
surface->w, surface->h,
format->BitsPerPixel, format->Rmask,
format->Gmask, format->Bmask,
format->Amask);
May 28, 2006
May 28, 2006
156
157
158
159
160
161
162
163
164
165
166
167
if (convert == NULL) {
return (NULL);
}
/* Save the original surface color key and alpha */
surface_flags = surface->flags;
if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
/* Convert colourkeyed surfaces to RGBA if requested */
if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) {
surface_flags &= ~SDL_SRCCOLORKEY;
} else {
colorkey = surface->format->colorkey;
May 29, 2006
May 29, 2006
168
SDL_SetColorKey(surface, 0, 0);
May 28, 2006
May 28, 2006
169
170
171
172
173
174
175
176
}
}
if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
/* Copy over the alpha channel to RGBA if requested */
if (format->Amask) {
surface->flags &= ~SDL_SRCALPHA;
} else {
alpha = surface->format->alpha;
May 29, 2006
May 29, 2006
177
SDL_SetAlpha(surface, 0, 0);
May 28, 2006
May 28, 2006
178
179
180
181
182
183
184
185
}
}
/* Copy over the image data */
bounds.x = 0;
bounds.y = 0;
bounds.w = surface->w;
bounds.h = surface->h;
May 29, 2006
May 29, 2006
186
glSDL_SoftBlit(surface, &bounds, convert, &bounds);
May 28, 2006
May 28, 2006
187
188
189
/* Clean up the original surface, and update converted surface */
if (convert != NULL) {
May 29, 2006
May 29, 2006
190
SDL_SetClipRect(convert, &surface->clip_rect);
May 28, 2006
May 28, 2006
191
192
193
194
195
196
}
if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
if (convert != NULL) {
Uint8 keyR, keyG, keyB;
May 29, 2006
May 29, 2006
197
198
199
SDL_GetRGB(colorkey, surface->format, &keyR, &keyG, &keyB);
SDL_SetColorKey(convert, cflags | (flags & SDL_RLEACCELOK),
SDL_MapRGB(convert->format, keyR, keyG, keyB));
May 28, 2006
May 28, 2006
200
}
May 29, 2006
May 29, 2006
201
SDL_SetColorKey(surface, cflags, colorkey);
May 28, 2006
May 28, 2006
202
203
204
205
}
if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
if (convert != NULL) {
May 29, 2006
May 29, 2006
206
SDL_SetAlpha(convert, aflags | (flags & SDL_RLEACCELOK), alpha);
May 28, 2006
May 28, 2006
207
208
209
210
}
if (format->Amask) {
surface->flags |= SDL_SRCALPHA;
} else {
May 29, 2006
May 29, 2006
211
SDL_SetAlpha(surface, aflags, alpha);
May 28, 2006
May 28, 2006
212
213
214
215
216
}
}
/* We're ready to go! */
return (convert);
May 1, 2006
May 1, 2006
217
218
219
220
221
222
223
224
225
}
/*----------------------------------------------------------
Some OpenGL function wrappers
----------------------------------------------------------*/
static struct
{
May 28, 2006
May 28, 2006
226
227
228
229
int do_blend;
int do_texture;
GLuint texture;
GLenum sfactor, dfactor;
May 1, 2006
May 1, 2006
230
231
} glstate;
May 28, 2006
May 28, 2006
232
static void
May 29, 2006
May 29, 2006
233
glSDL_reset(void)
May 1, 2006
May 1, 2006
234
{
May 28, 2006
May 28, 2006
235
236
237
238
239
glstate.do_blend = -1;
glstate.do_blend = -1;
glstate.texture = GLSDL_NOTEX;
glstate.sfactor = 0xffffffff;
glstate.dfactor = 0xffffffff;
May 1, 2006
May 1, 2006
240
241
}
May 28, 2006
May 28, 2006
242
static __inline__ void
May 29, 2006
May 29, 2006
243
glSDL_do_blend(_THIS, int on)
May 1, 2006
May 1, 2006
244
{
May 28, 2006
May 28, 2006
245
246
247
248
if (glstate.do_blend == on)
return;
if (on)
May 29, 2006
May 29, 2006
249
this->glEnable(GL_BLEND);
May 28, 2006
May 28, 2006
250
else
May 29, 2006
May 29, 2006
251
this->glDisable(GL_BLEND);
May 28, 2006
May 28, 2006
252
glstate.do_blend = on;
May 1, 2006
May 1, 2006
253
254
}
May 28, 2006
May 28, 2006
255
static __inline__ void
May 29, 2006
May 29, 2006
256
glSDL_do_texture(_THIS, int on)
May 1, 2006
May 1, 2006
257
{
May 28, 2006
May 28, 2006
258
259
260
261
if (glstate.do_texture == on)
return;
if (on)
May 29, 2006
May 29, 2006
262
this->glEnable(GL_TEXTURE_2D);
May 28, 2006
May 28, 2006
263
else
May 29, 2006
May 29, 2006
264
this->glDisable(GL_TEXTURE_2D);
May 28, 2006
May 28, 2006
265
glstate.do_texture = on;
May 1, 2006
May 1, 2006
266
267
}
May 28, 2006
May 28, 2006
268
static __inline__ void
May 29, 2006
May 29, 2006
269
glSDL_blendfunc(_THIS, GLenum sfactor, GLenum dfactor)
May 1, 2006
May 1, 2006
270
{
May 28, 2006
May 28, 2006
271
272
if ((sfactor == glstate.sfactor) && (dfactor == glstate.dfactor))
return;
May 1, 2006
May 1, 2006
273
May 29, 2006
May 29, 2006
274
this->glBlendFunc(sfactor, dfactor);
May 1, 2006
May 1, 2006
275
May 28, 2006
May 28, 2006
276
277
glstate.sfactor = sfactor;
glstate.dfactor = dfactor;
May 1, 2006
May 1, 2006
278
279
}
May 28, 2006
May 28, 2006
280
static __inline__ void
May 29, 2006
May 29, 2006
281
glSDL_texture(_THIS, GLuint tx)
May 1, 2006
May 1, 2006
282
{
May 28, 2006
May 28, 2006
283
284
if (tx == glstate.texture)
return;
May 1, 2006
May 1, 2006
285
May 29, 2006
May 29, 2006
286
this->glBindTexture(GL_TEXTURE_2D, tx);
May 28, 2006
May 28, 2006
287
glstate.texture = tx;
May 1, 2006
May 1, 2006
288
289
290
291
292
293
294
295
296
297
298
}
/*----------------------------------------------------------
glSDL specific data types
----------------------------------------------------------*/
typedef enum
{
May 28, 2006
May 28, 2006
299
300
301
302
GLSDL_TM_SINGLE,
GLSDL_TM_HORIZONTAL,
GLSDL_TM_VERTICAL,
GLSDL_TM_HUGE
May 1, 2006
May 1, 2006
303
304
305
306
307
} GLSDL_TileModes;
typedef struct private_hwdata
{
May 28, 2006
May 28, 2006
308
309
/* Size of surface in logic screen pixels */
int lw, lh;
May 1, 2006
May 1, 2006
310
May 28, 2006
May 28, 2006
311
312
313
314
315
316
317
int textures;
GLuint *texture;
int texsize; /* width/height of OpenGL texture */
GLSDL_TileModes tilemode;
int tilew, tileh; /* At least one must equal texsize! */
int tilespertex;
SDL_Rect virt; /* Total size of assembled surface */
May 1, 2006
May 1, 2006
318
May 28, 2006
May 28, 2006
319
320
/* Area of surface to upload when/after unlocking */
SDL_Rect invalid_area;
May 1, 2006
May 1, 2006
321
May 28, 2006
May 28, 2006
322
int temporary; /* Throw away after one use. */
May 1, 2006
May 1, 2006
323
May 28, 2006
May 28, 2006
324
325
SDL_Surface *next; /* The next Surface in our linked list of hardware surfaces ; == NULL if first surface */
SDL_Surface *prev; /* The prev Surface in our linked list of hardware surfaces ; == NULL if last surface */
May 1, 2006
May 1, 2006
326
327
328
} private_hwdata;
/* some function prototypes */
May 29, 2006
May 29, 2006
329
330
331
332
333
334
335
336
337
338
static void glSDL_Invalidate(SDL_Surface * surface, SDL_Rect * area);
static void glSDL_SetLogicSize(_THIS, SDL_Surface * surface, int w, int h);
static private_hwdata *glSDL_UploadSurface(_THIS, SDL_Surface * surface);
static private_hwdata *glSDL_GetTexInfo(SDL_Surface * surface);
static void glSDL_init_formats(_THIS);
static private_hwdata *glSDL_AddTexInfo(_THIS, SDL_Surface * surface);
static void glSDL_RemoveTexInfo(_THIS, SDL_Surface * surface);
static void glSDL_UnloadTexture(_THIS, private_hwdata * txi);
static int glSDL_BlitGL(_THIS, SDL_Surface * src,
SDL_Rect * srcrect, SDL_Rect * dstrect);
May 1, 2006
May 1, 2006
339
340
341
342
343
344
345
/* some variables */
static GLint maxtexsize = -1;
static SDL_PixelFormat *RGBfmt = NULL;
static SDL_PixelFormat *RGBAfmt = NULL;
static void *mirrorbuf = NULL;
/* the raw 888 opengl surface, hidden from the application */
May 28, 2006
May 28, 2006
346
SDL_Surface *OpenGL_Surface;
May 1, 2006
May 1, 2006
347
348
/* pointer to the beggining of the list used for memory allocation */
May 28, 2006
May 28, 2006
349
SDL_Surface *first = NULL;
May 1, 2006
May 1, 2006
350
351
#ifdef DEBUG_GLSDL
May 28, 2006
May 28, 2006
352
static __inline__ int
May 29, 2006
May 29, 2006
353
GLERET(const char *txt)
May 1, 2006
May 1, 2006
354
{
May 29, 2006
May 29, 2006
355
fprintf(stderr, "glSDL ERROR: '%s'\n", txt);
May 28, 2006
May 28, 2006
356
return -1;
May 1, 2006
May 1, 2006
357
}
May 28, 2006
May 28, 2006
358
static __inline__ void
May 29, 2006
May 29, 2006
359
GLERR(const char *txt)
May 1, 2006
May 1, 2006
360
{
May 29, 2006
May 29, 2006
361
fprintf(stderr, "glSDL ERROR: '%s'\n", txt);
May 1, 2006
May 1, 2006
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
}
#else
#define GLERET(x) (-1)
#define GLERR(x)
#endif
static SDL_VideoDevice underlying_device;
static int old_screen_flags;
/*
* List of video drivers known to support OpenGL
* The purpose of this is to make glSDL "portable" across
* all video backends that support OpenGL
*/
static VideoBootStrap *opengl_bootstrap =
#if SDL_VIDEO_DRIVER_QUARTZ
May 28, 2006
May 28, 2006
378
&QZ_bootstrap;
May 1, 2006
May 1, 2006
379
#elif SDL_VIDEO_DRIVER_X11
May 28, 2006
May 28, 2006
380
&X11_bootstrap;
May 1, 2006
May 1, 2006
381
#elif SDL_VIDEO_DRIVER_WINDIB
May 28, 2006
May 28, 2006
382
&WINDIB_bootstrap;
May 1, 2006
May 1, 2006
383
#elif SDL_VIDEO_DRIVER_BWINDOW
May 28, 2006
May 28, 2006
384
&BWINDOW_bootstrap;
May 1, 2006
May 1, 2006
385
#elif SDL_VIDEO_DRIVER_TOOLBOX
May 28, 2006
May 28, 2006
386
&TOOLBOX_bootstrap;
May 1, 2006
May 1, 2006
387
#elif SDL_VIDEO_DRIVER_CYBERGRAPHICS
May 28, 2006
May 28, 2006
388
&CGX_bootstrap;
May 1, 2006
May 1, 2006
389
#elif SDL_VIDEO_DRIVER_PHOTON
May 28, 2006
May 28, 2006
390
&ph_bootstrap;
May 1, 2006
May 1, 2006
391
#elif SDL_VIDEO_DRIVER_DC
May 28, 2006
May 28, 2006
392
&DC_bootstrap;
May 1, 2006
May 1, 2006
393
#else
May 28, 2006
May 28, 2006
394
NULL;
May 1, 2006
May 1, 2006
395
396
#endif
May 28, 2006
May 28, 2006
397
static int
May 29, 2006
May 29, 2006
398
glSDL_Available(void)
May 1, 2006
May 1, 2006
399
400
{
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
401
fprintf(stderr, "available\n");
May 1, 2006
May 1, 2006
402
#endif
May 28, 2006
May 28, 2006
403
404
if (opengl_bootstrap == NULL)
return 0;
May 29, 2006
May 29, 2006
405
return (opengl_bootstrap->available());
May 1, 2006
May 1, 2006
406
407
}
May 28, 2006
May 28, 2006
408
static void
May 29, 2006
May 29, 2006
409
glSDL_DeleteDevice(SDL_VideoDevice * device)
May 1, 2006
May 1, 2006
410
{
May 29, 2006
May 29, 2006
411
412
SDL_free(device->hidden);
SDL_free(device);
May 1, 2006
May 1, 2006
413
414
415
}
/* Create a glSDL device */
May 28, 2006
May 28, 2006
416
static SDL_VideoDevice *
May 29, 2006
May 29, 2006
417
glSDL_CreateDevice(int devindex)
May 1, 2006
May 1, 2006
418
{
May 28, 2006
May 28, 2006
419
SDL_VideoDevice *device;
May 1, 2006
May 1, 2006
420
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
421
fprintf(stderr, "entering createdevice\n");
May 1, 2006
May 1, 2006
422
423
#endif
May 28, 2006
May 28, 2006
424
/* Create the device with the underlying driver */
May 29, 2006
May 29, 2006
425
device = opengl_bootstrap->create(devindex);
May 28, 2006
May 28, 2006
426
427
/* Save the video device contents for future use */
May 29, 2006
May 29, 2006
428
SDL_memcpy(&underlying_device, device, sizeof(SDL_VideoDevice));
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
/* Hook glSDL on the video device */
device->VideoInit = glSDL_VideoInit;
device->ListModes = glSDL_ListModes;
device->VideoQuit = glSDL_VideoQuit;
device->UpdateRects = glSDL_UpdateRects;
device->FillHWRect = glSDL_FillHWRect;
device->SetHWColorKey = glSDL_SetHWColorKey;
device->SetHWAlpha = glSDL_SetHWAlpha;
device->AllocHWSurface = glSDL_AllocHWSurface;
device->LockHWSurface = glSDL_LockHWSurface;
device->UnlockHWSurface = glSDL_UnlockHWSurface;
device->FlipHWSurface = glSDL_FlipHWSurface;
device->FreeHWSurface = glSDL_FreeHWSurface;
device->CheckHWBlit = glSDL_CheckHWBlit;
device->SetColors = glSDL_SetColors;
device->SetVideoMode = glSDL_SetVideoMode;
device->info.hw_available = 1;
device->info.blit_hw = 1;
device->info.blit_hw_CC = 1;
device->info.blit_hw_A = 1;
device->info.blit_sw = 1;
device->info.blit_sw_CC = 1;
device->info.blit_sw_A = 1;
device->info.blit_fill = 1;
/* These functions are not supported by glSDL, so we NULLify them */
device->SetGamma = NULL;
device->GetGamma = NULL;
device->SetGammaRamp = NULL;
device->GetGammaRamp = NULL;
device->ToggleFullScreen = NULL;
device->free = glSDL_DeleteDevice;
May 1, 2006
May 1, 2006
463
464
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
465
fprintf(stderr, "leaving createdevice\n");
May 1, 2006
May 1, 2006
466
467
#endif
May 28, 2006
May 28, 2006
468
return device;
May 1, 2006
May 1, 2006
469
470
471
472
}
/* Our bootstraping structure */
VideoBootStrap glSDL_bootstrap = {
May 28, 2006
May 28, 2006
473
474
"glSDL", "glSDL - SDL over OpenGL",
glSDL_Available, glSDL_CreateDevice
May 1, 2006
May 1, 2006
475
476
};
May 28, 2006
May 28, 2006
477
static int
May 29, 2006
May 29, 2006
478
glSDL_VideoInit(_THIS, SDL_PixelFormat * vformat)
May 1, 2006
May 1, 2006
479
{
May 28, 2006
May 28, 2006
480
int r;
May 29, 2006
May 29, 2006
481
printf("glSDL videoinit\n");
May 1, 2006
May 1, 2006
482
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
483
fprintf(stderr, "videoinit\n");
May 1, 2006
May 1, 2006
484
#endif
May 29, 2006
May 29, 2006
485
r = underlying_device.VideoInit(this, vformat);
May 28, 2006
May 28, 2006
486
487
488
489
490
491
492
493
494
495
this->info.hw_available = 1;
this->info.blit_hw = 1;
this->info.blit_hw_CC = 1;
this->info.blit_hw_A = 1;
this->info.blit_sw = 1;
this->info.blit_sw_CC = 1;
this->info.blit_sw_A = 1;
this->info.blit_fill = 1;
return r;
May 1, 2006
May 1, 2006
496
497
}
May 28, 2006
May 28, 2006
498
SDL_Rect **
May 29, 2006
May 29, 2006
499
glSDL_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
May 1, 2006
May 1, 2006
500
{
May 28, 2006
May 28, 2006
501
return ((SDL_Rect **) - 1);
May 1, 2006
May 1, 2006
502
503
}
May 28, 2006
May 28, 2006
504
static void
May 29, 2006
May 29, 2006
505
glSDL_VideoQuit(_THIS)
May 1, 2006
May 1, 2006
506
{
May 28, 2006
May 28, 2006
507
508
509
510
SDL_Surface *scr;
/* free all hwdata structures */
while (first != NULL)
May 29, 2006
May 29, 2006
511
glSDL_RemoveTexInfo(this, first);
May 28, 2006
May 28, 2006
512
May 29, 2006
May 29, 2006
513
SDL_free(mirrorbuf);
May 28, 2006
May 28, 2006
514
515
mirrorbuf = NULL;
May 29, 2006
May 29, 2006
516
517
SDL_FreeFormat(RGBfmt);
SDL_FreeFormat(RGBAfmt);
May 28, 2006
May 28, 2006
518
519
RGBfmt = RGBAfmt = NULL;
May 29, 2006
May 29, 2006
520
SDL_FreeFormat(this->displayformatalphapixel);
May 28, 2006
May 28, 2006
521
522
this->displayformatalphapixel = NULL;
May 29, 2006
May 29, 2006
523
SDL_FreeSurface(OpenGL_Surface);
May 28, 2006
May 28, 2006
524
525
526
527
528
529
530
531
532
OpenGL_Surface = NULL;
/* restore the flags to gracefully exit from fullscreen */
this->screen->flags = old_screen_flags;
/* keep the screen */
scr = this->screen;
/* we cleaned up our stuff, now restore the underlying video driver */
May 29, 2006
May 29, 2006
533
SDL_memcpy(this, &underlying_device, sizeof(SDL_VideoDevice));
May 28, 2006
May 28, 2006
534
535
536
537
this->screen = scr;
/* call the underlying video driver's VideoQuit function */
May 29, 2006
May 29, 2006
538
this->VideoQuit(this);
May 1, 2006
May 1, 2006
539
540
}
May 28, 2006
May 28, 2006
541
static SDL_Surface *
May 29, 2006
May 29, 2006
542
543
glSDL_SetVideoMode(_THIS, SDL_Surface * current, int width, int height,
int bpp, Uint32 flags)
May 1, 2006
May 1, 2006
544
{
May 28, 2006
May 28, 2006
545
546
547
548
549
SDL_Surface *hooked_screen;
int i;
int flag_doublebuf = 0;
if (opengl_bootstrap == NULL) {
May 29, 2006
May 29, 2006
550
GLERR("No bootstrap for glSDL compiled in !\n");
May 28, 2006
May 28, 2006
551
552
553
554
555
return NULL;
}
/* we don't have OpenGL */
if ((flags & SDL_INTERNALOPENGL) == SDL_INTERNALOPENGL) {
May 29, 2006
May 29, 2006
556
GLERR("OpenGL video modes are not supported by glSDL !\n");
May 28, 2006
May 28, 2006
557
558
559
560
561
562
563
564
565
566
567
568
return (NULL);
}
/*
* Adjust the flags
*/
flags &= ~SDL_HWPALETTE;
flags |= SDL_INTERNALOPENGL;
/* remember whether the user requested DOUBLEBUF */
if (flags & SDL_DOUBLEBUF) {
May 29, 2006
May 29, 2006
569
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
May 28, 2006
May 28, 2006
570
571
flag_doublebuf = 1;
} else {
May 29, 2006
May 29, 2006
572
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
May 28, 2006
May 28, 2006
573
574
575
576
flag_doublebuf = 0;
}
hooked_screen =
May 29, 2006
May 29, 2006
577
578
underlying_device.SetVideoMode(this, current, width, height, 0,
flags);
May 28, 2006
May 28, 2006
579
580
if (!hooked_screen) {
May 29, 2006
May 29, 2006
581
GLERR("Unable to open an OpenGL window !\n");
May 28, 2006
May 28, 2006
582
583
584
585
586
return (NULL);
}
/* save the screen flags for restore time */
old_screen_flags = hooked_screen->flags;
May 1, 2006
May 1, 2006
587
588
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
589
fprintf(stderr, "got %d bpp\n", bpp);
May 1, 2006
May 1, 2006
590
591
#endif
May 28, 2006
May 28, 2006
592
593
594
595
596
597
/* setup the public surface format
* glSDL always returns the bpp its asked
*/
switch (bpp) {
case 32:
this->is_32bit = 1;
May 29, 2006
May 29, 2006
598
this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
May 1, 2006
May 1, 2006
599
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
May 29, 2006
May 29, 2006
600
601
0x00FF0000,
0x0000FF00, 0x000000FF, 0x00000000
May 1, 2006
May 1, 2006
602
#else
May 29, 2006
May 29, 2006
603
604
0x0000FF00,
0x00FF0000, 0xFF000000, 0x00000000
May 1, 2006
May 1, 2006
605
#endif
May 28, 2006
May 28, 2006
606
607
608
609
);
break;
case 24:
this->is_32bit = 0;
May 29, 2006
May 29, 2006
610
this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
May 1, 2006
May 1, 2006
611
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
May 29, 2006
May 29, 2006
612
613
0x00FF0000,
0x0000FF00, 0x000000FF, 0x00000000
May 1, 2006
May 1, 2006
614
#else
May 29, 2006
May 29, 2006
615
616
0x0000FF00,
0x00FF0000, 0xFF000000, 0x00000000
May 1, 2006
May 1, 2006
617
#endif
May 28, 2006
May 28, 2006
618
619
620
621
);
break;
case 16:
this->is_32bit = 0;
May 29, 2006
May 29, 2006
622
this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
May 1, 2006
May 1, 2006
623
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
May 29, 2006
May 29, 2006
624
625
0x0000F800,
0x000007E0, 0x0000001F, 0x00000000
May 1, 2006
May 1, 2006
626
#else
May 29, 2006
May 29, 2006
627
628
0x0000001F,
0x000007E0, 0x0000F800, 0x00000000
May 1, 2006
May 1, 2006
629
#endif
May 28, 2006
May 28, 2006
630
631
632
633
);
break;
case 15:
this->is_32bit = 0;
May 29, 2006
May 29, 2006
634
this->screen = SDL_CreateRGBSurface(flags, width, height, bpp,
May 1, 2006
May 1, 2006
635
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
May 29, 2006
May 29, 2006
636
637
0x00007C00,
0x000003E0, 0x0000001F, 0x00000000
May 1, 2006
May 1, 2006
638
#else
May 29, 2006
May 29, 2006
639
640
0x0000001F,
0x000003E0, 0x00007C00, 0x00000000
May 1, 2006
May 1, 2006
641
#endif
May 28, 2006
May 28, 2006
642
643
644
645
646
647
);
break;
case 8:
default:
this->is_32bit = 0;
this->screen =
May 29, 2006
May 29, 2006
648
SDL_CreateRGBSurface(flags, width, height, bpp, 0, 0, 0, 0);
May 28, 2006
May 28, 2006
649
650
651
/* give it a default palette if 8 bpp
* note : SDL already takes care of the palette for 4 bits & 1 bit surfaces
*/
May 1, 2006
May 1, 2006
652
653
654
655
656
/* if (bpp==8)
{
this->screen->format->palette->ncolors=255;
SDL_DitherColors(this->screen->format->palette->colors,bpp);
}*/
May 28, 2006
May 28, 2006
657
658
659
660
661
662
663
664
665
666
667
break;
}
/* also, we add SDL_HWSURFACE all the time, and let SDL create a shadow surface accordingly */
this->screen->flags =
hooked_screen->flags | SDL_HWSURFACE | SDL_INTERNALOPENGL;
/* add SDL_DOUBLEBUF if it was requested */
if (flag_doublebuf)
this->screen->flags |= SDL_DOUBLEBUF;
/* Tell SDL the alpha pixel format we'd like to have */
May 29, 2006
May 29, 2006
668
this->displayformatalphapixel = SDL_AllocFormat(32,
May 1, 2006
May 1, 2006
669
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
May 29, 2006
May 29, 2006
670
671
672
0xFF000000,
0x00FF0000,
0x0000FF00, 0x000000FF
May 1, 2006
May 1, 2006
673
#else
May 29, 2006
May 29, 2006
674
675
676
0x000000FF,
0x0000FF00,
0x00FF0000, 0xFF000000
May 1, 2006
May 1, 2006
677
#endif
May 28, 2006
May 28, 2006
678
);
May 1, 2006
May 1, 2006
679
May 28, 2006
May 28, 2006
680
/* Now create the raw OpenGL surface */
May 29, 2006
May 29, 2006
681
OpenGL_Surface = SDL_CreateRGBSurface(flags, width, height, 24,
May 1, 2006
May 1, 2006
682
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
May 29, 2006
May 29, 2006
683
684
0x000000FF,
0x0000FF00, 0x00FF0000, 0x00000000
May 1, 2006
May 1, 2006
685
#else
May 29, 2006
May 29, 2006
686
687
0xFF000000,
0x00FF0000, 0x0000FF00, 0x00000000
May 1, 2006
May 1, 2006
688
#endif
May 28, 2006
May 28, 2006
689
);
May 1, 2006
May 1, 2006
690
May 28, 2006
May 28, 2006
691
/* Here we have to setup OpenGL funcs ourselves */
May 1, 2006
May 1, 2006
692
693
694
695
696
697
698
699
700
701
702
703
704
#ifndef __QNXNTO__
#define SDL_PROC(ret,func,params) \
do { \
this->func = SDL_GL_GetProcAddress(#func); \
if ( ! this->func ) { \
SDL_SetError("Couldn't load GL function: %s\n", #func); \
return(NULL); \
} \
} while ( 0 );
#else
#define SDL_PROC(ret,func,params) this->func=func;
#endif /* __QNXNTO__ */
#include "../SDL_glfuncs.h"
May 28, 2006
May 28, 2006
705
#undef SDL_PROC
May 1, 2006
May 1, 2006
706
May 29, 2006
May 29, 2006
707
if (this->GL_MakeCurrent(this) < 0)
May 28, 2006
May 28, 2006
708
return (NULL);
May 1, 2006
May 1, 2006
709
710
711
712
713
714
715
716
717
#define SDL_PROC(ret,func,params) \
do { \
this->func = SDL_GL_GetProcAddress(#func); \
if ( ! this->func ) { \
SDL_SetError("Couldn't load GL function: %s\n", #func); \
return(NULL); \
} \
} while ( 0 );
#include "../SDL_glfuncs.h"
May 28, 2006
May 28, 2006
718
#undef SDL_PROC
May 1, 2006
May 1, 2006
719
720
721
#ifdef FAKE_MAXTEXSIZE
May 28, 2006
May 28, 2006
722
maxtexsize = FAKE_MAXTEXSIZE;
May 1, 2006
May 1, 2006
723
#else
May 29, 2006
May 29, 2006
724
this->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize);
May 1, 2006
May 1, 2006
725
726
#endif
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
727
fprintf(stderr, "glSDL: Max texture size: %d\n", maxtexsize);
May 1, 2006
May 1, 2006
728
729
#endif
May 29, 2006
May 29, 2006
730
glSDL_init_formats(this);
May 28, 2006
May 28, 2006
731
732
if (flag_doublebuf)
May 29, 2006
May 29, 2006
733
this->glDrawBuffer(GL_BACK);
May 28, 2006
May 28, 2006
734
else
May 29, 2006
May 29, 2006
735
this->glDrawBuffer(GL_FRONT);
May 28, 2006
May 28, 2006
736
May 29, 2006
May 29, 2006
737
this->glDisable(GL_DITHER);
May 28, 2006
May 28, 2006
738
May 29, 2006
May 29, 2006
739
740
if (glSDL_AddTexInfo(this, this->screen) < 0) {
GLERR("HookDevice() failed to add info to screen surface!");
May 28, 2006
May 28, 2006
741
742
743
return NULL;
}
May 29, 2006
May 29, 2006
744
glSDL_SetLogicSize(this, this->screen, this->screen->w, this->screen->h);
May 28, 2006
May 28, 2006
745
May 29, 2006
May 29, 2006
746
747
glSDL_do_texture(this, 0);
glSDL_do_blend(this, 0);
May 28, 2006
May 28, 2006
748
749
for (i = 0; i < 1 + flag_doublebuf; ++i) {
May 29, 2006
May 29, 2006
750
751
752
753
754
755
756
this->glBegin(GL_TRIANGLE_FAN);
this->glColor3ub(0, 0, 0);
this->glVertex2i(0, 0);
this->glVertex2i(this->screen->w, 0);
this->glVertex2i(this->screen->w, this->screen->h);
this->glVertex2i(0, this->screen->h);
this->glEnd();
May 28, 2006
May 28, 2006
757
if (!i)
May 29, 2006
May 29, 2006
758
this->GL_SwapBuffers(this);
May 28, 2006
May 28, 2006
759
760
}
May 29, 2006
May 29, 2006
761
mirrorbuf = SDL_malloc(this->screen->h * this->screen->pitch);
May 28, 2006
May 28, 2006
762
if (!mirrorbuf) {
May 29, 2006
May 29, 2006
763
GLERR("HookDevice() failed to allocate temp buffer for mirroring!");
May 28, 2006
May 28, 2006
764
765
766
767
return NULL;
}
return this->screen;
May 1, 2006
May 1, 2006
768
769
}
May 28, 2006
May 28, 2006
770
static int
May 29, 2006
May 29, 2006
771
glSDL_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
May 1, 2006
May 1, 2006
772
{
May 28, 2006
May 28, 2006
773
774
/* We don't need to fill this one */
return 0;
May 1, 2006
May 1, 2006
775
776
777
778
}
#ifdef DEBUG_GLSDL
May 28, 2006
May 28, 2006
779
static void
May 29, 2006
May 29, 2006
780
glSDL_print_glerror(_THIS, int point)
May 1, 2006
May 1, 2006
781
{
May 28, 2006
May 28, 2006
782
const char *err = "<unknown>";
May 29, 2006
May 29, 2006
783
switch (this->glGetError()) {
May 28, 2006
May 28, 2006
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
case GL_NO_ERROR:
return;
case GL_INVALID_ENUM:
err = "GL_INVALID_ENUM";
break;
case GL_INVALID_VALUE:
err = "GL_INVALID_VALUE";
break;
case GL_INVALID_OPERATION:
err = "GL_INVALID_OPERATION";
break;
case GL_STACK_OVERFLOW:
err = "GL_STACK_OVERFLOW";
break;
case GL_STACK_UNDERFLOW:
err = "GL_STACK_UNDERFLOW";
break;
case GL_OUT_OF_MEMORY:
err = "GL_OUT_OF_MEMORY";
default:
break;
}
May 29, 2006
May 29, 2006
806
fprintf(stderr, "OpenGL error \"%s\" at point %d.\n", err, point);
May 1, 2006
May 1, 2006
807
808
809
810
}
#endif
/* Get texinfo for a surface. */
May 28, 2006
May 28, 2006
811
static __inline__ private_hwdata *
May 29, 2006
May 29, 2006
812
glSDL_GetTexInfo(SDL_Surface * surface)
May 1, 2006
May 1, 2006
813
{
May 28, 2006
May 28, 2006
814
815
816
if (!surface)
return NULL;
return surface->hwdata;
May 1, 2006
May 1, 2006
817
818
819
820
}
/* Allocate a "blank" texinfo for a suface. */
May 28, 2006
May 28, 2006
821
static private_hwdata *
May 29, 2006
May 29, 2006
822
glSDL_AllocTexInfo(SDL_Surface * surface)
May 1, 2006
May 1, 2006
823
{
May 28, 2006
May 28, 2006
824
825
826
827
private_hwdata *txi;
if (!surface)
return NULL;
May 29, 2006
May 29, 2006
828
txi = glSDL_GetTexInfo(surface);
May 28, 2006
May 28, 2006
829
830
831
832
if (txi)
return txi; /* There already is one! --> */
/* ...and hook a new texinfo struct up to it. */
May 29, 2006
May 29, 2006
833
txi = (private_hwdata *) SDL_calloc(1, sizeof(private_hwdata));
May 28, 2006
May 28, 2006
834
if (!txi) {
May 29, 2006
May 29, 2006
835
GLERR("AllocTexInfo(): Failed allocating TexInfo struct!");
May 28, 2006
May 28, 2006
836
837
838
839
return NULL;
}
txi->temporary = 1;
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
840
fprintf(stderr, "glSDL: Allocated TexInfo %p.\n", txi);
May 1, 2006
May 1, 2006
841
#endif
May 28, 2006
May 28, 2006
842
return txi;
May 1, 2006
May 1, 2006
843
844
845
}
May 28, 2006
May 28, 2006
846
static void
May 29, 2006
May 29, 2006
847
glSDL_FreeTexInfo(_THIS, private_hwdata * txi)
May 1, 2006
May 1, 2006
848
{
May 28, 2006
May 28, 2006
849
850
if (!txi)
return;
May 1, 2006
May 1, 2006
851
May 29, 2006
May 29, 2006
852
853
854
glSDL_UnloadTexture(this, txi);
SDL_free(txi->texture);
SDL_free(txi);
May 1, 2006
May 1, 2006
855
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
856
fprintf(stderr, "glSDL: Freed TexInfo %p.\n", txi);
May 1, 2006
May 1, 2006
857
858
859
860
861
#endif
}
/* Detach and free the texinfo of a surface. */
May 28, 2006
May 28, 2006
862
static void
May 29, 2006
May 29, 2006
863
glSDL_RemoveTexInfo(_THIS, SDL_Surface * surface)
May 1, 2006
May 1, 2006
864
{
May 28, 2006
May 28, 2006
865
SDL_Surface *next, *prev;
May 29, 2006
May 29, 2006
866
if (!glSDL_GetTexInfo(surface))
May 28, 2006
May 28, 2006
867
868
869
870
871
872
873
874
875
876
877
878
879
880
return;
/* maintain our doubly linked list */
next = surface->hwdata->next;
prev = surface->hwdata->prev;
if (prev != NULL) {
prev->hwdata->next = next;
} else {
first = next;
}
if (next != NULL) {
next->hwdata->prev = prev;
}
May 29, 2006
May 29, 2006
881
glSDL_FreeTexInfo(this, surface->hwdata);
May 28, 2006
May 28, 2006
882
surface->hwdata = NULL;
May 1, 2006
May 1, 2006
883
884
885
886
887
888
889
890
}
/*
* Calculate chopping/tiling of a surface to
* fit it into the smallest possible OpenGL
* texture.
*/
May 28, 2006
May 28, 2006
891
static int
May 29, 2006
May 29, 2006
892
glSDL_CalcChop(private_hwdata * txi)
May 1, 2006
May 1, 2006
893
{
May 28, 2006
May 28, 2006
894
895
896
897
int rows, vw, vh;
int vertical = 0;
int texsize;
int lastw, lasth, minsize;
May 1, 2006
May 1, 2006
898
May 28, 2006
May 28, 2006
899
900
vw = txi->virt.w;
vh = txi->virt.h;
May 1, 2006
May 1, 2006
901
902
#ifdef DEBUG_GLSDL_CHOP
May 29, 2006
May 29, 2006
903
fprintf(stderr, "w=%d, h=%d ", vw, vh);
May 1, 2006
May 1, 2006
904
#endif
May 28, 2006
May 28, 2006
905
906
907
908
909
if (vh > vw) {
int t = vw;
vw = vh;
vh = t;
vertical = 1;
May 1, 2006
May 1, 2006
910
#ifdef DEBUG_GLSDL_CHOP
May 29, 2006
May 29, 2006
911
fprintf(stderr, "(vertical) \t");
May 1, 2006
May 1, 2006
912
#endif
May 28, 2006
May 28, 2006
913
}
May 1, 2006
May 1, 2006
914
May 28, 2006
May 28, 2006
915
916
917
918
919
/*
* Check whether this is a "huge" surface - at least one dimension
* must be <= than the maximum texture size, or we'll have to chop
* in both directions.
*/
May 1, 2006
May 1, 2006
920
#ifdef DEBUG_GLSDL
May 28, 2006
May 28, 2006
921
if (maxtexsize < 0)
May 29, 2006
May 29, 2006
922
return GLERET("glSDL_CalcChop() called before OpenGL init!");
May 1, 2006
May 1, 2006
923
#endif
May 28, 2006
May 28, 2006
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
if (vh > maxtexsize) {
/*
* Very simple hack for now; we just tile
* both ways with maximum size textures.
*/
texsize = maxtexsize;
txi->tilemode = GLSDL_TM_HUGE;
txi->texsize = texsize;
txi->tilew = texsize;
txi->tileh = texsize;
txi->tilespertex = 1;
/* Calculate number of textures needed */
txi->textures = (vw + texsize - 1) / texsize;
txi->textures *= (vh + texsize - 1) / texsize;
May 29, 2006
May 29, 2006
940
941
txi->texture = SDL_malloc(txi->textures * sizeof(int));
SDL_memset(txi->texture, -1, txi->textures * sizeof(int));
May 28, 2006
May 28, 2006
942
#ifdef DEBUG_GLSDL
May 29, 2006
May 29, 2006
943
fprintf(stderr, "two-way tiling; textures=%d\n", txi->textures);
May 1, 2006
May 1, 2006
944
#endif
May 28, 2006
May 28, 2006
945
if (!txi->texture) {
May 29, 2006
May 29, 2006
946
947
fprintf(stderr, "glSDL: INTERNAL ERROR: Failed to allocate"
" texture name table!\n");
May 28, 2006
May 28, 2006
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
return -3;
}
return 0;
}
/* Calculate minimum size */
rows = 1;
lastw = vw;
lasth = vh;
minsize = lastw > lasth ? lastw : lasth;
while (1) {
int w, h, size;
++rows;
w = vw / rows;
h = rows * vh;
size = w > h ? w : h;
if (size >= minsize) {
--rows;
break;
}
lastw = w;
lasth = h;
minsize = size;
}
if (minsize > maxtexsize) {
/* Handle multiple textures for very wide/tall surfaces. */
minsize = maxtexsize;
rows = (vw + minsize - 1) / minsize;
}
May 1, 2006
May 1, 2006
977
#ifdef DEBUG_GLSDL_CHOP
May 29, 2006
May 29, 2006
978
979
fprintf(stderr, "==> minsize=%d ", minsize);
fprintf(stderr, "(rows=%d) \t", rows);
May 1, 2006
May 1, 2006
980
981
#endif
May 28, 2006
May 28, 2006
982
983
984
985
/* Recalculate with nearest higher power-of-2 width. */
for (texsize = 1; texsize < minsize; texsize <<= 1);
txi->texsize = texsize;
rows = (vw + texsize - 1) / texsize;
May 1, 2006
May 1, 2006
986
#ifdef DEBUG_GLSDL_CHOP
May 29, 2006
May 29, 2006
987
fprintf(stderr, "==> texsize=%d (rows=%d) \t", texsize, rows);
May 1, 2006
May 1, 2006
988
989
#endif
May 28, 2006
May 28, 2006
990
991
/* Calculate number of tiles per texture */
txi->tilespertex = txi->texsize / vh;
May 1, 2006
May 1, 2006
992
#ifdef DEBUG_GLSDL_CHOP
May 29, 2006
May 29, 2006
993
fprintf(stderr, "tilespertex=%d \t", txi->tilespertex);
May 1, 2006
May 1, 2006
994
995
#endif
May 28, 2006
May 28, 2006
996
997
/* Calculate number of textures needed */
txi->textures = (rows + txi->tilespertex - 1) / txi->tilespertex;
May 29, 2006
May 29, 2006
998
999
txi->texture = (GLuint *) SDL_malloc(txi->textures * sizeof(GLuint));
SDL_memset(txi->texture, GLSDL_NOTEX, txi->textures * sizeof(GLuint));
May 1, 2006
May 1, 2006
1000
#ifdef DEBUG_GLSDL_CHOP