完成imageView创建

master
InkSoul 2024-02-29 23:30:33 +08:00
parent 4f45098811
commit 9a189740e3
2 changed files with 43 additions and 0 deletions

View File

@ -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;

View File

@ -59,6 +59,8 @@ private:
VkFormat swapChainImageFormat;
VkExtent2D swapChainExtent;
std::vector<VkImageView> swapChainImageViews;
struct QueueFamilyIndices
{
std::optional<uint32_t> graphicsFamily;
@ -120,6 +122,8 @@ private:
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
void createSwapChain();
void creatImageView();
};
HelloTriangleApplication::HelloTriangleApplication()