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