wgpu_rust_renderer/geometry/
geometry.rs

1use std::collections::HashMap;
2
3use crate::{
4	geometry::{
5		attribute::Attribute,
6		index::Index,
7	},
8	resource::resource::ResourceId,
9};
10
11// @TODO: Support shared attribute
12pub struct Geometry {
13	attributes: HashMap<&'static str, ResourceId<Attribute>>,
14	index: Option<ResourceId<Index>>,
15}
16
17impl Geometry {
18	pub fn new() -> Self {
19		Geometry {
20			attributes: HashMap::new(),
21			index: None,
22		}
23	}
24
25	pub fn set_attribute(&mut self, key: &'static str, attribute: ResourceId<Attribute>) -> &mut Self {
26		self.attributes.insert(key, attribute);
27		self
28	}
29
30	pub fn borrow_attribute(&self, key: &'static str) -> Option<&ResourceId<Attribute>> {
31		self.attributes.get(key)
32	}
33
34	pub fn set_index(&mut self, index: ResourceId<Index>) -> &mut Self {
35		self.index = Some(index);
36		self
37	}
38
39	pub fn remove_index(&mut self) -> &mut Self {
40		self.index = None;
41		self
42	}
43
44	pub fn borrow_index(&self) -> Option<&ResourceId<Index>> {
45		self.index.as_ref()
46	}
47}