mraphics_core/geometry/
geometry.rs1use crate::GadgetData;
2
3pub trait AllowedIndexFormat {}
4impl AllowedIndexFormat for u32 {}
5impl AllowedIndexFormat for u16 {}
6
7#[derive(Debug, Clone)]
8pub struct CustomIndices<T: AllowedIndexFormat> {
9 pub data: Vec<T>,
10 pub buffer: Option<wgpu::Buffer>,
11}
12
13impl<T: AllowedIndexFormat> CustomIndices<T> {
14 pub fn new(data: Vec<T>) -> Self {
15 Self { data, buffer: None }
16 }
17}
18
19#[derive(Debug, Clone)]
20pub enum GeometryIndices {
21 Sequential(u32),
22 CustomU16(CustomIndices<u16>),
23 CustomU32(CustomIndices<u32>),
24}
25
26#[derive(Debug)]
27pub struct GeometryView {
28 pub attributes: Vec<GadgetData>,
29 pub uniforms: Vec<GadgetData>,
30 pub indices: GeometryIndices,
31}
32
33impl GeometryView {
34 pub fn new() -> Self {
35 Self {
36 indices: GeometryIndices::Sequential(0),
37 attributes: Vec::new(),
38 uniforms: Vec::new(),
39 }
40 }
41
42 pub fn with_indices(mut self, indices: GeometryIndices) -> Self {
43 self.indices = indices;
44 self
45 }
46
47 pub fn with_attributes(mut self, attributes: Vec<GadgetData>) -> Self {
48 self.attributes = attributes;
49 self
50 }
51
52 pub fn with_uniforms(mut self, uniforms: Vec<GadgetData>) -> Self {
53 self.uniforms = uniforms;
54 self
55 }
56
57 pub fn reset_vertices(&mut self) {
58 self.attributes = Vec::new();
59 self.indices = GeometryIndices::Sequential(0);
60 }
61
62 pub fn reset_uniforms(&mut self) {
63 self.uniforms = Vec::new();
64 }
65}
66
67pub trait Geometry {
68 fn update_view(&self, view: &mut GeometryView);
69}