Merge branch 'vsync' into 'master'

Add support for non-adaptive VSync

Closes #7129

See merge request OpenMW/openmw!2769
This commit is contained in:
psi29a 2023-02-26 13:28:56 +00:00
commit e8e97679f7
16 changed files with 480 additions and 392 deletions

View file

@ -93,13 +93,18 @@ bool Launcher::GraphicsPage::loadSettings()
return false;
// Visuals
if (Settings::Manager::getBool("vsync", "Video"))
vSyncCheckBox->setCheckState(Qt::Checked);
int vsync = Settings::Manager::getInt("vsync mode", "Video");
if (vsync < 0 || vsync > 2)
vsync = 0;
vSyncComboBox->setCurrentIndex(vsync);
size_t windowMode = static_cast<size_t>(Settings::Manager::getInt("window mode", "Video"));
if (windowMode > static_cast<size_t>(Settings::WindowMode::Windowed))
windowMode = 0;
windowModeComboBox->setCurrentIndex(windowMode);
slotFullScreenChanged(windowMode);
if (Settings::Manager::getBool("window border", "Video"))
windowBorderCheckBox->setCheckState(Qt::Checked);
@ -185,9 +190,9 @@ void Launcher::GraphicsPage::saveSettings()
// Ensure we only set the new settings if they changed. This is to avoid cluttering the
// user settings file (which by definition should only contain settings the user has touched)
bool cVSync = vSyncCheckBox->checkState();
if (cVSync != Settings::Manager::getBool("vsync", "Video"))
Settings::Manager::setBool("vsync", "Video", cVSync);
int cVSync = vSyncComboBox->currentIndex();
if (cVSync != Settings::Manager::getInt("vsync mode", "Video"))
Settings::Manager::setInt("vsync mode", "Video", cVSync);
int cWindowMode = windowModeComboBox->currentIndex();
if (cWindowMode != Settings::Manager::getInt("window mode", "Video"))

View file

@ -473,7 +473,7 @@ void OMW::Engine::createWindow()
Settings::WindowMode windowMode
= static_cast<Settings::WindowMode>(Settings::Manager::getInt("window mode", "Video"));
bool windowBorder = Settings::Manager::getBool("window border", "Video");
bool vsync = Settings::Manager::getBool("vsync", "Video");
int vsync = Settings::Manager::getInt("vsync mode", "Video");
unsigned int antialiasing = std::max(0, Settings::Manager::getInt("antialiasing", "Video"));
int pos_x = SDL_WINDOWPOS_CENTERED_DISPLAY(screen), pos_y = SDL_WINDOWPOS_CENTERED_DISPLAY(screen);
@ -560,10 +560,10 @@ void OMW::Engine::createWindow()
traits->windowName = SDL_GetWindowTitle(mWindow);
traits->windowDecoration = !(SDL_GetWindowFlags(mWindow) & SDL_WINDOW_BORDERLESS);
traits->screenNum = SDL_GetWindowDisplayIndex(mWindow);
traits->vsync = vsync;
traits->vsync = 0;
traits->inheritedWindowData = new SDLUtil::GraphicsWindowSDL2::WindowData(mWindow);
graphicsWindow = new SDLUtil::GraphicsWindowSDL2(traits);
graphicsWindow = new SDLUtil::GraphicsWindowSDL2(traits, vsync);
if (!graphicsWindow->valid())
throw std::runtime_error("Failed to create GraphicsContext");

View file

@ -256,6 +256,7 @@ namespace MWGui
getWidget(mOkButton, "OkButton");
getWidget(mResolutionList, "ResolutionList");
getWidget(mWindowModeList, "WindowModeList");
getWidget(mVSyncModeList, "VSyncModeList");
getWidget(mWindowBorderButton, "WindowBorderButton");
getWidget(mTextureFilteringButton, "TextureFilteringButton");
getWidget(mControlsBox, "ControlsBox");
@ -315,6 +316,7 @@ namespace MWGui
mMaxLights->eventComboChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onMaxLightsChanged);
mWindowModeList->eventComboChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onWindowModeChanged);
mVSyncModeList->eventComboChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onVSyncModeChanged);
mKeyboardSwitch->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onKeyboardSwitchClicked);
mControllerSwitch->eventMouseButtonClick
@ -562,6 +564,16 @@ namespace MWGui
Settings::Manager::setStringArray("preferred locales", "General", currentLocales);
}
void SettingsWindow::onVSyncModeChanged(MyGUI::ComboBox* _sender, size_t pos)
{
if (pos == MyGUI::ITEM_NONE)
return;
int index = static_cast<int>(_sender->getIndexSelected());
Settings::Manager::setInt("vsync mode", "Video", index);
apply();
}
void SettingsWindow::onWindowModeChanged(MyGUI::ComboBox* _sender, size_t pos)
{
if (pos == MyGUI::ITEM_NONE)
@ -870,6 +882,16 @@ namespace MWGui
mResolutionList->setEnabled(false);
}
void SettingsWindow::updateVSyncModeSettings()
{
int index = static_cast<size_t>(Settings::Manager::getInt("vsync mode", "Video"));
if (index < 0 || index > 2)
index = 0;
mVSyncModeList->setIndexSelected(index);
}
void SettingsWindow::layoutControlsBox()
{
const int h = MWBase::Environment::get().getWindowManager()->getFontHeight() + 2;
@ -1033,6 +1055,7 @@ namespace MWGui
updateControlsBox();
updateLightSettings();
updateWindowModeSettings();
updateVSyncModeSettings();
resetScrollbars();
renderScriptSettings();
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mOkButton);

View file

@ -18,6 +18,8 @@ namespace MWGui
void updateLightSettings();
void updateVSyncModeSettings();
void updateWindowModeSettings();
void onResChange(int, int) override;
@ -29,6 +31,7 @@ namespace MWGui
// graphics
MyGUI::ListBox* mResolutionList;
MyGUI::ComboBox* mWindowModeList;
MyGUI::ComboBox* mVSyncModeList;
MyGUI::Button* mWindowBorderButton;
MyGUI::ComboBox* mTextureFilteringButton;
@ -83,6 +86,7 @@ namespace MWGui
void onLanguageChanged(size_t langPriority, MyGUI::ComboBox* _sender, size_t pos);
void onWindowModeChanged(MyGUI::ComboBox* _sender, size_t pos);
void onVSyncModeChanged(MyGUI::ComboBox* _sender, size_t pos);
void onRebindAction(MyGUI::Widget* _sender);
void onInputTabMouseWheel(MyGUI::Widget* _sender, int _rel);

View file

@ -1148,8 +1148,8 @@ namespace MWGui
|| setting.second == "window mode" || setting.second == "window border"))
changeRes = true;
else if (setting.first == "Video" && setting.second == "vsync")
mVideoWrapper->setSyncToVBlank(Settings::Manager::getBool("vsync", "Video"));
else if (setting.first == "Video" && setting.second == "vsync mode")
mVideoWrapper->setSyncToVBlank(Settings::Manager::getInt("vsync mode", "Video"));
else if (setting.first == "Video" && (setting.second == "gamma" || setting.second == "contrast"))
mVideoWrapper->setGammaContrast(
Settings::Manager::getFloat("gamma", "Video"), Settings::Manager::getFloat("contrast", "Video"));