comparison examples/common.rs @ 749:ee45bfde91bb

examples: Add missing reupload_texture_from_rgb_image() to common
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 29 Jan 2020 18:15:50 +0100
parents 0ebf6467e4ff
children 5e5e7136ac92
comparison
equal deleted inserted replaced
748:63f155923ea8 749:ee45bfde91bb
47 47
48 pub fn load_from_data(data: &[u8]) -> Result<DynamicImage, ImageError> { 48 pub fn load_from_data(data: &[u8]) -> Result<DynamicImage, ImageError> {
49 image::load_from_memory(data) 49 image::load_from_memory(data)
50 } 50 }
51 51
52 pub fn upload_texture_from_rgb_image(surface: &mut GlfwSurface, img: DynamicImage) -> Result<LoadedTexture, TextureLoadError> { 52 pub fn reupload_texture_from_rgb_image(tex: &mut Texture<Flat, Dim2, NormRGB8UI>, img: DynamicImage) -> Result<(), TextureLoadError> {
53 let (width, height) = img.dimensions();
54 let texels = img 53 let texels = img
55 .pixels() 54 .pixels()
56 .map(|(_x, _y, rgb)| (rgb[0], rgb[1], rgb[2])) 55 .map(|(_x, _y, rgb)| (rgb[0], rgb[1], rgb[2]))
57 .collect::<Vec<_>>(); 56 .collect::<Vec<_>>();
58 57
58 // the first argument disables mipmap generation (we don’t care so far)
59 tex.upload(GenMipmaps::No, &texels).unwrap();
60
61 Ok(())
62 }
63
64 pub fn upload_texture_from_rgb_image(surface: &mut GlfwSurface, img: DynamicImage) -> Result<LoadedTexture, TextureLoadError> {
65 let (width, height) = img.dimensions();
66
59 // create the luminance texture; the third argument is the number of mipmaps we want (leave it 67 // create the luminance texture; the third argument is the number of mipmaps we want (leave it
60 // to 0 for now) and the latest is a the sampler to use when sampling the texels in the 68 // to 0 for now) and the latest is a the sampler to use when sampling the texels in the
61 // shader (we’ll just use the default one) 69 // shader (we’ll just use the default one)
62 let tex = 70 let mut tex =
63 Texture::new(surface, [width, height], 0, Sampler::default()).expect("luminance texture creation"); 71 Texture::new(surface, [width, height], 0, Sampler::default()).expect("luminance texture creation");
64 72
65 // the first argument disables mipmap generation (we don’t care so far) 73 reupload_texture_from_rgb_image(&mut tex, img)?;
66 tex.upload(GenMipmaps::No, &texels).unwrap();
67 74
68 Ok(LoadedTexture::Rgb(tex)) 75 Ok(LoadedTexture::Rgb(tex))
69 } 76 }
70 77
71 pub fn load_rgb_texture(surface: &mut GlfwSurface, path: &Path) -> Result<LoadedTexture, TextureLoadError> { 78 pub fn load_rgb_texture(surface: &mut GlfwSurface, path: &Path) -> Result<LoadedTexture, TextureLoadError> {