From 1216c5f3dd1f902fb545db875e2b88f50d24e580 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sun, 9 Aug 2026 18:05:15 -0700 Subject: move PNG-specific code to a new module files::png this mirrors files::obj Force-Push: yes Change-Id: I17ccae0b54b49453100873ba707ee36406b96057 --- src/graphics/texture.rs | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'src/graphics') 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, + 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, + 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 -- cgit 1.4.1