diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 5e25d5ece5..122849634f 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -74,6 +74,14 @@ namespace return "16 : 10"; return boost::lexical_cast(xaspect) + " : " + boost::lexical_cast(yaspect); } + + std::string hlslGlsl () + { + if (Ogre::Root::getSingleton ().getRenderSystem ()->getName ().find("OpenGL") == std::string::npos) + return "hlsl"; + else + return "glsl"; + } } namespace MWGui @@ -103,8 +111,10 @@ namespace MWGui getWidget(mReflectObjectsButton, "ReflectObjectsButton"); getWidget(mReflectActorsButton, "ReflectActorsButton"); getWidget(mReflectTerrainButton, "ReflectTerrainButton"); + getWidget(mShadersButton, "ShadersButton"); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked); + mShadersButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onShadersToggled); mFullscreenButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); mWaterShaderButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); mReflectObjectsButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); @@ -189,6 +199,15 @@ namespace MWGui mReflectActorsButton->setCaptionWithReplacing(Settings::Manager::getBool("reflect actors", "Water") ? "#{sOn}" : "#{sOff}"); mReflectTerrainButton->setCaptionWithReplacing(Settings::Manager::getBool("reflect terrain", "Water") ? "#{sOn}" : "#{sOff}"); + std::string shaders; + if (!Settings::Manager::getBool("shaders", "Objects")) + shaders = "off"; + else + { + shaders = Settings::Manager::getString("shader mode", "General"); + } + mShadersButton->setCaption (shaders); + if (!MWRender::RenderingManager::waterShaderSupported()) { mWaterShaderButton->setEnabled(false); @@ -280,6 +299,10 @@ namespace MWGui Settings::Manager::setBool("fullscreen", "Video", newState); apply(); } + } + else if (_sender == mShadersButton) + { + } else if (_sender == mVSyncButton) { @@ -306,6 +329,45 @@ namespace MWGui } } + void SettingsWindow::onShadersToggled(MyGUI::Widget* _sender) + { + std::string val = static_cast(_sender)->getCaption(); + if (val == "off") + val = hlslGlsl(); + else if (val == hlslGlsl()) + val = "cg"; + else + val = "off"; + + static_cast(_sender)->setCaption(val); + + if (val == "off") + { + Settings::Manager::setBool("shaders", "Objects", false); + + // water shader not supported with object shaders off + mWaterShaderButton->setCaptionWithReplacing("#{sOff}"); + mWaterShaderButton->setEnabled(false); + mReflectObjectsButton->setEnabled(false); + mReflectActorsButton->setEnabled(false); + mReflectTerrainButton->setEnabled(false); + Settings::Manager::setBool("shader", "Water", false); + } + else + { + // re-enable + mWaterShaderButton->setEnabled(true); + mReflectObjectsButton->setEnabled(true); + mReflectActorsButton->setEnabled(true); + mReflectTerrainButton->setEnabled(true); + + Settings::Manager::setBool("shaders", "Objects", true); + Settings::Manager::setString("shader mode", "General", val); + } + + apply(); + } + void SettingsWindow::onFpsToggled(MyGUI::Widget* _sender) { int newLevel = (Settings::Manager::getInt("fps", "HUD") + 1) % 3; diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index e3827c7b03..2bcab9d21b 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -42,6 +42,7 @@ namespace MWGui MyGUI::Button* mReflectObjectsButton; MyGUI::Button* mReflectActorsButton; MyGUI::Button* mReflectTerrainButton; + MyGUI::Button* mShadersButton; // audio MyGUI::ScrollBar* mMasterVolumeSlider; @@ -59,6 +60,8 @@ namespace MWGui void onResolutionAccept(); void onResolutionCancel(); + void onShadersToggled(MyGUI::Widget* _sender); + void apply(); }; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index fa20cd48db..b3e3e42a4e 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -42,6 +42,15 @@ namespace MWRender { RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine) :mRendering(_rend), mObjects(mRendering), mActors(mRendering), mAmbientMode(0), mSunEnabled(0) { + // select best shader mode + if (Settings::Manager::getString("shader mode", "General") == "") + { + if (Ogre::Root::getSingleton ().getRenderSystem ()->getName().find("OpenGL") == std::string::npos) + Settings::Manager::setString("shader mode", "General", "hlsl"); + else + Settings::Manager::setString("shader mode", "General", "glsl"); + } + mRendering.createScene("PlayerCam", Settings::Manager::getFloat("field of view", "General"), 5); mRendering.setWindowEventListener(this); @@ -619,6 +628,24 @@ void RenderingManager::processChangedSettings(const Settings::CategorySettingVec sh::Factory::getInstance ().setGlobalSetting ("mrt_output", useMRT() ? "true" : "false"); mObjects.rebuildStaticGeometry (); } + else if (it->second == "shaders" && it->first == "Objects") + { + sh::Factory::getInstance ().setShadersEnabled (Settings::Manager::getBool("shaders", "Objects")); + mObjects.rebuildStaticGeometry (); + } + else if (it->second == "shader mode" && it->first == "General") + { + sh::Language lang; + std::string l = Settings::Manager::getString("shader mode", "General"); + if (l == "glsl") + lang = sh::Language_GLSL; + else if (l == "hlsl") + lang = sh::Language_HLSL; + else + lang = sh::Language_CG; + sh::Factory::getInstance ().setCurrentLanguage (lang); + mObjects.rebuildStaticGeometry (); + } } if (changeRes) diff --git a/files/mygui/openmw_settings_window.layout b/files/mygui/openmw_settings_window.layout index 7c508b1e97..9d25b3ee55 100644 --- a/files/mygui/openmw_settings_window.layout +++ b/files/mygui/openmw_settings_window.layout @@ -1,7 +1,10 @@ - + + + + @@ -100,6 +103,12 @@ + + + + + + diff --git a/files/mygui/openmw_windows.skin.xml b/files/mygui/openmw_windows.skin.xml index b379f84ced..a9eb23d68a 100644 --- a/files/mygui/openmw_windows.skin.xml +++ b/files/mygui/openmw_windows.skin.xml @@ -322,6 +322,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 883f32ae07..bd8bb64b3a 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -48,6 +48,8 @@ anisotropy = 4 # Number of texture mipmaps to generate num mipmaps = 5 +shader mode = + [Shadows] # Shadows are only supported when object shaders are on! enabled = false