# HG changeset patch # User Emmanuel Gil Peyrot # Date 1580318150 -3600 # Node ID ee45bfde91bb9be811cb9e5ba7e48294ebf4cb83 # Parent 63f155923ea8f0152a6da57808f62ce1e86c98d7 examples: Add missing reupload_texture_from_rgb_image() to common diff --git a/examples/common.rs b/examples/common.rs --- a/examples/common.rs +++ b/examples/common.rs @@ -49,21 +49,28 @@ pub fn load_from_data(data: &[u8]) -> Re image::load_from_memory(data) } -pub fn upload_texture_from_rgb_image(surface: &mut GlfwSurface, img: DynamicImage) -> Result { - let (width, height) = img.dimensions(); +pub fn reupload_texture_from_rgb_image(tex: &mut Texture, img: DynamicImage) -> Result<(), TextureLoadError> { let texels = img .pixels() .map(|(_x, _y, rgb)| (rgb[0], rgb[1], rgb[2])) .collect::>(); + // the first argument disables mipmap generation (we don’t care so far) + tex.upload(GenMipmaps::No, &texels).unwrap(); + + Ok(()) +} + +pub fn upload_texture_from_rgb_image(surface: &mut GlfwSurface, img: DynamicImage) -> Result { + let (width, height) = img.dimensions(); + // create the luminance texture; the third argument is the number of mipmaps we want (leave it // to 0 for now) and the latest is a the sampler to use when sampling the texels in the // shader (we’ll just use the default one) - let tex = + let mut tex = Texture::new(surface, [width, height], 0, Sampler::default()).expect("luminance texture creation"); - // the first argument disables mipmap generation (we don’t care so far) - tex.upload(GenMipmaps::No, &texels).unwrap(); + reupload_texture_from_rgb_image(&mut tex, img)?; Ok(LoadedTexture::Rgb(tex)) }