From 61a5ed1c90b380022a6710c38be6708f1dd7f017 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 11 Nov 2025 09:57:32 -0500 Subject: [PATCH] xo-imgui: refactor ex4a: create_iamge_views -> .cpp --- xo-imgui/example/ex4a/VulkanApp.cpp | 27 ++++++++++++++++++ xo-imgui/example/ex4a/VulkanApp.hpp | 44 +++++++++-------------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/xo-imgui/example/ex4a/VulkanApp.cpp b/xo-imgui/example/ex4a/VulkanApp.cpp index 95a8ad6e..0ae37ddd 100644 --- a/xo-imgui/example/ex4a/VulkanApp.cpp +++ b/xo-imgui/example/ex4a/VulkanApp.cpp @@ -215,4 +215,31 @@ MinimalImGuiVulkan::create_swapchain() vkGetSwapchainImagesKHR(device_, swapchain_, &n_image, this->swapchain_images_.data()); } +void +MinimalImGuiVulkan::create_image_views() +{ + swapchain_image_views_.resize(swapchain_images_.size()); + + for (size_t i = 0; i < swapchain_images_.size(); i++) { + VkImageViewCreateInfo create_info{}; + create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + create_info.image = swapchain_images_[i]; + create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + create_info.format = swapchain_image_format_; + create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + create_info.subresourceRange.aspectMask = 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; + + if (vkCreateImageView(device_, &create_info, nullptr, &swapchain_image_views_[i]) != VK_SUCCESS) { + throw std::runtime_error("Failed to create image views!"); + } + } +} + /* end VulkanApp.cpp */ diff --git a/xo-imgui/example/ex4a/VulkanApp.hpp b/xo-imgui/example/ex4a/VulkanApp.hpp index 3e0a1cb7..0c311068 100644 --- a/xo-imgui/example/ex4a/VulkanApp.hpp +++ b/xo-imgui/example/ex4a/VulkanApp.hpp @@ -52,30 +52,10 @@ private: */ void create_swapchain(); - void create_image_views() { - swapchainImageViews.resize(swapchain_images_.size()); - - for (size_t i = 0; i < swapchain_images_.size(); i++) { - VkImageViewCreateInfo createInfo{}; - createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - createInfo.image = swapchain_images_[i]; - createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; - createInfo.format = swapchain_image_format_; - createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; - createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; - createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; - createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; - createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - createInfo.subresourceRange.baseMipLevel = 0; - createInfo.subresourceRange.levelCount = 1; - createInfo.subresourceRange.baseArrayLayer = 0; - createInfo.subresourceRange.layerCount = 1; - - if (vkCreateImageView(device_, &createInfo, nullptr, &swapchainImageViews[i]) != VK_SUCCESS) { - throw std::runtime_error("Failed to create image views!"); - } - } - } + /* + * populate @ref swapchain_image_views_ + */ + void create_image_views(); void create_render_pass() { VkAttachmentDescription colorAttachment{}; @@ -120,10 +100,10 @@ private: } void create_framebuffers() { - framebuffers.resize(swapchainImageViews.size()); + framebuffers.resize(swapchain_image_views_.size()); - for (size_t i = 0; i < swapchainImageViews.size(); i++) { - VkImageView attachments[] = { swapchainImageViews[i] }; + for (size_t i = 0; i < swapchain_image_views_.size(); i++) { + VkImageView attachments[] = { swapchain_image_views_[i] }; VkFramebufferCreateInfo framebufferInfo{}; framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; @@ -462,10 +442,10 @@ private: } void cleanupImageViews() { - for (auto imageView : swapchainImageViews) { + for (auto imageView : swapchain_image_views_) { vkDestroyImageView(device_, imageView, nullptr); } - swapchainImageViews.clear(); + swapchain_image_views_.clear(); } void cleanupSwapchain() { @@ -518,11 +498,13 @@ private: VkDevice device_; VkQueue graphics_queue_; - VkSwapchainKHR swapchain_; + /* drawing state, dependent on window size */ VkFormat swapchain_image_format_; VkExtent2D swapchain_extent_; + VkSwapchainKHR swapchain_; std::vector swapchain_images_; - std::vector swapchainImageViews; + + std::vector swapchain_image_views_; VkRenderPass renderPass; std::vector framebuffers; VkCommandPool commandPool;