Derive Macro willow_codegen::Program [−][src]
#[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:
UniformLocation<T>
fields (use#[willow(uniform(T)]
if aliased)AttrLocation
fields (use#[willow(attribute)]
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: AttrLocation, normals: AttrLocation, projection: UniformLocation<Matrix>, }
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: &Program<Scene>, vertices: &Buffer, normals: &Buffer, projection: Matrix, ) { scene.call() .vertices(vertices) .normals(normals) .projection(projection) .draw_indexed(WebGlRenderingContext::TRIANGLES, indices); }