changeset 5195:ef5a61ea3202

Added the SDL_HINT_RENDER_DRIVER and SDL_HINT_RENDER_VSYNC hints.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 05 Feb 2011 10:35:36 -0800
parents 93052810ceb5
children e96c5be3e0b5
files include/SDL_hints.h src/render/SDL_render.c src/video/SDL_video.c
diffstat 3 files changed, 51 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_hints.h	Sat Feb 05 10:11:27 2011 -0800
+++ b/include/SDL_hints.h	Sat Feb 05 10:35:36 2011 -0800
@@ -67,6 +67,32 @@
  */
 #define SDL_HINT_FRAMEBUFFER_ACCELERATION   "SDL_FRAMEBUFFER_ACCELERATION"
 
+/**
+ *  \brief  A variable specifying which render driver to use.
+ *
+ *  If the application doesn't pick a specific renderer to use, this variable
+ *  specifies the name of the preferred renderer.  If the preferred renderer
+ *  can't be initialized, the normal default renderer is used.
+ *
+ *  This variable is case insensitive and can be set to the following values:
+ *    "direct3d"
+ *    "opengl"
+ *    "opengles"
+ *    "software"
+ */
+#define SDL_HINT_RENDER_DRIVER              "SDL_RENDER_DRIVER"
+
+/**
+ *  \brief  A variable controlling whether updates to the SDL 1.2 screen surface should be synchronized with the vertical refresh, to avoid tearing.
+ *
+ *  This variable can be set to the following values:
+ *    "0"       - Disable vsync
+ *    "1"       - Enable vsync
+ *
+ *  By default SDL does not sync screen surface updates with vertical refresh.
+ */
+#define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
+
 
 /**
  *  \brief  An enumeration of hint priorities
--- a/src/render/SDL_render.c	Sat Feb 05 10:11:27 2011 -0800
+++ b/src/render/SDL_render.c	Sat Feb 05 10:35:36 2011 -0800
@@ -23,6 +23,7 @@
 
 /* The SDL 2D rendering system */
 
+#include "SDL_hints.h"
 #include "SDL_render.h"
 #include "SDL_sysrender.h"
 #include "../video/SDL_pixels_c.h"
@@ -94,21 +95,32 @@
 {
     SDL_Renderer *renderer = NULL;
     int n = SDL_GetNumRenderDrivers();
+    const char *hint;
+
+    hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
+    if (hint) {
+        if (*hint == '0') {
+            flags &= ~SDL_RENDERER_PRESENTVSYNC;
+        } else {
+            flags |= SDL_RENDERER_PRESENTVSYNC;
+        }
+    }
 
     if (index < 0) {
-        char *override = SDL_getenv("SDL_VIDEO_RENDERER");
-
-        if (override) {
+        hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
+        if (hint) {
             for (index = 0; index < n; ++index) {
                 const SDL_RenderDriver *driver = render_drivers[index];
 
-                if (SDL_strcasecmp(override, driver->info.name) == 0) {
+                if (SDL_strcasecmp(hint, driver->info.name) == 0) {
                     /* Create a new renderer instance */
                     renderer = driver->CreateRenderer(window, flags);
                     break;
                 }
             }
-        } else {
+        }
+
+        if (!renderer) {
             for (index = 0; index < n; ++index) {
                 const SDL_RenderDriver *driver = render_drivers[index];
 
--- a/src/video/SDL_video.c	Sat Feb 05 10:11:27 2011 -0800
+++ b/src/video/SDL_video.c	Sat Feb 05 10:35:36 2011 -0800
@@ -117,6 +117,14 @@
         return SDL_TRUE;
     }
 
+    /* If the user has specified a software renderer we can't use a
+       texture framebuffer, or renderer creation will go recursive.
+     */
+    hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
+    if (hint && SDL_strcasecmp(hint, "software") == 0) {
+        return SDL_FALSE;
+    }
+
     /* See if the user or application wants a specific behavior */
     hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
     if (hint) {