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

Latest commit

 

History

History
1241 lines (1114 loc) · 39.7 KB

SDL_renderer_gl.c

File metadata and controls

1241 lines (1114 loc) · 39.7 KB
 
Jul 19, 2006
Jul 19, 2006
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
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"
Jul 28, 2006
Jul 28, 2006
24
#if SDL_VIDEO_RENDER_OGL
Jul 22, 2006
Jul 22, 2006
25
26
27
28
29
30
31
#include "SDL_video.h"
#include "SDL_opengl.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_rect_c.h"
#include "SDL_yuv_sw_c.h"
Jul 19, 2006
Jul 19, 2006
32
Aug 15, 2007
Aug 15, 2007
33
34
35
36
#ifdef __MACOSX__
#include <OpenGL/OpenGL.h>
#endif
Nov 22, 2008
Nov 22, 2008
37
Jul 19, 2006
Jul 19, 2006
38
39
/* OpenGL renderer implementation */
Aug 12, 2007
Aug 12, 2007
40
41
42
43
/* Details on optimizing the texture path on Mac OS X:
http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html
*/
Dec 6, 2008
Dec 6, 2008
44
45
46
47
/* !!! FIXME: this should go in a higher level than the GL renderer. */
static __inline__ int
bytes_per_pixel(const Uint32 format)
{
Dec 6, 2008
Dec 6, 2008
48
49
50
51
52
if (!SDL_ISPIXELFORMAT_FOURCC(format)) {
return SDL_BYTESPERPIXEL(format);
}
/* FOURCC format */
Dec 6, 2008
Dec 6, 2008
53
switch (format) {
Dec 6, 2008
Dec 6, 2008
54
55
56
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_YUY2:
Dec 6, 2008
Dec 6, 2008
57
case SDL_PIXELFORMAT_UYVY:
Dec 6, 2008
Dec 6, 2008
58
case SDL_PIXELFORMAT_YVYU:
Dec 6, 2008
Dec 6, 2008
59
60
return 2;
default:
Dec 6, 2008
Dec 6, 2008
61
return 1; /* shouldn't ever hit this. */
Dec 6, 2008
Dec 6, 2008
62
63
64
65
}
}
Aug 28, 2006
Aug 28, 2006
66
67
static const float inv255f = 1.0f / 255.0f;
Jul 19, 2006
Jul 19, 2006
68
static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
Jul 22, 2006
Jul 22, 2006
69
static int GL_ActivateRenderer(SDL_Renderer * renderer);
Aug 6, 2006
Aug 6, 2006
70
static int GL_DisplayModeChanged(SDL_Renderer * renderer);
Jul 19, 2006
Jul 19, 2006
71
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
Aug 11, 2007
Aug 11, 2007
72
73
74
static int GL_QueryTexturePixels(SDL_Renderer * renderer,
SDL_Texture * texture, void **pixels,
int *pitch);
Jul 19, 2006
Jul 19, 2006
75
76
77
78
79
80
81
static int GL_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
int ncolors);
static int GL_GetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture, SDL_Color * colors,
int firstcolor, int ncolors);
Aug 28, 2006
Aug 28, 2006
82
83
84
85
86
87
88
89
static int GL_SetTextureColorMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int GL_SetTextureAlphaMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int GL_SetTextureBlendMode(SDL_Renderer * renderer,
SDL_Texture * texture);
static int GL_SetTextureScaleMode(SDL_Renderer * renderer,
SDL_Texture * texture);
Jul 19, 2006
Jul 19, 2006
90
91
92
93
static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Aug 28, 2006
Aug 28, 2006
94
95
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch);
Jul 19, 2006
Jul 19, 2006
96
97
98
static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects);
Aug 28, 2006
Aug 28, 2006
99
100
static int GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
Uint8 a, const SDL_Rect * rect);
Jul 19, 2006
Jul 19, 2006
101
static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Aug 28, 2006
Aug 28, 2006
102
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
Jul 19, 2006
Jul 19, 2006
103
104
105
106
107
108
109
110
111
static void GL_RenderPresent(SDL_Renderer * renderer);
static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void GL_DestroyRenderer(SDL_Renderer * renderer);
SDL_RenderDriver GL_RenderDriver = {
GL_CreateRenderer,
{
"opengl",
Aug 6, 2006
Aug 6, 2006
112
113
(SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD |
SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
Aug 28, 2006
Aug 28, 2006
114
115
(SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
SDL_TEXTUREMODULATE_ALPHA),
Aug 5, 2006
Aug 5, 2006
116
117
118
119
120
(SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
SDL_TEXTUREBLENDMODE_MOD),
(SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
SDL_TEXTURESCALEMODE_SLOW),
Dec 1, 2008
Dec 1, 2008
121
15,
Jul 19, 2006
Jul 19, 2006
122
{
Aug 5, 2006
Aug 5, 2006
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX8,
SDL_PIXELFORMAT_RGB332,
SDL_PIXELFORMAT_RGB444,
SDL_PIXELFORMAT_RGB555,
SDL_PIXELFORMAT_ARGB4444,
SDL_PIXELFORMAT_ARGB1555,
SDL_PIXELFORMAT_RGB565,
SDL_PIXELFORMAT_RGB24,
SDL_PIXELFORMAT_BGR24,
SDL_PIXELFORMAT_RGB888,
SDL_PIXELFORMAT_BGR888,
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_ABGR8888,
Dec 1, 2008
Dec 1, 2008
138
SDL_PIXELFORMAT_ARGB2101010},
Jul 19, 2006
Jul 19, 2006
139
140
141
142
143
144
145
0,
0}
};
typedef struct
{
SDL_GLContext context;
Dec 5, 2008
Dec 5, 2008
146
SDL_bool updateSize;
Jul 22, 2006
Jul 22, 2006
147
SDL_bool GL_ARB_texture_rectangle_supported;
Aug 12, 2007
Aug 12, 2007
148
SDL_bool GL_EXT_paletted_texture_supported;
Dec 7, 2008
Dec 7, 2008
149
150
SDL_bool GL_APPLE_ycbcr_422_supported;
SDL_bool GL_MESA_ycbcr_texture_supported;
Dec 6, 2008
Dec 6, 2008
151
SDL_bool GL_ARB_fragment_program_supported;
Jul 22, 2006
Jul 22, 2006
152
153
154
155
156
157
158
int blendMode;
int scaleMode;
/* OpenGL functions */
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
#include "SDL_glfuncs.h"
#undef SDL_PROC
Aug 6, 2006
Aug 6, 2006
159
160
PFNGLCOLORTABLEEXTPROC glColorTableEXT;
Aug 12, 2007
Aug 12, 2007
161
162
void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
const GLvoid * pointer);
Dec 6, 2008
Dec 6, 2008
163
164
165
166
167
168
169
170
171
172
173
PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB;
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
PFNGLBINDPROGRAMARBPROC glBindProgramARB;
PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
/* (optional) fragment programs */
GLuint fragment_program_UYVY;
Jul 19, 2006
Jul 19, 2006
174
175
176
177
178
} GL_RenderData;
typedef struct
{
GLuint texture;
Dec 6, 2008
Dec 6, 2008
179
GLuint shader;
Jul 22, 2006
Jul 22, 2006
180
GLenum type;
Jul 19, 2006
Jul 19, 2006
181
182
GLfloat texw;
GLfloat texh;
Jul 22, 2006
Jul 22, 2006
183
184
GLenum format;
GLenum formattype;
Aug 6, 2006
Aug 6, 2006
185
Uint8 *palette;
Jul 19, 2006
Jul 19, 2006
186
187
void *pixels;
int pitch;
Jul 22, 2006
Jul 22, 2006
188
SDL_DirtyRectList dirty;
Dec 6, 2008
Dec 6, 2008
189
int HACK_RYAN_FIXME;
Jul 19, 2006
Jul 19, 2006
190
191
192
} GL_TextureData;
Jul 22, 2006
Jul 22, 2006
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
static void
GL_SetError(const char *prefix, GLenum result)
{
const char *error;
switch (result) {
case GL_NO_ERROR:
error = "GL_NO_ERROR";
break;
case GL_INVALID_ENUM:
error = "GL_INVALID_ENUM";
break;
case GL_INVALID_VALUE:
error = "GL_INVALID_VALUE";
break;
case GL_INVALID_OPERATION:
error = "GL_INVALID_OPERATION";
break;
case GL_STACK_OVERFLOW:
error = "GL_STACK_OVERFLOW";
break;
case GL_STACK_UNDERFLOW:
error = "GL_STACK_UNDERFLOW";
break;
case GL_OUT_OF_MEMORY:
error = "GL_OUT_OF_MEMORY";
break;
case GL_TABLE_TOO_LARGE:
error = "GL_TABLE_TOO_LARGE";
break;
default:
error = "UNKNOWN";
break;
}
SDL_SetError("%s: %s", prefix, error);
}
Jul 22, 2006
Jul 22, 2006
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
static int
GL_LoadFunctions(GL_RenderData * data)
{
#if defined(__QNXNTO__) && (_NTO_VERSION < 630)
#define __SDL_NOGETPROCADDR__
#elif defined(__MINT__)
#define __SDL_NOGETPROCADDR__
#endif
#ifdef __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#else
#define SDL_PROC(ret,func,params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
if ( ! data->func ) { \
SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
return -1; \
} \
} while ( 0 );
#endif /* __SDL_NOGETPROCADDR__ */
#include "SDL_glfuncs.h"
#undef SDL_PROC
return 0;
}
Jul 19, 2006
Jul 19, 2006
256
257
258
void
GL_AddRenderDriver(_THIS)
{
Jul 22, 2006
Jul 22, 2006
259
if (_this->GL_CreateContext) {
Jul 19, 2006
Jul 19, 2006
260
261
262
263
264
265
266
267
268
SDL_AddRenderDriver(0, &GL_RenderDriver);
}
}
SDL_Renderer *
GL_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_Renderer *renderer;
GL_RenderData *data;
Jul 28, 2006
Jul 28, 2006
269
GLint value;
Aug 6, 2006
Aug 6, 2006
270
int doublebuffer;
Jul 19, 2006
Jul 19, 2006
271
Aug 6, 2006
Aug 6, 2006
272
273
274
275
276
277
/* Render directly to the window, unless we're compositing */
#ifndef __MACOSX__
if (flags & SDL_RENDERER_SINGLEBUFFER) {
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
}
#endif
Jul 19, 2006
Jul 19, 2006
278
if (!(window->flags & SDL_WINDOW_OPENGL)) {
Jul 23, 2006
Jul 23, 2006
279
if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) {
Jul 22, 2006
Jul 22, 2006
280
281
return NULL;
}
Jul 19, 2006
Jul 19, 2006
282
283
}
Jul 22, 2006
Jul 22, 2006
284
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
Jul 19, 2006
Jul 19, 2006
285
286
287
288
289
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
Jul 22, 2006
Jul 22, 2006
290
data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
Jul 19, 2006
Jul 19, 2006
291
292
293
294
295
296
if (!data) {
GL_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
}
Jul 22, 2006
Jul 22, 2006
297
renderer->ActivateRenderer = GL_ActivateRenderer;
Aug 6, 2006
Aug 6, 2006
298
renderer->DisplayModeChanged = GL_DisplayModeChanged;
Jul 19, 2006
Jul 19, 2006
299
renderer->CreateTexture = GL_CreateTexture;
Aug 11, 2007
Aug 11, 2007
300
renderer->QueryTexturePixels = GL_QueryTexturePixels;
Jul 19, 2006
Jul 19, 2006
301
302
renderer->SetTexturePalette = GL_SetTexturePalette;
renderer->GetTexturePalette = GL_GetTexturePalette;
Aug 28, 2006
Aug 28, 2006
303
304
305
306
renderer->SetTextureColorMod = GL_SetTextureColorMod;
renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod;
renderer->SetTextureBlendMode = GL_SetTextureBlendMode;
renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
Jul 19, 2006
Jul 19, 2006
307
308
309
310
311
312
313
314
315
316
317
318
319
320
renderer->UpdateTexture = GL_UpdateTexture;
renderer->LockTexture = GL_LockTexture;
renderer->UnlockTexture = GL_UnlockTexture;
renderer->DirtyTexture = GL_DirtyTexture;
renderer->RenderFill = GL_RenderFill;
renderer->RenderCopy = GL_RenderCopy;
renderer->RenderPresent = GL_RenderPresent;
renderer->DestroyTexture = GL_DestroyTexture;
renderer->DestroyRenderer = GL_DestroyRenderer;
renderer->info = GL_RenderDriver.info;
renderer->window = window->id;
renderer->driverdata = data;
renderer->info.flags =
Aug 5, 2006
Aug 5, 2006
321
(SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
Jul 19, 2006
Jul 19, 2006
322
Jul 22, 2006
Jul 22, 2006
323
324
325
326
327
if (GL_LoadFunctions(data) < 0) {
GL_DestroyRenderer(renderer);
return NULL;
}
Jul 19, 2006
Jul 19, 2006
328
329
330
331
332
333
334
335
336
data->context = SDL_GL_CreateContext(window->id);
if (!data->context) {
GL_DestroyRenderer(renderer);
return NULL;
}
if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
GL_DestroyRenderer(renderer);
return NULL;
}
Aug 15, 2007
Aug 15, 2007
337
338
339
#ifdef __MACOSX__
/* Enable multi-threaded rendering */
/* Disabled until Ryan finishes his VBO/PBO code...
Jan 8, 2008
Jan 8, 2008
340
341
CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
*/
Aug 15, 2007
Aug 15, 2007
342
343
#endif
Aug 5, 2006
Aug 5, 2006
344
if (flags & SDL_RENDERER_PRESENTVSYNC) {
Jul 19, 2006
Jul 19, 2006
345
346
347
348
349
SDL_GL_SetSwapInterval(1);
} else {
SDL_GL_SetSwapInterval(0);
}
if (SDL_GL_GetSwapInterval() > 0) {
Aug 5, 2006
Aug 5, 2006
350
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
Jul 19, 2006
Jul 19, 2006
351
352
}
Aug 6, 2006
Aug 6, 2006
353
354
355
356
357
358
if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) {
if (!doublebuffer) {
renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
}
}
Jul 28, 2006
Jul 28, 2006
359
360
361
362
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
renderer->info.max_texture_width = value;
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
renderer->info.max_texture_height = value;
Jul 22, 2006
Jul 22, 2006
363
Jul 22, 2006
Jul 22, 2006
364
365
366
367
if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
|| SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
}
Aug 6, 2006
Aug 6, 2006
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
if (SDL_GL_ExtensionSupported("GL_EXT_paletted_texture")) {
data->GL_EXT_paletted_texture_supported = SDL_TRUE;
data->glColorTableEXT =
(PFNGLCOLORTABLEEXTPROC) SDL_GL_GetProcAddress("glColorTableEXT");
} else {
/* Don't advertise support for 8-bit indexed texture format */
Uint32 i, j;
SDL_RendererInfo *info = &renderer->info;
for (i = 0, j = 0; i < info->num_texture_formats; ++i) {
if (info->texture_formats[i] != SDL_PIXELFORMAT_INDEX8) {
info->texture_formats[j++] = info->texture_formats[i];
}
}
--info->num_texture_formats;
}
Dec 7, 2008
Dec 7, 2008
383
/*
Dec 7, 2008
Dec 7, 2008
384
385
386
387
388
389
if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) {
data->GL_APPLE_ycbcr_422_supported = SDL_TRUE;
}
if (SDL_GL_ExtensionSupported("GL_MESA_ycbcr_texture")) {
data->GL_MESA_ycbcr_texture_supported = SDL_TRUE;
}
Dec 7, 2008
Dec 7, 2008
390
*/
Aug 12, 2007
Aug 12, 2007
391
392
393
394
395
if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
data->glTextureRangeAPPLE =
(void (*)(GLenum, GLsizei, const GLvoid *))
SDL_GL_GetProcAddress("glTextureRangeAPPLE");
}
Jul 22, 2006
Jul 22, 2006
396
Dec 6, 2008
Dec 6, 2008
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/* we might use fragment programs for YUV data, etc. */
if (SDL_GL_ExtensionSupported("GL_ARB_fragment_program")) {
/* !!! FIXME: this doesn't check for errors. */
/* !!! FIXME: this should really reuse the glfuncs.h stuff. */
data->glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC)
SDL_GL_GetProcAddress("glGetProgramivARB");
data->glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC)
SDL_GL_GetProcAddress("glGetProgramStringARB");
data->glProgramLocalParameter4fvARB =
(PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)
SDL_GL_GetProcAddress("glProgramLocalParameter4fvARB");
data->glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)
SDL_GL_GetProcAddress("glDeleteProgramsARB");
data->glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)
SDL_GL_GetProcAddress("glGenProgramsARB");
data->glBindProgramARB = (PFNGLBINDPROGRAMARBPROC)
SDL_GL_GetProcAddress("glBindProgramARB");
data->glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)
SDL_GL_GetProcAddress("glProgramStringARB");
data->GL_ARB_fragment_program_supported = SDL_TRUE;
}
Jul 19, 2006
Jul 19, 2006
419
/* Set up parameters for rendering */
Jul 22, 2006
Jul 22, 2006
420
421
422
423
data->blendMode = -1;
data->scaleMode = -1;
data->glDisable(GL_DEPTH_TEST);
data->glDisable(GL_CULL_FACE);
Jul 22, 2006
Jul 22, 2006
424
if (data->GL_ARB_texture_rectangle_supported) {
Jul 22, 2006
Jul 22, 2006
425
data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
Jul 22, 2006
Jul 22, 2006
426
} else {
Jul 22, 2006
Jul 22, 2006
427
data->glEnable(GL_TEXTURE_2D);
Jul 22, 2006
Jul 22, 2006
428
}
Dec 5, 2008
Dec 5, 2008
429
data->updateSize = SDL_TRUE;
Jul 19, 2006
Jul 19, 2006
430
431
432
433
return renderer;
}
Jul 22, 2006
Jul 22, 2006
434
435
436
437
438
439
static int
GL_ActivateRenderer(SDL_Renderer * renderer)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
Aug 6, 2006
Aug 6, 2006
440
441
442
if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
return -1;
}
Dec 5, 2008
Dec 5, 2008
443
if (data->updateSize) {
Dec 6, 2008
Dec 6, 2008
444
445
446
447
448
449
450
data->glMatrixMode(GL_PROJECTION);
data->glLoadIdentity();
data->glMatrixMode(GL_MODELVIEW);
data->glLoadIdentity();
data->glViewport(0, 0, window->w, window->h);
data->glOrtho(0.0, (GLdouble) window->w, (GLdouble) window->h, 0.0,
0.0, 1.0);
Dec 5, 2008
Dec 5, 2008
451
452
data->updateSize = SDL_FALSE;
}
Aug 6, 2006
Aug 6, 2006
453
454
455
456
457
458
459
460
return 0;
}
static int
GL_DisplayModeChanged(SDL_Renderer * renderer)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
Dec 6, 2008
Dec 6, 2008
461
462
463
/* Rebind the context to the window area and update matrices */
data->updateSize = SDL_TRUE;
return GL_ActivateRenderer(renderer);
Jul 22, 2006
Jul 22, 2006
464
465
}
Jul 22, 2006
Jul 22, 2006
466
467
468
469
470
471
472
473
474
475
476
static __inline__ int
power_of_2(int input)
{
int value = 1;
while (value < input) {
value <<= 1;
}
return value;
}
Dec 6, 2008
Dec 6, 2008
477
478
479
480
#define DEBUG_PROGRAM_COMPILE 1
static GLuint
Dec 7, 2008
Dec 7, 2008
481
compile_shader(GL_RenderData *data, GLenum shader_type, const char *_code)
Dec 6, 2008
Dec 6, 2008
482
{
Dec 7, 2008
Dec 7, 2008
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
const int have_texture_rects = data->GL_ARB_texture_rectangle_supported;
const char *replacement = have_texture_rects ? "RECT" : "2D";
const size_t replacementlen = strlen(replacement);
const char *token = "%TEXTURETARGET%";
const size_t tokenlen = strlen(token);
char *code = NULL;
char *ptr = NULL;
GLuint program = 0;
/*
* The TEX instruction needs a different target depending on what we use.
* To handle this, we use "%TEXTURETARGET%" and replace the string before
* compiling the shader.
*/
code = SDL_strdup(_code);
if (code == NULL)
return 0;
for (ptr = SDL_strstr(code, token); ptr; ptr = SDL_strstr(ptr+1, token)) {
memcpy(ptr, replacement, replacementlen);
memmove(ptr+replacementlen, ptr+tokenlen, strlen(ptr+tokenlen)+1);
}
Dec 6, 2008
Dec 6, 2008
506
#if DEBUG_PROGRAM_COMPILE
Dec 7, 2008
Dec 7, 2008
507
printf("compiling shader:\n%s\n\n", code);
Dec 6, 2008
Dec 6, 2008
508
509
510
511
512
513
#endif
data->glGetError(); /* flush any existing error state. */
data->glGenProgramsARB(1, &program);
data->glBindProgramARB(shader_type, program);
data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
Dec 7, 2008
Dec 7, 2008
514
515
516
SDL_strlen(code), code);
SDL_free(code);
Dec 6, 2008
Dec 6, 2008
517
518
if (data->glGetError() == GL_INVALID_OPERATION)
Dec 7, 2008
Dec 7, 2008
519
{
Dec 6, 2008
Dec 6, 2008
520
521
522
523
524
525
526
527
528
529
530
#if DEBUG_PROGRAM_COMPILE
GLint pos = 0;
const GLubyte *errstr;
data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
printf("program compile error at position %d: %s\n\n",
(int) pos, (const char *) errstr);
#endif
data->glBindProgramARB(shader_type, 0);
data->glDeleteProgramsARB(1, &program);
return 0;
Dec 7, 2008
Dec 7, 2008
531
}
Dec 6, 2008
Dec 6, 2008
532
533
534
535
return program;
}
Dec 7, 2008
Dec 7, 2008
536
537
538
539
540
541
542
543
544
545
546
547
548
/*
* Fragment program that renders from UYVY textures.
* The UYVY to RGB equasion is:
* R = 1.164(Y-16) + 1.596(Cr-128)
* G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
* B = 1.164(Y-16) + 2.018(Cb-128)
* Byte layout is Cb, Y1, Cr, Y2, stored in the R, G, B, A channels.
* 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr
*
* !!! FIXME: this ignores blendmodes, etc.
* !!! FIXME: this could be more efficient...use a dot product for green, etc.
*/
Dec 6, 2008
Dec 6, 2008
549
550
551
static const char *fragment_program_UYVY_source_code =
"!!ARBfp1.0\n"
Dec 7, 2008
Dec 7, 2008
552
/* outputs... */
Dec 6, 2008
Dec 6, 2008
553
554
"OUTPUT outcolor = result.color;\n"
Dec 7, 2008
Dec 7, 2008
555
/* scratch registers... */
Dec 6, 2008
Dec 6, 2008
556
557
558
559
"TEMP uyvy;\n"
"TEMP luminance;\n"
"TEMP work;\n"
Dec 7, 2008
Dec 7, 2008
560
/* Halve the coordinates to grab the correct 32 bits for the fragment. */
Dec 6, 2008
Dec 6, 2008
561
562
"MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
Dec 7, 2008
Dec 7, 2008
563
/* Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in x, y, z, w. */
Dec 7, 2008
Dec 7, 2008
564
"TEX uyvy, work, texture[0], %TEXTURETARGET%;\n"
Dec 6, 2008
Dec 6, 2008
565
Dec 7, 2008
Dec 7, 2008
566
/* Do subtractions (128/255, 16/255, 128/255, 16/255) */
Dec 7, 2008
Dec 7, 2008
567
"SUB uyvy, uyvy, { 0.501960784313726, 0.06274509803922, 0.501960784313726, 0.06274509803922 };\n"
Dec 6, 2008
Dec 6, 2008
568
Dec 7, 2008
Dec 7, 2008
569
570
/* Choose the luminance component by texcoord. */
/* !!! FIXME: laziness wins out for now... just average Y1 and Y2. */
Dec 6, 2008
Dec 6, 2008
571
572
573
"ADD luminance, uyvy.yyyy, uyvy.wwww;\n"
"MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
Dec 7, 2008
Dec 7, 2008
574
/* Multiply luminance by its magic value. */
Dec 6, 2008
Dec 6, 2008
575
576
"MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n"
Dec 7, 2008
Dec 7, 2008
577
/* uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications. */
Dec 6, 2008
Dec 6, 2008
578
579
"MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n"
Dec 7, 2008
Dec 7, 2008
580
/* Add luminance to Cr and Cb, store to RGB channels. */
Dec 6, 2008
Dec 6, 2008
581
582
"ADD work.rgb, luminance, uyvy;\n"
Dec 7, 2008
Dec 7, 2008
583
/* Do final addition for Green channel. (!!! FIXME: this should be a DPH?) */
Dec 6, 2008
Dec 6, 2008
584
585
"ADD work.g, work.g, uyvy.w;\n"
Dec 7, 2008
Dec 7, 2008
586
/* Make sure alpha channel is fully opaque. (!!! FIXME: blend modes!) */
Dec 6, 2008
Dec 6, 2008
587
588
"MOV work.a, { 1.0 };\n"
Dec 7, 2008
Dec 7, 2008
589
/* Store out the final fragment color... */
Dec 6, 2008
Dec 6, 2008
590
591
"MOV outcolor, work;\n"
Dec 7, 2008
Dec 7, 2008
592
/* ...and we're done! */
Dec 6, 2008
Dec 6, 2008
593
594
595
"END\n";
Jul 19, 2006
Jul 19, 2006
596
597
598
599
600
601
static int
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
GL_TextureData *data;
Jul 22, 2006
Jul 22, 2006
602
603
GLint internalFormat;
GLenum format, type;
Jul 22, 2006
Jul 22, 2006
604
int texture_w, texture_h;
Dec 6, 2008
Dec 6, 2008
605
GLuint shader = 0;
Jul 22, 2006
Jul 22, 2006
606
GLenum result;
Jul 22, 2006
Jul 22, 2006
607
608
switch (texture->format) {
Aug 5, 2006
Aug 5, 2006
609
610
case SDL_PIXELFORMAT_INDEX1LSB:
case SDL_PIXELFORMAT_INDEX1MSB:
Jul 22, 2006
Jul 22, 2006
611
612
613
614
internalFormat = GL_RGB;
format = GL_COLOR_INDEX;
type = GL_BITMAP;
break;
Aug 5, 2006
Aug 5, 2006
615
case SDL_PIXELFORMAT_INDEX8:
Aug 6, 2006
Aug 6, 2006
616
617
618
619
620
if (!renderdata->GL_EXT_paletted_texture_supported) {
SDL_SetError("Unsupported texture format");
return -1;
}
internalFormat = GL_COLOR_INDEX8_EXT;
Jul 22, 2006
Jul 22, 2006
621
622
623
format = GL_COLOR_INDEX;
type = GL_UNSIGNED_BYTE;
break;
Aug 5, 2006
Aug 5, 2006
624
case SDL_PIXELFORMAT_RGB332:
Jul 22, 2006
Jul 22, 2006
625
626
627
628
internalFormat = GL_R3_G3_B2;
format = GL_RGB;
type = GL_UNSIGNED_BYTE_3_3_2;
break;
Aug 5, 2006
Aug 5, 2006
629
case SDL_PIXELFORMAT_RGB444:
Jul 22, 2006
Jul 22, 2006
630
631
632
633
internalFormat = GL_RGB4;
format = GL_RGB;
type = GL_UNSIGNED_SHORT_4_4_4_4;
break;
Aug 5, 2006
Aug 5, 2006
634
case SDL_PIXELFORMAT_RGB555:
Jul 22, 2006
Jul 22, 2006
635
636
637
638
internalFormat = GL_RGB5;
format = GL_RGB;
type = GL_UNSIGNED_SHORT_5_5_5_1;
break;
Aug 5, 2006
Aug 5, 2006
639
case SDL_PIXELFORMAT_ARGB4444:
Jul 22, 2006
Jul 22, 2006
640
641
642
643
internalFormat = GL_RGBA4;
format = GL_BGRA;
type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
break;
Aug 5, 2006
Aug 5, 2006
644
case SDL_PIXELFORMAT_ARGB1555:
Jul 22, 2006
Jul 22, 2006
645
646
647
648
internalFormat = GL_RGB5_A1;
format = GL_BGRA;
type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
break;
Aug 5, 2006
Aug 5, 2006
649
case SDL_PIXELFORMAT_RGB565:
Jul 22, 2006
Jul 22, 2006
650
651
652
653
internalFormat = GL_RGB8;
format = GL_RGB;
type = GL_UNSIGNED_SHORT_5_6_5;
break;
Aug 5, 2006
Aug 5, 2006
654
case SDL_PIXELFORMAT_RGB24:
Jul 22, 2006
Jul 22, 2006
655
656
657
658
internalFormat = GL_RGB8;
format = GL_RGB;
type = GL_UNSIGNED_BYTE;
break;
Aug 5, 2006
Aug 5, 2006
659
case SDL_PIXELFORMAT_RGB888:
Jul 22, 2006
Jul 22, 2006
660
internalFormat = GL_RGB8;
Jul 22, 2006
Jul 22, 2006
661
662
format = GL_BGRA;
type = GL_UNSIGNED_BYTE;
Jul 22, 2006
Jul 22, 2006
663
break;
Aug 5, 2006
Aug 5, 2006
664
case SDL_PIXELFORMAT_BGR24:
Jul 22, 2006
Jul 22, 2006
665
666
667
668
internalFormat = GL_RGB8;
format = GL_BGR;
type = GL_UNSIGNED_BYTE;
break;
Aug 5, 2006
Aug 5, 2006
669
case SDL_PIXELFORMAT_BGR888:
Jul 22, 2006
Jul 22, 2006
670
internalFormat = GL_RGB8;
Jul 22, 2006
Jul 22, 2006
671
672
format = GL_RGBA;
type = GL_UNSIGNED_BYTE;
Jul 22, 2006
Jul 22, 2006
673
break;
Aug 5, 2006
Aug 5, 2006
674
case SDL_PIXELFORMAT_ARGB8888:
Aug 12, 2007
Aug 12, 2007
675
676
677
678
679
#ifdef __MACOSX__
internalFormat = GL_RGBA;
format = GL_BGRA;
type = GL_UNSIGNED_INT_8_8_8_8_REV;
#else
Jul 22, 2006
Jul 22, 2006
680
681
internalFormat = GL_RGBA8;
format = GL_BGRA;
Jul 22, 2006
Jul 22, 2006
682
type = GL_UNSIGNED_BYTE;
Aug 12, 2007
Aug 12, 2007
683
#endif
Jul 22, 2006
Jul 22, 2006
684
break;
Aug 5, 2006
Aug 5, 2006
685
case SDL_PIXELFORMAT_ABGR8888:
Jul 22, 2006
Jul 22, 2006
686
687
internalFormat = GL_RGBA8;
format = GL_RGBA;
Jul 22, 2006
Jul 22, 2006
688
type = GL_UNSIGNED_BYTE;
Jul 22, 2006
Jul 22, 2006
689
break;
Aug 5, 2006
Aug 5, 2006
690
case SDL_PIXELFORMAT_ARGB2101010:
Jul 22, 2006
Jul 22, 2006
691
692
693
694
internalFormat = GL_RGB10_A2;
format = GL_BGRA;
type = GL_UNSIGNED_INT_2_10_10_10_REV;
break;
Dec 6, 2008
Dec 6, 2008
695
case SDL_PIXELFORMAT_UYVY:
Dec 7, 2008
Dec 7, 2008
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
if (renderdata->GL_APPLE_ycbcr_422_supported) {
internalFormat = GL_RGB;
format = GL_YCBCR_422_APPLE;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
type = GL_UNSIGNED_SHORT_8_8_APPLE;
#else
type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
#endif
} else if (renderdata->GL_MESA_ycbcr_texture_supported) {
internalFormat = GL_RGB;
format = GL_YCBCR_MESA;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
type = GL_UNSIGNED_SHORT_8_8_MESA;
#else
type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
#endif
} else if (renderdata->GL_ARB_fragment_program_supported) {
Dec 6, 2008
Dec 6, 2008
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
if (renderdata->fragment_program_UYVY == 0) {
renderdata->fragment_program_UYVY =
compile_shader(renderdata, GL_FRAGMENT_PROGRAM_ARB,
fragment_program_UYVY_source_code);
if (renderdata->fragment_program_UYVY == 0) {
SDL_SetError("Fragment program compile error");
return -1;
}
}
shader = renderdata->fragment_program_UYVY;
internalFormat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_BYTE;
} else {
SDL_SetError("Unsupported texture format");
return -1;
}
break;
Dec 7, 2008
Dec 7, 2008
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
case SDL_PIXELFORMAT_YUY2:
if (renderdata->GL_APPLE_ycbcr_422_supported) {
internalFormat = GL_RGB;
format = GL_YCBCR_422_APPLE;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
#else
type = GL_UNSIGNED_SHORT_8_8_APPLE;
#endif
} else if (renderdata->GL_MESA_ycbcr_texture_supported) {
internalFormat = GL_RGB;
format = GL_YCBCR_MESA;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
#else
type = GL_UNSIGNED_SHORT_8_8_MESA;
Dec 6, 2008
Dec 6, 2008
747
#endif
Dec 7, 2008
Dec 7, 2008
748
749
750
751
752
} else {
SDL_SetError("Unsupported texture format");
return -1;
}
break;
Jul 22, 2006
Jul 22, 2006
753
754
755
756
default:
SDL_SetError("Unsupported texture format");
return -1;
}
Jul 19, 2006
Jul 19, 2006
757
Jul 22, 2006
Jul 22, 2006
758
data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
Jul 19, 2006
Jul 19, 2006
759
760
761
762
763
if (!data) {
SDL_OutOfMemory();
return -1;
}
Dec 6, 2008
Dec 6, 2008
764
765
data->shader = shader;
Aug 6, 2006
Aug 6, 2006
766
767
768
769
770
771
772
773
774
775
if (texture->format == SDL_PIXELFORMAT_INDEX8) {
data->palette = (Uint8 *) SDL_malloc(3 * 256 * sizeof(Uint8));
if (!data->palette) {
SDL_OutOfMemory();
SDL_free(data);
return -1;
}
SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8));
}
Aug 11, 2007
Aug 11, 2007
776
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
Dec 6, 2008
Dec 6, 2008
777
data->pitch = texture->w * bytes_per_pixel(texture->format);
Aug 11, 2007
Aug 11, 2007
778
779
780
781
782
783
784
785
data->pixels = SDL_malloc(texture->h * data->pitch);
if (!data->pixels) {
SDL_OutOfMemory();
SDL_free(data);
return -1;
}
}
Jul 19, 2006
Jul 19, 2006
786
787
texture->driverdata = data;
Jul 22, 2006
Jul 22, 2006
788
789
renderdata->glGetError();
renderdata->glGenTextures(1, &data->texture);
Jul 22, 2006
Jul 22, 2006
790
791
792
793
if (renderdata->GL_ARB_texture_rectangle_supported) {
data->type = GL_TEXTURE_RECTANGLE_ARB;
texture_w = texture->w;
texture_h = texture->h;
Dec 6, 2008
Dec 6, 2008
794
795
data->texw = (GLfloat) texture_w;
data->texh = (GLfloat) texture_h;
Jul 22, 2006
Jul 22, 2006
796
797
798
799
} else {
data->type = GL_TEXTURE_2D;
texture_w = power_of_2(texture->w);
texture_h = power_of_2(texture->h);
Dec 6, 2008
Dec 6, 2008
800
data->texw = (GLfloat) (texture->w) / texture_w;
Jul 22, 2006
Jul 22, 2006
801
802
data->texh = (GLfloat) texture->h / texture_h;
}
Dec 6, 2008
Dec 6, 2008
803
Dec 6, 2008
Dec 6, 2008
804
805
/* YUV formats use RGBA but are really two bytes per pixel */
if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
Dec 6, 2008
Dec 6, 2008
806
807
808
data->HACK_RYAN_FIXME = 2;
} else {
data->HACK_RYAN_FIXME = 1;
Dec 6, 2008
Dec 6, 2008
809
}
Dec 6, 2008
Dec 6, 2008
810
texture_w /= data->HACK_RYAN_FIXME;
Dec 6, 2008
Dec 6, 2008
811
Jul 22, 2006
Jul 22, 2006
812
813
data->format = format;
data->formattype = type;
Jul 22, 2006
Jul 22, 2006
814
renderdata->glBindTexture(data->type, data->texture);
Aug 12, 2007
Aug 12, 2007
815
816
817
818
819
820
821
822
renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
Dec 6, 2008
Dec 6, 2008
823
#ifdef __MACOSX__
Aug 12, 2007
Aug 12, 2007
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC
#endif
#ifndef STORAGE_CACHED_APPLE
#define STORAGE_CACHED_APPLE 0x85BE
#endif
#ifndef STORAGE_SHARED_APPLE
#define STORAGE_SHARED_APPLE 0x85BF
#endif
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
GL_STORAGE_SHARED_APPLE);
} else {
renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
GL_STORAGE_CACHED_APPLE);
}
Nov 29, 2008
Nov 29, 2008
840
841
/* This causes a crash in testoverlay for some reason. Apple bug? */
#if 0
Jan 8, 2008
Jan 8, 2008
842
843
if (texture->access == SDL_TEXTUREACCESS_STREAMING
&& texture->format == SDL_PIXELFORMAT_ARGB8888) {
Aug 13, 2007
Aug 13, 2007
844
/*
Jan 8, 2008
Jan 8, 2008
845
846
847
848
849
850
if (renderdata->glTextureRangeAPPLE) {
renderdata->glTextureRangeAPPLE(data->type,
texture->h * data->pitch,
data->pixels);
}
*/
Aug 12, 2007
Aug 12, 2007
851
852
853
854
renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
texture_h, 0, format, type, data->pixels);
} else
Nov 29, 2008
Nov 29, 2008
855
#endif
Aug 12, 2007
Aug 12, 2007
856
857
#endif
{
Dec 6, 2008
Dec 6, 2008
858
printf("teximage2d(%d,%d)\n", (int) texture_w, (int) texture_h);
Aug 12, 2007
Aug 12, 2007
859
860
861
renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
texture_h, 0, format, type, NULL);
}
Jul 22, 2006
Jul 22, 2006
862
result = renderdata->glGetError();
Jul 22, 2006
Jul 22, 2006
863
864
865
866
if (result != GL_NO_ERROR) {
GL_SetError("glTexImage2D()", result);
return -1;
}
Jul 19, 2006
Jul 19, 2006
867
868
869
return 0;
}
Aug 11, 2007
Aug 11, 2007
870
871
872
873
874
875
876
877
878
879
880
static int
GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch)
{
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
*pixels = data->pixels;
*pitch = data->pitch;
return 0;
}
Jul 19, 2006
Jul 19, 2006
881
882
883
884
885
886
static int
GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor, int ncolors)
{
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
Aug 6, 2006
Aug 6, 2006
887
Uint8 *palette;
Jul 19, 2006
Jul 19, 2006
888
Aug 6, 2006
Aug 6, 2006
889
890
891
892
893
894
895
896
897
898
899
900
901
902
if (!data->palette) {
SDL_SetError("Texture doesn't have a palette");
return -1;
}
palette = data->palette + firstcolor * 3;
while (ncolors--) {
*palette++ = colors->r;
*palette++ = colors->g;
*palette++ = colors->b;
++colors;
}
renderdata->glBindTexture(data->type, data->texture);
renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
GL_UNSIGNED_BYTE, data->palette);
Jul 19, 2006
Jul 19, 2006
903
904
905
906
907
908
909
return 0;
}
static int
GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Color * colors, int firstcolor, int ncolors)
{
Aug 6, 2006
Aug 6, 2006
910
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
Jul 19, 2006
Jul 19, 2006
911
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
Aug 6, 2006
Aug 6, 2006
912
Uint8 *palette;
Jul 19, 2006
Jul 19, 2006
913
Aug 6, 2006
Aug 6, 2006
914
915
916
917
918
919
920
921
922
923
924
925
if (!data->palette) {
SDL_SetError("Texture doesn't have a palette");
return -1;
}
palette = data->palette + firstcolor * 3;
while (ncolors--) {
colors->r = *palette++;
colors->g = *palette++;
colors->b = *palette++;
colors->unused = SDL_ALPHA_OPAQUE;
++colors;
}
Jul 19, 2006
Jul 19, 2006
926
927
928
return 0;
}
Jul 22, 2006
Jul 22, 2006
929
static void
Jul 22, 2006
Jul 22, 2006
930
931
SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
int pitch)
Jul 22, 2006
Jul 22, 2006
932
{
Aug 5, 2006
Aug 5, 2006
933
if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) {
Jul 22, 2006
Jul 22, 2006
934
renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
Aug 5, 2006
Aug 5, 2006
935
} else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) {
Jul 22, 2006
Jul 22, 2006
936
renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
Jul 22, 2006
Jul 22, 2006
937
}
Jul 22, 2006
Jul 22, 2006
938
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Nov 29, 2008
Nov 29, 2008
939
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
Dec 6, 2008
Dec 6, 2008
940
(pitch / bytes_per_pixel(texture->format)) / ((GL_TextureData *)texture->driverdata)->HACK_RYAN_FIXME);
Jul 22, 2006
Jul 22, 2006
941
942
}
Aug 28, 2006
Aug 28, 2006
943
944
945
static int
GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 28, 2006
Aug 28, 2006
946
return 0;
Aug 28, 2006
Aug 28, 2006
947
948
949
950
951
}
static int
GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 28, 2006
Aug 28, 2006
952
return 0;
Aug 28, 2006
Aug 28, 2006
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
}
static int
GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
switch (texture->blendMode) {
case SDL_TEXTUREBLENDMODE_NONE:
case SDL_TEXTUREBLENDMODE_MASK:
case SDL_TEXTUREBLENDMODE_BLEND:
case SDL_TEXTUREBLENDMODE_ADD:
case SDL_TEXTUREBLENDMODE_MOD:
return 0;
default:
SDL_Unsupported();
texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
return -1;
}
}
static int
GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
switch (texture->scaleMode) {
case SDL_TEXTURESCALEMODE_NONE:
case SDL_TEXTURESCALEMODE_FAST:
case SDL_TEXTURESCALEMODE_SLOW:
return 0;
case SDL_TEXTURESCALEMODE_BEST:
SDL_Unsupported();
texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
return -1;
default:
SDL_Unsupported();
texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
return -1;
}
}
Jul 19, 2006
Jul 19, 2006
991
992
993
994
static int
GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
Jul 22, 2006
Jul 22, 2006
995
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
Jul 19, 2006
Jul 19, 2006
996
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
Jul 22, 2006
Jul 22, 2006
997
GLenum result;
Jul 19, 2006
Jul 19, 2006
998
Jul 22, 2006
Jul 22, 2006
999
1000
renderdata->glGetError();
SetupTextureUpdate(renderdata, texture, pitch);