From 9aafb51e0be1720019db1c3d0a294ce9a42653df Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 2 Nov 2023 20:22:33 +0100 Subject: feat(engine): add texturing --- engine/src/vertex.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'engine/src/vertex.rs') diff --git a/engine/src/vertex.rs b/engine/src/vertex.rs index 62f629b..9df646f 100644 --- a/engine/src/vertex.rs +++ b/engine/src/vertex.rs @@ -1,7 +1,7 @@ use std::mem::size_of; use crate::color::Color; -use crate::vector::Vec3; +use crate::vector::{Vec2, Vec3}; #[derive(Debug, Clone, Default)] #[repr(C)] @@ -9,6 +9,7 @@ pub struct Vertex { pos: Vec3, color: Color, + texture_coords: Vec2, } #[derive(Debug, Default)] @@ -16,6 +17,7 @@ pub struct Builder { pos: Option>, color: Option>, + texture_coords: Vec2, } impl Builder @@ -23,7 +25,7 @@ impl Builder #[must_use] pub fn new() -> Self { - Self { pos: None, color: None } + Self::default() } #[must_use] @@ -42,13 +44,25 @@ impl Builder self } + #[must_use] + pub fn texture_coords(mut self, texture_coords: Vec2) -> Self + { + self.texture_coords = texture_coords; + + self + } + #[must_use] pub fn build(self) -> Option { let pos = self.pos?; let color = self.color?; - Some(Vertex { pos, color }) + Some(Vertex { + pos, + color, + texture_coords: self.texture_coords, + }) } } @@ -69,6 +83,12 @@ impl Vertex component_cnt: AttributeComponentCnt::Three, component_size: size_of::(), }, + Attribute { + index: 2, + component_type: AttributeComponentType::Float, + component_cnt: AttributeComponentCnt::Two, + component_size: size_of::(), + }, ] } } -- cgit v1.2.3-18-g5258