-
Notifications
You must be signed in to change notification settings - Fork 12
Type Safe Shaders
hazzard993 edited this page May 18, 2019
·
2 revisions
These declarations have the possibility for type-safe shaders.
You can specify the uniforms within a shader so that all interaction with declared shaders are appropriate to the uniform values they contain.
A shader with typing information
const shader = love.graphics.newShader<{
time: [number]
}>(shaderCode);
This shader only contains a "time"
variable which can only be given one number.
shader.send("time", 0); // ✔
shader.send("timer", 0); // ❌
shader.send("time", 0, 0); // ❌
shader.send("time", "string"); // ❌
This typing information can be used for parameters too.
A function that requires a shader that accepts a "time" variable
function applyShaderWithTime(shader: Shader<{time: [number]}>) {
shader.send("time", 0);
love.graphics.setShader(shader);
}
This feature only takes effect when typing information for a shader is specified. When unspecified the shader is assumed to have every possible uniform within it (this may be disabled in the future).