From 9a189740e3f58f23254fb6effad8a4ab241e067e Mon Sep 17 00:00:00 2001 From: InkSoul Date: Thu, 29 Feb 2024 23:30:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90imageView=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VulkanTutorial.cpp | 39 +++++++++++++++++++++++++++++++++++++++ VulkanTutorial.h | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/VulkanTutorial.cpp b/VulkanTutorial.cpp index 39a7f06..2181801 100644 --- a/VulkanTutorial.cpp +++ b/VulkanTutorial.cpp @@ -109,6 +109,8 @@ void HelloTriangleApplication::initVulkan() { createLogicalDevice(); createSwapChain(); + + creatImageView(); } @@ -126,6 +128,11 @@ void HelloTriangleApplication::mainLoop(GLFWwindow* window){ void HelloTriangleApplication::cleanup(GLFWwindow* window) { + for (auto imageView : swapChainImageViews) + { + vkDestroyImageView(device, imageView, nullptr); + } + vkDestroySwapchainKHR(device, swapChain, nullptr); vkDestroySurfaceKHR(instance, surface, nullptr); @@ -523,6 +530,38 @@ void HelloTriangleApplication::createSwapChain() } +void HelloTriangleApplication::creatImageView() +{ + swapChainImageViews.resize(swapChainImages.size()); + + for (size_t i = 0; i < swapChainImages.size(); i++) + { + VkImageViewCreateInfo creatInfo{}; + creatInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + creatInfo.image = swapChainImages[i]; + creatInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; + creatInfo.format = swapChainImageFormat; + + creatInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + creatInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + creatInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + creatInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + + creatInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + creatInfo.subresourceRange.baseMipLevel = 0; + creatInfo.subresourceRange.levelCount = 1; + creatInfo.subresourceRange.baseArrayLayer = 0; + creatInfo.subresourceRange.layerCount = 1; + + if (vkCreateImageView(device,&creatInfo,nullptr,&swapChainImageViews[i]) != VK_SUCCESS) + { + throw std::runtime_error("failed to creat image view"); + } + + + } +} + bool HelloTriangleApplication::checkValidationLayerSupport() { uint32_t layerCount; diff --git a/VulkanTutorial.h b/VulkanTutorial.h index 6f8dc83..df26063 100644 --- a/VulkanTutorial.h +++ b/VulkanTutorial.h @@ -59,6 +59,8 @@ private: VkFormat swapChainImageFormat; VkExtent2D swapChainExtent; + std::vector swapChainImageViews; + struct QueueFamilyIndices { std::optional graphicsFamily; @@ -120,6 +122,8 @@ private: VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities); void createSwapChain(); + void creatImageView(); + }; HelloTriangleApplication::HelloTriangleApplication()