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