Macro softrender::declare_uniforms
[−]
[src]
macro_rules! declare_uniforms { ($(#[$($struct_attrs:tt)*])* pub struct $name:ident { $($(#[$($field_attrs:tt)*])* pub $field:ident: $t:ty,)* }) => { ... }; }
Declares a structure and implements the Barycentric
trait for it by delegating the trait to each member.
So, for example, this:
declare_uniforms!( pub struct MyUniforms { /// Position in world-space pub position: Vector4<f32>, pub normal: Vector4<f32>, pub uv: Vector2<f32>, } );
becomes:
pub struct MyUniforms { /// Position in world-space pub position: Vector4<f32>, pub normal: Vector4<f32>, pub uv: Vector2<f32>, } impl Barycentric for MyUniforms { fn interpolate(u: f32, ux: &Self, v: f32, vx: &Self, w: f32, wx: &Self) -> Self { MyUniforms { position: Barycentric::interpolate(u, &ux.position, v, &vx.position, w, &wx.position), normal: Barycentric::interpolate(u, &ux.normal, v, &vx.normal, w, &wx.normal), uv: Barycentric::interpolate(u, &ux.uv, v, &vx.uv, w, &wx.uv), } } }
note that the u
and v
in the Barycentric::interpolate
arguments are mostly unrelated to the uv
normal. They're both Barycentric coordinates,
but for different things.
For now, the struct itself must be pub
and all the members must be pub
, but hopefully that can change in the future.