changeset 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 63f155923ea8
children 31897f650d2d
files examples/common.rs
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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<LoadedTexture, TextureLoadError> {
-    let (width, height) = img.dimensions();
+pub fn reupload_texture_from_rgb_image(tex: &mut Texture<Flat, Dim2, NormRGB8UI>, img: DynamicImage) -> Result<(), TextureLoadError> {
     let texels = img
         .pixels()
         .map(|(_x, _y, rgb)| (rgb[0], rgb[1], rgb[2]))
         .collect::<Vec<_>>();
 
+    // 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<LoadedTexture, TextureLoadError> {
+    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))
 }