src/video/SDL_video.c
changeset 3424 032e64bbb56c
parent 3417 64a60c5d502e
child 3425 25ccea045c9f
     1.1 --- a/src/video/SDL_video.c	Mon Nov 02 07:57:51 2009 +0000
     1.2 +++ b/src/video/SDL_video.c	Sun Nov 08 04:16:42 2009 +0000
     1.3 @@ -1483,19 +1483,35 @@
     1.4          SDL_SetError("Invalid window ID");
     1.5          return -1;
     1.6      }
     1.7 +
     1.8 +    /* Free any existing renderer */
     1.9 +    SDL_DestroyRenderer(windowID);
    1.10 +
    1.11      if (index < 0) {
    1.12          const char *override = SDL_getenv("SDL_VIDEO_RENDERER");
    1.13 +        if (override) {
    1.14 +            int i, n = SDL_GetNumRenderDrivers();
    1.15 +            for (i = 0; i < n; ++i) {
    1.16 +                SDL_RenderDriver *driver =
    1.17 +                    &SDL_CurrentDisplay.render_drivers[i];
    1.18 +                if (SDL_strcasecmp(override, driver->info.name) == 0) {
    1.19 +                    index = i;
    1.20 +                    break;
    1.21 +                }
    1.22 +            }
    1.23 +        }
    1.24 +    }
    1.25 +    if (index < 0) {
    1.26          int n = SDL_GetNumRenderDrivers();
    1.27          for (index = 0; index < n; ++index) {
    1.28              SDL_RenderDriver *driver =
    1.29                  &SDL_CurrentDisplay.render_drivers[index];
    1.30  
    1.31 -            if (override) {
    1.32 -                if (SDL_strcasecmp(override, driver->info.name) == 0) {
    1.33 -                    break;
    1.34 -                }
    1.35 -            } else {
    1.36 -                if ((driver->info.flags & flags) == flags) {
    1.37 +            if ((driver->info.flags & flags) == flags) {
    1.38 +                /* Create a new renderer instance */
    1.39 +                window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
    1.40 +                if (window->renderer) {
    1.41 +                    /* Yay, we got one! */
    1.42                      break;
    1.43                  }
    1.44              }
    1.45 @@ -1504,18 +1520,16 @@
    1.46              SDL_SetError("Couldn't find matching render driver");
    1.47              return -1;
    1.48          }
    1.49 +    } else {
    1.50 +        if (index >= SDL_GetNumRenderDrivers()) {
    1.51 +            SDL_SetError("index must be -1 or in the range of 0 - %d",
    1.52 +                         SDL_GetNumRenderDrivers() - 1);
    1.53 +            return -1;
    1.54 +        }
    1.55 +
    1.56 +        /* Create a new renderer instance */
    1.57 +        window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
    1.58      }
    1.59 -    if (index >= SDL_GetNumRenderDrivers()) {
    1.60 -        SDL_SetError("index must be -1 or in the range of 0 - %d",
    1.61 -                     SDL_GetNumRenderDrivers() - 1);
    1.62 -        return -1;
    1.63 -    }
    1.64 -    /* Free any existing renderer */
    1.65 -    SDL_DestroyRenderer(windowID);
    1.66 -
    1.67 -    /* Create a new renderer instance */
    1.68 -    window->renderer = SDL_CurrentDisplay.render_drivers[index]
    1.69 -        .CreateRenderer(window, flags);
    1.70  
    1.71      if (window->renderer == NULL) {
    1.72          /* Assuming renderer set its error */