xo-imgui: refactor ex4a: cleanup() etc.
This commit is contained in:
parent
5754e0f94a
commit
826298d097
2 changed files with 107 additions and 75 deletions
|
|
@ -623,4 +623,92 @@ MinimalImGuiVulkan::record_command_buffer(VkCommandBuffer cmdbuf, uint32_t image
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::recreate_swapchain()
|
||||
{
|
||||
// handle window minimization: wait until window has valid size
|
||||
this->wait_not_minimized();
|
||||
|
||||
// wait until device idle before cleaning up resources
|
||||
vkDeviceWaitIdle(device_);
|
||||
|
||||
// cleanup old swapchain
|
||||
this->cleanup_framebuffers();
|
||||
this->cleanup_image_views();
|
||||
this->cleanup_swapchain();
|
||||
|
||||
// create new swapchain
|
||||
this->create_swapchain();
|
||||
this->create_image_views();
|
||||
this->create_framebuffers();
|
||||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::wait_not_minimized()
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
SDL_GetWindowSize(window_, &width, &height);
|
||||
while (width == 0 || height == 0) {
|
||||
SDL_GetWindowSize(window_, &width, &height);
|
||||
SDL_WaitEvent(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::cleanup_framebuffers()
|
||||
{
|
||||
for (auto framebuffer : framebuffers_) {
|
||||
vkDestroyFramebuffer(device_, framebuffer, nullptr);
|
||||
}
|
||||
framebuffers_.clear();
|
||||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::cleanup_image_views()
|
||||
{
|
||||
for (auto imageView : swapchain_image_views_) {
|
||||
vkDestroyImageView(device_, imageView, nullptr);
|
||||
}
|
||||
swapchain_image_views_.clear();
|
||||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::cleanup_swapchain()
|
||||
{
|
||||
vkDestroySwapchainKHR(device_, this->swapchain_, nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
MinimalImGuiVulkan::cleanup()
|
||||
{
|
||||
ImGui_ImplVulkan_Shutdown();
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
||||
vkDestroySemaphore(device_, render_finished_semaphores_[i], nullptr);
|
||||
vkDestroySemaphore(device_, image_available_semaphores_[i], nullptr);
|
||||
vkDestroyFence(device_, inflight_fences_[i], nullptr);
|
||||
}
|
||||
|
||||
vkDestroyCommandPool(device_, command_pool_, nullptr);
|
||||
|
||||
this->cleanup_framebuffers();
|
||||
this->cleanup_image_views();
|
||||
this->cleanup_swapchain();
|
||||
|
||||
vkDestroyRenderPass(device_, render_pass_, nullptr);
|
||||
vkDestroyDescriptorPool(device_, descriptor_pool_, nullptr);
|
||||
vkDestroyDevice(device_, nullptr);
|
||||
vkDestroySurfaceKHR(instance_, this->surface_, nullptr);
|
||||
vkDestroyInstance(instance_, nullptr);
|
||||
this->instance_ = nullptr;
|
||||
|
||||
SDL_DestroyWindow(window_);
|
||||
this->window_ = nullptr;
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
/* end VulkanApp.cpp */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue