Use settings values for Video settings

* Convert window mode, vsync mode into enums, screenshot type into a struct.
* Add missing doc for screenshot type.
macos_ci_fix
elsid 1 year ago
parent 8380da2e1d
commit dcd81d026f
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -96,32 +96,29 @@ bool Launcher::GraphicsPage::loadSettings()
// Visuals
int vsync = Settings::Manager::getInt("vsync mode", "Video");
if (vsync < 0 || vsync > 2)
vsync = 0;
const int vsync = Settings::video().mVsyncMode;
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);
const Settings::WindowMode windowMode = Settings::video().mWindowMode;
if (Settings::Manager::getBool("window border", "Video"))
windowModeComboBox->setCurrentIndex(static_cast<int>(windowMode));
handleWindowModeChange(windowMode);
if (Settings::video().mWindowBorder)
windowBorderCheckBox->setCheckState(Qt::Checked);
// aaValue is the actual value (0, 1, 2, 4, 8, 16)
int aaValue = Settings::Manager::getInt("antialiasing", "Video");
const int aaValue = Settings::video().mAntialiasing;
// aaIndex is the index into the allowed values in the pull down.
int aaIndex = antiAliasingComboBox->findText(QString::number(aaValue));
const int aaIndex = antiAliasingComboBox->findText(QString::number(aaValue));
if (aaIndex != -1)
antiAliasingComboBox->setCurrentIndex(aaIndex);
int width = Settings::Manager::getInt("resolution x", "Video");
int height = Settings::Manager::getInt("resolution y", "Video");
const int width = Settings::video().mResolutionX;
const int height = Settings::video().mResolutionY;
QString resolution = QString::number(width) + QString(" x ") + QString::number(height);
screenComboBox->setCurrentIndex(Settings::Manager::getInt("screen", "Video"));
screenComboBox->setCurrentIndex(Settings::video().mScreen);
int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith);
@ -137,7 +134,7 @@ bool Launcher::GraphicsPage::loadSettings()
customHeightSpinBox->setValue(height);
}
float fpsLimit = Settings::Manager::getFloat("framerate limit", "Video");
const float fpsLimit = Settings::video().mFramerateLimit;
if (fpsLimit != 0)
{
framerateLimitCheckBox->setCheckState(Qt::Checked);
@ -198,23 +195,10 @@ void Launcher::GraphicsPage::saveSettings()
{
// Visuals
// 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)
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"))
Settings::Manager::setInt("window mode", "Video", cWindowMode);
bool cWindowBorder = windowBorderCheckBox->checkState();
if (cWindowBorder != Settings::Manager::getBool("window border", "Video"))
Settings::Manager::setBool("window border", "Video", cWindowBorder);
int cAAValue = antiAliasingComboBox->currentText().toInt();
if (cAAValue != Settings::Manager::getInt("antialiasing", "Video"))
Settings::Manager::setInt("antialiasing", "Video", cAAValue);
Settings::video().mVsyncMode.set(static_cast<SDLUtil::VSyncMode>(vSyncComboBox->currentIndex()));
Settings::video().mWindowMode.set(static_cast<Settings::WindowMode>(windowModeComboBox->currentIndex()));
Settings::video().mWindowBorder.set(windowBorderCheckBox->checkState() == Qt::Checked);
Settings::video().mAntialiasing.set(antiAliasingComboBox->currentText().toInt());
int cWidth = 0;
int cHeight = 0;
@ -234,25 +218,17 @@ void Launcher::GraphicsPage::saveSettings()
cHeight = customHeightSpinBox->value();
}
if (cWidth != Settings::Manager::getInt("resolution x", "Video"))
Settings::Manager::setInt("resolution x", "Video", cWidth);
if (cHeight != Settings::Manager::getInt("resolution y", "Video"))
Settings::Manager::setInt("resolution y", "Video", cHeight);
int cScreen = screenComboBox->currentIndex();
if (cScreen != Settings::Manager::getInt("screen", "Video"))
Settings::Manager::setInt("screen", "Video", cScreen);
Settings::video().mResolutionX.set(cWidth);
Settings::video().mResolutionY.set(cHeight);
Settings::video().mScreen.set(screenComboBox->currentIndex());
if (framerateLimitCheckBox->checkState() != Qt::Unchecked)
{
float cFpsLimit = framerateLimitSpinBox->value();
if (cFpsLimit != Settings::Manager::getFloat("framerate limit", "Video"))
Settings::Manager::setFloat("framerate limit", "Video", cFpsLimit);
Settings::video().mFramerateLimit.set(framerateLimitSpinBox->value());
}
else if (Settings::Manager::getFloat("framerate limit", "Video") != 0)
else if (Settings::video().mFramerateLimit != 0)
{
Settings::Manager::setFloat("framerate limit", "Video", 0);
Settings::video().mFramerateLimit.set(0);
}
// Lighting
@ -392,8 +368,12 @@ void Launcher::GraphicsPage::screenChanged(int screen)
void Launcher::GraphicsPage::slotFullScreenChanged(int mode)
{
if (mode == static_cast<int>(Settings::WindowMode::Fullscreen)
|| mode == static_cast<int>(Settings::WindowMode::WindowedFullscreen))
handleWindowModeChange(static_cast<Settings::WindowMode>(mode));
}
void Launcher::GraphicsPage::handleWindowModeChange(Settings::WindowMode mode)
{
if (mode == Settings::WindowMode::Fullscreen || mode == Settings::WindowMode::WindowedFullscreen)
{
standardRadioButton->toggle();
customRadioButton->setEnabled(false);

@ -3,7 +3,7 @@
#include "ui_graphicspage.h"
#include <components/settings/settings.hpp>
#include <components/settings/windowmode.hpp>
namespace Files
{
@ -40,6 +40,7 @@ namespace Launcher
static QRect getMaximumResolution();
bool setupSDL();
void handleWindowModeChange(Settings::WindowMode state);
};
}
#endif

@ -1,13 +1,5 @@
#include "maindialog.hpp"
#include <components/debug/debuglog.hpp>
#include <components/files/configurationmanager.hpp>
#include <components/files/conversion.hpp>
#include <components/files/qtconversion.hpp>
#include <components/misc/helpviewer.hpp>
#include <components/misc/utf8qtextstream.hpp>
#include <components/version/version.hpp>
#include <QCloseEvent>
#include <QDir>
#include <QMessageBox>
@ -15,10 +7,15 @@
#include <QTime>
#include <components/debug/debugging.hpp>
#include <components/debug/debuglog.hpp>
#include <components/files/configurationmanager.hpp>
#include <components/files/conversion.hpp>
#include <components/files/qtconfigpath.hpp>
#include <components/files/qtconversion.hpp>
#include <components/misc/helpviewer.hpp>
#include <components/misc/utf8qtextstream.hpp>
#include <components/settings/settings.hpp>
#include <components/version/version.hpp>
#include "datafilespage.hpp"
#include "graphicspage.hpp"

@ -452,14 +452,13 @@ void OMW::Engine::setSkipMenu(bool skipMenu, bool newGame)
void OMW::Engine::createWindow()
{
int screen = Settings::Manager::getInt("screen", "Video");
int width = Settings::Manager::getInt("resolution x", "Video");
int height = Settings::Manager::getInt("resolution y", "Video");
Settings::WindowMode windowMode
= static_cast<Settings::WindowMode>(Settings::Manager::getInt("window mode", "Video"));
bool windowBorder = Settings::Manager::getBool("window border", "Video");
int vsync = Settings::Manager::getInt("vsync mode", "Video");
unsigned int antialiasing = std::max(0, Settings::Manager::getInt("antialiasing", "Video"));
const int screen = Settings::video().mScreen;
const int width = Settings::video().mResolutionX;
const int height = Settings::video().mResolutionY;
const Settings::WindowMode windowMode = Settings::video().mWindowMode;
const bool windowBorder = Settings::video().mWindowBorder;
const SDLUtil::VSyncMode vsync = Settings::video().mVsyncMode;
unsigned antialiasing = static_cast<unsigned>(Settings::video().mAntialiasing);
int pos_x = SDL_WINDOWPOS_CENTERED_DISPLAY(screen), pos_y = SDL_WINDOWPOS_CENTERED_DISPLAY(screen);
@ -482,8 +481,7 @@ void OMW::Engine::createWindow()
if (!windowBorder)
flags |= SDL_WINDOW_BORDERLESS;
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
Settings::Manager::getBool("minimize on focus loss", "Video") ? "1" : "0");
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, Settings::video().mMinimizeOnFocusLoss ? "1" : "0");
checkSDLError(SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8));
checkSDLError(SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8));
@ -513,7 +511,7 @@ void OMW::Engine::createWindow()
Log(Debug::Warning) << "Warning: " << antialiasing << "x antialiasing not supported, trying "
<< antialiasing / 2;
antialiasing /= 2;
Settings::Manager::setInt("antialiasing", "Video", antialiasing);
Settings::video().mAntialiasing.set(antialiasing);
checkSDLError(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing));
continue;
}
@ -560,7 +558,7 @@ void OMW::Engine::createWindow()
SDL_DestroyWindow(mWindow);
mWindow = nullptr;
antialiasing /= 2;
Settings::Manager::setInt("antialiasing", "Video", antialiasing);
Settings::video().mAntialiasing.set(antialiasing);
checkSDLError(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing));
continue;
}
@ -866,7 +864,7 @@ void OMW::Engine::go()
// Do not try to outsmart the OS thread scheduler (see bug #4785).
mViewer->setUseConfigureAffinity(false);
mEnvironment.setFrameRateLimit(Settings::Manager::getFloat("framerate limit", "Video"));
mEnvironment.setFrameRateLimit(Settings::video().mFramerateLimit);
prepareEngine();

