How to upload texture data to a layer of a Texture2dArray (or the sRGB variant)?
I am writing a 2D mapping application using 256x256 pixel tiles. To reduce the number of draw calls I created a Texture2dArray with 32 layers acting as a cache of the visible tiles.
Using the raw_upload_from_pixel_buffer(...) function from TextureAnyMipmap I was able to upload data to only the first layer:
let dyn: image::DynamicImage = ...
let pixbuf = glium::texture::pixel_buffer::PixelBuffer::new_empty(display, 256*256*4);
pixbuf.write(&dyn.to_rgba().into_raw()[..]);
texture_2d_array.mipmap(0).unwrap().raw_upload_from_pixel_buffer(pixbuf.as_slice(), 0..256, 0..256, 0..1);
How to access the other layers? Is there a more elegant/performant solution?
If anyone else finds this post, looking for a solution to the same problem: it seems that it is now possible to upload from a PixelBuffer to any layer of a Texture2dArray by using almost exactly the code of the original poster.
Just change the last range from 0..1 to target_layer..target_layer + 1.