#![feature(plugin, custom_attribute)]
#![plugin(gfx_macros)]
mod secret_lib;
#[repr(packed)]
#[vertex_format]
#[derive(Copy)]
struct MyVertex {
a0: [f32; 2],
#[normalized]
a1: i16,
#[as_float]
a2: [i8; 4],
#[as_double]
a3: f64,
#[name = "a_a4"]
a4: [f32; 3],
}
#[repr(packed)]
#[vertex_format]
#[derive(Copy)]
struct MyInstance {
a0: [f32; 2],
}
#[test]
fn test_vertex_format() {
use secret_lib::gfx::attrib::{Type, IntSubType, FloatSubType,
IntSize, FloatSize, SignFlag,
Format, Stride};
use secret_lib::{gfx, Res};
use secret_lib::gfx::device::{BufferRole, BufferInfo, BufferUsage};
use secret_lib::gfx::device::handle::{Buffer, Manager, Producer};
let mut hm = Manager::new();
let handle = hm.make_buffer((), BufferInfo {
role: BufferRole::Vertex,
usage: BufferUsage::Static,
size: 0,
});
let buf_vert: Buffer<Res, MyVertex> = Buffer::from_raw(handle.clone());
let buf_inst: Buffer<Res, MyInstance> = Buffer::from_raw(handle.clone());
let mesh = gfx::Mesh::from_format_instanced::<MyVertex, MyInstance>(buf_vert, 0, buf_inst);
let stride_vert = 34 as Stride;
let stride_inst = 8 as Stride;
assert_eq!(mesh.attributes, vec![
gfx::Attribute {
name: "a0".to_string(),
buffer: handle.clone(),
format: Format {
elem_count: 2,
elem_type: Type::Float(FloatSubType::Default, FloatSize::F32),
offset: 0,
stride: stride_vert,
instance_rate: 0,
},
},
gfx::Attribute {
name: "a1".to_string(),
buffer: handle.clone(),
format: Format {
elem_count: 1,
elem_type: Type::Int(IntSubType::Normalized, IntSize::U16, SignFlag::Signed),
offset: 8,
stride: stride_vert,
instance_rate: 0,
},
},
gfx::Attribute {
name: "a2".to_string(),
buffer: handle.clone(),
format: Format {
elem_count: 4,
elem_type: Type::Int(IntSubType::AsFloat, IntSize::U8, SignFlag::Signed),
offset: 10,
stride: stride_vert,
instance_rate: 0,
},
},
gfx::Attribute {
name: "a3".to_string(),
buffer: handle.clone(),
format: Format {
elem_count: 1,
elem_type: Type::Float(FloatSubType::Precision, FloatSize::F64),
offset: 14,
stride: stride_vert,
instance_rate: 0,
},
},
gfx::Attribute {
name: "a_a4".to_string(),
buffer: handle.clone(),
format: Format {
elem_count: 3,
elem_type: Type::Float(FloatSubType::Default, FloatSize::F32),
offset: 22,
stride: stride_vert,
instance_rate: 0,
},
},
gfx::Attribute {
name: "a0".to_string(),
buffer: handle.clone(),
format: Format {
elem_count: 2,
elem_type: Type::Float(FloatSubType::Default, FloatSize::F32),
offset: 0,
stride: stride_inst,
instance_rate: 1,
},
},
]);
}