1use std::rc::Rc;
3
4use crate::{Gl, IndexBuffer, VertexBuffer};
5
6#[derive(Debug)]
14pub struct Vertices<G>
15where
16 G: Gl,
17{
18 indices: Rc<IndexBuffer<G>>,
19 position: Rc<VertexBuffer<G>>,
20 attrs: Rc<Vec<(mod3d_base::VertexAttr, VertexBuffer<G>)>>,
21}
22
23impl<G> Clone for Vertices<G>
25where
26 G: Gl,
27{
28 fn clone(&self) -> Self {
29 let indices = self.indices.clone();
30 let position = self.position.clone();
31 let attrs = self.attrs.clone();
32 Self {
33 indices,
34 position,
35 attrs,
36 }
37 }
38}
39
40impl<G> Vertices<G>
42where
43 G: Gl,
44{
45 pub fn create(vertices: &mod3d_base::Vertices<G>, _renderer: &mut G) -> Self {
52 let indices = vertices
53 .borrow_indices()
54 .unwrap()
55 .borrow_client()
56 .as_index_buffer()
57 .clone()
58 .into();
59 let position = vertices
60 .borrow_attr(mod3d_base::VertexAttr::Position)
61 .unwrap()
62 .borrow_client()
63 .as_vertex_buffer()
64 .clone()
65 .into();
66 let mut attrs = Vec::new();
67 for buffer in vertices.iter_attrs() {
68 attrs.push((
69 buffer.vertex_attr(),
70 buffer.borrow_client().as_vertex_buffer().clone(),
71 ));
72 }
73 let attrs = attrs.into();
74 Self {
75 indices,
76 position,
77 attrs,
78 }
79 }
80 pub fn borrow(
83 &self,
84 ) -> (
85 &IndexBuffer<G>,
86 &VertexBuffer<G>,
87 &Vec<(mod3d_base::VertexAttr, VertexBuffer<G>)>,
88 ) {
89 (&self.indices, &self.position, &self.attrs)
90 }
91}
92
93impl<G> std::fmt::Display for Vertices<G>
95where
96 G: Gl,
97{
98 fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
99 writeln!(fmt, "ind:{}", self.indices)?;
100 writeln!(fmt, "pos:{}", self.position)
101 }
102}
103
104impl<G> Default for Vertices<G>
106where
107 G: Gl,
108{
109 fn default() -> Self {
111 let indices = IndexBuffer::default().into();
112 let position = VertexBuffer::default().into();
113 let attrs = Vec::new().into();
114 Self {
115 indices,
116 position,
117 attrs,
118 }
119 }
120}
121
122impl<G> mod3d_base::VerticesClient for Vertices<G> where G: Gl {}