Add cmd line option to switch off vsync.

Useful to profile.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2021-02-13 13:09:55 +00:00
parent 3051fbe3fe
commit a75833847e
3 changed files with 14 additions and 6 deletions

View file

@ -85,6 +85,7 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit
("timer-interval,i", po::value<int>()->default_value(options.timerInterval), "Timer interval in ms")
("loose-mutex,l", "Loose mutex")
("sdl-driver", po::value<int>()->default_value(options.sdlDriver), "SDL driver")
("gl-swap", po::value<int>()->default_value(options.glSwapInterval), "SDL_GL_SwapInterval")
("imgui", "Render with Dear ImGui")
("size", po::value<std::string>(), "WxH")
;
@ -114,6 +115,7 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit
options.looseMutex = vm.count("loose-mutex");
options.timerInterval = vm["timer-interval"].as<int>();
options.sdlDriver = vm["sdl-driver"].as<int>();
options.glSwapInterval = vm["gl-swap"].as<int>();
options.imgui = vm.count("imgui");
if (vm.count("config"))

View file

@ -38,6 +38,7 @@ struct EmulatorOptions
int sdlDriver = -1; // default = -1 to let SDL choose
bool imgui = false; // use imgui renderer
std::pair<int, int> size; // width x height
int glSwapInterval = 1; // SDL_GL_SetSwapInterval
std::vector<std::string> registryOptions;
};

View file

@ -105,6 +105,11 @@ void run_sdl(int argc, const char * argv [])
frame.reset(new SDLRendererFrame(options));
#endif
if (SDL_GL_SetSwapInterval(options.glSwapInterval))
{
throw std::runtime_error(SDL_GetError());
}
SetFrame(frame);
if (options.log)
@ -131,14 +136,14 @@ void run_sdl(int argc, const char * argv [])
{
// we need to switch off vsync, otherwise FPS is limited to 60
// and it will take longer to run
const int res = SDL_GL_SetSwapInterval(0);
// if this fails, should we throw, print something or just ignore?
if (SDL_GL_SetSwapInterval(0))
{
throw std::runtime_error(SDL_GetError());
}
const auto redraw = [&frame, res]{
const auto redraw = [&frame]{
frame->UpdateTexture();
if (res == 0) {
frame->RenderPresent();
}
frame->RenderPresent();
};
const auto refresh = [redraw, &video]{