pub fn encode_load_texture_array_from_image_buffers<'a, I, P, Container>(
    device: &wgpu::Device,
    encoder: &mut wgpu::CommandEncoder,
    usage: wgpu::TextureUsage,
    buffers: I,
) -> Option<wgpu::Texture>
where
    I: IntoIterator<Item = &'a image::ImageBuffer<P, Container>>,
    I::IntoIter: ExactSizeIterator,
    P: 'static + Pixel,
    Container: 'a + std::ops::Deref<Target = [P::Subpixel]>,
{
    let mut buffers = buffers.into_iter();
    let array_layers = buffers.len() as u32;
    let first_buffer = buffers.next()?;

    // Build the texture ready to receive the data.
    let texture = wgpu::TextureBuilder::from_image_view(first_buffer)
        .array_layer_count(array_layers)
        .usage(wgpu::TextureBuilder::REQUIRED_IMAGE_TEXTURE_USAGE | usage)
        .build(device);

    // Copy each buffer to the texture, one layer at a time.
    for (layer, buffer) in Some(first_buffer).into_iter().chain(buffers).enumerate() {
        // Upload the pixel data.
        let subpixel_data: &[P::Subpixel] = std::ops::Deref::deref(buffer);
        let buffer = device
            .create_buffer_mapped(subpixel_data.len(), wgpu::BufferUsage::COPY_SRC)
            .fill_from_slice(subpixel_data);

        // Submit command for copying pixel data to the texture.
        let buffer_copy_view = texture.default_buffer_copy_view(&buffer);
        let mut texture_copy_view = texture.default_copy_view();
        texture_copy_view.array_layer = layer as u32;
        let extent = texture.extent();
        encoder.copy_buffer_to_texture(buffer_copy_view, texture_copy_view, extent);
    }

    Some(texture)
}
/// Encode the necessary commands to load a texture array directly from a sequence of image
/// buffers.
///
/// NOTE: The returned texture will remain empty until the given `encoder` has its command buffer
/// submitted to the given `device`'s queue.
///
/// No format or size conversions are performed - the given buffer is loaded directly into GPU
/// memory.
///
/// Pixel type compatibility is ensured via the `Pixel` trait.
///
/// Returns `None` if there are no images in the given sequence.
Encode the necessary commands to load a texture array directly from a sequence of image
buffers.

The returned texture will remain empty until the given `encoder` has its command buffer
submitted to the given `device`'s queue.

No format or size conversions are performed - the given buffer is loaded directly into GPU
memory.

Pixel type compatibility is ensured via the `Pixel` trait.

Returns `None` if there are no images in the given sequence.
Encode the necessary commands to load a texture array directly from a sequence of image buffers . The returned texture will remain empty until the given ` encoder ` has its command buffer submitted to the given ` device ` ' s queue . No format or size conversions are performed - the given buffer is loaded directly into GPU memory . Pixel type compatibility is ensured via the ` Pixel ` trait . Returns ` None ` if there are no images in the given sequence .
pub fn encode_load_texture_array_from_image_buffers<'a, I, P, Container>(
    device: &wgpu::Device,
    encoder: &mut wgpu::CommandEncoder,
    usage: wgpu::TextureUsage,
    buffers: I,
) -> Option<wgpu::Texture>
where
    I: IntoIterator<Item = &'a image::ImageBuffer<P, Container>>,
    I::IntoIter: ExactSizeIterator,
    P: 'static + Pixel,
    Container: 'a + std::ops::Deref<Target = [P::Subpixel]>,
{
    let mut buffers = buffers.into_iter();
    let array_layers = buffers.len() as u32;
    let first_buffer = buffers.next()?;
    // Build the texture ready to receive the data.
    let texture = wgpu::TextureBuilder::from_image_view(first_buffer)
        .array_layer_count(array_layers)
        .usage(wgpu::TextureBuilder::REQUIRED_IMAGE_TEXTURE_USAGE | usage)
        .build(device);
    // Copy each buffer to the texture, one layer at a time.
    for (layer, buffer) in Some(first_buffer).into_iter().chain(buffers).enumerate() {
        // Upload the pixel data.
        let subpixel_data: &[P::Subpixel] = std::ops::Deref::deref(buffer);
        let buffer = device
            .create_buffer_mapped(subpixel_data.len(), wgpu::BufferUsage::COPY_SRC)
            .fill_from_slice(subpixel_data);
        // Submit command for copying pixel data to the texture.
        let buffer_copy_view = texture.default_buffer_copy_view(&buffer);
        let mut texture_copy_view = texture.default_copy_view();
        texture_copy_view.array_layer = layer as u32;
        let extent = texture.extent();
        encoder.copy_buffer_to_texture(buffer_copy_view, texture_copy_view, extent);
    }
    Some(texture)
}
pub fn encode_load_texture_array_from_image_buffers < ' a , I , P , Container > ( device : & wgpu :: Device , encoder : & mut wgpu :: CommandEncoder , usage : wgpu :: TextureUsage , buffers : I , ) -> Option < wgpu :: Texture > where I : IntoIterator < Item = & ' a image :: ImageBuffer < P , Container > > , I :: IntoIter : ExactSizeIterator , P : ' static + Pixel , Container : ' a + std :: ops :: Deref < Target = [ P :: Subpixel ] > , { let mut buffers = buffers . into_iter ( ) ; let array_layers = buffers . len ( ) as u32 ; let first_buffer = buffers . next ( ) ? ; // Build the texture ready to receive the data. let texture = wgpu :: TextureBuilder :: from_image_view ( first_buffer ) . array_layer_count ( array_layers ) . usage ( wgpu :: TextureBuilder :: REQUIRED_IMAGE_TEXTURE_USAGE | usage ) . build ( device ) ; // Copy each buffer to the texture, one layer at a time. for ( layer , buffer ) in Some ( first_buffer ) . into_iter ( ) . chain ( buffers ) . enumerate ( ) { // Upload the pixel data. let subpixel_data : & [ P :: Subpixel ] = std :: ops :: Deref :: deref ( buffer ) ; let buffer = device . create_buffer_mapped ( subpixel_data . len ( ) , wgpu :: BufferUsage :: COPY_SRC ) . fill_from_slice ( subpixel_data ) ; // Submit command for copying pixel data to the texture. let buffer_copy_view = texture . default_buffer_copy_view ( & buffer ) ; let mut texture_copy_view = texture . default_copy_view ( ) ; texture_copy_view . array_layer = layer as u32 ; let extent = texture . extent ( ) ; encoder . copy_buffer_to_texture ( buffer_copy_view , texture_copy_view , extent ) ; } Some ( texture ) }
Encode the necessary commands to load a texture array directly from a sequence of image
buffers.
Encode the necessary commands to load a texture array directly from a sequence of image buffers .
device
&wgpu::Device
encoder
&mut wgpu::CommandEncoder
usage
wgpu::TextureUsage
buffers
I
device
&wgpu::Device
encoder
&mut wgpu::CommandEncoder
usage
wgpu::TextureUsage
buffers
I