@ -354,7 +354,7 @@ namespace MWGui
+= MyGUI::newDelegate(this, &SettingsWindow::onResetDefaultBindings);
// fill resolution list
int screen = Settings::Manager::getInt("screen", "Video");
const int screen = Settings::video().mScreen;
int numDisplayModes = SDL_GetNumDisplayModes(screen);
std::vector<std::pair<int, int>> resolutions;
for (int i = 0; i < numDisplayModes; i++)
@ -396,8 +396,7 @@ namespace MWGui
updateMaxLightsComboBox(mMaxLights);
Settings::WindowMode windowMode
= static_cast<Settings::WindowMode>(Settings::Manager::getInt("window mode", "Video"));
const Settings::WindowMode windowMode = Settings::video().mWindowMode;
mWindowBorderButton->setEnabled(
windowMode != Settings::WindowMode::Fullscreen && windowMode != Settings::WindowMode::WindowedFullscreen);
@ -491,8 +490,8 @@ namespace MWGui
int resX, resY;
parseResolution(resX, resY, resStr);
Settings::Manager::setInt("resolution x", "Video", resX);
Settings::Manager::setInt("resolution y", "Video", resY);
Settings::video().mResolutionX.set(resX);
Settings::video().mResolutionY.set(resY);
apply();
}
@ -506,8 +505,8 @@ namespace MWGui
{
mResolutionList->setIndexSelected(MyGUI::ITEM_NONE);
int currentX = Settings::Manager::getInt("resolution x", "Video");
int currentY = Settings::Manager::getInt("resolution y", "Video");
const int currentX = Settings::video().mResolutionX;
const int currentY = Settings::video().mResolutionY;
for (size_t i = 0; i < mResolutionList->getItemCount(); ++i)
{
@ -591,23 +590,22 @@ namespace MWGui
"#{OMWEngine:ChangeRequiresRestart}", { "#{Interface:OK}" }, true);
}
void SettingsWindow::onVSyncModeChanged(MyGUI::ComboBox* _sender, size_t pos)
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);
Settings::video().mVsyncMode.set(static_cast<SDLUtil::VSyncMode>(sender->getIndexSelected()));
apply();
}
void SettingsWindow::onWindowModeChanged(MyGUI::ComboBox* _sender, size_t pos)
void SettingsWindow::onWindowModeChanged(MyGUI::ComboBox* sender, size_t pos)
{
if (pos == MyGUI::ITEM_NONE)
return;
int index = static_cast<int>(_sender->getIndexSelected());
if (index == static_cast<size_t>(Settings::WindowMode::WindowedFullscreen))
const Settings::WindowMode windowMode = static_cast<Settings::WindowMode>(sender->getIndexSelected());
if (windowMode == Settings::WindowMode::WindowedFullscreen)
{
mResolutionList->setEnabled(false);
mWindowModeHint->setVisible(true);
@ -618,12 +616,12 @@ namespace MWGui
mWindowModeHint->setVisible(false);
}
if (index == static_cast<size_t>(Settings::WindowMode::Windowed))
if (windowMode == Settings::WindowMode::Windowed)
mWindowBorderButton->setEnabled(true);
else
mWindowBorderButton->setEnabled(false);
Settings::Manager::setInt("window mode", "Video", index);
Settings::video().mWindowMode.set(windowMode);
apply();
}
@ -849,14 +847,12 @@ namespace MWGui
void SettingsWindow::updateWindowModeSettings()
{
size_t index = static_cast<size_t>(Settings::Manager::getInt("window mode", "Video"));
const Settings::WindowMode windowMode = Settings::video().mWindowMode;
const std::size_t windowModeIndex = static_cast<std::size_t>(windowMode);
if (index > static_cast<size_t>(Settings::WindowMode::Windowed))
index = MyGUI::ITEM_NONE;
mWindowModeList->setIndexSelected(windowModeIndex);
mWindowModeList->setIndexSelected(index);
if (index != static_cast<size_t>(Settings::WindowMode::Windowed) && index != MyGUI::ITEM_NONE)
if (windowMode != Settings::WindowMode::Windowed && windowModeIndex != MyGUI::ITEM_NONE)
{
// check if this resolution is supported in fullscreen
if (mResolutionList->getIndexSelected() != MyGUI::ITEM_NONE)
@ -864,8 +860,8 @@ namespace MWGui
const std::string& resStr = mResolutionList->getItemNameAt(mResolutionList->getIndexSelected());
int resX, resY;
parseResolution(resX, resY, resStr);
Settings::Manager::setInt("resolution x", "Video", resX);
Settings::Manager::setInt("resolution y", "Video", resY);
Settings::video().mResolutionX.set(resX);
Settings::video().mResolutionY.set(resY);
}
bool supported = false;
@ -882,8 +878,7 @@ namespace MWGui
fallbackY = resY;
}
if (resX == Settings::Manager::getInt("resolution x", "Video")
&& resY == Settings::Manager::getInt("resolution y", "Video"))
if (resX == Settings::video().mResolutionX && resY == Settings::video().mResolutionY)
supported = true;
}
@ -891,26 +886,21 @@ namespace MWGui
{
if (fallbackX != 0 && fallbackY != 0)
{
Settings::Manager::setInt("resolution x", "Video", fallbackX);
Settings::Manager::setInt("resolution y", "Video", fallbackY);
Settings::video().mResolutionX.set(fallbackX);
Settings::video().mResolutionY.set(fallbackY);
}
}
mWindowBorderButton->setEnabled(false);
}
if (index == static_cast<size_t>(Settings::WindowMode::WindowedFullscreen))
if (windowMode == Settings::WindowMode::WindowedFullscreen)
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);
mVSyncModeList->setIndexSelected(static_cast<size_t>(Settings::video().mVsyncMode));
}
void SettingsWindow::layoutControlsBox()

