use std::mem::size_of; use crate::color::Color; use crate::vector::{Vec2, Vec3}; #[derive(Debug, Clone, Default)] #[repr(C)] pub struct Vertex { pos: Vec3, color: Color, texture_coords: Vec2, normal: Vec3, } #[derive(Debug, Default)] pub struct Builder { pos: Option>, color: Option>, texture_coords: Vec2, normal: Option>, } impl Builder { #[must_use] pub fn new() -> Self { Self::default() } #[must_use] pub fn pos(mut self, pos: Vec3) -> Self { self.pos = Some(pos); self } #[must_use] pub fn color(mut self, color: Color) -> Self { self.color = Some(color); self } #[must_use] pub fn texture_coords(mut self, texture_coords: Vec2) -> Self { self.texture_coords = texture_coords; self } #[must_use] pub fn normal(mut self, normal: Vec3) -> Self { self.normal = Some(normal); self } #[must_use] pub fn build(self) -> Option { let pos = self.pos?; let color = self.color.unwrap_or_default(); let normal = self.normal.unwrap_or_default(); Some(Vertex { pos, color, texture_coords: self.texture_coords, normal, }) } } impl Vertex { pub(crate) fn attrs() -> &'static [Attribute] { #[allow(clippy::cast_possible_truncation)] &[ Attribute { index: 0, component_type: AttributeComponentType::Float, component_cnt: AttributeComponentCnt::Three, component_size: size_of::() as u32, }, Attribute { index: 1, component_type: AttributeComponentType::Float, component_cnt: AttributeComponentCnt::Three, component_size: size_of::() as u32, }, Attribute { index: 2, component_type: AttributeComponentType::Float, component_cnt: AttributeComponentCnt::Two, component_size: size_of::() as u32, }, Attribute { index: 3, component_type: AttributeComponentType::Float, component_cnt: AttributeComponentCnt::Three, component_size: size_of::() as u32, }, ] } } pub(crate) struct Attribute { pub(crate) index: u32, pub(crate) component_type: AttributeComponentType, pub(crate) component_cnt: AttributeComponentCnt, pub(crate) component_size: u32, } pub(crate) enum AttributeComponentType { Float, } #[derive(Debug, Clone, Copy)] #[repr(u32)] #[allow(dead_code)] pub(crate) enum AttributeComponentCnt { One = 1, Two = 2, Three = 3, Four = 4, }