Mercurial > sdl-ios-xcode
comparison src/video/glesrenderer/SDL_renderer_gles.c @ 2456:da4fd7cf8745 gsoc2008_iphone
Renamed functions and structures to GLES (rather than GL) to avoid confusion with the OpenGL renderer, which prior used the same names. Removed references to GL_IMG_texture_format_BGRA8888, which will not be supported here. Made it so renderer no longer caches texture filter mode, because I think that is actually bound to specific textures, so we'd need to cache the currently bound texture too ... I don't want to go through that trouble. DOES cache blend function though.
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Sat, 16 Aug 2008 00:25:03 +0000 |
parents | aad0c5ccf6bb |
children |
comparison
equal
deleted
inserted
replaced
2455:0416aeddbb86 | 2456:da4fd7cf8745 |
---|---|
28 #include "SDL_sysvideo.h" | 28 #include "SDL_sysvideo.h" |
29 #include "SDL_pixels_c.h" | 29 #include "SDL_pixels_c.h" |
30 #include "SDL_rect_c.h" | 30 #include "SDL_rect_c.h" |
31 #include "SDL_yuv_sw_c.h" | 31 #include "SDL_yuv_sw_c.h" |
32 | 32 |
33 /* OpenGL ES 1.1 renderer implementation */ | 33 /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */ |
34 | 34 |
35 static const float inv255f = 1.0f / 255.0f; | 35 static const float inv255f = 1.0f / 255.0f; |
36 | 36 |
37 static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); | 37 static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags); |
38 static int GL_ActivateRenderer(SDL_Renderer * renderer); | 38 static int GLES_ActivateRenderer(SDL_Renderer * renderer); |
39 static int GL_DisplayModeChanged(SDL_Renderer * renderer); | 39 static int GLES_DisplayModeChanged(SDL_Renderer * renderer); |
40 static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 40 static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
41 static int GL_QueryTexturePixels(SDL_Renderer * renderer, | 41 static int GLES_QueryTexturePixels(SDL_Renderer * renderer, |
42 SDL_Texture * texture, void **pixels, | 42 SDL_Texture * texture, void **pixels, |
43 int *pitch); | 43 int *pitch); |
44 static int GL_SetTexturePalette(SDL_Renderer * renderer, | 44 static int GLES_SetTexturePalette(SDL_Renderer * renderer, |
45 SDL_Texture * texture, | 45 SDL_Texture * texture, |
46 const SDL_Color * colors, int firstcolor, | 46 const SDL_Color * colors, int firstcolor, |
47 int ncolors); | 47 int ncolors); |
48 static int GL_GetTexturePalette(SDL_Renderer * renderer, | 48 static int GLES_GetTexturePalette(SDL_Renderer * renderer, |
49 SDL_Texture * texture, SDL_Color * colors, | 49 SDL_Texture * texture, SDL_Color * colors, |
50 int firstcolor, int ncolors); | 50 int firstcolor, int ncolors); |
51 static int GL_SetTextureColorMod(SDL_Renderer * renderer, | 51 static int GLES_SetTextureColorMod(SDL_Renderer * renderer, |
52 SDL_Texture * texture); | 52 SDL_Texture * texture); |
53 static int GL_SetTextureAlphaMod(SDL_Renderer * renderer, | 53 static int GLES_SetTextureAlphaMod(SDL_Renderer * renderer, |
54 SDL_Texture * texture); | 54 SDL_Texture * texture); |
55 static int GL_SetTextureBlendMode(SDL_Renderer * renderer, | 55 static int GLES_SetTextureBlendMode(SDL_Renderer * renderer, |
56 SDL_Texture * texture); | 56 SDL_Texture * texture); |
57 static int GL_SetTextureScaleMode(SDL_Renderer * renderer, | 57 static int GLES_SetTextureScaleMode(SDL_Renderer * renderer, |
58 SDL_Texture * texture); | 58 SDL_Texture * texture); |
59 static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 59 static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
60 const SDL_Rect * rect, const void *pixels, | 60 const SDL_Rect * rect, const void *pixels, |
61 int pitch); | 61 int pitch); |
62 static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 62 static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
63 const SDL_Rect * rect, int markDirty, void **pixels, | 63 const SDL_Rect * rect, int markDirty, void **pixels, |
64 int *pitch); | 64 int *pitch); |
65 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 65 static void GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
66 static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 66 static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
67 int numrects, const SDL_Rect * rects); | 67 int numrects, const SDL_Rect * rects); |
68 static int GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, | 68 static int GLES_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, |
69 Uint8 a, const SDL_Rect * rect); | 69 Uint8 a, const SDL_Rect * rect); |
70 static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 70 static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
71 const SDL_Rect * srcrect, const SDL_Rect * dstrect); | 71 const SDL_Rect * srcrect, const SDL_Rect * dstrect); |
72 static void GL_RenderPresent(SDL_Renderer * renderer); | 72 static void GLES_RenderPresent(SDL_Renderer * renderer); |
73 static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 73 static void GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
74 static void GL_DestroyRenderer(SDL_Renderer * renderer); | 74 static void GLES_DestroyRenderer(SDL_Renderer * renderer); |
75 | 75 |
76 | 76 |
77 SDL_RenderDriver GL_ES_RenderDriver = { | 77 SDL_RenderDriver GL_ES_RenderDriver = { |
78 GL_CreateRenderer, | 78 GLES_CreateRenderer, |
79 { | 79 { |
80 "opengl_es", | 80 "opengl_es", |
81 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD | | 81 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD | |
82 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), | 82 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), |
83 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | | 83 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | |
84 SDL_TEXTUREMODULATE_ALPHA), | 84 SDL_TEXTUREMODULATE_ALPHA), |
85 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK | | 85 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK | |
86 SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | | 86 SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | |
87 SDL_TEXTUREBLENDMODE_MOD), | 87 SDL_TEXTUREBLENDMODE_MOD), |
88 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | | 88 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | |
89 SDL_TEXTURESCALEMODE_SLOW), | 89 SDL_TEXTURESCALEMODE_SLOW), 2, |
90 #ifdef GL_IMG_texture_format_BGRA8888 | 90 { |
91 3, | |
92 #else | |
93 2, | |
94 #endif | |
95 { | |
96 #ifdef GL_IMG_texture_format_BGRA8888 | |
97 SDL_PIXELFORMAT_ARGB8888, | |
98 #endif | |
99 SDL_PIXELFORMAT_RGB24, | 91 SDL_PIXELFORMAT_RGB24, |
100 SDL_PIXELFORMAT_ABGR8888, | 92 SDL_PIXELFORMAT_ABGR8888, |
101 }, | 93 }, |
102 0, | 94 0, |
103 0} | 95 0} |
106 typedef struct | 98 typedef struct |
107 { | 99 { |
108 SDL_GLContext context; | 100 SDL_GLContext context; |
109 SDL_bool updateSize; | 101 SDL_bool updateSize; |
110 int blendMode; | 102 int blendMode; |
111 int scaleMode; | |
112 | 103 |
113 #ifndef APIENTRY | 104 #ifndef APIENTRY |
114 #define APIENTRY | 105 #define APIENTRY |
115 #endif | 106 #endif |
116 | 107 |
120 /* OpenGL ES functions */ | 111 /* OpenGL ES functions */ |
121 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; | 112 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; |
122 #include "SDL_glesfuncs.h" | 113 #include "SDL_glesfuncs.h" |
123 #undef SDL_PROC | 114 #undef SDL_PROC |
124 | 115 |
125 } GL_RenderData; | 116 } GLES_RenderData; |
126 | 117 |
127 typedef struct | 118 typedef struct |
128 { | 119 { |
129 GLuint texture; | 120 GLuint texture; |
130 GLenum type; | 121 GLenum type; |
133 GLenum format; | 124 GLenum format; |
134 GLenum formattype; | 125 GLenum formattype; |
135 void *pixels; | 126 void *pixels; |
136 int pitch; | 127 int pitch; |
137 SDL_DirtyRectList dirty; | 128 SDL_DirtyRectList dirty; |
138 } GL_TextureData; | 129 } GLES_TextureData; |
139 | 130 |
140 static void | 131 static void |
141 GL_SetError(const char *prefix, GLenum result) | 132 GLES_SetError(const char *prefix, GLenum result) |
142 { | 133 { |
143 const char *error; | 134 const char *error; |
144 | 135 |
145 switch (result) { | 136 switch (result) { |
146 case GL_NO_ERROR: | 137 case GL_NO_ERROR: |
170 } | 161 } |
171 SDL_SetError("%s: %s", prefix, error); | 162 SDL_SetError("%s: %s", prefix, error); |
172 } | 163 } |
173 | 164 |
174 static int | 165 static int |
175 GL_LoadFunctions(GL_RenderData * data) | 166 GLES_LoadFunctions(GLES_RenderData * data) |
176 { | 167 { |
177 | 168 |
178 #define SDL_PROC(ret,func,params) \ | 169 #define SDL_PROC(ret,func,params) \ |
179 data->func = func; | 170 data->func = func; |
180 #include "SDL_glesfuncs.h" | 171 #include "SDL_glesfuncs.h" |
182 | 173 |
183 return 0; | 174 return 0; |
184 } | 175 } |
185 | 176 |
186 void | 177 void |
187 GL_AddRenderDriver(_THIS) | 178 GLES_AddRenderDriver(_THIS) |
188 { | 179 { |
189 if (_this->GL_CreateContext) { | 180 if (_this->GL_CreateContext) { |
190 SDL_AddRenderDriver(0, &GL_ES_RenderDriver); | 181 SDL_AddRenderDriver(0, &GL_ES_RenderDriver); |
191 } | 182 } |
192 } | 183 } |
193 | 184 |
194 SDL_Renderer * | 185 SDL_Renderer * |
195 GL_CreateRenderer(SDL_Window * window, Uint32 flags) | 186 GLES_CreateRenderer(SDL_Window * window, Uint32 flags) |
196 { | 187 { |
197 | 188 |
198 printf("gl(es) create renderer ...\n"); | |
199 | |
200 SDL_Renderer *renderer; | 189 SDL_Renderer *renderer; |
201 GL_RenderData *data; | 190 GLES_RenderData *data; |
202 GLint value; | 191 GLint value; |
203 int doublebuffer; | 192 int doublebuffer; |
204 | 193 |
205 if (!(window->flags & SDL_WINDOW_OPENGL)) { | 194 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
206 if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) { | 195 if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) { |
212 if (!renderer) { | 201 if (!renderer) { |
213 SDL_OutOfMemory(); | 202 SDL_OutOfMemory(); |
214 return NULL; | 203 return NULL; |
215 } | 204 } |
216 | 205 |
217 data = (GL_RenderData *) SDL_calloc(1, sizeof(*data)); | 206 data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data)); |
218 if (!data) { | 207 if (!data) { |
219 GL_DestroyRenderer(renderer); | 208 GLES_DestroyRenderer(renderer); |
220 SDL_OutOfMemory(); | 209 SDL_OutOfMemory(); |
221 return NULL; | 210 return NULL; |
222 } | 211 } |
223 | 212 |
224 renderer->ActivateRenderer = GL_ActivateRenderer; | 213 renderer->ActivateRenderer = GLES_ActivateRenderer; |
225 renderer->DisplayModeChanged = GL_DisplayModeChanged; | 214 renderer->DisplayModeChanged = GLES_DisplayModeChanged; |
226 renderer->CreateTexture = GL_CreateTexture; | 215 renderer->CreateTexture = GLES_CreateTexture; |
227 renderer->QueryTexturePixels = GL_QueryTexturePixels; | 216 renderer->QueryTexturePixels = GLES_QueryTexturePixels; |
228 renderer->SetTexturePalette = GL_SetTexturePalette; | 217 renderer->SetTexturePalette = GLES_SetTexturePalette; |
229 renderer->GetTexturePalette = GL_GetTexturePalette; | 218 renderer->GetTexturePalette = GLES_GetTexturePalette; |
230 renderer->SetTextureColorMod = GL_SetTextureColorMod; | 219 renderer->SetTextureColorMod = GLES_SetTextureColorMod; |
231 renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod; | 220 renderer->SetTextureAlphaMod = GLES_SetTextureAlphaMod; |
232 renderer->SetTextureBlendMode = GL_SetTextureBlendMode; | 221 renderer->SetTextureBlendMode = GLES_SetTextureBlendMode; |
233 renderer->SetTextureScaleMode = GL_SetTextureScaleMode; | 222 renderer->SetTextureScaleMode = GLES_SetTextureScaleMode; |
234 renderer->UpdateTexture = GL_UpdateTexture; | 223 renderer->UpdateTexture = GLES_UpdateTexture; |
235 renderer->LockTexture = GL_LockTexture; | 224 renderer->LockTexture = GLES_LockTexture; |
236 renderer->UnlockTexture = GL_UnlockTexture; | 225 renderer->UnlockTexture = GLES_UnlockTexture; |
237 renderer->DirtyTexture = GL_DirtyTexture; | 226 renderer->DirtyTexture = GLES_DirtyTexture; |
238 renderer->RenderFill = GL_RenderFill; | 227 renderer->RenderFill = GLES_RenderFill; |
239 renderer->RenderCopy = GL_RenderCopy; | 228 renderer->RenderCopy = GLES_RenderCopy; |
240 renderer->RenderPresent = GL_RenderPresent; | 229 renderer->RenderPresent = GLES_RenderPresent; |
241 renderer->DestroyTexture = GL_DestroyTexture; | 230 renderer->DestroyTexture = GLES_DestroyTexture; |
242 renderer->DestroyRenderer = GL_DestroyRenderer; | 231 renderer->DestroyRenderer = GLES_DestroyRenderer; |
243 renderer->info = GL_ES_RenderDriver.info; | 232 renderer->info = GL_ES_RenderDriver.info; |
244 renderer->window = window->id; | 233 renderer->window = window->id; |
245 renderer->driverdata = data; | 234 renderer->driverdata = data; |
246 | 235 |
247 | 236 |
248 renderer->info.flags = (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED); | 237 renderer->info.flags = (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED); |
249 | 238 |
250 if (GL_LoadFunctions(data) < 0) { | 239 if (GLES_LoadFunctions(data) < 0) { |
251 GL_DestroyRenderer(renderer); | 240 GLES_DestroyRenderer(renderer); |
252 return NULL; | 241 return NULL; |
253 } | 242 } |
254 | 243 |
255 data->context = SDL_GL_CreateContext(window->id); | 244 data->context = SDL_GL_CreateContext(window->id); |
256 if (!data->context) { | 245 if (!data->context) { |
257 GL_DestroyRenderer(renderer); | 246 GLES_DestroyRenderer(renderer); |
258 return NULL; | 247 return NULL; |
259 } | 248 } |
260 if (SDL_GL_MakeCurrent(window->id, data->context) < 0) { | 249 if (SDL_GL_MakeCurrent(window->id, data->context) < 0) { |
261 GL_DestroyRenderer(renderer); | 250 GLES_DestroyRenderer(renderer); |
262 return NULL; | 251 return NULL; |
263 } | 252 } |
264 | 253 |
265 if (flags & SDL_RENDERER_PRESENTVSYNC) { | 254 if (flags & SDL_RENDERER_PRESENTVSYNC) { |
266 SDL_GL_SetSwapInterval(1); | 255 SDL_GL_SetSwapInterval(1); |
291 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); | 280 data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); |
292 renderer->info.max_texture_height = value; | 281 renderer->info.max_texture_height = value; |
293 | 282 |
294 /* Set up parameters for rendering */ | 283 /* Set up parameters for rendering */ |
295 data->blendMode = -1; | 284 data->blendMode = -1; |
296 data->scaleMode = -1; | |
297 data->glDisable(GL_DEPTH_TEST); | 285 data->glDisable(GL_DEPTH_TEST); |
298 data->glDisable(GL_CULL_FACE); | 286 data->glDisable(GL_CULL_FACE); |
299 data->glEnable(GL_TEXTURE_2D); | 287 data->glEnable(GL_TEXTURE_2D); |
300 data->updateSize = SDL_TRUE; | 288 data->updateSize = SDL_TRUE; |
301 | 289 |
302 return renderer; | 290 return renderer; |
303 } | 291 } |
304 | 292 |
305 static int GL_ActivateRenderer(SDL_Renderer * renderer) | 293 static int GLES_ActivateRenderer(SDL_Renderer * renderer) |
306 { | 294 { |
307 | 295 |
308 GL_RenderData *data = (GL_RenderData *)renderer->driverdata; | 296 GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata; |
309 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 297 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
310 | 298 |
311 if (SDL_GL_MakeCurrent(window->id, data->context) < 0) { | 299 if (SDL_GL_MakeCurrent(window->id, data->context) < 0) { |
312 return -1; | 300 return -1; |
313 } | 301 } |
323 } | 311 } |
324 return 0; | 312 return 0; |
325 } | 313 } |
326 | 314 |
327 static int | 315 static int |
328 GL_DisplayModeChanged(SDL_Renderer * renderer) | 316 GLES_DisplayModeChanged(SDL_Renderer * renderer) |
329 { | 317 { |
330 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; | 318 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
331 | 319 |
332 data->updateSize = SDL_TRUE; | 320 data->updateSize = SDL_TRUE; |
333 return 0; | 321 return 0; |
334 } | 322 } |
335 | 323 |
343 } | 331 } |
344 return value; | 332 return value; |
345 } | 333 } |
346 | 334 |
347 static int | 335 static int |
348 GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 336 GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
349 { | 337 { |
350 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; | 338 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; |
351 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 339 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
352 GL_TextureData *data; | 340 GLES_TextureData *data; |
353 GLint internalFormat; | 341 GLint internalFormat; |
354 GLenum format, type; | 342 GLenum format, type; |
355 int texture_w, texture_h; | 343 int texture_w, texture_h; |
356 GLenum result; | 344 GLenum result; |
357 switch (texture->format) { | 345 switch (texture->format) { |
362 case SDL_PIXELFORMAT_RGB444: | 350 case SDL_PIXELFORMAT_RGB444: |
363 case SDL_PIXELFORMAT_RGB555: | 351 case SDL_PIXELFORMAT_RGB555: |
364 case SDL_PIXELFORMAT_ARGB4444: | 352 case SDL_PIXELFORMAT_ARGB4444: |
365 case SDL_PIXELFORMAT_ARGB1555: | 353 case SDL_PIXELFORMAT_ARGB1555: |
366 case SDL_PIXELFORMAT_BGR24: | 354 case SDL_PIXELFORMAT_BGR24: |
367 case SDL_PIXELFORMAT_BGR888: /* can't convert 32 bit format to 24 */ | 355 case SDL_PIXELFORMAT_BGR888: |
368 case SDL_PIXELFORMAT_RGB888: | 356 case SDL_PIXELFORMAT_RGB888: |
369 case SDL_PIXELFORMAT_RGBA8888: | 357 case SDL_PIXELFORMAT_RGBA8888: |
370 case SDL_PIXELFORMAT_ARGB2101010: | 358 case SDL_PIXELFORMAT_ARGB2101010: |
371 SDL_SetError("Unsupported format"); | |
372 return -1; | |
373 case SDL_PIXELFORMAT_ARGB8888: | 359 case SDL_PIXELFORMAT_ARGB8888: |
374 #ifdef GL_IMG_texture_format_BGRA8888 | |
375 internalFormat = GL_RGBA; | |
376 format = GL_RGBA; | |
377 type = GL_UNSIGNED_BYTE; | |
378 break; | |
379 #else | |
380 SDL_SetError("Unsupported format"); | |
381 return -1; | |
382 #endif | |
383 case SDL_PIXELFORMAT_RGB24: | 360 case SDL_PIXELFORMAT_RGB24: |
384 internalFormat = GL_RGB; | 361 internalFormat = GL_RGB; |
385 format = GL_RGB; | 362 format = GL_RGB; |
386 type = GL_UNSIGNED_BYTE; | 363 type = GL_UNSIGNED_BYTE; |
387 break; | 364 break; |
410 */ | 387 */ |
411 default: | 388 default: |
412 SDL_SetError("Unsupported texture format"); | 389 SDL_SetError("Unsupported texture format"); |
413 return -1; | 390 return -1; |
414 } | 391 } |
415 data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); | 392 |
393 data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data)); | |
416 if (!data) { | 394 if (!data) { |
417 SDL_OutOfMemory(); | 395 SDL_OutOfMemory(); |
418 return -1; | 396 return -1; |
419 } | 397 } |
420 | 398 |
432 | 410 |
433 renderdata->glGetError(); | 411 renderdata->glGetError(); |
434 renderdata->glGenTextures(1, &data->texture); | 412 renderdata->glGenTextures(1, &data->texture); |
435 | 413 |
436 data->type = GL_TEXTURE_2D; | 414 data->type = GL_TEXTURE_2D; |
415 /* no NPOV textures allowed in OpenGL ES (yet) */ | |
437 texture_w = power_of_2(texture->w); | 416 texture_w = power_of_2(texture->w); |
438 texture_h = power_of_2(texture->h); | 417 texture_h = power_of_2(texture->h); |
439 data->texw = (GLfloat) texture->w / texture_w; | 418 data->texw = (GLfloat) texture->w / texture_w; |
440 data->texh = (GLfloat) texture->h / texture_h; | 419 data->texh = (GLfloat) texture->h / texture_h; |
441 | 420 |
454 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, | 433 renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, |
455 texture_h, 0, format, type, NULL); | 434 texture_h, 0, format, type, NULL); |
456 | 435 |
457 result = renderdata->glGetError(); | 436 result = renderdata->glGetError(); |
458 if (result != GL_NO_ERROR) { | 437 if (result != GL_NO_ERROR) { |
459 GL_SetError("glTexImage2D()", result); | 438 GLES_SetError("glTexImage2D()", result); |
460 return -1; | 439 return -1; |
461 } | 440 } |
462 return 0; | 441 return 0; |
463 } | 442 } |
464 | 443 |
465 static int | 444 static int |
466 GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, | 445 GLES_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, |
467 void **pixels, int *pitch) | 446 void **pixels, int *pitch) |
468 { | 447 { |
469 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 448 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; |
470 | 449 |
471 *pixels = data->pixels; | 450 *pixels = data->pixels; |
472 *pitch = data->pitch; | 451 *pitch = data->pitch; |
473 return 0; | 452 return 0; |
474 } | 453 } |
475 | 454 |
476 static int | 455 static int |
477 GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | 456 GLES_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, |
478 const SDL_Color * colors, int firstcolor, int ncolors) | 457 const SDL_Color * colors, int firstcolor, int ncolors) |
479 { | 458 { |
480 SDL_SetError("OpenGL ES does not support paletted textures"); | 459 SDL_SetError("OpenGL ES does not support paletted textures"); |
481 return -1; | 460 return -1; |
482 } | 461 } |
483 | 462 |
484 static int | 463 static int |
485 GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | 464 GLES_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, |
486 SDL_Color * colors, int firstcolor, int ncolors) | 465 SDL_Color * colors, int firstcolor, int ncolors) |
487 { | 466 { |
488 SDL_SetError("OpenGL ES does not support paletted textures"); | 467 SDL_SetError("OpenGL ES does not support paletted textures"); |
489 return -1; | 468 return -1; |
490 } | 469 } |
491 | 470 |
492 static void | 471 static void |
493 SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture, | 472 SetupTextureUpdate(GLES_RenderData * renderdata, SDL_Texture * texture, |
494 int pitch) | 473 int pitch) |
495 { | 474 { |
496 | 475 |
497 | 476 |
498 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 477 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; |
499 renderdata->glBindTexture(data->type, data->texture); | 478 renderdata->glBindTexture(data->type, data->texture); |
500 renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | 479 renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
501 } | 480 } |
502 | 481 |
503 static int | 482 static int |
504 GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | 483 GLES_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) |
505 { | 484 { |
506 return 0; | 485 return 0; |
507 } | 486 } |
508 | 487 |
509 static int | 488 static int |
510 GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | 489 GLES_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) |
511 { | 490 { |
512 return 0; | 491 return 0; |
513 } | 492 } |
514 | 493 |
515 static int | 494 static int |
516 GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | 495 GLES_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) |
517 { | 496 { |
518 switch (texture->blendMode) { | 497 switch (texture->blendMode) { |
519 case SDL_TEXTUREBLENDMODE_NONE: | 498 case SDL_TEXTUREBLENDMODE_NONE: |
520 case SDL_TEXTUREBLENDMODE_MASK: | 499 case SDL_TEXTUREBLENDMODE_MASK: |
521 case SDL_TEXTUREBLENDMODE_BLEND: | 500 case SDL_TEXTUREBLENDMODE_BLEND: |
528 return -1; | 507 return -1; |
529 } | 508 } |
530 } | 509 } |
531 | 510 |
532 static int | 511 static int |
533 GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | 512 GLES_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) |
534 { | 513 { |
535 switch (texture->scaleMode) { | 514 switch (texture->scaleMode) { |
536 case SDL_TEXTURESCALEMODE_NONE: | 515 case SDL_TEXTURESCALEMODE_NONE: |
537 case SDL_TEXTURESCALEMODE_FAST: | 516 case SDL_TEXTURESCALEMODE_FAST: |
538 case SDL_TEXTURESCALEMODE_SLOW: | 517 case SDL_TEXTURESCALEMODE_SLOW: |
547 return -1; | 526 return -1; |
548 } | 527 } |
549 } | 528 } |
550 | 529 |
551 static int | 530 static int |
552 GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 531 GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
553 const SDL_Rect * rect, const void *pixels, int pitch) | 532 const SDL_Rect * rect, const void *pixels, int pitch) |
554 { | 533 { |
555 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; | 534 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; |
556 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 535 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; |
557 GLenum result; | 536 GLenum result; |
558 | 537 |
559 SetupTextureUpdate(renderdata, texture, pitch); | 538 SetupTextureUpdate(renderdata, texture, pitch); |
560 renderdata->glGetError(); | 539 renderdata->glGetError(); |
561 renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, | 540 renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, |
562 rect->h, data->format, data->formattype, | 541 rect->h, data->format, data->formattype, |
563 pixels); | 542 pixels); |
564 result = renderdata->glGetError(); | 543 result = renderdata->glGetError(); |
565 if (result != GL_NO_ERROR) { | 544 if (result != GL_NO_ERROR) { |
566 GL_SetError("glTexSubImage2D()", result); | 545 GLES_SetError("glTexSubImage2D()", result); |
567 return -1; | 546 return -1; |
568 } | 547 } |
569 return 0; | 548 return 0; |
570 } | 549 } |
571 | 550 |
572 static int | 551 static int |
573 GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 552 GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
574 const SDL_Rect * rect, int markDirty, void **pixels, | 553 const SDL_Rect * rect, int markDirty, void **pixels, |
575 int *pitch) | 554 int *pitch) |
576 { | 555 { |
577 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 556 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; |
578 | 557 |
579 if (markDirty) { | 558 if (markDirty) { |
580 SDL_AddDirtyRect(&data->dirty, rect); | 559 SDL_AddDirtyRect(&data->dirty, rect); |
581 } | 560 } |
582 | 561 |
586 *pitch = data->pitch; | 565 *pitch = data->pitch; |
587 return 0; | 566 return 0; |
588 } | 567 } |
589 | 568 |
590 static void | 569 static void |
591 GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 570 GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
592 { | 571 { |
593 } | 572 } |
594 | 573 |
595 static void | 574 static void |
596 GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects, | 575 GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects, |
597 const SDL_Rect * rects) | 576 const SDL_Rect * rects) |
598 { | 577 { |
599 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 578 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; |
600 int i; | 579 int i; |
601 | 580 |
602 for (i = 0; i < numrects; ++i) { | 581 for (i = 0; i < numrects; ++i) { |
603 SDL_AddDirtyRect(&data->dirty, &rects[i]); | 582 SDL_AddDirtyRect(&data->dirty, &rects[i]); |
604 } | 583 } |
605 } | 584 } |
606 | 585 |
607 static int | 586 static int |
608 GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, | 587 GLES_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
609 const SDL_Rect * rect) | 588 const SDL_Rect * rect) |
610 { | 589 { |
611 | 590 |
612 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; | 591 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
613 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 592 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
614 | 593 |
615 /* set proper drawing color */ | 594 /* set proper drawing color */ |
616 GLfloat oldClearColor[4]; | 595 GLfloat oldClearColor[4]; |
617 | 596 |
630 | 609 |
631 return 0; | 610 return 0; |
632 } | 611 } |
633 | 612 |
634 static int | 613 static int |
635 GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 614 GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
636 const SDL_Rect * srcrect, const SDL_Rect * dstrect) | 615 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
637 { | 616 { |
638 | 617 |
639 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; | 618 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
640 GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata; | 619 GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; |
641 int minx, miny, maxx, maxy; | 620 int minx, miny, maxx, maxy; |
642 GLfloat minu, maxu, minv, maxv; | 621 GLfloat minu, maxu, minv, maxv; |
643 int i; | 622 int i; |
644 void *temp_buffer; /* used for reformatting dirty rect pixels */ | 623 void *temp_buffer; /* used for reformatting dirty rect pixels */ |
645 void *temp_ptr; | 624 void *temp_ptr; |
690 (GLfloat) texture->a * inv255f); | 669 (GLfloat) texture->a * inv255f); |
691 } else { | 670 } else { |
692 data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | 671 data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |
693 } | 672 } |
694 | 673 |
695 //if (texture->blendMode != data->blendMode) { | 674 if (texture->blendMode != data->blendMode) { |
696 switch (texture->blendMode) { | 675 switch (texture->blendMode) { |
697 case SDL_TEXTUREBLENDMODE_NONE: | 676 case SDL_TEXTUREBLENDMODE_NONE: |
698 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); | 677 data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); |
699 data->glDisable(GL_BLEND); | 678 data->glDisable(GL_BLEND); |
700 break; | 679 break; |
714 data->glEnable(GL_BLEND); | 693 data->glEnable(GL_BLEND); |
715 data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); | 694 data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); |
716 break; | 695 break; |
717 } | 696 } |
718 data->blendMode = texture->blendMode; | 697 data->blendMode = texture->blendMode; |
719 // } | 698 } |
720 | 699 |
721 // if (texture->scaleMode != data->scaleMode) { | 700 switch (texture->scaleMode) { |
722 switch (texture->scaleMode) { | 701 case SDL_TEXTURESCALEMODE_NONE: |
723 case SDL_TEXTURESCALEMODE_NONE: | 702 case SDL_TEXTURESCALEMODE_FAST: |
724 case SDL_TEXTURESCALEMODE_FAST: | 703 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, |
725 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, | 704 GL_NEAREST); |
726 GL_NEAREST); | 705 data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, |
727 data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, | 706 GL_NEAREST); |
728 GL_NEAREST); | 707 break; |
729 break; | 708 case SDL_TEXTURESCALEMODE_SLOW: |
730 case SDL_TEXTURESCALEMODE_SLOW: | 709 case SDL_TEXTURESCALEMODE_BEST: |
731 case SDL_TEXTURESCALEMODE_BEST: | 710 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, |
732 data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, | 711 GL_LINEAR); |
733 GL_LINEAR); | 712 data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, |
734 data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, | 713 GL_LINEAR); |
735 GL_LINEAR); | 714 break; |
736 break; | 715 } |
737 } | |
738 data->scaleMode = texture->scaleMode; | |
739 //} | |
740 | 716 |
741 if (data->GL_OES_draw_texture_supported && data->useDrawTexture) { | 717 if (data->GL_OES_draw_texture_supported && data->useDrawTexture) { |
742 /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */ | 718 /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */ |
743 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | 719 SDL_Window *window = SDL_GetWindowFromID(renderer->window); |
744 GLint cropRect[4]; | 720 GLint cropRect[4]; |
788 | 764 |
789 return 0; | 765 return 0; |
790 } | 766 } |
791 | 767 |
792 static void | 768 static void |
793 GL_RenderPresent(SDL_Renderer * renderer) | 769 GLES_RenderPresent(SDL_Renderer * renderer) |
794 { | 770 { |
795 SDL_GL_SwapWindow(renderer->window); | 771 SDL_GL_SwapWindow(renderer->window); |
796 } | 772 } |
797 | 773 |
798 static void | 774 static void |
799 GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 775 GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
800 { | 776 { |
801 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; | 777 GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; |
802 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 778 GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; |
803 | 779 |
804 if (!data) { | 780 if (!data) { |
805 return; | 781 return; |
806 } | 782 } |
807 if (data->texture) { | 783 if (data->texture) { |
814 SDL_free(data); | 790 SDL_free(data); |
815 texture->driverdata = NULL; | 791 texture->driverdata = NULL; |
816 } | 792 } |
817 | 793 |
818 static void | 794 static void |
819 GL_DestroyRenderer(SDL_Renderer * renderer) | 795 GLES_DestroyRenderer(SDL_Renderer * renderer) |
820 { | 796 { |
821 GL_RenderData *data = (GL_RenderData *) renderer->driverdata; | 797 GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; |
822 | 798 |
823 if (data) { | 799 if (data) { |
824 if (data->context) { | 800 if (data->context) { |
825 /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */ | 801 /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */ |
826 SDL_GL_DeleteContext(data->context); | 802 SDL_GL_DeleteContext(data->context); |