Add support for adaptive vsync

This commit is contained in:
Benau 2020-06-13 16:10:27 +08:00
parent a2675497e0
commit 5ca51fd2a9
2 changed files with 26 additions and 5 deletions

View File

@ -242,6 +242,27 @@ bool versionCorrect(int major, int minor)
#endif
}
// Used in OptionsScreenVideo for live updating vertical sync config
extern "C" void update_swap_interval(int swap_interval)
{
#ifndef IOS_STK
// iOS always use vertical sync
if (swap_interval > 1)
swap_interval = 1;
// Try adaptive vsync first if support
if (swap_interval > 0)
{
int ret = SDL_GL_SetSwapInterval(-1);
if (ret == 0)
return;
}
SDL_GL_SetSwapInterval(swap_interval);
#endif
}
bool CIrrDeviceSDL::createWindow()
{
// Ignore alpha size here, this follow irr_driver.cpp:450
@ -287,11 +308,7 @@ bool CIrrDeviceSDL::createWindow()
return false;
}
int swap_interval = CreationParams.SwapInterval;
if (swap_interval > 1)
swap_interval = 1;
SDL_GL_SetSwapInterval(swap_interval);
update_swap_interval(CreationParams.SwapInterval);
return true;
}

View File

@ -615,6 +615,7 @@ void OptionsScreenVideo::updateBlurTooltip()
} // updateBlurTooltip
// --------------------------------------------------------------------------------------------
extern "C" void update_swap_interval(int swap_interval);
void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
const int playerID)
@ -726,6 +727,9 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
GUIEngine::SpinnerWidget* vsync = getWidget<GUIEngine::SpinnerWidget>("vsync");
assert( vsync != NULL );
UserConfigParams::m_swap_interval = vsync->getValue();
#if !defined(SERVER_ONLY) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
update_swap_interval(UserConfigParams::m_swap_interval);
#endif
}
else if (name == "rememberWinpos")
{