Skip to content

Commit

Permalink
FINALLY added vsync.
Browse files Browse the repository at this point in the history
Defaults to on for all platforms except the RPi. Force it off with "--vsync 0".

Will try to use late swap tearing if supported on the current system.
  • Loading branch information
Aloshi committed Nov 22, 2014
1 parent f899b8a commit 635b9f9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ You can use `--help` or `-h` to view a list of command-line options. Briefly out
--no-exit - do not display 'exit' in the ES menu.
--debug - print additional output to the console, primarily about input.
--windowed - run ES in a window, works best in conjunction with --resolution [w] [h].
--vsync [0/1] - turn vsync on or off (default is on), only works in fullscreen.
--scrape - run the interactive command-line metadata scraper.
```

Expand Down
5 changes: 5 additions & 0 deletions es-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
}else if(strcmp(argv[i], "--windowed") == 0)
{
Settings::getInstance()->setBool("Windowed", true);
}else if(strcmp(argv[i], "--vsync") == 0)
{
Settings::getInstance()->setBool("VSync", atoi(argv[i + 1]));
i++; // skip vsync value
}else if(strcmp(argv[i], "--scrape") == 0)
{
scrape_cmdline = true;
Expand All @@ -75,6 +79,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
"--debug even more logging\n"
"--scrape scrape using command line interface\n"
"--windowed not fullscreen, should be used with --resolution\n"
"--vsync [0/1] turn vsync on or off (default is on)\n"
"--help, -h summon a sentient, angry tuba\n\n"
"More information available in README.md.\n";
return false; //exit after printing help
Expand Down
14 changes: 13 additions & 1 deletion es-core/src/Renderer_init_sdlgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace Renderer
#ifdef USE_OPENGL_ES
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
#endif
//SDL_GL_SetSwapInterval(1); //0 for immediate updates, 1 for updates synchronized with the vertical retrace, -1 for late swap tearing

SDL_DisplayMode dispMode;
SDL_GetDesktopDisplayMode(0, &dispMode);
Expand Down Expand Up @@ -96,6 +95,19 @@ namespace Renderer

sdlContext = SDL_GL_CreateContext(sdlWindow);

// vsync
if(Settings::getInstance()->getBool("VSync"))
{
// SDL_GL_SetSwapInterval(0) for immediate updates (no vsync, default),
// 1 for updates synchronized with the vertical retrace,
// or -1 for late swap tearing.
// SDL_GL_SetSwapInterval returns 0 on success, -1 on error.
// if vsync is requested, try late swap tearing; if that doesn't work, try normal vsync
// if that doesn't work, report an error
if(SDL_GL_SetSwapInterval(-1) != 0 && SDL_GL_SetSwapInterval(1) != 0)
LOG(LogWarning) << "Tried to enable vsync, but failed! (" << SDL_GetError() << ")";
}

//hide mouse cursor
initialCursorState = SDL_ShowCursor(0) == 1;

Expand Down
10 changes: 10 additions & 0 deletions es-core/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ std::vector<const char*> settings_dont_save = boost::assign::list_of
("ParseGamelistOnly")
("ShowExit")
("Windowed")
("VSync")
("IgnoreGamelist");

Settings::Settings()
Expand All @@ -41,6 +42,15 @@ void Settings::setDefaults()
mBoolMap["DrawFramerate"] = false;
mBoolMap["ShowExit"] = true;
mBoolMap["Windowed"] = false;

#ifdef _RPI_
// don't enable VSync by default on the Pi, since it already
// has trouble trying to render things at 60fps in certain menus
mBoolMap["VSync"] = false;
#else
mBoolMap["VSync"] = true;
#endif

mBoolMap["EnableSounds"] = true;
mBoolMap["ShowHelpPrompts"] = true;
mBoolMap["ScrapeRatings"] = true;
Expand Down

0 comments on commit 635b9f9

Please sign in to comment.