From 450f587844f4511350190d2e7d5da8440182d2b9 Mon Sep 17 00:00:00 2001 From: Cody Glassman Date: Wed, 8 Jan 2025 14:12:00 -0800 Subject: [PATCH 1/4] lua - add ability to query the currently active shaders --- CMakeLists.txt | 2 +- apps/openmw/mwlua/postprocessingbindings.cpp | 35 +++++++++++++++++++- apps/openmw/mwrender/postprocessor.cpp | 5 +++ apps/openmw/mwrender/postprocessor.hpp | 2 ++ files/lua_api/openmw/postprocessing.lua | 12 +++++++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7d7bf9b3f..cd2309158b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 50) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 76) +set(OPENMW_LUA_API_REVISION 77) set(OPENMW_POSTPROCESSING_API_REVISION 2) set(OPENMW_VERSION_COMMITHASH "") diff --git a/apps/openmw/mwlua/postprocessingbindings.cpp b/apps/openmw/mwlua/postprocessingbindings.cpp index e64bf0fa9e..6d569b908b 100644 --- a/apps/openmw/mwlua/postprocessingbindings.cpp +++ b/apps/openmw/mwlua/postprocessingbindings.cpp @@ -1,5 +1,7 @@ #include "postprocessingbindings.hpp" +#include "MyGUI_LanguageManager.h" + #include #include "../mwbase/environment.hpp" @@ -8,6 +10,14 @@ #include "luamanagerimp.hpp" +namespace +{ + std::string getLocalizedMyGUIString(std::string_view unlocalized) + { + return MyGUI::LanguageManager::getInstance().replaceTags(std::string(unlocalized)).asUTF8(); + } +} + namespace MWLua { struct Shader; @@ -37,7 +47,7 @@ namespace MWLua if (!mShader) return "Shader(nil)"; - return Misc::StringUtils::format("Shader(%s, %s)", mShader->getName(), mShader->getFileName()); + return Misc::StringUtils::format("Shader(%s, %s)", mShader->getName(), mShader->getFileName().value()); } enum @@ -139,6 +149,15 @@ namespace MWLua return MWBase::Environment::get().getWorld()->getPostProcessor()->isTechniqueEnabled(shader.mShader); }; + shader["name"] = sol::readonly_property( + [](const Shader& shader) { return getLocalizedMyGUIString(shader.mShader->getName()); }); + shader["author"] = sol::readonly_property( + [](const Shader& shader) { return getLocalizedMyGUIString(shader.mShader->getAuthor()); }); + shader["description"] = sol::readonly_property( + [](const Shader& shader) { return getLocalizedMyGUIString(shader.mShader->getDescription()); }); + shader["version"] = sol::readonly_property( + [](const Shader& shader) { return getLocalizedMyGUIString(shader.mShader->getVersion()); }); + shader["setBool"] = getSetter(context); shader["setFloat"] = getSetter(context); shader["setInt"] = getSetter(context); @@ -164,6 +183,20 @@ namespace MWLua return shader; }; + api["getChain"] = []() { + std::vector chain; + + for (const auto& shader : MWBase::Environment::get().getWorld()->getPostProcessor()->getChain()) + { + // Don't expose internal shaders to the API, they should be invisible to the user + if (shader->getInternal()) + continue; + chain.emplace_back(shader); + } + + return chain; + }; + return LuaUtil::makeReadOnly(api); } diff --git a/apps/openmw/mwrender/postprocessor.cpp b/apps/openmw/mwrender/postprocessor.cpp index 8b835a4d47..72b8077bf8 100644 --- a/apps/openmw/mwrender/postprocessor.cpp +++ b/apps/openmw/mwrender/postprocessor.cpp @@ -786,6 +786,11 @@ namespace MWRender return mTemplates.back(); } + PostProcessor::TechniqueList PostProcessor::getChain() + { + return mTechniques; + } + void PostProcessor::loadChain() { mTechniques.clear(); diff --git a/apps/openmw/mwrender/postprocessor.hpp b/apps/openmw/mwrender/postprocessor.hpp index af6eeae62b..6b1f4612f1 100644 --- a/apps/openmw/mwrender/postprocessor.hpp +++ b/apps/openmw/mwrender/postprocessor.hpp @@ -178,6 +178,8 @@ namespace MWRender std::shared_ptr loadTechnique(const std::string& name, bool loadNextFrame = false); + TechniqueList getChain(); + bool isEnabled() const { return mUsePostProcessing; } void disable(); diff --git a/files/lua_api/openmw/postprocessing.lua b/files/lua_api/openmw/postprocessing.lua index 18e2edd376..a333470374 100644 --- a/files/lua_api/openmw/postprocessing.lua +++ b/files/lua_api/openmw/postprocessing.lua @@ -4,6 +4,12 @@ -- @module postprocessing -- @usage local postprocessing = require('openmw.postprocessing') +--- +-- @type Shader +-- @field #string name Name of the shader +-- @field #string description Description of the shader +-- @field #string author Author of the shader +-- @field #string version Version of the shader --- -- Load a shader and return its handle. @@ -15,6 +21,12 @@ -- -- It must be enabled to see its effect. -- local vignetteShader = postprocessing.load('vignette') +--- +-- Returns the ordered list of active shaders. +-- Active shaders may change between frames. +-- @function [parent=#postprocessing] getChain +-- @return #list<#Shader> list The currently active shaders, in order + --- -- Enable the shader. Has no effect if the shader is already enabled or does -- not exist. Will not apply until the next frame. From 179341b221694e43d1e074736743ed0688274851 Mon Sep 17 00:00:00 2001 From: Cody Glassman Date: Wed, 8 Jan 2025 14:29:09 -0800 Subject: [PATCH 2/4] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8310cb8c32..cbffc23bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 0.50.0 ------ + Feature #8285: Expose list of active shaders in postprocessing API 0.49.0 ------ From feeb15d1fffa95b98f9038a3f2df1715abefbff6 Mon Sep 17 00:00:00 2001 From: Cody Glassman Date: Thu, 16 Jan 2025 16:02:59 -0800 Subject: [PATCH 3/4] use table instead of vector in return type --- apps/openmw/mwlua/postprocessingbindings.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwlua/postprocessingbindings.cpp b/apps/openmw/mwlua/postprocessingbindings.cpp index 6d569b908b..79c1cc1574 100644 --- a/apps/openmw/mwlua/postprocessingbindings.cpp +++ b/apps/openmw/mwlua/postprocessingbindings.cpp @@ -183,15 +183,15 @@ namespace MWLua return shader; }; - api["getChain"] = []() { - std::vector chain; + api["getChain"] = [context]() { + sol::table chain(context.sol(), sol::create); for (const auto& shader : MWBase::Environment::get().getWorld()->getPostProcessor()->getChain()) { // Don't expose internal shaders to the API, they should be invisible to the user if (shader->getInternal()) continue; - chain.emplace_back(shader); + chain.add(Shader(shader)); } return chain; From 514174ffc44d1158c24ac289d959fcfab54f262f Mon Sep 17 00:00:00 2001 From: Cody Glassman Date: Mon, 27 Jan 2025 14:25:59 -0800 Subject: [PATCH 4/4] allow handles to be fetched for non-dynamic shaders --- apps/openmw/mwlua/postprocessingbindings.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/openmw/mwlua/postprocessingbindings.cpp b/apps/openmw/mwlua/postprocessingbindings.cpp index 79c1cc1574..6127cb4b27 100644 --- a/apps/openmw/mwlua/postprocessingbindings.cpp +++ b/apps/openmw/mwlua/postprocessingbindings.cpp @@ -177,9 +177,6 @@ namespace MWLua if (!shader.mShader || !shader.mShader->isValid()) throw std::runtime_error(Misc::StringUtils::format("Failed loading shader '%s'", name)); - if (!shader.mShader->getDynamic()) - throw std::runtime_error(Misc::StringUtils::format("Shader '%s' is not marked as dynamic", name)); - return shader; };