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.