#[derive(Program)]
{
// Attributes available to this derive:
#[willow]
}
Expand description
Derives a user-friendly wrapper for WebGlProgram
from a struct.
The struct must only contain the following fields:
- Exactly one
ProgramData
field Uniform<T>
fields (use#[willow(uniform(T)]
if aliased)Attribute<T>
fields (use#[willow(attribute(T))]
if aliased)
In the struct attribute, the path to the GLSL shaders must be specified:
ⓘ
#[willow(path = "scene")]
This will load the GLSL shaders by running include_str!("scene.vert")
and
include_str!("scene.frag")
.
If they are already loaded in a constant, write this instead:
ⓘ
#[willow(vert = VERTEX_SHADER_CODE, frag = FRAGMENT_SHADER_CODE)]
§Example
ⓘ
#[derive(willow::Program)]
#[willow(path = "scene")]
struct Scene {
vertices: Attribute<Vector3<f32>>,
normals: Attribute<Vector3<f32>>,
projection: Uniform<Matrix4<f32>>,
}
With the files scene.vert
and scene.frag
containing at least these declarations:
attribute vec3 vertices;
attribute vec3 normals;
uniform mat4 projection;
Then it can be used like this:
ⓘ
fn render(
gl: &WebGlRenderingContext,
scene: &Scene,
buffer: &Buffer,
projection: Matrix,
) {
scene.call()
.vertices(vertices)
.normals(normals)
.projection(projection)
.draw_indexed(WebGlRenderingContext::TRIANGLES, indices);
}