grafix_toolbox/kit/opengl/control/
obj.rs1use {super::state::*, crate::stdlib::*};
2
3#[derive(Debug)]
4pub struct Obj<T: State> {
5 t: Dummy<Cell<T>>,
6 pub obj: u32,
7}
8impl<T: State> Obj<T> {
9 pub fn new() -> Self {
10 let obj = T::New();
11 Self { t: Dummy, obj }
12 }
13}
14impl<T: State> Drop for Obj<T> {
15 fn drop(&mut self) {
16 T::Drop(self.obj);
17 }
18}
19impl<T: State> Default for Obj<T> {
20 fn default() -> Self {
21 Self::new()
22 }
23}
24impl<T: State> Eq for Obj<T> {}
25impl<T: State> PartialEq for Obj<T> {
26 fn eq(&self, r: &Self) -> bool {
27 self.obj == r.obj
28 }
29}
30
31pub struct Bind<'l, T: State>(Dummy<&'l *const T>);
32impl<T: State> Bind<'_, T> {
33 pub fn new(o: &Obj<T>) -> Self {
34 T::Lock(o.obj);
35 T::Bind(o.obj);
36 Self(Dummy)
37 }
38 pub fn zero() -> Self {
39 T::Lock(0);
40 T::Bind(0);
41 Self(Dummy)
42 }
43}
44impl<T: State> Drop for Bind<'_, T> {
45 fn drop(&mut self) {
46 T::Unlock();
47 }
48}
49
50#[derive(Debug)]
51pub struct ArrObj<T: State, D> {
52 t: Dummy<(Cell<T>, D)>,
53 pub obj: u32,
54 pub len: usize,
55}
56impl<T: State, D> ArrObj<T, D> {
57 pub fn new_empty(len: usize) -> Self {
58 Self { t: Dummy, obj: T::New(), len }
59 }
60 pub fn size(&self) -> usize {
61 self.len * type_size::<D>()
62 }
63}
64impl<T: State, D> Drop for ArrObj<T, D> {
65 fn drop(&mut self) {
66 T::Drop(self.obj);
67 }
68}
69impl<T: State, D> Default for ArrObj<T, D> {
70 fn default() -> Self {
71 Self::new_empty(0)
72 }
73}
74impl<T: State, D> Eq for ArrObj<T, D> {}
75impl<T: State, D> PartialEq for ArrObj<T, D> {
76 fn eq(&self, r: &Self) -> bool {
77 self.obj == r.obj
78 }
79}
80pub trait ArrObjLease {}
81impl<T: State, D> ArrObjLease for ArrObj<T, D> {}
82impl ArrObjLease for () {}