Merge branch 'feature/vsync-hint'

Closes #6115.
This commit is contained in:
Iris Morelle 2021-10-06 01:38:42 -03:00
commit 1d512e13c6
No known key found for this signature in database
GPG key ID: E312033F4023A753
6 changed files with 47 additions and 1 deletions

View file

@ -263,6 +263,20 @@
{_GUI_PREFERENCES_SPACER_ROW}
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[toggle_button]
id = "vsync"
label = _ "VSync"
tooltip = _ "Reduces tearing by synchronizing rendering with the screen refresh rate (requires restart to take effect)"
[/toggle_button]
[/column]
[/row]
[row]
[column]
border = "all"

View file

@ -454,6 +454,12 @@ void preferences_dialog::post_build(window& window)
register_bool("fps_limiter", true,
[]() { return draw_delay() != 0; }, [](bool v) { set_draw_delay(v ? -1 : 0); });
/* VSYNC */
register_bool("vsync", true, vsync, set_vsync);
if(!CVideo::get_singleton().supports_vsync()) {
find_widget<widget>(&window, "vsync", false).set_visible(gui2::widget::visibility::invisible);
}
/* SELECT THEME */
connect_signal_mouse_left_click(
find_widget<button>(&window, "choose_theme", false),

View file

@ -416,6 +416,11 @@ bool fullscreen()
return get("fullscreen", true);
}
bool vsync()
{
return get("vsync", true);
}
void _set_resolution(const point& res)
{
preferences::set("xresolution", std::to_string(res.x));
@ -432,6 +437,11 @@ void _set_fullscreen(bool ison)
prefs["fullscreen"] = ison;
}
void set_vsync(bool ison)
{
prefs["vsync"] = ison;
}
bool turbo()
{
if(CVideo::get_singleton().non_interactive()) {

View file

@ -81,6 +81,9 @@ namespace preferences {
bool fullscreen();
void _set_fullscreen(bool ison);
bool vsync();
void set_vsync(bool ison);
bool turbo();
void _set_turbo(bool ison);

View file

@ -220,8 +220,14 @@ void CVideo::init_window()
window_flags |= SDL_WINDOW_MAXIMIZED;
}
uint32_t renderer_flags = SDL_RENDERER_SOFTWARE;
if(supports_vsync() && preferences::vsync()) {
LOG_DP << "VSYNC on\n";
renderer_flags |= SDL_RENDERER_PRESENTVSYNC;
}
// Initialize window
window.reset(new sdl::window("", x, y, w, h, window_flags, SDL_RENDERER_SOFTWARE));
window.reset(new sdl::window("", x, y, w, h, window_flags, renderer_flags));
std::cerr << "Setting mode to " << w << "x" << h << std::endl;
@ -490,6 +496,11 @@ bool CVideo::is_fullscreen() const
return (window->get_flags() & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
}
bool CVideo::supports_vsync() const
{
return sdl_get_version() >= version_info{2, 0, 17};
}
int CVideo::set_help_string(const std::string& str)
{
font::remove_floating_label(help_string_);

View file

@ -105,6 +105,8 @@ public:
bool is_fullscreen() const;
bool supports_vsync() const;
bool set_resolution(const unsigned width, const unsigned height);
/**