From 341826e9a2b89713fc47ffbc914d18e23c7d9287 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 12 Oct 2023 21:29:36 +0200 Subject: feat(engine): add vertex coloring --- engine/src/vertex.rs | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 engine/src/vertex.rs (limited to 'engine/src/vertex.rs') diff --git a/engine/src/vertex.rs b/engine/src/vertex.rs new file mode 100644 index 0000000..e03eacb --- /dev/null +++ b/engine/src/vertex.rs @@ -0,0 +1,101 @@ +use std::mem::size_of; + +use crate::color::Color; +use crate::vector::Vec3; + +#[derive(Debug)] +#[repr(C)] +pub struct Vertex +{ + pos: Vec3, + color: Color, +} + +#[derive(Debug, Default)] +pub struct Builder +{ + pos: Option>, + color: Option>, +} + +impl Builder +{ + #[must_use] + pub fn new() -> Self + { + Self { + pos: None, + color: None, + } + } + + #[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 build(self) -> Option + { + let pos = self.pos?; + let color = self.color?; + + Some(Vertex { pos, color }) + } +} + +impl Vertex +{ + pub(crate) fn attrs() -> &'static [Attribute] + { + &[ + Attribute { + index: 0, + component_type: AttributeComponentType::Float, + component_cnt: AttributeComponentCnt::Three, + component_size: size_of::(), + }, + Attribute { + index: 1, + component_type: AttributeComponentType::Float, + component_cnt: AttributeComponentCnt::Three, + component_size: size_of::(), + }, + ] + } +} + +pub(crate) struct Attribute +{ + pub(crate) index: usize, + pub(crate) component_type: AttributeComponentType, + pub(crate) component_cnt: AttributeComponentCnt, + pub(crate) component_size: usize, +} + +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, +} -- cgit v1.2.3-18-g5258