Compare commits

..

No commits in common. "a576fe418865080e3b996eb551a97d71fbd60b22" and "73160af503ada094c713881188d5967fd3612560" have entirely different histories.

View file

@ -144,7 +144,6 @@ struct VulkanApp {
swap_chain_images: Vec<ffi::VkImage>, swap_chain_images: Vec<ffi::VkImage>,
swap_chain_image_format: ffi::VkFormat, swap_chain_image_format: ffi::VkFormat,
swap_chain_extent: ffi::VkExtent2D, swap_chain_extent: ffi::VkExtent2D,
swap_chain_image_views: Vec<ffi::VkImageView>,
} }
impl VulkanApp { impl VulkanApp {
@ -162,7 +161,6 @@ impl VulkanApp {
swap_chain_images: Vec::new(), swap_chain_images: Vec::new(),
swap_chain_image_format: 0, swap_chain_image_format: 0,
swap_chain_extent: unsafe { std::mem::zeroed() }, swap_chain_extent: unsafe { std::mem::zeroed() },
swap_chain_image_views: Vec::new(),
} }
} }
@ -197,7 +195,6 @@ impl VulkanApp {
self.pick_physical_device(); self.pick_physical_device();
self.create_logical_device(); self.create_logical_device();
self.create_swap_chain(); self.create_swap_chain();
self.create_image_views();
} }
fn create_instance(&mut self) { fn create_instance(&mut self) {
@ -636,7 +633,7 @@ impl VulkanApp {
} }
} }
Some(0) return Some(0);
} }
fn choose_swap_present_mode( fn choose_swap_present_mode(
@ -769,55 +766,10 @@ impl VulkanApp {
self.swap_chain_image_format = swap_chain_support.formats[surface_format_idx].format; self.swap_chain_image_format = swap_chain_support.formats[surface_format_idx].format;
self.swap_chain_extent = extent; self.swap_chain_extent = extent;
} }
fn create_image_views(&mut self) {
self.swap_chain_image_views
.resize(self.swap_chain_images.len(), std::ptr::null_mut());
for (idx, image) in self.swap_chain_images.iter().enumerate() {
let mut create_info: ffi::VkImageViewCreateInfo = unsafe { std::mem::zeroed() };
create_info.sType = ffi::VkStructureType_VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
create_info.image = image.clone();
create_info.viewType = ffi::VkImageViewType_VK_IMAGE_VIEW_TYPE_2D;
create_info.format = self.swap_chain_image_format;
create_info.components.r = ffi::VkComponentSwizzle_VK_COMPONENT_SWIZZLE_IDENTITY;
create_info.components.g = ffi::VkComponentSwizzle_VK_COMPONENT_SWIZZLE_IDENTITY;
create_info.components.b = ffi::VkComponentSwizzle_VK_COMPONENT_SWIZZLE_IDENTITY;
create_info.components.a = ffi::VkComponentSwizzle_VK_COMPONENT_SWIZZLE_IDENTITY;
create_info.subresourceRange.aspectMask =
ffi::VkImageAspectFlagBits_VK_IMAGE_ASPECT_COLOR_BIT;
create_info.subresourceRange.baseMipLevel = 0;
create_info.subresourceRange.levelCount = 1;
create_info.subresourceRange.baseArrayLayer = 0;
create_info.subresourceRange.layerCount = 1;
let result = unsafe {
ffi::vkCreateImageView(
self.device,
std::ptr::addr_of!(create_info),
std::ptr::null(),
std::ptr::addr_of_mut!(self.swap_chain_image_views[idx]),
)
};
if result != ffi::VkResult_VK_SUCCESS {
panic!("Failed to create image view {}!", idx);
}
}
}
} }
impl Drop for VulkanApp { impl Drop for VulkanApp {
fn drop(&mut self) { fn drop(&mut self) {
for view in &self.swap_chain_image_views {
unsafe {
// The type of view is a ptr, so view.clone() merely copies the ptr.
ffi::vkDestroyImageView(self.device, view.clone(), std::ptr::null());
}
}
if !self.swap_chain.is_null() { if !self.swap_chain.is_null() {
unsafe { unsafe {
ffi::vkDestroySwapchainKHR(self.device, self.swap_chain, std::ptr::null()); ffi::vkDestroySwapchainKHR(self.device, self.swap_chain, std::ptr::null());