fn read_texture_file(
        &self,
        file_path: impl Into<String>,
    ) -> Result<TextureImage> {
        let path_string = file_path.into();

        let mipmaps = read_file_mipmaps(&path_string)?;
        let packed_mipmap_data: Vec<&[u8]> = mipmaps
            .iter()
            .map(|mipmap| mipmap.as_raw() as &[u8])
            .collect();

        let mut texture = self.create_empty_2d_texture(
            path_string,
            mipmaps[0].width(),
            mipmaps[0].height(),
            mipmaps.len() as u32,
        )?;

        let mut transfer_buffer = CpuBuffer::new(
            self.device.clone(),
            vk::BufferUsageFlags::TRANSFER_SRC,
        )?;

        unsafe {
            transfer_buffer.write_data_arrays(&packed_mipmap_data)?;

            let mipmap_sizes: Vec<MipmapExtent> = mipmaps
                .iter()
                .map(|mipmap| MipmapExtent {
                    width: mipmap.width(),
                    height: mipmap.height(),
                })
                .collect();

            texture
                .upload_mipmaps_from_buffer(&transfer_buffer, &mipmap_sizes)?;
        }
        Ok(texture)
    }
/// Read a file from the local filesystem into memory as a usable texture.
Read a file from the local filesystem into memory as a usable texture.
Read a file from the local filesystem into memory as a usable texture .
fn read_texture_file(
        &self,
        file_path: impl Into<String>,
    ) -> Result<TextureImage> {
        let path_string = file_path.into();
        let mipmaps = read_file_mipmaps(&path_string)?;
        let packed_mipmap_data: Vec<&[u8]> = mipmaps
            .iter()
            .map(|mipmap| mipmap.as_raw() as &[u8])
            .collect();
        let mut texture = self.create_empty_2d_texture(
            path_string,
            mipmaps[0].width(),
            mipmaps[0].height(),
            mipmaps.len() as u32,
        )?;
        let mut transfer_buffer = CpuBuffer::new(
            self.device.clone(),
            vk::BufferUsageFlags::TRANSFER_SRC,
        )?;
        unsafe {
            transfer_buffer.write_data_arrays(&packed_mipmap_data)?;
            let mipmap_sizes: Vec<MipmapExtent> = mipmaps
                .iter()
                .map(|mipmap| MipmapExtent {
                    width: mipmap.width(),
                    height: mipmap.height(),
                })
                .collect();
            texture
                .upload_mipmaps_from_buffer(&transfer_buffer, &mipmap_sizes)?;
        }
        Ok(texture)
    }
fn read_texture_file ( & self , file_path : impl Into < String > , ) -> Result < TextureImage > { let path_string = file_path . into ( ) ; let mipmaps = read_file_mipmaps ( & path_string ) ? ; let packed_mipmap_data : Vec < & [ u8 ] > = mipmaps . iter ( ) . map ( | mipmap | mipmap . as_raw ( ) as & [ u8 ] ) . collect ( ) ; let mut texture = self . create_empty_2d_texture ( path_string , mipmaps [ 0 ] . width ( ) , mipmaps [ 0 ] . height ( ) , mipmaps . len ( ) as u32 , ) ? ; let mut transfer_buffer = CpuBuffer :: new ( self . device . clone ( ) , vk :: BufferUsageFlags :: TRANSFER_SRC , ) ? ; unsafe { transfer_buffer . write_data_arrays ( & packed_mipmap_data ) ? ; let mipmap_sizes : Vec < MipmapExtent > = mipmaps . iter ( ) . map ( | mipmap | MipmapExtent { width : mipmap . width ( ) , height : mipmap . height ( ) , } ) . collect ( ) ; texture . upload_mipmaps_from_buffer ( & transfer_buffer , & mipmap_sizes ) ? ; } Ok ( texture ) }
Read a file from the local filesystem into memory as a usable texture.
Read a file from the local filesystem into memory as a usable texture .
&self
file_path
impl Into<String>