mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Introduce IShaderConstantSetter abstraction
This commit is contained in:
parent
b2c2a6ff47
commit
baa4c7cd21
2 changed files with 206 additions and 130 deletions
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue