diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-02 20:22:33 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-02 20:22:33 +0100 |
commit | 9aafb51e0be1720019db1c3d0a294ce9a42653df (patch) | |
tree | 40881ff26bff5a928280223d8aced87e1370d63b /engine/src/vertex.rs | |
parent | f2c54d47e6b61198520824117339aaa21c32accd (diff) |
feat(engine): add texturing
Diffstat (limited to 'engine/src/vertex.rs')
-rw-r--r-- | engine/src/vertex.rs | 26 |
1 files changed, 23 insertions, 3 deletions
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<f32>, color: Color<f32>, + texture_coords: Vec2<f32>, } #[derive(Debug, Default)] @@ -16,6 +17,7 @@ pub struct Builder { pos: Option<Vec3<f32>>, color: Option<Color<f32>>, + texture_coords: Vec2<f32>, } impl Builder @@ -23,7 +25,7 @@ impl Builder #[must_use] pub fn new() -> Self { - Self { pos: None, color: None } + Self::default() } #[must_use] @@ -43,12 +45,24 @@ impl Builder } #[must_use] + pub fn texture_coords(mut self, texture_coords: Vec2<f32>) -> Self + { + self.texture_coords = texture_coords; + + self + } + + #[must_use] pub fn build(self) -> Option<Vertex> { 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::<f32>(), }, + Attribute { + index: 2, + component_type: AttributeComponentType::Float, + component_cnt: AttributeComponentCnt::Two, + component_size: size_of::<f32>(), + }, ] } } |