1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-05 20:43:11 +00:00

Merge branch 'lua_pp_order' into 'master'

lua - add ability to query the currently active shaders

Closes #8285

See merge request OpenMW/openmw!4506
This commit is contained in:
psi29a 2025-07-02 09:45:00 +00:00
commit 4520eb077d
5 changed files with 54 additions and 4 deletions

View file

@ -1,6 +1,7 @@
0.50.0
------
Feature #8285: Expose list of active shaders in postprocessing API
0.49.0
------

View file

@ -1,5 +1,7 @@
#include "postprocessingbindings.hpp"
#include "MyGUI_LanguageManager.h"
#include <components/lua/util.hpp>
#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<bool>(context);
shader["setFloat"] = getSetter<float>(context);
shader["setInt"] = getSetter<int>(context);
@ -158,12 +177,23 @@ 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;
};
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.add(Shader(shader));
}
return chain;
};
return LuaUtil::makeReadOnly(api);
}

View file

@ -786,6 +786,11 @@ namespace MWRender
return mTemplates.back();
}
PostProcessor::TechniqueList PostProcessor::getChain()
{
return mTechniques;
}
void PostProcessor::loadChain()
{
mTechniques.clear();

View file

@ -178,6 +178,8 @@ namespace MWRender
std::shared_ptr<fx::Technique> loadTechnique(const std::string& name, bool loadNextFrame = false);
TechniqueList getChain();
bool isEnabled() const { return mUsePostProcessing; }
void disable();

View file

@ -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.