Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added the SDL_HINT_RENDER_DRIVER and SDL_HINT_RENDER_VSYNC hints.
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Feb 5, 2011
1 parent 790c851 commit abaf210
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
26 changes: 26 additions & 0 deletions include/SDL_hints.h
Expand Up @@ -67,6 +67,32 @@ extern "C" {
*/
#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
Expand Down
22 changes: 17 additions & 5 deletions src/render/SDL_render.c
Expand Up @@ -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"
Expand Down Expand Up @@ -94,21 +95,32 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
{
SDL_Renderer *renderer = NULL;
int n = SDL_GetNumRenderDrivers();
const char *hint;

if (index < 0) {
char *override = SDL_getenv("SDL_VIDEO_RENDERER");
hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
if (hint) {
if (*hint == '0') {
flags &= ~SDL_RENDERER_PRESENTVSYNC;
} else {
flags |= SDL_RENDERER_PRESENTVSYNC;
}
}

if (override) {
if (index < 0) {
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];

Expand Down
8 changes: 8 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -117,6 +117,14 @@ ShouldUseTextureFramebuffer()
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) {
Expand Down

0 comments on commit abaf210

Please sign in to comment.