makepad_platform/
draw_matrix.rs1#![allow(dead_code)]
2use {
3 crate::{
4 makepad_math::Mat4,
5 id_pool::*,
6 }
7};
8
9#[derive(Debug)]
10pub struct DrawMatrix(PoolId);
11
12#[derive(Default, Clone, Debug, PartialEq, Copy, Hash, Ord, PartialOrd, Eq)]
13pub struct DrawMatrixId(usize, u64);
14
15#[derive(Default)]
16pub struct CxDrawMatrix{
17 parent: DrawMatrixId,
18 parent_version: u64,
19
20 local_version: u64,
21 local: Mat4,
22
23 object_to_world: Mat4,
24 world_to_object: Option<Mat4>
25}
26
27impl DrawMatrixId{
28 pub fn index(&self)->usize{self.0}
29 pub fn generation(&self)->u64{self.1}
30}
31
32impl DrawMatrix {
33 pub fn id(&self) -> DrawMatrixId {DrawMatrixId(self.0.id, self.0.generation)}
34 pub fn identity()->DrawMatrixId{
35 DrawMatrixId(0, 0)
36 }
37}
38
39pub struct CxDrawMatrixPool{
40 pool: IdPool<CxDrawMatrix>,
41 identity: DrawMatrix
42}
43
44impl Default for CxDrawMatrixPool{
45 fn default()->Self{
46 let mut pool = IdPool::default();
47 let identity = DrawMatrix(pool.alloc());
48
49 return Self{
50 pool,
51 identity
52 }
53 }
54}
55
56impl CxDrawMatrixPool {
57 pub fn alloc(&mut self) -> DrawMatrix {
58 DrawMatrix(self.pool.alloc())
59 }
60
61 pub fn update_local(&mut self, index:DrawMatrixId, new_mat:&Mat4){
62 let d = &mut self.pool.pool[index.0];
63 if d.local != *new_mat{
64 d.local_version += 1;
65 d.local = *new_mat;
66 }
67 }
68
69 pub fn update_parent(&mut self, index:DrawMatrixId){
70 fn update_parent(_index:usize, _pool:&mut Vec<IdPoolItem<CxDrawMatrix>>){
71
72 }
73 update_parent(index.0, &mut self.pool.pool);
74 let d = &mut self.pool.pool[index.0];
75 if d.parent.0 != 0{ }
81 }
82
83 }
88
89impl std::ops::Index<DrawMatrixId> for CxDrawMatrixPool {
90
91 type Output = CxDrawMatrix;
92 fn index(&self, index: DrawMatrixId) -> &Self::Output {
93 let d = &self.pool.pool[index.0];
94 if d.generation != index.1 {
95 error!("MatrixNode id generation wrong {} {} {}", index.0, d.generation, index.1)
96 }
97 &d.item
98 }
99}
100
101impl std::ops::IndexMut<DrawMatrixId> for CxDrawMatrixPool {
102 fn index_mut(&mut self, index: DrawMatrixId) -> &mut Self::Output {
103 let d = &mut self.pool.pool[index.0];
104 if d.generation != index.1 {
105 error!("MatrixNode id generation wrong {} {} {}", index.0, d.generation, index.1)
106 }
107 &mut d.item
108
109 }
110}
111