pub use {format::*, mapping::*, vao::*}; pub type AttrArr = ArrObject; pub type IdxArr = ArrObject; pub type UniformArr = ShdArrObj; pub type ShdStorageArr = ShdArrObj; #[derive(Debug)] pub struct ShdArrObj { pub array: ArrObject, loc: Cell, } impl ShdArrObj { pub fn new(args: impl AllocArgs) -> Self { ArrObject::new(args).into() } } impl Drop for ShdArrObj { fn drop(&mut self) { UniformState::::drop(self.array.obj); } } impl From> for ShdArrObj { fn from(array: ArrObject) -> Self { let (size, max) = (array.size(), T::max_size()); if size > max { FAIL!("GL {} buffer({}|{size}) exceeds maximum size {max}", type_name::(), array.obj); } Self { array, loc: Def() } } } impl UniformArr { pub fn Bind(&self) -> ShdArrBinding { let loc = self.loc.take(); let (b, l) = ShdArrBinding::::new(self, loc); self.loc.set(l); b } } impl ShdStorageArr { pub fn Bind(&self, loc: u32) -> Option> { ShdArrBinding::::new(self, loc) } } pub struct ShdArrBinding<'l, T: ShdBuffType> { t: Dummy<&'l T>, pub l: u32, } impl<'l> ShdArrBinding<'l, Uniform> { pub fn new(o: &'l UniformArr, hint: u32) -> (Self, u32) { let l = UniformState::::Bind(o.array.obj, hint); (Self { t: Dummy, l }, l) } } impl<'l> ShdArrBinding<'l, ShdStorage> { pub fn new(o: &'l ShdStorageArr, loc: u32) -> Option { if UniformState::::BindLocation(o.array.obj, loc) { Some(Self { t: Dummy, l: loc }) } else { None } } } impl Clone for ShdArrBinding<'_, T> { fn clone(&self) -> Self { let &Self { t, l } = self; UniformState::::Clone(l); Self { t, l } } } impl Drop for ShdArrBinding<'_, T> { fn drop(&mut self) { UniformState::::Unbind(self.l); } } mod args; mod format; mod mapping; mod vao; mod vao_args; use {super::internal::*, crate::lib::*, args::*};