1
0

Creating imageviews per image , done with the presentation layer

This commit is contained in:
2023-05-05 17:33:10 +02:00
parent 0825cba8e7
commit c1a32c7e30

View File

@@ -58,6 +58,8 @@ const std::vector<const char*> deviceExtensions = {
std::vector<VkImage> swapChainImages; std::vector<VkImage> swapChainImages;
VkFormat swapChainImageFormat; VkFormat swapChainImageFormat;
VkExtent2D swapChainExtent; VkExtent2D swapChainExtent;
std::vector<VkImageView> swapChainImageViews;
struct SwapChainSupportDetails { struct SwapChainSupportDetails {
VkSurfaceCapabilitiesKHR capabilities; VkSurfaceCapabilitiesKHR capabilities;
@@ -82,7 +84,7 @@ const std::vector<const char*> deviceExtensions = {
pickPhysicalDevice(); pickPhysicalDevice();
createLogicalDevice(); createLogicalDevice();
createSwapChain(); createSwapChain();
createImageViews();
} }
void createSurface() { void createSurface() {
@@ -203,6 +205,32 @@ const std::vector<const char*> deviceExtensions = {
} }
void createImageViews() {
swapChainImageViews.resize(swapChainImages.size());
for (size_t i = 0; i < swapChainImages.size(); i++) {
VkImageViewCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
createInfo.image = swapChainImages[i];
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
createInfo.format = swapChainImageFormat;
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!");
}
}
}
void pickPhysicalDevice() { void pickPhysicalDevice() {
uint32_t deviceCount = 0; uint32_t deviceCount = 0;
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr); vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
@@ -498,6 +526,11 @@ const std::vector<const char*> deviceExtensions = {
} }
void cleanup(){ void cleanup(){
for (auto imageView : swapChainImageViews) {
vkDestroyImageView(device, imageView, nullptr);
}
vkDestroySwapchainKHR(device, swapChain, nullptr); vkDestroySwapchainKHR(device, swapChain, nullptr);
vkDestroyDevice(device, nullptr); vkDestroyDevice(device, nullptr);