use chain::Chain;
use std::vec::Vec;
pub type VertexFormat = Vec<VertexComponentFormat>;
pub fn vertex_format_size(vf: &VertexFormat) -> usize {
vf.len()
}
pub struct VertexComponentFormat {
pub component_type: Type,
pub dim: Dim
}
pub enum Type {
Integral,
Unsigned,
Floating,
Boolean
}
pub enum Dim {
Dim1,
Dim2,
Dim3,
Dim4
}
pub trait Vertex {
fn vertex_format() -> VertexFormat;
}
impl Vertex for () {
fn vertex_format() -> VertexFormat {
Vec::new()
}
}
impl Vertex for i32 {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Integral, dim: Dim::Dim1 } ]
}
}
impl Vertex for [i32; 1] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Integral, dim: Dim::Dim1 } ]
}
}
impl Vertex for [i32; 2] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Integral, dim: Dim::Dim2 } ]
}
}
impl Vertex for [i32; 3] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Integral, dim: Dim::Dim3 } ]
}
}
impl Vertex for [i32; 4] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Integral, dim: Dim::Dim4 } ]
}
}
impl Vertex for u32 {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Unsigned, dim: Dim::Dim1 } ]
}
}
impl Vertex for [u32; 1] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Unsigned, dim: Dim::Dim1 } ]
}
}
impl Vertex for [u32; 2] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Unsigned, dim: Dim::Dim2 } ]
}
}
impl Vertex for [u32; 3] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Unsigned, dim: Dim::Dim3 } ]
}
}
impl Vertex for [u32; 4] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Unsigned, dim: Dim::Dim4 } ]
}
}
impl Vertex for f32 {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Floating, dim: Dim::Dim1 } ]
}
}
impl Vertex for [f32; 1] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Floating, dim: Dim::Dim1 } ]
}
}
impl Vertex for [f32; 2] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Floating, dim: Dim::Dim2 } ]
}
}
impl Vertex for [f32; 3] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Floating, dim: Dim::Dim3 } ]
}
}
impl Vertex for [f32; 4] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Floating, dim: Dim::Dim4 } ]
}
}
impl Vertex for bool {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Boolean, dim: Dim::Dim1 } ]
}
}
impl Vertex for [bool; 1] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Boolean, dim: Dim::Dim1 } ]
}
}
impl Vertex for [bool; 2] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Boolean, dim: Dim::Dim2 } ]
}
}
impl Vertex for [bool; 3] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Boolean, dim: Dim::Dim3 } ]
}
}
impl Vertex for [bool; 4] {
fn vertex_format() -> VertexFormat {
vec![ VertexComponentFormat { component_type: Type::Boolean, dim: Dim::Dim4 } ]
}
}
impl<A, B> Vertex for Chain<A, B> where A: Vertex, B: Vertex {
fn vertex_format() -> VertexFormat {
let mut t = A::vertex_format();
t.extend(B::vertex_format());
t
}
}
impl<A, B> Vertex for (A, B) where A: Vertex, B: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, B>::vertex_format()
}
}
impl<A, B, C> Vertex for (A, B, C) where A: Vertex, B: Vertex, C: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, Chain<B, C>>::vertex_format()
}
}
impl<A, B, C, D> Vertex for (A, B, C, D) where A: Vertex, B: Vertex, C: Vertex, D: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, Chain<B, Chain<C, D>>>::vertex_format()
}
}
impl<A, B, C, D, E> Vertex for (A, B, C, D, E) where A: Vertex, B: Vertex, C: Vertex, D: Vertex, E: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, Chain<B, Chain<C, Chain<D, E>>>>::vertex_format()
}
}
impl<A, B, C, D, E, F> Vertex for (A, B, C, D, E, F) where A: Vertex, B: Vertex, C: Vertex, D: Vertex, E: Vertex, F: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, Chain<B, Chain<C, Chain<D, Chain<E, F>>>>>::vertex_format()
}
}
impl<A, B, C, D, E, F, G> Vertex for (A, B, C, D, E, F, G) where A: Vertex, B: Vertex, C: Vertex, D: Vertex, E: Vertex, F: Vertex, G: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, Chain<B, Chain<C, Chain<D, Chain<E, Chain<F, G>>>>>>::vertex_format()
}
}
impl<A, B, C, D, E, F, G, H> Vertex for (A, B, C, D, E, F, G, H) where A: Vertex, B: Vertex, C: Vertex, D: Vertex, E: Vertex, F: Vertex, G: Vertex, H: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, Chain<B, Chain<C, Chain<D, Chain<E, Chain<F, Chain<G, H>>>>>>>::vertex_format()
}
}
impl<A, B, C, D, E, F, G, H, I> Vertex for (A, B, C, D, E, F, G, H, I) where A: Vertex, B: Vertex, C: Vertex, D: Vertex, E: Vertex, F: Vertex, G: Vertex, H: Vertex, I: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, Chain<B, Chain<C, Chain<D, Chain<E, Chain<F, Chain<G, Chain<H, I>>>>>>>>::vertex_format()
}
}
impl<A, B, C, D, E, F, G, H, I, J> Vertex for (A, B, C, D, E, F, G, H, I, J) where A: Vertex, B: Vertex, C: Vertex, D: Vertex, E: Vertex, F: Vertex, G: Vertex, H: Vertex, I: Vertex, J: Vertex {
fn vertex_format() -> VertexFormat {
Chain::<A, Chain<B, Chain<C, Chain<D, Chain<E, Chain<F, Chain<G, Chain<H, Chain<I, J>>>>>>>>>::vertex_format()
}
}