Glium: Write to Layer of Texture2dArray


#1

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?


#2

Hi,
The answer is short because I don’t have much time.

Unfortunately the proper method is not implemented yet.

For the moment you can upload to an array by creating a SimpleFrameBuffer:

let fb = SimpleFrameBuffer::new(display, array.layer(2).unwrap().main_level()).unwrap();

And copy from another texture:

let temporary_texture = Texture2d::new(...);
temporary_texture.as_surface().blit_to(fb);