xo-imgui: refactor ex4a: create_iamge_views -> .cpp
This commit is contained in:
parent
08257f19fd
commit
61a5ed1c90
2 changed files with 40 additions and 31 deletions
|
|
@ -215,4 +215,31 @@ MinimalImGuiVulkan::create_swapchain()
|
||||||
vkGetSwapchainImagesKHR(device_, swapchain_, &n_image, this->swapchain_images_.data());
|
vkGetSwapchainImagesKHR(device_, swapchain_, &n_image, this->swapchain_images_.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MinimalImGuiVulkan::create_image_views()
|
||||||
|
{
|
||||||
|
swapchain_image_views_.resize(swapchain_images_.size());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < swapchain_images_.size(); i++) {
|
||||||
|
VkImageViewCreateInfo create_info{};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||||
|
create_info.image = swapchain_images_[i];
|
||||||
|
create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
create_info.format = swapchain_image_format_;
|
||||||
|
create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
create_info.subresourceRange.baseMipLevel = 0;
|
||||||
|
create_info.subresourceRange.levelCount = 1;
|
||||||
|
create_info.subresourceRange.baseArrayLayer = 0;
|
||||||
|
create_info.subresourceRange.layerCount = 1;
|
||||||
|
|
||||||
|
if (vkCreateImageView(device_, &create_info, nullptr, &swapchain_image_views_[i]) != VK_SUCCESS) {
|
||||||
|
throw std::runtime_error("Failed to create image views!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* end VulkanApp.cpp */
|
/* end VulkanApp.cpp */
|
||||||
|
|
|
||||||
|
|
@ -52,30 +52,10 @@ private:
|
||||||
*/
|
*/
|
||||||
void create_swapchain();
|
void create_swapchain();
|
||||||
|
|
||||||
void create_image_views() {
|
/*
|
||||||
swapchainImageViews.resize(swapchain_images_.size());
|
* populate @ref swapchain_image_views_
|
||||||
|
*/
|
||||||
for (size_t i = 0; i < swapchain_images_.size(); i++) {
|
void create_image_views();
|
||||||
VkImageViewCreateInfo createInfo{};
|
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
|
||||||
createInfo.image = swapchain_images_[i];
|
|
||||||
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
|
||||||
createInfo.format = swapchain_image_format_;
|
|
||||||
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 create_render_pass() {
|
void create_render_pass() {
|
||||||
VkAttachmentDescription colorAttachment{};
|
VkAttachmentDescription colorAttachment{};
|
||||||
|
|
@ -120,10 +100,10 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_framebuffers() {
|
void create_framebuffers() {
|
||||||
framebuffers.resize(swapchainImageViews.size());
|
framebuffers.resize(swapchain_image_views_.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < swapchainImageViews.size(); i++) {
|
for (size_t i = 0; i < swapchain_image_views_.size(); i++) {
|
||||||
VkImageView attachments[] = { swapchainImageViews[i] };
|
VkImageView attachments[] = { swapchain_image_views_[i] };
|
||||||
|
|
||||||
VkFramebufferCreateInfo framebufferInfo{};
|
VkFramebufferCreateInfo framebufferInfo{};
|
||||||
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||||
|
|
@ -462,10 +442,10 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupImageViews() {
|
void cleanupImageViews() {
|
||||||
for (auto imageView : swapchainImageViews) {
|
for (auto imageView : swapchain_image_views_) {
|
||||||
vkDestroyImageView(device_, imageView, nullptr);
|
vkDestroyImageView(device_, imageView, nullptr);
|
||||||
}
|
}
|
||||||
swapchainImageViews.clear();
|
swapchain_image_views_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupSwapchain() {
|
void cleanupSwapchain() {
|
||||||
|
|
@ -518,11 +498,13 @@ private:
|
||||||
VkDevice device_;
|
VkDevice device_;
|
||||||
VkQueue graphics_queue_;
|
VkQueue graphics_queue_;
|
||||||
|
|
||||||
VkSwapchainKHR swapchain_;
|
/* drawing state, dependent on window size */
|
||||||
VkFormat swapchain_image_format_;
|
VkFormat swapchain_image_format_;
|
||||||
VkExtent2D swapchain_extent_;
|
VkExtent2D swapchain_extent_;
|
||||||
|
VkSwapchainKHR swapchain_;
|
||||||
std::vector<VkImage> swapchain_images_;
|
std::vector<VkImage> swapchain_images_;
|
||||||
std::vector<VkImageView> swapchainImageViews;
|
|
||||||
|
std::vector<VkImageView> swapchain_image_views_;
|
||||||
VkRenderPass renderPass;
|
VkRenderPass renderPass;
|
||||||
std::vector<VkFramebuffer> framebuffers;
|
std::vector<VkFramebuffer> framebuffers;
|
||||||
VkCommandPool commandPool;
|
VkCommandPool commandPool;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue