#![forbid(unsafe_code)] use crate::linear_algebra::{ Vec2, Vec3, Mat4, Transformation }; use std::mem::size_of; use vulkanalia::vk::{ self, HasBuilder }; pub static VERTICES: [Vertex; 8] = [ Vertex::new(Vec3::new(-0.5, -0.5, 0.0), Vec3::new(1.0, 0.0, 0.0), Vec2::new(1.0, 0.0)), Vertex::new(Vec3::new( 0.5, -0.5, 0.0), Vec3::new(0.0, 1.0, 0.0), Vec2::new(0.0, 0.0)), Vertex::new(Vec3::new( 0.5, 0.5, 0.0), Vec3::new(0.0, 0.0, 1.0), Vec2::new(0.0, 1.0)), Vertex::new(Vec3::new(-0.5, 0.5, 0.0), Vec3::new(1.0, 1.0, 1.0), Vec2::new(1.0, 1.0)), Vertex::new(Vec3::new(-0.5, -0.5, 0.5), Vec3::new(1.0, 0.0, 0.0), Vec2::new(1.0, 0.0)), Vertex::new(Vec3::new( 0.5, -0.5, 0.5), Vec3::new(0.0, 1.0, 0.0), Vec2::new(0.0, 0.0)), Vertex::new(Vec3::new( 0.5, 0.5, 0.5), Vec3::new(0.0, 0.0, 1.0), Vec2::new(0.0, 1.0)), Vertex::new(Vec3::new(-0.5, 0.5, 0.5), Vec3::new(1.0, 1.0, 1.0), Vec2::new(1.0, 1.0)), ]; pub const INDICES: &[u16] = &[ 0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4, ]; #[repr(C)] #[derive(Clone, Debug)] pub struct Vertex { pub position: Vec3, pub color: Vec3, pub texture_coordinates: Vec2, } #[repr(C)] #[derive(Clone, Debug)] pub struct UniformBlock { pub scale: Vec3, pub model: Transformation, pub view: Transformation, pub projection: Mat4, } impl Vertex { const fn new(position: Vec3, color: Vec3, texture_coordinates: Vec2) -> Self { Self { position, color, texture_coordinates } } 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; 3] { let mut offset: usize = 0; let position = vk::VertexInputAttributeDescription::builder() .binding(0) .location(0) .format(vk::Format::R32G32B32_SFLOAT) .offset(offset as u32) .build(); offset += size_of::>(); let color = vk::VertexInputAttributeDescription::builder() .binding(0) .location(1) .format(vk::Format::R32G32B32_SFLOAT) .offset(offset as u32) .build(); offset += size_of::>(); let texture_coordinates = vk::VertexInputAttributeDescription::builder() .binding(0) .location(2) .format(vk::Format::R32G32_SFLOAT) .offset(offset as u32) .build(); [position, color, texture_coordinates] } }