| 2953 | } |
| 2954 | |
| 2955 | void Demo::resize() { |
| 2956 | // Don't react to resize until after first initialization. |
| 2957 | if (!initialized) { |
| 2958 | return; |
| 2959 | } |
| 2960 | |
| 2961 | // Don't do anything if the surface has zero size, as vulkan disallows creating swapchains with zero area |
| 2962 | // We use is_minimized to track this because zero size window usually occurs from minimizing |
| 2963 | if (width == 0 || height == 0) { |
| 2964 | is_minimized = true; |
| 2965 | return; |
| 2966 | } else { |
| 2967 | is_minimized = false; |
| 2968 | } |
| 2969 | |
| 2970 | // In order to properly resize the window, we must re-create the |
| 2971 | // swapchain |
| 2972 | // |
| 2973 | // First, destroy the old swapchain and its associated resources, setting swapchain_ready to false to prevent draw from |
| 2974 | // running |
| 2975 | if (swapchain_ready) { |
| 2976 | swapchain_ready = false; |
| 2977 | auto result = device.waitIdle(); |
| 2978 | VERIFY(result == vk::Result::eSuccess); |
| 2979 | |
| 2980 | device.destroyImageView(depth.view); |
| 2981 | device.destroyImage(depth.image); |
| 2982 | device.freeMemory(depth.mem); |
| 2983 | depth = {}; |
| 2984 | |
| 2985 | for (auto &swapchain_resource : swapchain_resources) { |
| 2986 | device.destroyFramebuffer(swapchain_resource.framebuffer); |
| 2987 | device.destroyImageView(swapchain_resource.view); |
| 2988 | device.destroySemaphore(swapchain_resource.draw_complete_semaphore); |
| 2989 | if (separate_present_queue) { |
| 2990 | device.destroySemaphore(swapchain_resource.image_ownership_semaphore); |
| 2991 | } |
| 2992 | } |
| 2993 | swapchain_resources.clear(); |
| 2994 | } |
| 2995 | // Second, recreate the swapchain, depth buffer, and framebuffers. |
| 2996 | prepare_swapchain(); |
| 2997 | } |
| 2998 | |
| 2999 | void Demo::set_image_layout(vk::Image image, vk::ImageAspectFlags aspectMask, vk::ImageLayout oldLayout, vk::ImageLayout newLayout, |
| 3000 | vk::AccessFlags srcAccessMask, vk::PipelineStageFlags src_stages, vk::PipelineStageFlags dest_stages) { |
no outgoing calls
no test coverage detected