Added the SDL_HINT_RENDER_DRIVER and SDL_HINT_RENDER_VSYNC hints.
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Feb 2011 10:35:36 -0800
changeset 5192ef5a61ea3202
parent 5191 93052810ceb5
child 5193 e96c5be3e0b5
Added the SDL_HINT_RENDER_DRIVER and SDL_HINT_RENDER_VSYNC hints.
include/SDL_hints.h
src/render/SDL_render.c
src/video/SDL_video.c
     1.1 --- a/include/SDL_hints.h	Sat Feb 05 10:11:27 2011 -0800
     1.2 +++ b/include/SDL_hints.h	Sat Feb 05 10:35:36 2011 -0800
     1.3 @@ -67,6 +67,32 @@
     1.4   */
     1.5  #define SDL_HINT_FRAMEBUFFER_ACCELERATION   "SDL_FRAMEBUFFER_ACCELERATION"
     1.6  
     1.7 +/**
     1.8 + *  \brief  A variable specifying which render driver to use.
     1.9 + *
    1.10 + *  If the application doesn't pick a specific renderer to use, this variable
    1.11 + *  specifies the name of the preferred renderer.  If the preferred renderer
    1.12 + *  can't be initialized, the normal default renderer is used.
    1.13 + *
    1.14 + *  This variable is case insensitive and can be set to the following values:
    1.15 + *    "direct3d"
    1.16 + *    "opengl"
    1.17 + *    "opengles"
    1.18 + *    "software"
    1.19 + */
    1.20 +#define SDL_HINT_RENDER_DRIVER              "SDL_RENDER_DRIVER"
    1.21 +
    1.22 +/**
    1.23 + *  \brief  A variable controlling whether updates to the SDL 1.2 screen surface should be synchronized with the vertical refresh, to avoid tearing.
    1.24 + *
    1.25 + *  This variable can be set to the following values:
    1.26 + *    "0"       - Disable vsync
    1.27 + *    "1"       - Enable vsync
    1.28 + *
    1.29 + *  By default SDL does not sync screen surface updates with vertical refresh.
    1.30 + */
    1.31 +#define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
    1.32 +
    1.33  
    1.34  /**
    1.35   *  \brief  An enumeration of hint priorities
     2.1 --- a/src/render/SDL_render.c	Sat Feb 05 10:11:27 2011 -0800
     2.2 +++ b/src/render/SDL_render.c	Sat Feb 05 10:35:36 2011 -0800
     2.3 @@ -23,6 +23,7 @@
     2.4  
     2.5  /* The SDL 2D rendering system */
     2.6  
     2.7 +#include "SDL_hints.h"
     2.8  #include "SDL_render.h"
     2.9  #include "SDL_sysrender.h"
    2.10  #include "../video/SDL_pixels_c.h"
    2.11 @@ -94,21 +95,32 @@
    2.12  {
    2.13      SDL_Renderer *renderer = NULL;
    2.14      int n = SDL_GetNumRenderDrivers();
    2.15 +    const char *hint;
    2.16 +
    2.17 +    hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
    2.18 +    if (hint) {
    2.19 +        if (*hint == '0') {
    2.20 +            flags &= ~SDL_RENDERER_PRESENTVSYNC;
    2.21 +        } else {
    2.22 +            flags |= SDL_RENDERER_PRESENTVSYNC;
    2.23 +        }
    2.24 +    }
    2.25  
    2.26      if (index < 0) {
    2.27 -        char *override = SDL_getenv("SDL_VIDEO_RENDERER");
    2.28 -
    2.29 -        if (override) {
    2.30 +        hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
    2.31 +        if (hint) {
    2.32              for (index = 0; index < n; ++index) {
    2.33                  const SDL_RenderDriver *driver = render_drivers[index];
    2.34  
    2.35 -                if (SDL_strcasecmp(override, driver->info.name) == 0) {
    2.36 +                if (SDL_strcasecmp(hint, driver->info.name) == 0) {
    2.37                      /* Create a new renderer instance */
    2.38                      renderer = driver->CreateRenderer(window, flags);
    2.39                      break;
    2.40                  }
    2.41              }
    2.42 -        } else {
    2.43 +        }
    2.44 +
    2.45 +        if (!renderer) {
    2.46              for (index = 0; index < n; ++index) {
    2.47                  const SDL_RenderDriver *driver = render_drivers[index];
    2.48  
     3.1 --- a/src/video/SDL_video.c	Sat Feb 05 10:11:27 2011 -0800
     3.2 +++ b/src/video/SDL_video.c	Sat Feb 05 10:35:36 2011 -0800
     3.3 @@ -117,6 +117,14 @@
     3.4          return SDL_TRUE;
     3.5      }
     3.6  
     3.7 +    /* If the user has specified a software renderer we can't use a
     3.8 +       texture framebuffer, or renderer creation will go recursive.
     3.9 +     */
    3.10 +    hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
    3.11 +    if (hint && SDL_strcasecmp(hint, "software") == 0) {
    3.12 +        return SDL_FALSE;
    3.13 +    }
    3.14 +
    3.15      /* See if the user or application wants a specific behavior */
    3.16      hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
    3.17      if (hint) {