[][src]Derive Macro luminance::UniformInterface

#[derive(UniformInterface)]
{
    // Attributes available to this derive:
    #[uniform]
}

The UniformInterface derive proc-macro.

The procedural macro is very simple to use. You declare a struct as you would normally do:


#[derive(Debug, UniformInterface)]
struct MyIface {
  time: Uniform<f32>,
  resolution: Uniform<[f32; 4]>
}

The effect of this declaration is declaring the MyIface struct along with an effective implementation of UniformInterface that will try to get the "time" and "resolution" uniforms in the corresponding shader program. If any of the two uniforms fails to map (inactive uniform, for instance), the whole struct cannot be generated, and an error is arisen (see UniformInterface::uniform_interface’s documentation for further details).

If you don’t use a parameter in your shader, you might not want the whole interface to fail building if that parameter cannot be mapped. You can do that via the #[unbound] field attribute:


#[derive(Debug, UniformInterface)]
struct MyIface {
  #[uniform(unbound)]
  time: Uniform<f32>, // if this field cannot be mapped, it’ll be ignored
  resolution: Uniform<[f32; 4]>
}

You can also change the default mapping with the #[uniform(name = "string_mapping")] attribute. This changes the name that must be queried from the shader program for the mapping to be complete:


#[derive(Debug, UniformInterface)]
struct MyIface {
  time: Uniform<f32>,
  #[uniform(name = "res")]
  resolution: Uniform<[f32; 4]> // maps "res" from the shader program
}

Finally, you can mix both attributes if you want to change the mapping and have an unbound uniform if it cannot be mapped:


#[derive(Debug, UniformInterface)]
struct MyIface {
  time: Uniform<f32>,
  #[uniform(name = "res", unbound)]
  resolution: Uniform<[f32; 4]> // must map "res" from the shader program and ignored otherwise
}