From 303b0ee8c6c4e5ca6fab15dfdd08af3757de96c4 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 28 Sep 2014 15:43:33 +1000 Subject: [PATCH] Update scenewidget when antialiasing settings change. --- apps/opencs/model/settings/usersettings.cpp | 13 +++++- apps/opencs/view/render/scenewidget.cpp | 44 ++++++++++++++++++++- apps/opencs/view/settings/rangeview.cpp | 4 +- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 2e5aaad42..bc197ab48 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -192,6 +192,17 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() ritd->setEditorSetting (true); } + section = "Video"; + { + QString defaultValue = "None"; + QStringList values = QStringList() + << defaultValue << "MSAA 2" << "MSAA 4" << "MSAA 8" << "MSAA 16"; + Setting *antialiasing = createSetting (Type_SpinBox, section, "antialiasing"); + antialiasing->setDeclaredValues (values); + antialiasing->setEditorSetting (true); + antialiasing->setWidgetWidth(15); + } + section = "Proxy Selection Test"; { /****************************************************************** @@ -483,7 +494,7 @@ void CSMSettings::UserSettings::updateUserSetting(const QString &settingKey, sh::Factory::getInstance ().setShadersEnabled (list.at(0) == "true" ? true : false); } - emit userSettingUpdated (settingKey, list); // TODO: isn't this circular? + emit userSettingUpdated (settingKey, list); } CSMSettings::Setting *CSMSettings::UserSettings::findSetting diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 1b0b578f6..c399fca6b 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -128,7 +128,16 @@ namespace CSVRender params.insert(std::make_pair("externalWindowHandle", windowHandle.str())); params.insert(std::make_pair("title", windowTitle.str())); - params.insert(std::make_pair("FSAA", "0")); // TODO setting + + std::string antialiasing = + CSMSettings::UserSettings::instance().settingValue("Video/antialiasing").toStdString(); + if(antialiasing == "MSAA 16") antialiasing = "16"; + else if(antialiasing == "MSAA 8") antialiasing = "8"; + else if(antialiasing == "MSAA 4") antialiasing = "4"; + else if(antialiasing == "MSAA 2") antialiasing = "2"; + else antialiasing = "0"; + params.insert(std::make_pair("FSAA", antialiasing)); + params.insert(std::make_pair("vsync", "false")); // TODO setting #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE params.insert(std::make_pair("macAPI", "cocoa")); @@ -402,5 +411,38 @@ namespace CSVRender { if(key.contains(QRegExp("^\\b(Objects|Shader|Scene)", Qt::CaseInsensitive))) flagAsModified(); + + // minimise unnecessary ogre window creation by updating only when there is a change + if(key == "Video/antialiasing") + { + std::string result; + + Ogre::ConfigOptionMap& renderOpt = + Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions(); + + Ogre::ConfigOptionMap::iterator it = renderOpt.begin(); + + for(; it != renderOpt.end(); ++it) + { + if(it->first == "FSAA") + result = it->second.currentValue; + } + + QString antialiasing = "0"; + if(!list.empty()) + { + antialiasing = list.at(0); + + if(antialiasing == "MSAA 16") antialiasing = "16"; + else if(antialiasing == "MSAA 8") antialiasing = "8"; + else if(antialiasing == "MSAA 4") antialiasing = "4"; + else if(antialiasing == "MSAA 2") antialiasing = "2"; + } + + if(result != antialiasing.toStdString()) + { + updateOgreWindow(); + } + } } } diff --git a/apps/opencs/view/settings/rangeview.cpp b/apps/opencs/view/settings/rangeview.cpp index 49cc170e1..6b47b1cac 100644 --- a/apps/opencs/view/settings/rangeview.cpp +++ b/apps/opencs/view/settings/rangeview.cpp @@ -129,8 +129,8 @@ void CSVSettings::RangeView::buildSpinBox (CSMSettings::Setting *setting) mRangeWidget->setProperty ("wrapping", setting->wrapping()); dynamic_cast (mRangeWidget)->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); - if(setting->type() == CSMSettings::Type_SpinBox) - dynamic_cast (mRangeWidget)->setValue (setting->defaultValues().at(0).toInt()); // FIXME: can there be more than one? + if(setting->type() == CSMSettings::Type_SpinBox && setting->declaredValues().isEmpty()) + dynamic_cast (mRangeWidget)->setValue (setting->defaultValues().at(0).toInt()); } void CSVSettings::RangeView::slotUpdateView (int value)