1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
use crate::uses::{GL::tex::*, *}; impl<S: TexSize, F: TexFmt, RS, RF> From<&Tex2d<RS, RF>> for Image<S, F> { fn from(tex: &Tex2d<RS, RF>) -> Self { let ((w, h), data) = (uVec2::to((tex.param.w, tex.param.h)), tex.Save::<S, F>(0)); Self { w, h, data, s: Dummy } } } impl<S: TexSize, F: TexFmt, RS, RF> From<Tex2d<RS, RF>> for Image<S, F> { fn from(tex: Tex2d<RS, RF>) -> Self { (&tex).into() } } impl<S: TexSize, F: TexFmt, T: Borrow<Image<S, F>>> From<T> for Tex2d<S, F> { fn from(img: T) -> Self { let img = img.borrow(); Tex2d::new((img.w, img.h), &img.data) } } impl<S: TexSize, F: TexFmt> From<&[&Cube<S, F>]> for CubeTex<S, F> { fn from(mips: &[&Cube<S, F>]) -> Self { let w = i32::to(mips[0][0].w); let l = TexParam::mip_levels(w); let p = TexParam { w, h: w, d: 1, l }; ASSERT!(i32::to(mips.len()) <= l, "Given {} images, but only {} mip levels", mips.len(), l); let l = mips.len(); let mut t = CubeTex::new_empty((l, w, w)); mips.iter().enumerate().for_each(|(l, cube)| { cube.iter().enumerate().for_each(|(n, i)| { debug_assert!({ let (_w, _h, _) = uVec3::to(p.dim(l)); ASSERT!(_w == i.w && _h == i.h, "Mip size at level {} is {:?}, must be {:?}", l, (_w, _h), (i.w, i.h)); true }); t.Update((&i.data, l, 0, 0, n)); }) }); t } } impl<'a, S: TexSize, F: TexFmt> From<&Vec<Cube<S, F>>> for CubeTex<S, F> { fn from(m: &Vec<Cube<S, F>>) -> Self { let m: Vec<_> = m.iter().collect(); m.as_slice().into() } } impl<'a, S: TexSize, F: TexFmt> From<Vec<Cube<S, F>>> for CubeTex<S, F> { fn from(m: Vec<Cube<S, F>>) -> Self { m.into() } } impl<S: TexSize, F: TexFmt> From<&Cube<S, F>> for CubeTex<S, F> { fn from(m: &Cube<S, F>) -> Self { [m][..].into() } } type Cube<S, F> = [Image<S, F>; 6];