diff options
Diffstat (limited to 'src/graphics/texture.rs')
| -rw-r--r-- | src/graphics/texture.rs | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/src/graphics/texture.rs b/src/graphics/texture.rs index a6085e3..b28d540 100644 --- a/src/graphics/texture.rs +++ b/src/graphics/texture.rs @@ -6,9 +6,6 @@ use crate::graphics::util::{ begin_transient_commands, end_transient_commands }; -use std::io::Cursor; - -use png::Decoder; use vulkanalia::{ Device, Instance }; use vulkanalia::vk::{ self, HasBuilder, InstanceV1_0, DeviceV1_0 }; @@ -22,15 +19,18 @@ pub struct Texture { impl Texture { - pub fn new(permanent: &Permanent) -> Result<(Self, u32)> { + pub fn new(width: u32, height: u32, pixels: Vec<u8>, + permanent: &Permanent) + -> Result<(Self, u32)> + { let graphics_queue = &permanent.graphics_queue; let instance = &permanent.instance; let device = &permanent.device; let transient_command_pool = &permanent.transient_command_pool; let (image, image_memory, image_view, mip_count) - = init_texture(instance, device, graphics_queue, - &transient_command_pool)?; + = init_texture(width, height, pixels, instance, device, + graphics_queue, &transient_command_pool)?; Ok((Texture { image, @@ -51,19 +51,13 @@ impl Texture { #[allow(unsafe_code)] -fn init_texture(instance: &Instance, device: &Device, queue: &vk::Queue, - command_pool: &vk::CommandPool) +fn init_texture(width: u32, height: u32, pixels: Vec<u8>, + instance: &Instance, device: &Device, + queue: &vk::Queue, command_pool: &vk::CommandPool) -> Result<(vk::Image, vk::DeviceMemory, vk::ImageView, u32)> { let physical_device = device.physical_device(); - let png = include_bytes!("../../textures/forest_leaves_04_diff.png"); - - let decoder = Decoder::new(Cursor::new(png)); - let mut reader = decoder.read_info()?; - - let (width, height) = reader.info().size(); - let format_properties = unsafe { instance.get_physical_device_format_properties(physical_device, vk::Format::R8G8B8A8_SRGB) @@ -79,15 +73,12 @@ fn init_texture(instance: &Instance, device: &Device, queue: &vk::Queue, 1 }; - let mut pixels = vec![0; reader.info().raw_bytes()]; - reader.next_frame(&mut pixels)?; - let (staging_buffer, staging_memory, _byte_size) = stage_in_buffer(instance, device, &pixels)?; let (image, image_memory) - = allocate_image(instance, device, - width, height, mip_count, vk::SampleCountFlags::_1, + = allocate_image(instance, device, width, height, mip_count, + vk::SampleCountFlags::_1, vk::Format::R8G8B8A8_SRGB, vk::ImageTiling::OPTIMAL, vk::ImageUsageFlags::SAMPLED |