forked from pupbrained/vulkan-test
image views
This commit is contained in:
parent
a7fc65008f
commit
bda0032e44
31
src/main.cpp
31
src/main.cpp
|
@ -96,6 +96,7 @@ class Application {
|
||||||
std::vector<VkImage> mSwapChainImages;
|
std::vector<VkImage> mSwapChainImages;
|
||||||
VkFormat mSwapChainImageFormat;
|
VkFormat mSwapChainImageFormat;
|
||||||
VkExtent2D mSwapChainExtent;
|
VkExtent2D mSwapChainExtent;
|
||||||
|
std::vector<VkImageView> mSwapChainImageViews;
|
||||||
|
|
||||||
fn initWindow() -> void {
|
fn initWindow() -> void {
|
||||||
if (glfwInit() == GLFW_FALSE)
|
if (glfwInit() == GLFW_FALSE)
|
||||||
|
@ -115,6 +116,7 @@ class Application {
|
||||||
pickPhysicalDevice();
|
pickPhysicalDevice();
|
||||||
createLogicalDevice();
|
createLogicalDevice();
|
||||||
createSwapChain();
|
createSwapChain();
|
||||||
|
createImageViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mainLoop() -> void {
|
fn mainLoop() -> void {
|
||||||
|
@ -122,6 +124,8 @@ class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup() -> void {
|
fn cleanup() -> void {
|
||||||
|
for (VkImageView_T* imageView : mSwapChainImageViews) { vkDestroyImageView(mDevice, imageView, nullptr); }
|
||||||
|
|
||||||
vkDestroySwapchainKHR(mDevice, mSwapChain, nullptr);
|
vkDestroySwapchainKHR(mDevice, mSwapChain, nullptr);
|
||||||
vkDestroyDevice(mDevice, nullptr);
|
vkDestroyDevice(mDevice, nullptr);
|
||||||
|
|
||||||
|
@ -328,6 +332,33 @@ class Application {
|
||||||
mSwapChainExtent = extent;
|
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
|
static fn chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats
|
||||||
) -> VkSurfaceFormatKHR {
|
) -> VkSurfaceFormatKHR {
|
||||||
for (const auto& availableFormat : availableFormats) {
|
for (const auto& availableFormat : availableFormats) {
|
||||||
|
|
Loading…
Reference in a new issue