diff --git a/Core/Config.cpp b/Core/Config.cpp index f8a70ae981..af24885d82 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1263,10 +1263,9 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { auto postShaderChain = iniFile.GetOrCreateSection("PostShaderList")->ToMap(); vPostShaderNames.clear(); for (auto it : postShaderChain) { - vPostShaderNames.push_back(it.second); + if (it.second != "Off") + vPostShaderNames.push_back(it.second); } - if (vPostShaderNames.empty()) - vPostShaderNames.push_back("Off"); // This caps the exponent 4 (so 16x.) if (iAnisotropyLevel > 4) { @@ -1699,10 +1698,9 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title auto postShaderChain = iniFile.GetOrCreateSection("PostShaderList")->ToMap(); vPostShaderNames.clear(); for (auto it : postShaderChain) { - vPostShaderNames.push_back(it.second); + if (it.second != "Off") + vPostShaderNames.push_back(it.second); } - if (vPostShaderNames.empty()) - vPostShaderNames.push_back("Off"); IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) { if (setting->perGame_) { @@ -1737,10 +1735,9 @@ void Config::unloadGameConfig() { auto postShaderChain = iniFile.GetOrCreateSection("PostShaderList")->ToMap(); vPostShaderNames.clear(); for (auto it : postShaderChain) { - vPostShaderNames.push_back(it.second); + if (it.second != "Off") + vPostShaderNames.push_back(it.second); } - if (vPostShaderNames.empty()) - vPostShaderNames.push_back("Off"); LoadStandardControllerIni(); } diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index c86ef008b4..6c9782027c 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -953,8 +953,7 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, auto shaderChain = GetFullPostShadersChain(g_Config.vPostShaderNames); if (op.PostShaderUniform.shader < shaderChain.size()) { std::string shaderName = shaderChain[op.PostShaderUniform.shader]->section; - if (shaderName != "Off") - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = op.PostShaderUniform.value.f; + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = op.PostShaderUniform.value.f; } } break; @@ -969,21 +968,19 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, } value; value.u = Memory::Read_U32(op.addr); std::string shaderName = shaderChain[op.PostShaderUniform.shader]->section; - if (shaderName != "Off") { - switch (op.PostShaderUniform.format) { - case 0: - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x000000FF; - break; - case 1: - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x0000FFFF; - break; - case 2: - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u; - break; - case 3: - g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.f; - break; - } + switch (op.PostShaderUniform.format) { + case 0: + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x000000FF; + break; + case 1: + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u & 0x0000FFFF; + break; + case 2: + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.u; + break; + case 3: + g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderName.c_str(), op.PostShaderUniform.uniform + 1)] = value.f; + break; } } } diff --git a/GPU/Common/PostShader.cpp b/GPU/Common/PostShader.cpp index e415aa9226..ecf4724b9e 100644 --- a/GPU/Common/PostShader.cpp +++ b/GPU/Common/PostShader.cpp @@ -126,6 +126,9 @@ void LoadPostShaderInfo(const std::vector &directories) { section.Get("SSAA", &info.SSAAFilterLevel, 0); section.Get("60fps", &info.requires60fps, false); + if (info.parent == "Off") + info.parent = ""; + for (size_t i = 0; i < ARRAY_SIZE(info.settings); ++i) { auto &setting = info.settings[i]; section.Get(StringFromFormat("SettingName%d", i + 1).c_str(), &setting.name, ""); @@ -198,7 +201,7 @@ std::vector GetPostShaderChain(const std::string &name) { while (shaderInfo) { backwards.push_back(shaderInfo); - if (!shaderInfo->parent.empty() && shaderInfo->parent != "Off") { + if (!shaderInfo->parent.empty()) { shaderInfo = GetPostShaderInfo(shaderInfo->parent); } else { shaderInfo = nullptr; @@ -219,8 +222,6 @@ std::vector GetPostShaderChain(const std::string &name) { std::vector GetFullPostShadersChain(const std::vector &names) { std::vector fullChain; for (auto shaderName : names) { - if (shaderName == "Off") - break; auto shaderChain = GetPostShaderChain(shaderName); fullChain.insert(fullChain.end(), shaderChain.begin(), shaderChain.end()); } diff --git a/GPU/Common/PresentationCommon.cpp b/GPU/Common/PresentationCommon.cpp index 2122980b66..9c294a4f39 100644 --- a/GPU/Common/PresentationCommon.cpp +++ b/GPU/Common/PresentationCommon.cpp @@ -211,7 +211,7 @@ static std::string ReadShaderSrc(const std::string &filename) { // Note: called on resize and settings changes. bool PresentationCommon::UpdatePostShader() { std::vector shaderInfo; - if (!g_Config.vPostShaderNames.empty() && g_Config.vPostShaderNames[0] != "Off") { + if (!g_Config.vPostShaderNames.empty()) { ReloadAllPostShaderInfo(); shaderInfo = GetFullPostShadersChain(g_Config.vPostShaderNames); } @@ -735,7 +735,7 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u void PresentationCommon::CalculateRenderResolution(int *width, int *height, int *scaleFactor, bool *upscaling, bool *ssaa) { // Check if postprocessing shader is doing upscaling as it requires native resolution std::vector shaderInfo; - if (!g_Config.vPostShaderNames.empty() && g_Config.vPostShaderNames[0] != "Off") { + if (!g_Config.vPostShaderNames.empty()) { ReloadAllPostShaderInfo(); shaderInfo = GetFullPostShadersChain(g_Config.vPostShaderNames); } diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index ba77244124..618f675ec5 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -18,6 +18,7 @@ #include "ppsspp_config.h" #include +#include #include "Common/Net/Resolve.h" #include "Common/GPU/OpenGL/GLFeatures.h" @@ -78,8 +79,6 @@ #include "Windows/W32Util/ShellUtil.h" #endif -extern bool g_ShaderNameListChanged; - GameSettingsScreen::GameSettingsScreen(std::string gamePath, std::string gameID, bool editThenRestore) : UIDialogScreenWithGameBackground(gamePath), gameID_(gameID), enableReports_(false), editThenRestore_(editThenRestore) { lastVertical_ = UseVerticalLayout(); @@ -313,10 +312,10 @@ void GameSettingsScreen::CreateViews() { graphicsSettings->Add(new ItemHeader(gr->T("Postprocessing effect"))); - std::vector alreadyAddedShader; - for (int i = 0; i < g_Config.vPostShaderNames.size() && i < ARRAY_SIZE(shaderNames_); ++i) { + std::set alreadyAddedShader; + for (int i = 0; i < g_Config.vPostShaderNames.size() + 1 && i < ARRAY_SIZE(shaderNames_); ++i) { // Vector element pointer get invalidated on resize, cache name to have always a valid reference in the rendering thread - shaderNames_[i] = g_Config.vPostShaderNames[i]; + shaderNames_[i] = i == g_Config.vPostShaderNames.size() ? "Off" : g_Config.vPostShaderNames[i]; postProcChoice_ = graphicsSettings->Add(new ChoiceWithValueDisplay(&shaderNames_[i], StringFromFormat("%s #%d", gr->T("Postprocessing Shader"), i + 1), &PostShaderTranslateName)); postProcChoice_->OnClick.Add([=](EventParams &e) { auto gr = GetI18NCategory("Graphics"); @@ -331,11 +330,15 @@ void GameSettingsScreen::CreateViews() { return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; }); + // No need for settings on the last one. + if (i == g_Config.vPostShaderNames.size()) + continue; + auto shaderChain = GetPostShaderChain(g_Config.vPostShaderNames[i]); for (auto shaderInfo : shaderChain) { // Disable duplicated shader slider - bool duplicated = std::find(alreadyAddedShader.begin(), alreadyAddedShader.end(), shaderInfo->section) != alreadyAddedShader.end(); - alreadyAddedShader.push_back(shaderInfo->section); + bool duplicated = alreadyAddedShader.find(shaderInfo->section) != alreadyAddedShader.end(); + alreadyAddedShader.insert(shaderInfo->section); for (size_t i = 0; i < ARRAY_SIZE(shaderInfo->settings); ++i) { auto &setting = shaderInfo->settings[i]; if (!setting.name.empty()) { @@ -1255,11 +1258,6 @@ void GameSettingsScreen::update() { RecreateViews(); lastVertical_ = vertical; } - if (g_ShaderNameListChanged) { - g_ShaderNameListChanged = false; - g_Config.bShaderChainRequires60FPS = PostShaderChainRequires60FPS(GetFullPostShadersChain(g_Config.vPostShaderNames)); - RecreateViews(); - } } void GameSettingsScreen::onFinish(DialogResult result) { @@ -1287,6 +1285,14 @@ void GameSettingsScreen::onFinish(DialogResult result) { NativeMessageReceived("gpu_clearCache", ""); } +void GameSettingsScreen::sendMessage(const char *message, const char *value) { + UIDialogScreenWithGameBackground::sendMessage(message, value); + if (!strcmp(message, "postshader_updated")) { + g_Config.bShaderChainRequires60FPS = PostShaderChainRequires60FPS(GetFullPostShadersChain(g_Config.vPostShaderNames)); + RecreateViews(); + } +} + #if PPSSPP_PLATFORM(ANDROID) void GameSettingsScreen::CallbackMemstickFolder(bool yes) { auto sy = GetI18NCategory("System"); @@ -1525,9 +1531,9 @@ UI::EventReturn GameSettingsScreen::OnLanguageChange(UI::EventParams &e) { UI::EventReturn GameSettingsScreen::OnPostProcShaderChange(UI::EventParams &e) { g_Config.vPostShaderNames.erase(std::remove(g_Config.vPostShaderNames.begin(), g_Config.vPostShaderNames.end(), "Off"), g_Config.vPostShaderNames.end()); - g_Config.vPostShaderNames.push_back("Off"); - g_ShaderNameListChanged = true; + NativeMessageReceived("gpu_resized", ""); + NativeMessageReceived("postshader_updated", ""); return UI::EVENT_DONE; } diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index 76fd384aed..ec7542f483 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -37,6 +37,7 @@ public: std::string tag() const override { return "settings"; } protected: + void sendMessage(const char *message, const char *value) override; void CreateViews() override; void CallbackRestoreDefaults(bool yes); void CallbackRenderingBackend(bool yes); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index c5e8a9f720..2ee6ba8463 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -430,10 +430,11 @@ PostProcScreen::PostProcScreen(const std::string &title, int id) : ListPopupScre shaders_ = GetAllPostShaderInfo(); std::vector items; int selected = -1; + const std::string selectedName = id_ >= g_Config.vPostShaderNames.size() ? "Off" : g_Config.vPostShaderNames[id_]; for (int i = 0; i < (int)shaders_.size(); i++) { if (!shaders_[i].visible) continue; - if (shaders_[i].section == g_Config.vPostShaderNames[id_]) + if (shaders_[i].section == selectedName) selected = i; items.push_back(ps->T(shaders_[i].section.c_str(), shaders_[i].name.c_str())); } @@ -443,7 +444,11 @@ PostProcScreen::PostProcScreen(const std::string &title, int id) : ListPopupScre void PostProcScreen::OnCompleted(DialogResult result) { if (result != DR_OK) return; - g_Config.vPostShaderNames[id_] = shaders_[listView_->GetSelected()].section; + const std::string &value = shaders_[listView_->GetSelected()].section; + if (id_ < g_Config.vPostShaderNames.size()) + g_Config.vPostShaderNames[id_] = value; + else + g_Config.vPostShaderNames.push_back(value); } TextureShaderScreen::TextureShaderScreen(const std::string &title) : ListPopupScreen(title) { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index e36f59a016..1631461115 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -144,7 +144,6 @@ std::string config_filename; // Really need to clean this mess of globals up... but instead I add more :P bool g_TakeScreenshot; -bool g_ShaderNameListChanged = false; static bool isOuya; static bool resized = false; static bool restarting = false; diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 867ff4fe52..689cd6366c 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -50,7 +50,6 @@ #include "Core/Core.h" extern bool g_TakeScreenshot; -extern bool g_ShaderNameListChanged; namespace MainWindow { extern HINSTANCE hInst; @@ -156,8 +155,15 @@ namespace MainWindow { void UpdateDynamicMenuCheckmarks(HMENU menu) { int item = ID_SHADERS_BASE + 1; - for (size_t i = 0; i < availableShaders.size(); i++) - CheckMenuItem(menu, item++, ((g_Config.vPostShaderNames[0] == availableShaders[i] && (g_Config.vPostShaderNames[0] == "Off" || g_Config.vPostShaderNames[1] == "Off")) ? MF_CHECKED : MF_UNCHECKED)); + for (size_t i = 0; i < availableShaders.size(); i++) { + bool checked = false; + if (g_Config.vPostShaderNames.empty() && availableShaders[i] == "Off") + checked = true; + else if (g_Config.vPostShaderNames.size() == 1 && availableShaders[i] == g_Config.vPostShaderNames[0]) + checked = true; + + CheckMenuItem(menu, item++, checked ? MF_CHECKED : MF_UNCHECKED); + } } bool CreateShadersSubmenu(HMENU menu) { @@ -191,7 +197,9 @@ namespace MainWindow { continue; int checkedStatus = MF_UNCHECKED; availableShaders.push_back(i->section); - if (g_Config.vPostShaderNames[0] == i->section && (g_Config.vPostShaderNames[0] == "Off" || g_Config.vPostShaderNames[1] == "Off")) { + if (g_Config.vPostShaderNames.empty() && i->section == "Off") { + checkedStatus = MF_CHECKED; + } else if (g_Config.vPostShaderNames.size() == 1 && g_Config.vPostShaderNames[0] == i->section) { checkedStatus = MF_CHECKED; } @@ -1060,10 +1068,10 @@ namespace MainWindow { g_Config.vPostShaderNames.clear(); if (availableShaders[index] != "Off") g_Config.vPostShaderNames.push_back(availableShaders[index]); - g_Config.vPostShaderNames.push_back("Off"); - g_ShaderNameListChanged = true; g_Config.bShaderChainRequires60FPS = PostShaderChainRequires60FPS(GetFullPostShadersChain(g_Config.vPostShaderNames)); + NativeMessageReceived("gpu_resized", ""); + NativeMessageReceived("postshader_updated", ""); break; }