Skip to content

Commit 635b9f9

Browse files
committed
FINALLY added vsync.
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.
1 parent f899b8a commit 635b9f9

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ You can use `--help` or `-h` to view a list of command-line options. Briefly out
111111
--no-exit - do not display 'exit' in the ES menu.
112112
--debug - print additional output to the console, primarily about input.
113113
--windowed - run ES in a window, works best in conjunction with --resolution [w] [h].
114+
--vsync [0/1] - turn vsync on or off (default is on), only works in fullscreen.
114115
--scrape - run the interactive command-line metadata scraper.
115116
```
116117

es-app/src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
5757
}else if(strcmp(argv[i], "--windowed") == 0)
5858
{
5959
Settings::getInstance()->setBool("Windowed", true);
60+
}else if(strcmp(argv[i], "--vsync") == 0)
61+
{
62+
Settings::getInstance()->setBool("VSync", atoi(argv[i + 1]));
63+
i++; // skip vsync value
6064
}else if(strcmp(argv[i], "--scrape") == 0)
6165
{
6266
scrape_cmdline = true;
@@ -75,6 +79,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
7579
"--debug even more logging\n"
7680
"--scrape scrape using command line interface\n"
7781
"--windowed not fullscreen, should be used with --resolution\n"
82+
"--vsync [0/1] turn vsync on or off (default is on)\n"
7883
"--help, -h summon a sentient, angry tuba\n\n"
7984
"More information available in README.md.\n";
8085
return false; //exit after printing help

es-core/src/Renderer_init_sdlgl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ namespace Renderer
4949
#ifdef USE_OPENGL_ES
5050
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
5151
#endif
52-
//SDL_GL_SetSwapInterval(1); //0 for immediate updates, 1 for updates synchronized with the vertical retrace, -1 for late swap tearing
5352

5453
SDL_DisplayMode dispMode;
5554
SDL_GetDesktopDisplayMode(0, &dispMode);
@@ -96,6 +95,19 @@ namespace Renderer
9695

9796
sdlContext = SDL_GL_CreateContext(sdlWindow);
9897

98+
// vsync
99+
if(Settings::getInstance()->getBool("VSync"))
100+
{
101+
// SDL_GL_SetSwapInterval(0) for immediate updates (no vsync, default),
102+
// 1 for updates synchronized with the vertical retrace,
103+
// or -1 for late swap tearing.
104+
// SDL_GL_SetSwapInterval returns 0 on success, -1 on error.
105+
// if vsync is requested, try late swap tearing; if that doesn't work, try normal vsync
106+
// if that doesn't work, report an error
107+
if(SDL_GL_SetSwapInterval(-1) != 0 && SDL_GL_SetSwapInterval(1) != 0)
108+
LOG(LogWarning) << "Tried to enable vsync, but failed! (" << SDL_GetError() << ")";
109+
}
110+
99111
//hide mouse cursor
100112
initialCursorState = SDL_ShowCursor(0) == 1;
101113

es-core/src/Settings.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ std::vector<const char*> settings_dont_save = boost::assign::list_of
1616
("ParseGamelistOnly")
1717
("ShowExit")
1818
("Windowed")
19+
("VSync")
1920
("IgnoreGamelist");
2021

2122
Settings::Settings()
@@ -41,6 +42,15 @@ void Settings::setDefaults()
4142
mBoolMap["DrawFramerate"] = false;
4243
mBoolMap["ShowExit"] = true;
4344
mBoolMap["Windowed"] = false;
45+
46+
#ifdef _RPI_
47+
// don't enable VSync by default on the Pi, since it already
48+
// has trouble trying to render things at 60fps in certain menus
49+
mBoolMap["VSync"] = false;
50+
#else
51+
mBoolMap["VSync"] = true;
52+
#endif
53+
4454
mBoolMap["EnableSounds"] = true;
4555
mBoolMap["ShowHelpPrompts"] = true;
4656
mBoolMap["ScrapeRatings"] = true;

0 commit comments

Comments
 (0)