@ -294,8 +294,7 @@ namespace MWGui
+= MyGUI::newDelegate(this, &WindowManager::onClipboardRequested);
mVideoWrapper = std::make_unique<SDLUtil::VideoWrapper>(window, viewer);
mVideoWrapper->setGammaContrast(
Settings::Manager::getFloat("gamma", "Video"), Settings::Manager::getFloat("contrast", "Video"));
mVideoWrapper->setGammaContrast(Settings::video().mGamma, Settings::video().mContrast);
if (useShaders)
mGuiPlatform->getRenderManagerPtr()->enableShaders(mResourceSystem->getSceneManager()->getShaderManager());
@ -1157,25 +1156,22 @@ namespace MWGui
changeRes = true;
else if (setting.first == "Video" && setting.second == "vsync mode")
mVideoWrapper->setSyncToVBlank(Settings::Manager::getInt("vsync mode", "Video"));
mVideoWrapper->setSyncToVBlank(Settings::video().mVsyncMode);
else if (setting.first == "Video" && (setting.second == "gamma" || setting.second == "contrast"))
mVideoWrapper->setGammaContrast(
Settings::Manager::getFloat("gamma", "Video"), Settings::Manager::getFloat("contrast", "Video"));
mVideoWrapper->setGammaContrast(Settings::video().mGamma, Settings::video().mContrast);
}
if (changeRes)
{
mVideoWrapper->setVideoMode(Settings::Manager::getInt("resolution x", "Video"),
Settings::Manager::getInt("resolution y", "Video"),
static_cast<Settings::WindowMode>(Settings::Manager::getInt("window mode", "Video")),
Settings::Manager::getBool("window border", "Video"));
mVideoWrapper->setVideoMode(Settings::video().mResolutionX, Settings::video().mResolutionY,
Settings::video().mWindowMode, Settings::video().mWindowBorder);
}
}
void WindowManager::windowResized(int x, int y)
{
Settings::Manager::setInt("resolution x", "Video", x);
Settings::Manager::setInt("resolution y", "Video", y);
Settings::video().mResolutionX.set(x);
Settings::video().mResolutionY.set(y);
// We only want to process changes to window-size related settings.
Settings::CategorySettingVector filter = { { "Video", "resolution x" }, { "Video", "resolution y" } };

@ -4,7 +4,7 @@
#include <SDL_keyboard.h>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
@ -170,10 +170,9 @@ namespace MWInput
void ActionManager::screenshot()
{
const std::string& settingStr = Settings::Manager::getString("screenshot type", "Video");
bool regularScreenshot = settingStr.empty() || settingStr == "regular";
const Settings::ScreenshotSettings& settings = Settings::video().mScreenshotType;
if (regularScreenshot)
if (settings.mType == Settings::ScreenshotType::Regular)
{
mScreenCaptureHandler->setFramesToCapture(1);
mScreenCaptureHandler->captureNextFrame(*mViewer);

@ -42,8 +42,7 @@ namespace MWInput
float angle = 0;
SDL_DisplayOrientation currentOrientation
= SDL_GetDisplayOrientation(Settings::Manager::getInt("screen", "Video"));
SDL_DisplayOrientation currentOrientation = SDL_GetDisplayOrientation(Settings::video().mScreen);
switch (currentOrientation)
{
case SDL_ORIENTATION_UNKNOWN:

@ -94,8 +94,8 @@ namespace MWLua
api["getViewTransform"] = [camera]() { return LuaUtil::TransformM{ camera->getViewMatrix() }; };
api["viewportToWorldVector"] = [camera, renderingManager](osg::Vec2f pos) -> osg::Vec3f {
double width = Settings::Manager::getInt("resolution x", "Video");
double height = Settings::Manager::getInt("resolution y", "Video");
const double width = Settings::video().mResolutionX;
const double height = Settings::video().mResolutionY;
double aspect = (height == 0.0) ? 1.0 : width / height;
double fovTan = std::tan(osg::DegreesToRadians(renderingManager->getFieldOfView()) / 2);
osg::Matrixf invertedViewMatrix;
@ -106,8 +106,8 @@ namespace MWLua
};
api["worldToViewportVector"] = [camera](osg::Vec3f pos) {
double width = Settings::Manager::getInt("resolution x", "Video");
double height = Settings::Manager::getInt("resolution y", "Video");
const double width = Settings::video().mResolutionX;
const double height = Settings::video().mResolutionY;
osg::Matrix windowMatrix
= osg::Matrix::translate(1.0, 1.0, 1.0) * osg::Matrix::scale(0.5 * width, 0.5 * height, 0.5);

@ -239,10 +239,7 @@ namespace MWLua
return luaManager->uiResourceManager()->registerTexture(data);
};
api["screenSize"] = []() {
return osg::Vec2f(
Settings::Manager::getInt("resolution x", "Video"), Settings::Manager::getInt("resolution y", "Video"));
};
api["screenSize"] = []() { return osg::Vec2f(Settings::video().mResolutionX, Settings::video().mResolutionY); };
api["_getAllUiModes"] = [](sol::this_state lua) {
sol::table res(lua, sol::create);

@ -154,7 +154,7 @@ namespace MWRender
public:
CharacterPreviewRTTNode(uint32_t sizeX, uint32_t sizeY)
: RTTNode(sizeX, sizeY, Settings::Manager::getInt("antialiasing", "Video"), false, 0,
: RTTNode(sizeX, sizeY, Settings::video().mAntialiasing, false, 0,
StereoAwareness::Unaware_MultiViewShaders, shouldAddMSAAIntermediateTarget())
, mAspectRatio(static_cast<float>(sizeX) / static_cast<float>(sizeY))
{

@ -112,7 +112,7 @@ namespace MWRender
: osg::Group()
, mEnableLiveReload(false)
, mRootNode(rootNode)
, mSamples(Settings::Manager::getInt("antialiasing", "Video"))
, mSamples(Settings::video().mAntialiasing)
, mDirty(false)
, mDirtyFrameId(0)
, mRendering(rendering)

@ -1230,8 +1230,8 @@ namespace MWRender
if (mViewDistance < mNearClip)
throw std::runtime_error("Viewing distance is less than near clip");
double width = Settings::Manager::getInt("resolution x", "Video");
double height = Settings::Manager::getInt("resolution y", "Video");
const double width = Settings::video().mResolutionX;
const double height = Settings::video().mResolutionY;
double aspect = (height == 0.0) ? 1.0 : width / height;
float fov = mFieldOfView;

@ -8,6 +8,7 @@
#include <osg/Texture2D>
#include <osg/TextureCubeMap>
#include <components/loadinglistener/loadinglistener.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <components/misc/strings/conversion.hpp>
#include <components/resource/resourcesystem.hpp>
@ -20,7 +21,6 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwgui/loadingscreen.hpp"
#include "postprocessor.hpp"
#include "util.hpp"
@ -29,7 +29,7 @@
namespace MWRender
{
enum Screenshot360Type
enum class Screenshot360Type
{
Spherical,
Cylindrical,
@ -161,59 +161,46 @@ namespace MWRender
bool ScreenshotManager::screenshot360(osg::Image* image)
{
int screenshotW = mViewer->getCamera()->getViewport()->width();
int screenshotH = mViewer->getCamera()->getViewport()->height();
Screenshot360Type screenshotMapping = Spherical;
const Settings::ScreenshotSettings& settings = Settings::video().mScreenshotType;
const std::string& settingStr = Settings::Manager::getString("screenshot type", "Video");
std::vector<std::string_view> settingArgs;
Misc::StringUtils::split(settingStr, settingArgs);
Screenshot360Type screenshotMapping = Screenshot360Type::Spherical;
if (settingArgs.size() > 0)
switch (settings.mType)
{
std::string_view typeStrings[4] = { "spherical", "cylindrical", "planet", "cubemap" };
bool found = false;
for (int i = 0; i < 4; ++i)
{
if (settingArgs[0] == typeStrings[i])
{
screenshotMapping = static_cast<Screenshot360Type>(i);
found = true;
break;
}
}
if (!found)
{
Log(Debug::Warning) << "Wrong screenshot type: " << settingArgs[0] << ".";
case Settings::ScreenshotType::Regular:
Log(Debug::Warning) << "Wrong screenshot 360 type: regular.";
return false;
}
case Settings::ScreenshotType::Cylindrical:
screenshotMapping = Screenshot360Type::Cylindrical;
break;
case Settings::ScreenshotType::Spherical:
screenshotMapping = Screenshot360Type::Spherical;
break;
case Settings::ScreenshotType::Planet:
screenshotMapping = Screenshot360Type::Planet;
break;
case Settings::ScreenshotType::Cubemap:
screenshotMapping = Screenshot360Type::RawCubemap;
break;
}
// planet mapping needs higher resolution
int cubeSize = screenshotMapping == Planet ? screenshotW : screenshotW / 2;
int screenshotW = mViewer->getCamera()->getViewport()->width();
if (settingArgs.size() > 1)
{
screenshotW = std::min(10000, Misc::StringUtils::toNumeric<int>(settingArgs[1], 0));
}
if (settings.mWidth.has_value())
screenshotW = *settings.mWidth;
if (settingArgs.size() > 2)
{
screenshotH = std::min(10000, Misc::StringUtils::toNumeric<int>(settingArgs[2], 0));
}
int screenshotH = mViewer->getCamera()->getViewport()->height();
if (settingArgs.size() > 3)
{
cubeSize = std::min(5000, Misc::StringUtils::toNumeric<int>(settingArgs[3], 0));
}
if (settings.mHeight.has_value())
screenshotH = *settings.mHeight;
bool rawCubemap = screenshotMapping == RawCubemap;
// planet mapping needs higher resolution
const int cubeSize = screenshotMapping == Screenshot360Type::Planet ? screenshotW : screenshotW / 2;
const bool rawCubemap = screenshotMapping == Screenshot360Type::RawCubemap;
if (rawCubemap)
screenshotW = cubeSize * 6; // the image will consist of 6 cube sides in a row
else if (screenshotMapping == Planet)
else if (screenshotMapping == Screenshot360Type::Planet)
screenshotH = screenshotW; // use square resolution for planet mapping
std::vector<osg::ref_ptr<osg::Image>> images;
@ -276,7 +263,7 @@ namespace MWRender
stateset->setAttributeAndModes(shaderMgr.getProgram("360"), osg::StateAttribute::ON);
stateset->addUniform(new osg::Uniform("cubeMap", 0));
stateset->addUniform(new osg::Uniform("mapping", screenshotMapping));
stateset->addUniform(new osg::Uniform("mapping", static_cast<int>(screenshotMapping)));
stateset->setTextureAttributeAndModes(0, cubeTexture, osg::StateAttribute::ON);
screenshotCamera->addChild(quad);

@ -70,7 +70,7 @@ namespace MWRender
bool shouldAddMSAAIntermediateTarget()
{
return Settings::shaders().mAntialiasAlphaTest && Settings::Manager::getInt("antialiasing", "Video") > 1;
return Settings::shaders().mAntialiasAlphaTest && Settings::video().mAntialiasing > 1;
}
}

@ -87,6 +87,8 @@ add_component_dir (settings
settingvalue
shadermanager
values
screenshotsettings
windowmode
)
add_component_dir (bsa
@ -336,7 +338,15 @@ add_component_dir (fontloader
)
add_component_dir (sdlutil
gl4es_init sdlgraphicswindow imagetosurface sdlinputwrapper sdlvideowrapper events sdlcursormanager sdlmappings
events
gl4es_init
imagetosurface
sdlcursormanager
sdlgraphicswindow
sdlinputwrapper
sdlmappings
sdlvideowrapper
vsyncmode
)
add_component_dir (version

@ -14,22 +14,16 @@ namespace SDLUtil
close(true);
}
GraphicsWindowSDL2::GraphicsWindowSDL2(osg::GraphicsContext::Traits* traits, int vsync)
GraphicsWindowSDL2::GraphicsWindowSDL2(osg::GraphicsContext::Traits* traits, VSyncMode vsyncMode)
: mWindow(nullptr)
, mContext(nullptr)
, mValid(false)
, mRealized(false)
, mOwnsWindow(false)
, mVSyncMode(vsyncMode)
{
_traits = traits;
if (vsync == 2)
mVSyncMode = VSyncMode::Adaptive;
else if (vsync == 1)
mVSyncMode = VSyncMode::Enabled;
else
mVSyncMode = VSyncMode::Disabled;
init();
if (GraphicsWindowSDL2::valid())
{

@ -5,14 +5,10 @@
#include <osgViewer/GraphicsWindow>
#include "vsyncmode.hpp"
namespace SDLUtil
{
enum VSyncMode
{
Disabled = 0,
Enabled = 1,
Adaptive = 2
};
class GraphicsWindowSDL2 : public osgViewer::GraphicsWindow
{
@ -29,7 +25,7 @@ namespace SDLUtil
virtual ~GraphicsWindowSDL2();
public:
GraphicsWindowSDL2(osg::GraphicsContext::Traits* traits, int vsync);
GraphicsWindowSDL2(osg::GraphicsContext::Traits* traits, VSyncMode vsyncMode);
bool isSameKindAs(const Object* object) const override
{

@ -1,7 +1,7 @@
#include "sdlinputwrapper.hpp"
#include <components/debug/debuglog.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#include <osgViewer/Viewer>
@ -187,8 +187,10 @@ namespace SDLUtil
{
case SDL_DISPLAYEVENT_ORIENTATION:
if (mSensorListener
&& evt.display.display == (unsigned int)Settings::Manager::getInt("screen", "Video"))
&& evt.display.display == static_cast<Uint32>(Settings::video().mScreen))
{
mSensorListener->displayOrientationChanged();
}
break;
default:
break;

@ -30,14 +30,8 @@ namespace SDLUtil
SDL_SetWindowGammaRamp(mWindow, mOldSystemGammaRamp, &mOldSystemGammaRamp[256], &mOldSystemGammaRamp[512]);
}
void VideoWrapper::setSyncToVBlank(int mode)
void VideoWrapper::setSyncToVBlank(VSyncMode vsyncMode)
{
VSyncMode vsyncMode = VSyncMode::Disabled;
if (mode == 1)
vsyncMode = VSyncMode::Enabled;
else if (mode == 2)
vsyncMode = VSyncMode::Adaptive;
osgViewer::Viewer::Windows windows;
mViewer->getWindows(windows);
mViewer->stopThreading();
@ -47,7 +41,7 @@ namespace SDLUtil
if (GraphicsWindowSDL2* sdl2win = dynamic_cast<GraphicsWindowSDL2*>(win))
sdl2win->setSyncToVBlank(vsyncMode);
else
win->setSyncToVBlank(static_cast<bool>(mode));
win->setSyncToVBlank(vsyncMode != VSyncMode::Disabled);
}
mViewer->startThreading();
}

@ -5,6 +5,8 @@
#include <SDL_types.h>
#include "vsyncmode.hpp"
struct SDL_Window;
namespace osgViewer
@ -26,7 +28,7 @@ namespace SDLUtil
VideoWrapper(SDL_Window* window, osg::ref_ptr<osgViewer::Viewer> viewer);
~VideoWrapper();
void setSyncToVBlank(int mode);
void setSyncToVBlank(VSyncMode vsyncMode);
void setGammaContrast(float gamma, float contrast);

@ -0,0 +1,14 @@
#ifndef OPENMW_COMPONENTS_SDLUTIL_VSYNCMODE_H
#define OPENMW_COMPONENTS_SDLUTIL_VSYNCMODE_H
namespace SDLUtil
{
enum VSyncMode
{
Disabled = 0,
Enabled = 1,
Adaptive = 2
};
}
#endif

@ -1,8 +1,12 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_CATEGORIES_VIDEO_H
#define OPENMW_COMPONENTS_SETTINGS_CATEGORIES_VIDEO_H
#include "components/settings/sanitizerimpl.hpp"
#include "components/settings/settingvalue.hpp"
#include <components/settings/sanitizerimpl.hpp>
#include <components/settings/screenshotsettings.hpp>
#include <components/settings/settingvalue.hpp>
#include <components/settings/windowmode.hpp>
#include <components/sdlutil/vsyncmode.hpp>
#include <osg/Math>
#include <osg/Vec2f>
@ -20,16 +24,16 @@ namespace Settings
SettingValue<int> mResolutionX{ mIndex, "Video", "resolution x", makeMaxSanitizerInt(1) };
SettingValue<int> mResolutionY{ mIndex, "Video", "resolution y", makeMaxSanitizerInt(1) };
SettingValue<int> mWindowMode{ mIndex, "Video", "window mode", makeEnumSanitizerInt({ 0, 1, 2 }) };
SettingValue<WindowMode> mWindowMode{ mIndex, "Video", "window mode" };
SettingValue<int> mScreen{ mIndex, "Video", "screen", makeMaxSanitizerInt(0) };
SettingValue<bool> mMinimizeOnFocusLoss{ mIndex, "Video", "minimize on focus loss" };
SettingValue<bool> mWindowBorder{ mIndex, "Video", "window border" };
SettingValue<int> mAntialiasing{ mIndex, "Video", "antialiasing", makeMaxSanitizerInt(0) };
SettingValue<int> mVsyncMode{ mIndex, "Video", "vsync mode", makeEnumSanitizerInt({ 0, 1, 2 }) };
SettingValue<SDLUtil::VSyncMode> mVsyncMode{ mIndex, "Video", "vsync mode" };
SettingValue<float> mFramerateLimit{ mIndex, "Video", "framerate limit", makeMaxSanitizerFloat(0) };
SettingValue<float> mContrast{ mIndex, "Video", "contrast", makeMaxStrictSanitizerFloat(0) };
SettingValue<float> mGamma{ mIndex, "Video", "gamma", makeMaxStrictSanitizerFloat(0) };
SettingValue<std::string> mScreenshotType{ mIndex, "Video", "screenshot type" };
SettingValue<ScreenshotSettings> mScreenshotType{ mIndex, "Video", "screenshot type" };
};
}

@ -0,0 +1,29 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_SCREENSHOTSETTINGS_H
#define OPENMW_COMPONENTS_SETTINGS_SCREENSHOTSETTINGS_H
#include <optional>
#include <ostream>
namespace Settings
{
enum class ScreenshotType
{
Regular,
Cylindrical,
Spherical,
Planet,
Cubemap,
};
struct ScreenshotSettings
{
ScreenshotType mType;
std::optional<int> mWidth;
std::optional<int> mHeight;
std::optional<int> mCubeSize;
auto operator<=>(const ScreenshotSettings& value) const = default;
};
}
#endif

@ -119,6 +119,23 @@ namespace Settings
Log(Debug::Warning) << "Invalid HRTF mode value: " << static_cast<int>(value) << ", fallback to auto (-1)";
return -1;
}
ScreenshotType parseScreenshotType(std::string_view value)
{
if (value == "regular")
return ScreenshotType::Regular;
if (value == "spherical")
return ScreenshotType::Spherical;
if (value == "cylindrical")
return ScreenshotType::Cylindrical;
if (value == "planet")
return ScreenshotType::Planet;
if (value == "cubemap")
return ScreenshotType::Cubemap;
Log(Debug::Warning) << "Invalid screenshot type: " << value << ", fallback to regular";
return ScreenshotType::Regular;
}
}
CategorySettingValueMap Manager::mDefaultSettings = CategorySettingValueMap();
@ -501,6 +518,16 @@ namespace Settings
setInt(setting, category, toInt(value));
}
void Manager::set(std::string_view setting, std::string_view category, WindowMode value)
{
setInt(setting, category, static_cast<int>(value));
}
void Manager::set(std::string_view setting, std::string_view category, SDLUtil::VSyncMode value)
{
setInt(setting, category, static_cast<int>(value));
}
void Manager::recordInit(std::string_view setting, std::string_view category)
{
sInitialized.emplace(category, setting);
@ -547,4 +574,28 @@ namespace Settings
Log(Debug::Warning) << "Unknown lighting method '" << value << "', returning fallback '" << fallback << "'";
return SceneUtil::LightingMethod::PerObjectUniform;
}
ScreenshotSettings parseScreenshotSettings(std::string_view value)
{
std::vector<std::string_view> settingArgs;
Misc::StringUtils::split(value, settingArgs);
ScreenshotSettings result;
if (settingArgs.size() > 0)
result.mType = parseScreenshotType(settingArgs[0]);
else
result.mType = ScreenshotType::Regular;
if (settingArgs.size() > 1)
result.mWidth = std::min(10000, Misc::StringUtils::toNumeric<int>(settingArgs[1], 0));
if (settingArgs.size() > 2)
result.mHeight = std::min(10000, Misc::StringUtils::toNumeric<int>(settingArgs[2], 0));
if (settingArgs.size() > 3)
result.mCubeSize = std::min(5000, Misc::StringUtils::toNumeric<int>(settingArgs[3], 0));
return result;
}
}

@ -5,9 +5,12 @@
#include "gyroscopeaxis.hpp"
#include "hrtfmode.hpp"
#include "navmeshrendermode.hpp"
#include "screenshotsettings.hpp"
#include "windowmode.hpp"
#include <components/detournavigator/collisionshapetype.hpp>
#include <components/sceneutil/lightingmethod.hpp>
#include <components/sdlutil/vsyncmode.hpp>
#include <filesystem>
#include <set>
@ -27,13 +30,6 @@ namespace Files
namespace Settings
{
enum class WindowMode
{
Fullscreen = 0,
WindowedFullscreen,
Windowed
};
///
/// \brief Settings management (can change during runtime)
///
@ -114,6 +110,8 @@ namespace Settings
static void set(std::string_view setting, std::string_view category, const MyGUI::Colour& value);
static void set(std::string_view setting, std::string_view category, SceneUtil::LightingMethod value);
static void set(std::string_view setting, std::string_view category, HrtfMode value);
static void set(std::string_view setting, std::string_view category, WindowMode value);
static void set(std::string_view setting, std::string_view category, SDLUtil::VSyncMode value);
private:
static std::set<std::pair<std::string_view, std::string_view>> sInitialized;
@ -239,6 +237,32 @@ namespace Settings
return HrtfMode::Enable;
return HrtfMode::Disable;
}
template <>
inline WindowMode Manager::getImpl<WindowMode>(std::string_view setting, std::string_view category)
{
const int value = getInt(setting, category);
if (value < 0 || 2 < value)
return WindowMode::Fullscreen;
return static_cast<WindowMode>(value);
}
template <>
inline SDLUtil::VSyncMode Manager::getImpl<SDLUtil::VSyncMode>(std::string_view setting, std::string_view category)
{
const int value = getInt(setting, category);
if (value < 0 || 2 < value)
return SDLUtil::VSyncMode::Disabled;
return static_cast<SDLUtil::VSyncMode>(value);
}
ScreenshotSettings parseScreenshotSettings(std::string_view value);
template <>
inline ScreenshotSettings Manager::getImpl<ScreenshotSettings>(std::string_view setting, std::string_view category)
{
return parseScreenshotSettings(getString(setting, category));
}
}
#endif // COMPONENTS_SETTINGS_H

@ -42,6 +42,9 @@ namespace Settings
NavMeshRenderMode,
LightingMethod,
HrtfMode,
WindowMode,
VSyncMode,
ScreenshotSettings,
};
template <class T>
@ -161,6 +164,24 @@ namespace Settings
return SettingValueType::HrtfMode;
}
template <>
inline constexpr SettingValueType getSettingValueType<WindowMode>()
{
return SettingValueType::WindowMode;
}
template <>
inline constexpr SettingValueType getSettingValueType<SDLUtil::VSyncMode>()
{
return SettingValueType::VSyncMode;
}
template <>
inline constexpr SettingValueType getSettingValueType<ScreenshotSettings>()
{
return SettingValueType::ScreenshotSettings;
}
inline constexpr std::string_view getSettingValueTypeName(SettingValueType type)
{
switch (type)
@ -203,6 +224,12 @@ namespace Settings
return "lighting method";
case SettingValueType::HrtfMode:
return "hrtf mode";
case SettingValueType::WindowMode:
return "window mode";
case SettingValueType::VSyncMode:
return "vsync mode";
case SettingValueType::ScreenshotSettings:
return "screenshot settings";
}
return "unsupported";
}
@ -361,6 +388,17 @@ namespace Settings
}
return stream;
}
else if constexpr (std::is_same_v<T, ScreenshotSettings>)
{
stream << "ScreenshotSettings{ .mType = " << static_cast<int>(value.mValue.mType);
if (value.mValue.mWidth.has_value())
stream << ", .mWidth = " << *value.mValue.mWidth;
if (value.mValue.mHeight.has_value())
stream << ", .mHeight = " << *value.mValue.mHeight;
if (value.mValue.mCubeSize.has_value())
stream << ", .mCubeSize = " << *value.mValue.mCubeSize;
return stream << " }";
}
else
return stream << value.mValue;
}

