use core::marker::PhantomData;
use linear::*;
pub trait HasUniform {
type U;
fn update1_i32(uniform: &Self::U, x: i32);
fn update2_i32(uniform: &Self::U, xy: [i32; 2]);
fn update3_i32(uniform: &Self::U, xyz: [i32; 3]);
fn update4_i32(uniform: &Self::U, xyzw: [i32; 4]);
fn update1_slice_i32(uniform: &Self::U, x: &[i32]);
fn update2_slice_i32(uniform: &Self::U, xy: &[[i32; 2]]);
fn update3_slice_i32(uniform: &Self::U, xyz: &[[i32; 3]]);
fn update4_slice_i32(uniform: &Self::U, xyzw: &[[i32; 4]]);
fn update1_u32(uniform: &Self::U, x: u32);
fn update2_u32(uniform: &Self::U, xy: [u32; 2]);
fn update3_u32(uniform: &Self::U, xyz: [u32; 3]);
fn update4_u32(uniform: &Self::U, xyzw: [u32; 4]);
fn update1_slice_u32(uniform: &Self::U, x: &[u32]);
fn update2_slice_u32(uniform: &Self::U, xy: &[[u32; 2]]);
fn update3_slice_u32(uniform: &Self::U, xyz: &[[u32; 3]]);
fn update4_slice_u32(uniform: &Self::U, xyzw: &[[u32; 4]]);
fn update1_f32(uniform: &Self::U, x: f32);
fn update2_f32(uniform: &Self::U, xy: [f32; 2]);
fn update3_f32(uniform: &Self::U, xyz: [f32; 3]);
fn update4_f32(uniform: &Self::U, xyzw: [f32; 4]);
fn update1_slice_f32(uniform: &Self::U, x: &[f32]);
fn update2_slice_f32(uniform: &Self::U, xy: &[[f32; 2]]);
fn update3_slice_f32(uniform: &Self::U, xyz: &[[f32; 3]]);
fn update4_slice_f32(uniform: &Self::U, xyzw: &[[f32; 4]]);
fn update22_f32(uniform: &Self::U, x: M22);
fn update33_f32(uniform: &Self::U, x: M33);
fn update44_f32(uniform: &Self::U, x: M44);
fn update22_slice_f32(uniform: &Self::U, x: &[M22]);
fn update33_slice_f32(uniform: &Self::U, x: &[M33]);
fn update44_slice_f32(uniform: &Self::U, x: &[M44]);
fn update1_bool(uniform: &Self::U, x: bool);
fn update2_bool(uniform: &Self::U, xy: [bool; 2]);
fn update3_bool(uniform: &Self::U, xyz: [bool; 3]);
fn update4_bool(uniform: &Self::U, xyzw: [bool; 4]);
fn update1_slice_bool(uniform: &Self::U, x: &[bool]);
fn update2_slice_bool(uniform: &Self::U, xy: &[[bool; 2]]);
fn update3_slice_bool(uniform: &Self::U, xyz: &[[bool; 3]]);
fn update4_slice_bool(uniform: &Self::U, xyzw: &[[bool; 4]]);
}
#[derive(Debug)]
pub struct Uniform<C, T> where C: HasUniform, T: Uniformable {
pub repr: C::U,
_t: PhantomData<T>
}
impl<C, T> Uniform<C, T> where C: HasUniform, T: Uniformable {
pub fn new(repr: C::U) -> Uniform<C, T> {
Uniform {
repr: repr,
_t: PhantomData
}
}
pub fn update(&self, x: T) {
T::update(self, x);
}
}
#[derive(Debug)]
pub enum UniformName {
StringName(String),
SemanticName(u32)
}
pub trait Uniformable: Sized {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform;
}
impl Uniformable for i32 {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update1_i32(&u.repr, x)
}
}
impl Uniformable for [i32; 2] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update2_i32(&u.repr, x)
}
}
impl Uniformable for [i32; 3] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update3_i32(&u.repr, x)
}
}
impl Uniformable for [i32; 4] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update4_i32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [i32] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update1_slice_i32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[i32; 2]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update2_slice_i32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[i32; 3]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update3_slice_i32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[i32; 4]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update4_slice_i32(&u.repr, x)
}
}
impl Uniformable for u32 {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update1_u32(&u.repr, x)
}
}
impl Uniformable for [u32; 2] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update2_u32(&u.repr, x)
}
}
impl Uniformable for [u32; 3] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update3_u32(&u.repr, x)
}
}
impl Uniformable for [u32; 4] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update4_u32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [u32] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update1_slice_u32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[u32; 2]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update2_slice_u32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[u32; 3]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update3_slice_u32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[u32; 4]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update4_slice_u32(&u.repr, x)
}
}
impl Uniformable for f32 {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update1_f32(&u.repr, x)
}
}
impl Uniformable for [f32; 2] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update2_f32(&u.repr, x)
}
}
impl Uniformable for [f32; 3] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update3_f32(&u.repr, x)
}
}
impl Uniformable for [f32; 4] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update4_f32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [f32] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update1_slice_f32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[f32; 2]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update2_slice_f32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[f32; 3]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update3_slice_f32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[f32; 4]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update4_slice_f32(&u.repr, x)
}
}
impl Uniformable for M22 {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update22_f32(&u.repr, x)
}
}
impl Uniformable for M33 {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update33_f32(&u.repr, x)
}
}
impl Uniformable for M44 {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update44_f32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [M22] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update22_slice_f32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [M33] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update33_slice_f32(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [M44] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update44_slice_f32(&u.repr, x)
}
}
impl Uniformable for bool {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update1_bool(&u.repr, x)
}
}
impl Uniformable for [bool; 2] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update2_bool(&u.repr, x)
}
}
impl Uniformable for [bool; 3] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update3_bool(&u.repr, x)
}
}
impl Uniformable for [bool; 4] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update4_bool(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [bool] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update1_slice_bool(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[bool; 2]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update2_slice_bool(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[bool; 3]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update3_slice_bool(&u.repr, x)
}
}
impl<'a> Uniformable for &'a [[bool; 4]] {
fn update<C>(u: &Uniform<C, Self>, x: Self) where C: HasUniform {
C::update4_slice_bool(&u.repr, x)
}
}