Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 2740:22c96d28449f
Added OpenGL ES support
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Tue, 02 Sep 2008 02:27:06 +0000 |
parents | 204be4fc2726 |
children | 453ec0c21f6f |
comparison
equal
deleted
inserted
replaced
2739:68862734a5fd | 2740:22c96d28449f |
---|---|
25 | 25 |
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 | |
31 | |
30 #include "SDL_renderer_gl.h" | 32 #include "SDL_renderer_gl.h" |
33 #include "SDL_renderer_gles.h" | |
34 | |
31 #include "SDL_renderer_sw.h" | 35 #include "SDL_renderer_sw.h" |
32 #include "../events/SDL_sysevents.h" | 36 #include "../events/SDL_sysevents.h" |
33 #include "../events/SDL_events_c.h" | 37 #include "../events/SDL_events_c.h" |
38 | |
39 #if SDL_VIDEO_OPENGL_ES | |
40 #include "SDL_opengles.h" | |
41 #endif /* SDL_VIDEO_OPENGL_ES */ | |
34 | 42 |
35 #if SDL_VIDEO_OPENGL | 43 #if SDL_VIDEO_OPENGL |
36 #include "SDL_opengl.h" | 44 #include "SDL_opengl.h" |
37 | 45 |
38 /* On Windows, windows.h defines CreateWindow */ | 46 /* On Windows, windows.h defines CreateWindow */ |
101 &RISCOS_bootstrap, | 109 &RISCOS_bootstrap, |
102 #endif | 110 #endif |
103 #if SDL_VIDEO_DRIVER_OS2FS | 111 #if SDL_VIDEO_DRIVER_OS2FS |
104 &OS2FSLib_bootstrap, | 112 &OS2FSLib_bootstrap, |
105 #endif | 113 #endif |
106 #if SDL_VIDEO_DRIVER_NDS | 114 #if SDL_VIDEO_DRIVER_UIKIT |
107 &NDS_bootstrap, | 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 |
244 _this->gl_config.accum_blue_size = 0; | 252 _this->gl_config.accum_blue_size = 0; |
245 _this->gl_config.accum_alpha_size = 0; | 253 _this->gl_config.accum_alpha_size = 0; |
246 _this->gl_config.stereo = 0; | 254 _this->gl_config.stereo = 0; |
247 _this->gl_config.multisamplebuffers = 0; | 255 _this->gl_config.multisamplebuffers = 0; |
248 _this->gl_config.multisamplesamples = 0; | 256 _this->gl_config.multisamplesamples = 0; |
257 _this->gl_config.retained_backing = 1; /* most systems have retained backing on the color buffers */ | |
249 _this->gl_config.accelerated = -1; /* not known, don't set */ | 258 _this->gl_config.accelerated = -1; /* not known, don't set */ |
250 | 259 |
251 /* Initialize the video subsystem */ | 260 /* Initialize the video subsystem */ |
252 if (_this->VideoInit(_this) < 0) { | 261 if (_this->VideoInit(_this) < 0) { |
253 SDL_VideoQuit(); | 262 SDL_VideoQuit(); |
263 | 272 |
264 /* The software renderer is always available */ | 273 /* The software renderer is always available */ |
265 for (i = 0; i < _this->num_displays; ++i) { | 274 for (i = 0; i < _this->num_displays; ++i) { |
266 #if SDL_VIDEO_RENDER_OGL | 275 #if SDL_VIDEO_RENDER_OGL |
267 SDL_AddRenderDriver(i, &GL_RenderDriver); | 276 SDL_AddRenderDriver(i, &GL_RenderDriver); |
277 #endif | |
278 | |
279 #if SDL_VIDEO_RENDER_OGL_ES | |
280 SDL_AddRenderDriver(i, &GL_ES_RenderDriver); | |
268 #endif | 281 #endif |
269 if (_this->displays[i].num_render_drivers > 0) { | 282 if (_this->displays[i].num_render_drivers > 0) { |
270 SDL_AddRenderDriver(i, &SW_RenderDriver); | 283 SDL_AddRenderDriver(i, &SW_RenderDriver); |
271 } | 284 } |
272 } | 285 } |
1411 return 0; | 1424 return 0; |
1412 } | 1425 } |
1413 | 1426 |
1414 if (index < 0) { | 1427 if (index < 0) { |
1415 const char *override = SDL_getenv("SDL_VIDEO_RENDERER"); | 1428 const char *override = SDL_getenv("SDL_VIDEO_RENDERER"); |
1416 int n = SDL_GetNumRenderDrivers(); | 1429 |
1430 int n = SDL_GetNumRenderDrivers(); | |
1431 | |
1417 for (index = 0; index < n; ++index) { | 1432 for (index = 0; index < n; ++index) { |
1418 SDL_RenderDriver *driver = | 1433 SDL_RenderDriver *driver = |
1419 &SDL_CurrentDisplay.render_drivers[index]; | 1434 &SDL_CurrentDisplay.render_drivers[index]; |
1420 | 1435 |
1421 if (override) { | 1436 if (override) { |
1444 SDL_DestroyRenderer(windowID); | 1459 SDL_DestroyRenderer(windowID); |
1445 | 1460 |
1446 /* Create a new renderer instance */ | 1461 /* Create a new renderer instance */ |
1447 window->renderer = SDL_CurrentDisplay.render_drivers[index] | 1462 window->renderer = SDL_CurrentDisplay.render_drivers[index] |
1448 .CreateRenderer(window, flags); | 1463 .CreateRenderer(window, flags); |
1464 | |
1449 SDL_SelectRenderer(window->id); | 1465 SDL_SelectRenderer(window->id); |
1450 | 1466 |
1451 return 0; | 1467 return 0; |
1452 } | 1468 } |
1453 | 1469 |
1547 SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface"); | 1563 SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface"); |
1548 return 0; | 1564 return 0; |
1549 } | 1565 } |
1550 fmt = surface->format; | 1566 fmt = surface->format; |
1551 | 1567 |
1552 if (format) { | 1568 if (format) { /* if we were passed in a format */ |
1553 if (!SDL_PixelFormatEnumToMasks | 1569 if (!SDL_PixelFormatEnumToMasks |
1554 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | 1570 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
1555 SDL_SetError("Unknown pixel format"); | 1571 SDL_SetError("Unknown pixel format"); |
1556 return 0; | 1572 return 0; |
1557 } | 1573 } |
1558 } else { | 1574 } else { |
1559 if (surface->format->Amask | 1575 if (surface->format->Amask |
1560 || !(surface->map->info.flags & | 1576 || !(surface->map->info.flags & |
1561 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { | 1577 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { |
1562 bpp = fmt->BitsPerPixel; | 1578 bpp = fmt->BitsPerPixel; |
1563 Rmask = fmt->Rmask; | 1579 Rmask = fmt->Rmask; |
1564 Gmask = fmt->Gmask; | 1580 Gmask = fmt->Gmask; |
1565 Bmask = fmt->Bmask; | 1581 Bmask = fmt->Bmask; |
1566 Amask = fmt->Amask; | 1582 Amask = fmt->Amask; |
1567 } else { | 1583 } else { |
1577 SDL_SetError("Unknown pixel format"); | 1593 SDL_SetError("Unknown pixel format"); |
1578 return 0; | 1594 return 0; |
1579 } | 1595 } |
1580 } | 1596 } |
1581 | 1597 |
1582 textureID = | 1598 textureID = SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, |
1583 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, | |
1584 surface->h); | 1599 surface->h); |
1585 if (!textureID) { | 1600 if (!textureID) { |
1586 return 0; | 1601 return 0; |
1587 } | 1602 } |
1588 | 1603 |
1613 if (dst_fmt->palette) { | 1628 if (dst_fmt->palette) { |
1614 /* FIXME: Should we try to copy fmt->palette? */ | 1629 /* FIXME: Should we try to copy fmt->palette? */ |
1615 SDL_DitherColors(dst_fmt->palette->colors, | 1630 SDL_DitherColors(dst_fmt->palette->colors, |
1616 SDL_BITSPERPIXEL(format)); | 1631 SDL_BITSPERPIXEL(format)); |
1617 } | 1632 } |
1618 } | 1633 } |
1619 | 1634 dst = SDL_ConvertSurface(surface, dst_fmt, 0); |
1620 dst = SDL_ConvertSurface(surface, dst_fmt, 0); | |
1621 if (dst) { | 1635 if (dst) { |
1622 SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch); | 1636 SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch); |
1623 SDL_FreeSurface(dst); | 1637 SDL_FreeSurface(dst); |
1624 } | 1638 } |
1625 if (dst_fmt->palette) { | 1639 if (dst_fmt->palette) { |
1629 } | 1643 } |
1630 if (!dst) { | 1644 if (!dst) { |
1631 SDL_DestroyTexture(textureID); | 1645 SDL_DestroyTexture(textureID); |
1632 return 0; | 1646 return 0; |
1633 } | 1647 } |
1634 } | 1648 } |
1635 | 1649 |
1636 if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { | 1650 if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { |
1637 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, | 1651 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, |
1638 fmt->palette->ncolors); | 1652 fmt->palette->ncolors); |
1639 } | 1653 } |
1997 } | 2011 } |
1998 | 2012 |
1999 int | 2013 int |
2000 SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect) | 2014 SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect) |
2001 { | 2015 { |
2016 | |
2002 SDL_Renderer *renderer; | 2017 SDL_Renderer *renderer; |
2003 SDL_Window *window; | 2018 SDL_Window *window; |
2004 SDL_Rect real_rect; | 2019 SDL_Rect real_rect; |
2005 | 2020 |
2006 if (!_this) { | 2021 if (!_this) { |
2282 } | 2297 } |
2283 | 2298 |
2284 SDL_bool | 2299 SDL_bool |
2285 SDL_GL_ExtensionSupported(const char *extension) | 2300 SDL_GL_ExtensionSupported(const char *extension) |
2286 { | 2301 { |
2287 #if SDL_VIDEO_OPENGL | 2302 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES |
2288 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); | 2303 |
2304 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); | |
2289 const char *extensions; | 2305 const char *extensions; |
2290 const char *start; | 2306 const char *start; |
2291 const char *where, *terminator; | 2307 const char *where, *terminator; |
2292 | 2308 |
2293 /* Extension names should not have spaces. */ | 2309 /* Extension names should not have spaces. */ |
2338 } | 2354 } |
2339 | 2355 |
2340 int | 2356 int |
2341 SDL_GL_SetAttribute(SDL_GLattr attr, int value) | 2357 SDL_GL_SetAttribute(SDL_GLattr attr, int value) |
2342 { | 2358 { |
2343 #if SDL_VIDEO_OPENGL | 2359 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES |
2344 int retval; | 2360 int retval; |
2345 | 2361 |
2346 if (!_this) { | 2362 if (!_this) { |
2347 SDL_UninitializedVideo(); | 2363 SDL_UninitializedVideo(); |
2348 return -1; | 2364 return -1; |
2396 _this->gl_config.multisamplesamples = value; | 2412 _this->gl_config.multisamplesamples = value; |
2397 break; | 2413 break; |
2398 case SDL_GL_ACCELERATED_VISUAL: | 2414 case SDL_GL_ACCELERATED_VISUAL: |
2399 _this->gl_config.accelerated = value; | 2415 _this->gl_config.accelerated = value; |
2400 break; | 2416 break; |
2417 case SDL_GL_RETAINED_BACKING: | |
2418 _this->gl_config.retained_backing = value; | |
2419 break; | |
2401 default: | 2420 default: |
2402 SDL_SetError("Unknown OpenGL attribute"); | 2421 SDL_SetError("Unknown OpenGL attribute"); |
2403 retval = -1; | 2422 retval = -1; |
2404 break; | 2423 break; |
2405 } | 2424 } |
2411 } | 2430 } |
2412 | 2431 |
2413 int | 2432 int |
2414 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) | 2433 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) |
2415 { | 2434 { |
2416 #if SDL_VIDEO_OPENGL | 2435 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES |
2417 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); | 2436 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); |
2418 GLenum attrib = 0; | 2437 GLenum attrib = 0; |
2419 | 2438 |
2420 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv"); | 2439 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv"); |
2421 if (!glGetIntegervFunc) { | 2440 if (!glGetIntegervFunc) { |
2422 return -1; | 2441 return -1; |
2423 } | 2442 } |
2424 switch (attr) { | 2443 switch (attr) { |
2444 case SDL_GL_RETAINED_BACKING: | |
2445 *value = _this->gl_config.retained_backing; | |
2446 return 0; | |
2425 case SDL_GL_RED_SIZE: | 2447 case SDL_GL_RED_SIZE: |
2426 attrib = GL_RED_BITS; | 2448 attrib = GL_RED_BITS; |
2427 break; | 2449 break; |
2428 case SDL_GL_BLUE_SIZE: | 2450 case SDL_GL_BLUE_SIZE: |
2429 attrib = GL_BLUE_BITS; | 2451 attrib = GL_BLUE_BITS; |
2433 break; | 2455 break; |
2434 case SDL_GL_ALPHA_SIZE: | 2456 case SDL_GL_ALPHA_SIZE: |
2435 attrib = GL_ALPHA_BITS; | 2457 attrib = GL_ALPHA_BITS; |
2436 break; | 2458 break; |
2437 case SDL_GL_DOUBLEBUFFER: | 2459 case SDL_GL_DOUBLEBUFFER: |
2460 #ifndef SDL_VIDEO_OPENGL_ES | |
2438 attrib = GL_DOUBLEBUFFER; | 2461 attrib = GL_DOUBLEBUFFER; |
2439 break; | 2462 break; |
2463 #else | |
2464 /* I believe double buffering is the only option in OpenGL ES | |
2465 -- in any case, GL_DOUBLEBUFFER doesn't exist */ | |
2466 *value = 1; | |
2467 return 0; | |
2468 #endif | |
2440 case SDL_GL_DEPTH_SIZE: | 2469 case SDL_GL_DEPTH_SIZE: |
2441 attrib = GL_DEPTH_BITS; | 2470 attrib = GL_DEPTH_BITS; |
2442 break; | 2471 break; |
2443 case SDL_GL_STENCIL_SIZE: | 2472 case SDL_GL_STENCIL_SIZE: |
2444 attrib = GL_STENCIL_BITS; | 2473 attrib = GL_STENCIL_BITS; |
2445 break; | 2474 break; |
2475 #ifndef SDL_VIDEO_OPENGL_ES | |
2446 case SDL_GL_ACCUM_RED_SIZE: | 2476 case SDL_GL_ACCUM_RED_SIZE: |
2447 attrib = GL_ACCUM_RED_BITS; | 2477 attrib = GL_ACCUM_RED_BITS; |
2448 break; | 2478 break; |
2449 case SDL_GL_ACCUM_GREEN_SIZE: | 2479 case SDL_GL_ACCUM_GREEN_SIZE: |
2450 attrib = GL_ACCUM_GREEN_BITS; | 2480 attrib = GL_ACCUM_GREEN_BITS; |
2453 attrib = GL_ACCUM_BLUE_BITS; | 2483 attrib = GL_ACCUM_BLUE_BITS; |
2454 break; | 2484 break; |
2455 case SDL_GL_ACCUM_ALPHA_SIZE: | 2485 case SDL_GL_ACCUM_ALPHA_SIZE: |
2456 attrib = GL_ACCUM_ALPHA_BITS; | 2486 attrib = GL_ACCUM_ALPHA_BITS; |
2457 break; | 2487 break; |
2458 case SDL_GL_STEREO: | 2488 case SDL_GL_STEREO: |
2459 attrib = GL_STEREO; | 2489 attrib = GL_STEREO; |
2460 break; | 2490 break; |
2461 case SDL_GL_MULTISAMPLEBUFFERS: | 2491 #else |
2462 attrib = GL_SAMPLE_BUFFERS_ARB; | 2492 case SDL_GL_ACCUM_RED_SIZE: |
2463 break; | 2493 case SDL_GL_ACCUM_GREEN_SIZE: |
2464 case SDL_GL_MULTISAMPLESAMPLES: | 2494 case SDL_GL_ACCUM_BLUE_SIZE: |
2465 attrib = GL_SAMPLES_ARB; | 2495 case SDL_GL_ACCUM_ALPHA_SIZE: |
2466 break; | 2496 case SDL_GL_STEREO: |
2497 /* none of these are supported in OpenGL ES */ | |
2498 *value = 0; | |
2499 return 0; | |
2500 #endif | |
2501 case SDL_GL_MULTISAMPLEBUFFERS: | |
2502 #ifndef SDL_VIDEO_OPENGL_ES | |
2503 attrib = GL_SAMPLE_BUFFERS_ARB; | |
2504 #else | |
2505 attrib = GL_SAMPLE_BUFFERS; | |
2506 #endif | |
2507 break; | |
2508 case SDL_GL_MULTISAMPLESAMPLES: | |
2509 #ifndef SDL_VIDEO_OPENGL_ES | |
2510 attrib = GL_SAMPLES_ARB; | |
2511 #else | |
2512 attrib = GL_SAMPLES; | |
2513 #endif | |
2514 break; | |
2467 case SDL_GL_BUFFER_SIZE: | 2515 case SDL_GL_BUFFER_SIZE: |
2468 { | 2516 { |
2469 GLint bits = 0; | 2517 GLint bits = 0; |
2470 GLint component; | 2518 GLint component; |
2471 | 2519 |
2508 | 2556 |
2509 if (!window) { | 2557 if (!window) { |
2510 return NULL; | 2558 return NULL; |
2511 } | 2559 } |
2512 if (!(window->flags & SDL_WINDOW_OPENGL)) { | 2560 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
2513 SDL_SetError("The specified window isn't an OpenGL window"); | |
2514 return NULL; | 2561 return NULL; |
2515 } | 2562 } |
2516 return _this->GL_CreateContext(_this, window); | 2563 return _this->GL_CreateContext(_this, window); |
2517 } | 2564 } |
2518 | 2565 |
2567 SDL_GL_SwapWindow(SDL_WindowID windowID) | 2614 SDL_GL_SwapWindow(SDL_WindowID windowID) |
2568 { | 2615 { |
2569 SDL_Window *window = SDL_GetWindowFromID(windowID); | 2616 SDL_Window *window = SDL_GetWindowFromID(windowID); |
2570 | 2617 |
2571 if (!window) { | 2618 if (!window) { |
2619 SDL_SetError("The specified window doesn't exist"); | |
2572 return; | 2620 return; |
2573 } | 2621 } |
2574 if (!(window->flags & SDL_WINDOW_OPENGL)) { | 2622 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
2575 SDL_SetError("The specified window isn't an OpenGL window"); | 2623 SDL_SetError("The specified window isn't an OpenGL window"); |
2576 return; | 2624 return; |