mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-26 05:15:27 +01:00
Introduce IShaderConstantSetter abstraction
This commit is contained in:
@@ -8,10 +8,10 @@
|
||||
#include "irrlichttypes_bloated.h"
|
||||
#include <IMaterialRendererServices.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <variant>
|
||||
#include "nodedef.h"
|
||||
|
||||
class IGameDef;
|
||||
|
||||
/*
|
||||
shader.{h,cpp}: Shader handling stuff.
|
||||
*/
|
||||
@@ -39,6 +39,25 @@ struct ShaderInfo {
|
||||
virtual ~ShaderInfo() = default;
|
||||
};
|
||||
|
||||
/*
|
||||
Abstraction for pushing constants (or what we pretend is) into
|
||||
shaders. These end up as `#define` prepended to the shader source.
|
||||
*/
|
||||
|
||||
// Shader constants are either an int or a float in GLSL
|
||||
typedef std::map<std::string, std::variant<int, float>> ShaderConstants;
|
||||
|
||||
class IShaderConstantSetter {
|
||||
public:
|
||||
virtual ~IShaderConstantSetter() = default;
|
||||
/**
|
||||
* Called when the final shader source is being generated
|
||||
* @param name name of the shader
|
||||
* @param constants current set of constants, free to modify
|
||||
*/
|
||||
virtual void onGenerate(const std::string &name, ShaderConstants &constants) = 0;
|
||||
};
|
||||
|
||||
/*
|
||||
Abstraction for updating uniforms used by shaders
|
||||
*/
|
||||
@@ -235,6 +254,9 @@ public:
|
||||
const std::string &filename, const std::string &program)=0;
|
||||
virtual void rebuildShaders()=0;
|
||||
|
||||
/// @note Takes ownership of @p setter.
|
||||
virtual void addShaderConstantSetter(IShaderConstantSetter *setter) = 0;
|
||||
|
||||
/// @note Takes ownership of @p setter.
|
||||
virtual void addShaderUniformSetterFactory(IShaderUniformSetterFactory *setter) = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user