grafix_toolbox/kit/opengl/
buffer.rs1pub use {format::*, mapping::*};
2
3pub type AttrArr<D> = ArrObj<Attribute, D>;
4pub type IdxArr<D> = ArrObj<Index, D>;
5
6pub type UniformArr = ShdArrObj<Uniform, f32>;
7pub type ShdStorageArr = ShdArrObj<ShdStorage, f32>;
8
9#[derive(Debug)]
10pub struct ShdArrObj<T: ShdBuffType, D> {
11 pub array: ArrObj<T, D>,
12 loc: Cell<u32>,
13}
14impl<T: ShdBuffType, D> ShdArrObj<T, D> {
15 pub fn new(args: impl AllocArgs<D>) -> Self {
16 ArrObj::new(args).into()
17 }
18}
19impl<T: ShdBuffType, D> Drop for ShdArrObj<T, D> {
20 fn drop(&mut self) {
21 UniformState::<T>::drop(self.array.obj);
22 }
23}
24impl<T: ShdBuffType, D> From<ArrObj<T, D>> for ShdArrObj<T, D> {
25 fn from(array: ArrObj<T, D>) -> Self {
26 let (size, max) = (array.size(), T::max_size());
27 if size > max {
28 FAIL!("GL {} buffer({}|{size}) exceeds maximum size {max}", type_name::<T>(), array.obj);
29 }
30 Self { array, loc: Def() }
31 }
32}
33impl UniformArr {
34 pub fn Bind(&self) -> ShdArrBind<Uniform> {
35 let loc = self.loc.take();
36 let (b, l) = ShdArrBind::<Uniform>::new(self, loc);
37 self.loc.set(l);
38 b
39 }
40}
41impl ShdStorageArr {
42 pub fn Bind(&self, loc: u32) -> Option<ShdArrBind<ShdStorage>> {
43 ShdArrBind::<ShdStorage>::new(self, loc)
44 }
45}
46
47pub struct ShdArrBind<'l, T: ShdBuffType> {
48 t: Dummy<&'l T>,
49 pub l: u32,
50}
51impl<'l> ShdArrBind<'l, Uniform> {
52 fn new(o: &'l UniformArr, hint: u32) -> (Self, u32) {
53 let l = UniformState::<Uniform>::Bind(o.array.obj, hint);
54 (Self { t: Dummy, l }, l)
55 }
56}
57impl<'l> ShdArrBind<'l, ShdStorage> {
58 fn new(o: &'l ShdStorageArr, loc: u32) -> Option<Self> {
59 if !UniformState::<ShdStorage>::BindLocation(o.array.obj, loc) {
60 None?
61 }
62 Self { t: Dummy, l: loc }.into()
63 }
64}
65impl<T: ShdBuffType> Clone for ShdArrBind<'_, T> {
66 fn clone(&self) -> Self {
67 let Self { t, l } = *self;
68 UniformState::<T>::Clone(l);
69 Self { t, l }
70 }
71}
72impl<T: ShdBuffType> Drop for ShdArrBind<'_, T> {
73 fn drop(&mut self) {
74 UniformState::<T>::Unbind(self.l);
75 }
76}
77
78mod args;
79mod format;
80mod mapping;
81
82use {super::internal::*, crate::lib::*, args::*};