comparison src/video/SDL_video.c @ 2743:453ec0c21f6f

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