comparison src/video/SDL_video.c @ 3488:3d2f42580488

Fixed bug #771 Cleaned up the code a bit and made sure that an OpenGL window gets the OpenGL renderer. Inspired by a patch from Mason Wheeler.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 24 Nov 2009 16:43:18 +0000
parents c87dbbde2bc2
children e1bd98b56e94
comparison
equal deleted inserted replaced
3487:24d13328c44a 3488:3d2f42580488
1488 1488
1489 /* Free any existing renderer */ 1489 /* Free any existing renderer */
1490 SDL_DestroyRenderer(windowID); 1490 SDL_DestroyRenderer(windowID);
1491 1491
1492 if (index < 0) { 1492 if (index < 0) {
1493 const char *override = SDL_getenv("SDL_VIDEO_RENDERER"); 1493 char *override = SDL_getenv("SDL_VIDEO_RENDERER");
1494 int n = SDL_GetNumRenderDrivers();
1495
1496 if (!override && (window->flags & SDL_WINDOW_OPENGL)) {
1497 override = "opengl";
1498 }
1494 if (override) { 1499 if (override) {
1495 int i, n = SDL_GetNumRenderDrivers(); 1500 for (index = 0; index < n; ++index) {
1496 for (i = 0; i < n; ++i) {
1497 SDL_RenderDriver *driver = 1501 SDL_RenderDriver *driver =
1498 &SDL_CurrentDisplay.render_drivers[i]; 1502 &SDL_CurrentDisplay.render_drivers[index];
1503
1499 if (SDL_strcasecmp(override, driver->info.name) == 0) { 1504 if (SDL_strcasecmp(override, driver->info.name) == 0) {
1500 index = i; 1505 /* Create a new renderer instance */
1506 window->renderer = driver->CreateRenderer(window, flags);
1501 break; 1507 break;
1502 } 1508 }
1503 } 1509 }
1504 } 1510 } else {
1505 } 1511 for (index = 0; index < n; ++index) {
1506 if (index < 0) { 1512 SDL_RenderDriver *driver =
1507 int n = SDL_GetNumRenderDrivers(); 1513 &SDL_CurrentDisplay.render_drivers[index];
1508 for (index = 0; index < n; ++index) { 1514
1509 SDL_RenderDriver *driver = 1515 if ((driver->info.flags & flags) == flags) {
1510 &SDL_CurrentDisplay.render_drivers[index]; 1516 /* Create a new renderer instance */
1511 1517 window->renderer = driver->CreateRenderer(window, flags);
1512 if ((driver->info.flags & flags) == flags) { 1518 if (window->renderer) {
1513 /* Create a new renderer instance */ 1519 /* Yay, we got one! */
1514 window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags); 1520 break;
1515 if (window->renderer) { 1521 }
1516 /* Yay, we got one! */
1517 break;
1518 } 1522 }
1519 } 1523 }
1520 } 1524 }
1521 if (index == n) { 1525 if (index == n) {
1522 SDL_SetError("Couldn't find matching render driver"); 1526 SDL_SetError("Couldn't find matching render driver");
1526 if (index >= SDL_GetNumRenderDrivers()) { 1530 if (index >= SDL_GetNumRenderDrivers()) {
1527 SDL_SetError("index must be -1 or in the range of 0 - %d", 1531 SDL_SetError("index must be -1 or in the range of 0 - %d",
1528 SDL_GetNumRenderDrivers() - 1); 1532 SDL_GetNumRenderDrivers() - 1);
1529 return -1; 1533 return -1;
1530 } 1534 }
1531
1532 /* Create a new renderer instance */ 1535 /* Create a new renderer instance */
1533 window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags); 1536 window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
1534 } 1537 }
1535 1538
1536 if (window->renderer == NULL) { 1539 if (window->renderer == NULL) {