forked from pupbrained/vulkan-test
image views
This commit is contained in:
parent
a7fc65008f
commit
bda0032e44
39
src/main.cpp
39
src/main.cpp
|
@ -92,10 +92,11 @@ class Application {
|
|||
VkQueue mGraphicsQueue;
|
||||
VkQueue mPresentQueue;
|
||||
|
||||
VkSwapchainKHR mSwapChain;
|
||||
std::vector<VkImage> mSwapChainImages;
|
||||
VkFormat mSwapChainImageFormat;
|
||||
VkExtent2D mSwapChainExtent;
|
||||
VkSwapchainKHR mSwapChain;
|
||||
std::vector<VkImage> mSwapChainImages;
|
||||
VkFormat mSwapChainImageFormat;
|
||||
VkExtent2D mSwapChainExtent;
|
||||
std::vector<VkImageView> mSwapChainImageViews;
|
||||
|
||||
fn initWindow() -> void {
|
||||
if (glfwInit() == GLFW_FALSE)
|
||||
|
@ -115,6 +116,7 @@ class Application {
|
|||
pickPhysicalDevice();
|
||||
createLogicalDevice();
|
||||
createSwapChain();
|
||||
createImageViews();
|
||||
}
|
||||
|
||||
fn mainLoop() -> void {
|
||||
|
@ -122,6 +124,8 @@ class Application {
|
|||
}
|
||||
|
||||
fn cleanup() -> void {
|
||||
for (VkImageView_T* imageView : mSwapChainImageViews) { vkDestroyImageView(mDevice, imageView, nullptr); }
|
||||
|
||||
vkDestroySwapchainKHR(mDevice, mSwapChain, nullptr);
|
||||
vkDestroyDevice(mDevice, nullptr);
|
||||
|
||||
|
@ -328,6 +332,33 @@ class Application {
|
|||
mSwapChainExtent = extent;
|
||||
}
|
||||
|
||||
fn createImageViews() -> void {
|
||||
mSwapChainImageViews.resize(mSwapChainImages.size());
|
||||
|
||||
for (usize i = 0; i < mSwapChainImages.size(); i++) {
|
||||
VkImageViewCreateInfo createInfo {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
createInfo.image = mSwapChainImages[i];
|
||||
|
||||
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
createInfo.format = mSwapChainImageFormat;
|
||||
|
||||
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(mDevice, &createInfo, nullptr, &mSwapChainImageViews[i]) != VK_SUCCESS)
|
||||
throw std::runtime_error("Failed to create image views!");
|
||||
}
|
||||
}
|
||||
|
||||
static fn chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats
|
||||
) -> VkSurfaceFormatKHR {
|
||||
for (const auto& availableFormat : availableFormats) {
|
||||
|
|
Loading…
Reference in a new issue