macro_rules! gfx_parameters {
($name:ident/$link_name:ident {
$($gl_name:ident@ $field:ident: $ty:ty,)*
}) => {
#[derive(Clone, Debug)]
pub struct $name<R: $crate::Resources> {
$(pub $field: $ty,)*
pub _r: ::std::marker::PhantomData<R>,
}
#[derive(Clone, Debug)]
pub struct $link_name {
$($field: Option<$crate::shade::ParameterId>,)*
}
impl<R: $crate::Resources> $crate::shade::ShaderParam for $name<R> {
type Resources = R;
type Link = $link_name;
fn create_link(_: Option<&$name<R>>, info: &$crate::ProgramInfo)
-> Result<$link_name, $crate::shade::ParameterError> {
use $crate::shade::Parameter;
let mut link = $link_name{
$( $field: None, )*
};
for (i, u) in info.uniforms.iter().enumerate() {
match &u.name[..] {
$(
stringify!($gl_name) => {
if !<$ty as Parameter<R>>::check_uniform(u) {
return Err($crate::shade::ParameterError::BadUniform(u.name.clone()))
}
link.$field = Some(i as $crate::shade::ParameterId);
},
)*
_ => return Err($crate::shade::ParameterError::MissingUniform(u.name.clone()))
}
}
for (i, b) in info.blocks.iter().enumerate() {
match &b.name[..] {
$(
stringify!($gl_name) => {
if !<$ty as Parameter<R>>::check_block(b) {
return Err($crate::shade::ParameterError::BadBlock(b.name.clone()))
}
link.$field = Some(i as $crate::shade::ParameterId);
},
)*
_ => return Err($crate::shade::ParameterError::MissingBlock(b.name.clone()))
}
}
for (i, t) in info.textures.iter().enumerate() {
match &t.name[..] {
$(
stringify!($gl_name) => {
if !<$ty as Parameter<R>>::check_texture(t) {
return Err($crate::shade::ParameterError::BadBlock(t.name.clone()))
}
link.$field = Some(i as $crate::shade::ParameterId);
},
)*
_ => return Err($crate::shade::ParameterError::MissingBlock(t.name.clone()))
}
}
Ok(link)
}
fn fill_params(&self, link: &$link_name, storage: &mut $crate::ParamStorage<R>) {
use $crate::shade::Parameter;
$(
if let Some(id) = link.$field {
self.$field.put(id, storage);
}
)*
}
}
}
}