use super::*; use crate::GL::{mesh::*, *}; impl Tex2d { pub fn Cast(&self, minification: i32) -> Tex2d { let s = LeakyStatic!(Shader, { Shader::pure([vs_mesh__2d_screen, ps_mesh__2d_screen]) }); let sampl = &Sampler::linear(); GLSave!(BLEND); GLDisable!(BLEND); let TexParam { w, h, .. } = self.param; let out = Fbo::::new((w, h).div(minification).max((1, 1))); let t = self.Bind(sampl); let _ = Uniforms!(s, ("tex", t)); out.bind(); Screen::Draw(); GLRestore!(BLEND); out.tex } } impl From<&Tex2d> for Image { fn from(tex: &Tex2d) -> Self { let ((w, h), data) = (uVec2((tex.param.w, tex.param.h)), tex.Save::(0)); Self { w, h, data, s: Dummy } } } impl From> for Image { fn from(tex: Tex2d) -> Self { (&tex).into() } } impl>> From for Tex2d { fn from(img: T) -> Self { let img = img.borrow(); Tex2d::new((img.w, img.h), &img.data[..]) } } impl Tex2d { pub fn from_type(img: &Image) -> Self { let mut t = Tex2d::new_empty((img.w, img.h), 1); t.UpdateCustom::(&img.data[..]); t } } impl From<&[&Cube]> for CubeTex { fn from(mips: &[&Cube]) -> Self { let w = i32(mips[0][0].w); let p = TexParam { w, h: w, d: 1, l: i32(mips.len()) }.validate(); let mut t = CubeTex::new_empty((p.w, p.h), p.l); mips.iter().enumerate().for_each(|(l, cube)| { cube.iter().enumerate().for_each(|(n, i)| { debug_assert!({ let (_w, _h, _) = uVec3(p.dim(l)); ASSERT!(_w == i.w && _h == i.h, "Mip size at level {l} is {:?}, must be {:?}", (_w, _h), (i.w, i.h)); true }); t.Update((&i.data, l, 0, 0, n)); }) }); t } } impl From<&[Cube]> for CubeTex { fn from(m: &[Cube]) -> Self { m.iter().collect_vec().as_slice().into() } } impl From<&Cube> for CubeTex { fn from(m: &Cube) -> Self { [m][..].into() } } type Cube = [Image; 6];