use super::*; pub struct Fbo { pub fb: Framebuffer, pub tex: Tex2d, } impl Fbo { pub fn new(args: impl FboArgs) -> Self { let (w, h) = args.get(); let tex = Tex2d::::new_empty((w, h), 1); let fb = Framebuffer::new().attach((&tex, gl::COLOR_ATTACHMENT0)); Self { fb, tex } } } impl Frame for Fbo { fn ClearColor(&self, args: impl ClearArgs) { self.fb.Clear(gl::COLOR, args); } fn size(&self) -> uVec2 { let TexParam { w, h, .. } = self.tex.param; uVec2((w, h)) } fn bind(&self) -> Binding { self.fb.Bind(&self.tex) } } pub struct Slab { pub src: Fbo, pub tgt: Fbo, } impl Slab { pub fn new(args: impl FboArgs) -> Self { Self { src: Fbo::new(args), tgt: Fbo::new(args) } } pub fn swap(&mut self) { mem::swap(&mut self.src, &mut self.tgt); } } pub trait FboArgs: Copy { fn get(self) -> iVec2; } impl FboArgs for (W, H) where i32: Cast + Cast, { fn get(self) -> iVec2 { iVec2(self) } }