Add allocate image views
This commit is contained in:
@@ -327,6 +327,30 @@ void RenderEngine::create_swapchain(VkPresentModeKHR desired_present_mode)
|
|||||||
swapchain_extent_ = extent;
|
swapchain_extent_ = extent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderEngine::create_image_views()
|
||||||
|
{
|
||||||
|
VkImageViewCreateInfo image_view_info{};
|
||||||
|
image_view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||||
|
image_view_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
image_view_info.format = swapchain_image_format_;
|
||||||
|
image_view_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
image_view_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
image_view_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
image_view_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
image_view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
image_view_info.subresourceRange.baseMipLevel = 0;
|
||||||
|
image_view_info.subresourceRange.levelCount = 1;
|
||||||
|
image_view_info.subresourceRange.baseArrayLayer = 0;
|
||||||
|
image_view_info.subresourceRange.layerCount = 1;
|
||||||
|
|
||||||
|
swapchain_image_views_.resize(swapchain_images_.size());
|
||||||
|
for (uint32_t i = 0; i < swapchain_images_.size(); ++i)
|
||||||
|
{
|
||||||
|
image_view_info.image = swapchain_images_[i];
|
||||||
|
VK_CHECK(vkCreateImageView(device_, &image_view_info, nullptr, &swapchain_image_views_[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RenderEngine::create_surface()
|
void RenderEngine::create_surface()
|
||||||
{
|
{
|
||||||
VK_CHECK(glfwCreateWindowSurface(instance_, window_, nullptr, &surface_));
|
VK_CHECK(glfwCreateWindowSurface(instance_, window_, nullptr, &surface_));
|
||||||
@@ -344,10 +368,15 @@ window_(window)
|
|||||||
pick_physical_device();
|
pick_physical_device();
|
||||||
create_logical_device();
|
create_logical_device();
|
||||||
create_swapchain(desired_present_mode);
|
create_swapchain(desired_present_mode);
|
||||||
|
create_image_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderEngine::~RenderEngine()
|
RenderEngine::~RenderEngine()
|
||||||
{
|
{
|
||||||
|
for (auto image_view : swapchain_image_views_)
|
||||||
|
vkDestroyImageView(device_, image_view, nullptr);
|
||||||
|
swapchain_image_views_.clear();
|
||||||
|
|
||||||
if (swapchain_ != VK_NULL_HANDLE)
|
if (swapchain_ != VK_NULL_HANDLE)
|
||||||
vkDestroySwapchainKHR(device_, swapchain_, nullptr);
|
vkDestroySwapchainKHR(device_, swapchain_, nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class RenderEngine
|
|||||||
std::vector<VkImage> swapchain_images_;
|
std::vector<VkImage> swapchain_images_;
|
||||||
VkFormat swapchain_image_format_;
|
VkFormat swapchain_image_format_;
|
||||||
VkExtent2D swapchain_extent_;
|
VkExtent2D swapchain_extent_;
|
||||||
|
std::vector<VkImageView> swapchain_image_views_;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
|
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
|
||||||
@@ -66,6 +67,7 @@ class RenderEngine
|
|||||||
void pick_physical_device();
|
void pick_physical_device();
|
||||||
void create_logical_device();
|
void create_logical_device();
|
||||||
void create_swapchain(VkPresentModeKHR desired_present_mode);
|
void create_swapchain(VkPresentModeKHR desired_present_mode);
|
||||||
|
void create_image_views();
|
||||||
public:
|
public:
|
||||||
// Can throw the exception
|
// Can throw the exception
|
||||||
RenderEngine(CoreInstance& core, GLFWwindow* window, VkPresentModeKHR desired_present_mode = VK_PRESENT_MODE_MAILBOX_KHR);
|
RenderEngine(CoreInstance& core, GLFWwindow* window, VkPresentModeKHR desired_present_mode = VK_PRESENT_MODE_MAILBOX_KHR);
|
||||||
|
|||||||
Reference in New Issue
Block a user