1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-06 10:15:19 +01:00

Increase flexibility of ShaderSource

This commit is contained in:
sfan5
2025-08-07 16:04:44 +02:00
parent 1b37eb2e0b
commit 5e23e478b1
6 changed files with 89 additions and 49 deletions

View File

@@ -7,6 +7,7 @@
#include "irrlichttypes_bloated.h"
#include <IMaterialRendererServices.h>
#include "irr_ptr.h"
#include <string>
#include <map>
#include <variant>
@@ -51,26 +52,41 @@ public:
Abstraction for updating uniforms used by shaders
*/
namespace video {
class IMaterialRendererServices;
}
class IShaderUniformSetter {
public:
virtual ~IShaderUniformSetter() = default;
/**
* Called when uniforms need to be updated
* @param services interface for setting uniforms
*/
virtual void onSetUniforms(video::IMaterialRendererServices *services) = 0;
virtual void onSetMaterial(const video::SMaterial& material)
{ }
};
class IShaderUniformSetterRC : public IShaderUniformSetter, public IReferenceCounted
{
// Reference counted variant for special use-cases
};
class IShaderUniformSetterFactory {
public:
virtual ~IShaderUniformSetterFactory() = default;
virtual IShaderUniformSetter* create() = 0;
/**
* Called to create an uniform setter for a specific shader
* @param name name of the shader
* @return new uniform setter (or nullptr). caller takes ownership.
*/
virtual IShaderUniformSetter *create(const std::string &name) = 0;
};
/*
Helpers to set uniforms only when changed.
Be warned that when using this you can't attach a IShaderUniformSetter to
multiple different shaders. But you probably don't want to anyway.
*/
template <typename T, std::size_t count, bool cache>
class CachedShaderSetting {
@@ -217,6 +233,8 @@ struct ShaderInfo {
video::E_MATERIAL_TYPE material = video::EMT_SOLID;
// Input constants
ShaderConstants input_constants;
// Extra uniform callback
irr_ptr<IShaderUniformSetterRC> setter_cb;
};
class IShaderSource {
@@ -239,11 +257,13 @@ public:
* @param name name of the shader (directory on disk)
* @param input_const primary key constants for this shader
* @param base_mat base material to use
* @param setter_cb additional uniform setter to use
* @return shader ID
* @note `base_material` only controls alpha behavior
*/
virtual u32 getShader(const std::string &name,
const ShaderConstants &input_const, video::E_MATERIAL_TYPE base_mat) = 0;
const ShaderConstants &input_const, video::E_MATERIAL_TYPE base_mat,
IShaderUniformSetterRC *setter_cb = nullptr) = 0;
/// @brief Helper: Generates or gets a shader suitable for nodes and entities
u32 getShader(const std::string &name,