@ -0,0 +1,14 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_WINDOWMODE_H
#define OPENMW_COMPONENTS_SETTINGS_WINDOWMODE_H
namespace Settings
{
enum class WindowMode
{
Fullscreen = 0,
WindowedFullscreen = 1,
Windowed = 2,
};
}
#endif

@ -273,7 +273,7 @@ namespace Stereo
void Manager::updateStereoFramebuffer()
{
// VR-TODO: in VR, still need to have this framebuffer attached before the postprocessor is created
// auto samples = Settings::Manager::getInt("antialiasing", "Video");
// auto samples = /*do not use Settings here*/;
// auto eyeRes = eyeResolution();
// if (mMultiviewFramebuffer)

@ -194,3 +194,12 @@ Gamma is an exponent that makes colors brighter if greater than 1.0 and darker i
This setting can be changed in the Detail tab of the Video panel of the Options menu.
It has been reported to not work on some Linux systems,
and therefore the in-game setting in the Options menu has been disabled on Linux systems.
screenshot type
---------------
:Type: screenshot settings
:Default: regular
Type of screenshot to take (regular, cylindrical, spherical, planet or cubemap), optionally followed by
screenshot width, height and cubemap resolution in pixels (e.g. spherical 1600 1000 1200).

@ -640,7 +640,7 @@ contrast = 1.0
# Video gamma setting. (>0.0). No effect in Linux.
gamma = 1.0
# Type of screenshot to take (regular, cylindrical, spherical or planet), optionally followed by
# Type of screenshot to take (regular, cylindrical, spherical, planet or cubemap), optionally followed by
# screenshot width, height and cubemap resolution in pixels. (e.g. spherical 1600 1000 1200)
screenshot type = regular

Loading…
Cancel
Save