comparison src/video/SDL_video.c @ 2745:587d2b5fb805

Added support for OpenGL ES renderer
author Holmes Futrell <hfutrell@umail.ucsb.edu>
date Tue, 02 Sep 2008 20:19:45 +0000
parents 1aede15771d0
children 0969758c8809
comparison
equal deleted inserted replaced
2744:1aede15771d0 2745:587d2b5fb805
26 #include "SDL.h" 26 #include "SDL.h"
27 #include "SDL_sysvideo.h" 27 #include "SDL_sysvideo.h"
28 #include "SDL_blit.h" 28 #include "SDL_blit.h"
29 #include "SDL_pixels_c.h" 29 #include "SDL_pixels_c.h"
30 #include "SDL_renderer_gl.h" 30 #include "SDL_renderer_gl.h"
31 #include "SDL_renderer_gles.h"
31 #include "SDL_renderer_sw.h" 32 #include "SDL_renderer_sw.h"
32 #include "../events/SDL_sysevents.h" 33 #include "../events/SDL_sysevents.h"
33 #include "../events/SDL_events_c.h" 34 #include "../events/SDL_events_c.h"
35
36 #if SDL_VIDEO_OPENGL_ES
37 #include "SDL_opengles.h"
38 #endif /* SDL_VIDEO_OPENGL_ES */
34 39
35 #if SDL_VIDEO_OPENGL 40 #if SDL_VIDEO_OPENGL
36 #include "SDL_opengl.h" 41 #include "SDL_opengl.h"
37 42
38 /* On Windows, windows.h defines CreateWindow */ 43 /* On Windows, windows.h defines CreateWindow */
103 #if SDL_VIDEO_DRIVER_OS2FS 108 #if SDL_VIDEO_DRIVER_OS2FS
104 &OS2FSLib_bootstrap, 109 &OS2FSLib_bootstrap,
105 #endif 110 #endif
106 #if SDL_VIDEO_DRIVER_NDS 111 #if SDL_VIDEO_DRIVER_NDS
107 &NDS_bootstrap, 112 &NDS_bootstrap,
113 #endif
114 #if SDL_VIDEO_DRIVER_UIKIT
115 &UIKIT_bootstrap,
108 #endif 116 #endif
109 #if SDL_VIDEO_DRIVER_DUMMY 117 #if SDL_VIDEO_DRIVER_DUMMY
110 &DUMMY_bootstrap, 118 &DUMMY_bootstrap,
111 #endif 119 #endif
112 NULL 120 NULL
242 _this->gl_config.accum_blue_size = 0; 250 _this->gl_config.accum_blue_size = 0;
243 _this->gl_config.accum_alpha_size = 0; 251 _this->gl_config.accum_alpha_size = 0;
244 _this->gl_config.stereo = 0; 252 _this->gl_config.stereo = 0;
245 _this->gl_config.multisamplebuffers = 0; 253 _this->gl_config.multisamplebuffers = 0;
246 _this->gl_config.multisamplesamples = 0; 254 _this->gl_config.multisamplesamples = 0;
255 _this->gl_config.retained_backing = 1;
247 _this->gl_config.accelerated = -1; /* not known, don't set */ 256 _this->gl_config.accelerated = -1; /* not known, don't set */
248 257
249 /* Initialize the video subsystem */ 258 /* Initialize the video subsystem */
250 if (_this->VideoInit(_this) < 0) { 259 if (_this->VideoInit(_this) < 0) {
251 SDL_VideoQuit(); 260 SDL_VideoQuit();
259 } 268 }
260 /* The software renderer is always available */ 269 /* The software renderer is always available */
261 for (i = 0; i < _this->num_displays; ++i) { 270 for (i = 0; i < _this->num_displays; ++i) {
262 #if SDL_VIDEO_RENDER_OGL 271 #if SDL_VIDEO_RENDER_OGL
263 SDL_AddRenderDriver(i, &GL_RenderDriver); 272 SDL_AddRenderDriver(i, &GL_RenderDriver);
273 #endif
274
275 #if SDL_VIDEO_RENDER_OGL_ES
276 SDL_AddRenderDriver(i, &GL_ES_RenderDriver);
264 #endif 277 #endif
265 if (_this->displays[i].num_render_drivers > 0) { 278 if (_this->displays[i].num_render_drivers > 0) {
266 SDL_AddRenderDriver(i, &SW_RenderDriver); 279 SDL_AddRenderDriver(i, &SW_RenderDriver);
267 } 280 }
268 } 281 }
2200 } 2213 }
2201 2214
2202 SDL_bool 2215 SDL_bool
2203 SDL_GL_ExtensionSupported(const char *extension) 2216 SDL_GL_ExtensionSupported(const char *extension)
2204 { 2217 {
2205 #if SDL_VIDEO_OPENGL 2218 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
2206 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); 2219 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
2207 const char *extensions; 2220 const char *extensions;
2208 const char *start; 2221 const char *start;
2209 const char *where, *terminator; 2222 const char *where, *terminator;
2210 2223
2254 } 2267 }
2255 2268
2256 int 2269 int
2257 SDL_GL_SetAttribute(SDL_GLattr attr, int value) 2270 SDL_GL_SetAttribute(SDL_GLattr attr, int value)
2258 { 2271 {
2259 #if SDL_VIDEO_OPENGL 2272 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
2260 int retval; 2273 int retval;
2261 2274
2262 if (!_this) { 2275 if (!_this) {
2263 SDL_UninitializedVideo(); 2276 SDL_UninitializedVideo();
2264 return -1; 2277 return -1;
2310 case SDL_GL_MULTISAMPLESAMPLES: 2323 case SDL_GL_MULTISAMPLESAMPLES:
2311 _this->gl_config.multisamplesamples = value; 2324 _this->gl_config.multisamplesamples = value;
2312 break; 2325 break;
2313 case SDL_GL_ACCELERATED_VISUAL: 2326 case SDL_GL_ACCELERATED_VISUAL:
2314 _this->gl_config.accelerated = value; 2327 _this->gl_config.accelerated = value;
2328 break;
2329 case SDL_GL_RETAINED_BACKING:
2330 _this->gl_config.retained_backing = value;
2315 break; 2331 break;
2316 default: 2332 default:
2317 SDL_SetError("Unknown OpenGL attribute"); 2333 SDL_SetError("Unknown OpenGL attribute");
2318 retval = -1; 2334 retval = -1;
2319 break; 2335 break;
2326 } 2342 }
2327 2343
2328 int 2344 int
2329 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) 2345 SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
2330 { 2346 {
2331 #if SDL_VIDEO_OPENGL 2347 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
2332 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); 2348 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
2333 GLenum attrib = 0; 2349 GLenum attrib = 0;
2334 2350
2335 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv"); 2351 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
2336 if (!glGetIntegervFunc) { 2352 if (!glGetIntegervFunc) {
2337 return -1; 2353 return -1;
2338 } 2354 }
2339 switch (attr) { 2355 switch (attr) {
2356 case SDL_GL_RETAINED_BACKING:
2357 *value = _this->gl_config.retained_backing;
2358 return 0;
2340 case SDL_GL_RED_SIZE: 2359 case SDL_GL_RED_SIZE:
2341 attrib = GL_RED_BITS; 2360 attrib = GL_RED_BITS;
2342 break; 2361 break;
2343 case SDL_GL_BLUE_SIZE: 2362 case SDL_GL_BLUE_SIZE:
2344 attrib = GL_BLUE_BITS; 2363 attrib = GL_BLUE_BITS;
2348 break; 2367 break;
2349 case SDL_GL_ALPHA_SIZE: 2368 case SDL_GL_ALPHA_SIZE:
2350 attrib = GL_ALPHA_BITS; 2369 attrib = GL_ALPHA_BITS;
2351 break; 2370 break;
2352 case SDL_GL_DOUBLEBUFFER: 2371 case SDL_GL_DOUBLEBUFFER:
2372 #ifndef SDL_VIDEO_OPENGL_ES
2353 attrib = GL_DOUBLEBUFFER; 2373 attrib = GL_DOUBLEBUFFER;
2354 break; 2374 break;
2375 #else
2376 /*
2377 * I believe double buffering is the only option in OpenGL ES
2378 * -- in any case, GL_DOUBLEBUFFER doesn't exist
2379 */
2380 *value = 1;
2381 return 0;
2382 #endif
2355 case SDL_GL_DEPTH_SIZE: 2383 case SDL_GL_DEPTH_SIZE:
2356 attrib = GL_DEPTH_BITS; 2384 attrib = GL_DEPTH_BITS;
2357 break; 2385 break;
2358 case SDL_GL_STENCIL_SIZE: 2386 case SDL_GL_STENCIL_SIZE:
2359 attrib = GL_STENCIL_BITS; 2387 attrib = GL_STENCIL_BITS;
2360 break; 2388 break;
2389 #ifndef SDL_VIDEO_OPENGL_ES
2361 case SDL_GL_ACCUM_RED_SIZE: 2390 case SDL_GL_ACCUM_RED_SIZE:
2362 attrib = GL_ACCUM_RED_BITS; 2391 attrib = GL_ACCUM_RED_BITS;
2363 break; 2392 break;
2364 case SDL_GL_ACCUM_GREEN_SIZE: 2393 case SDL_GL_ACCUM_GREEN_SIZE:
2365 attrib = GL_ACCUM_GREEN_BITS; 2394 attrib = GL_ACCUM_GREEN_BITS;
2371 attrib = GL_ACCUM_ALPHA_BITS; 2400 attrib = GL_ACCUM_ALPHA_BITS;
2372 break; 2401 break;
2373 case SDL_GL_STEREO: 2402 case SDL_GL_STEREO:
2374 attrib = GL_STEREO; 2403 attrib = GL_STEREO;
2375 break; 2404 break;
2405 #else
2406 case SDL_GL_ACCUM_RED_SIZE:
2407 case SDL_GL_ACCUM_GREEN_SIZE:
2408 case SDL_GL_ACCUM_BLUE_SIZE:
2409 case SDL_GL_ACCUM_ALPHA_SIZE:
2410 case SDL_GL_STEREO:
2411 /* none of these are supported in OpenGL ES */
2412 *value = 0;
2413 return 0;
2414 #endif
2376 case SDL_GL_MULTISAMPLEBUFFERS: 2415 case SDL_GL_MULTISAMPLEBUFFERS:
2416 #ifndef SDL_VIDEO_OPENGL_ES
2377 attrib = GL_SAMPLE_BUFFERS_ARB; 2417 attrib = GL_SAMPLE_BUFFERS_ARB;
2418 #else
2419 attrib = GL_SAMPLE_BUFFERS;
2420 #endif
2378 break; 2421 break;
2379 case SDL_GL_MULTISAMPLESAMPLES: 2422 case SDL_GL_MULTISAMPLESAMPLES:
2423 #ifndef SDL_VIDEO_OPENGL_ES
2380 attrib = GL_SAMPLES_ARB; 2424 attrib = GL_SAMPLES_ARB;
2425 #else
2426 attrib = GL_SAMPLES;
2427 #endif
2381 break; 2428 break;
2382 case SDL_GL_BUFFER_SIZE: 2429 case SDL_GL_BUFFER_SIZE:
2383 { 2430 {
2384 GLint bits = 0; 2431 GLint bits = 0;
2385 GLint component; 2432 GLint component;