#![forbid(unsafe_code)] use std::mem::size_of; use vulkanalia::vk::{ self, HasBuilder }; pub static VERTICES: [Vertex; 3] = [ Vertex::new(Vec2( 0.0, -0.5), Vec3(1.0, 0.0, 0.0)), Vertex::new(Vec2( 0.5, 0.5), Vec3(0.0, 1.0, 0.0)), Vertex::new(Vec2(-0.5, 0.5), Vec3(0.0, 0.0, 1.0)), ]; #[derive(Clone, Debug)] pub struct Vec2(T, T); #[derive(Clone, Debug)] pub struct Vec3(T, T, T); #[derive(Clone, Debug)] #[allow(unused)] pub struct Vec4(T, T, T, T); #[repr(C)] #[derive(Clone, Debug)] pub struct Vertex { pub position: Vec2, pub color: Vec3, } impl Vertex { const fn new(position: Vec2, color: Vec3) -> Self { Self { position, color } } pub fn binding_description() -> vk::VertexInputBindingDescription { vk::VertexInputBindingDescription::builder() .binding(0) .stride(size_of::>() as u32) .input_rate(vk::VertexInputRate::VERTEX) .build() } pub fn attribute_descriptions() -> [vk::VertexInputAttributeDescription; 2] { let position = vk::VertexInputAttributeDescription::builder() .binding(0) .location(0) .format(vk::Format::R32G32_SFLOAT) .offset(0) .build(); let color = vk::VertexInputAttributeDescription::builder() .binding(0) .location(1) .format(vk::Format::R32G32B32_SFLOAT) .offset(size_of::>() as u32) .build(); [position, color] } }