1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
extern crate proc_macro;
use TokenStream;
use Result;
/// 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:
/// ```ignore
/// #[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:
/// ```ignore
/// #[willow(vert = VERTEX_SHADER_CODE, frag = FRAGMENT_SHADER_CODE)]
/// ```
///
/// # Example
/// ```ignore
/// #[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:
/// ```glsl
/// attribute vec3 vertices;
/// attribute vec3 normals;
/// uniform mat4 projection;
/// ```
///
/// Then it can be used like this:
/// ```ignore
/// fn render(
/// gl: &WebGlRenderingContext,
/// scene: &Scene,
/// buffer: &Buffer,
/// projection: Matrix,
/// ) {
/// scene.call()
/// .vertices(vertices)
/// .normals(normals)
/// .projection(projection)
/// .draw_indexed(WebGlRenderingContext::TRIANGLES, indices);
/// }
/// ```