mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 15:24:34 +00:00
Updated docs to include device and swapchain deletion.
Fix example triangle to properly exit if swapchain recreation fails.
This commit is contained in:
parent
8a053cadc3
commit
d169f3e32d
@ -185,6 +185,11 @@ auto dev_ret = device_builder.add_pNext(&descriptor_indexing_features)
|
||||
.build ();
|
||||
```
|
||||
|
||||
To destroy a `vkb::Device`, call `vkb::destroy_device()`.
|
||||
```cpp
|
||||
vkb::destroy_device(vkb_device);
|
||||
```
|
||||
|
||||
### Queues
|
||||
|
||||
By default, `vkb::DeviceBuilder` will enable one queue from each queue family available on the `VkPhysicalDevice`. This is done because in practice, most use cases only need a single queue from each family.
|
||||
@ -245,3 +250,9 @@ if !(swap_ret){
|
||||
// Note that this is the same vkb::Swapchain which was fed into vkb::SwapchainBuilder
|
||||
vkb_swapchain = swap_ret.value();
|
||||
```
|
||||
|
||||
To destroy the swapchain, call `vkb::destroy_swapchain()`. This is null out the VkSwapchainHandle inside of it.
|
||||
|
||||
```cpp
|
||||
vkb::destroy_swapchain(vkb_swapchain);
|
||||
```
|
@ -71,20 +71,23 @@ int device_initialization (Init& init) {
|
||||
}
|
||||
|
||||
int create_swapchain (Init& init) {
|
||||
|
||||
vkb::SwapchainBuilder swapchain_builder{ init.device };
|
||||
auto swap_ret = swapchain_builder.use_default_format_selection ()
|
||||
.use_default_present_mode_selection ()
|
||||
auto swap_ret = swapchain_builder
|
||||
.set_old_swapchain (init.swapchain)
|
||||
.build ();
|
||||
static int count = 0;
|
||||
count++;
|
||||
std::cout << count << '\n';
|
||||
if (!swap_ret) {
|
||||
std::cout << swap_ret.error ().message () << " " << swap_ret.vk_result () << "\n";
|
||||
init.swapchain.swapchain = VK_NULL_HANDLE;
|
||||
return -1;
|
||||
}
|
||||
init.swapchain = swap_ret.value ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int get_queues (Init& init, RenderData& data) {
|
||||
auto gq = init.device.get_queue (vkb::QueueType::graphics);
|
||||
if (!gq.has_value ()) {
|
||||
@ -442,11 +445,7 @@ int recreate_swapchain (Init& init, RenderData& data) {
|
||||
|
||||
init.swapchain.destroy_image_views (data.swapchain_image_views);
|
||||
|
||||
int created_swapchain = create_swapchain (init);
|
||||
while (created_swapchain != 0) {
|
||||
init.swapchain.swapchain = VK_NULL_HANDLE;
|
||||
created_swapchain = create_swapchain (init);
|
||||
}
|
||||
if (0 != create_swapchain (init)) return -1;
|
||||
if (0 != create_framebuffers (init, data)) return -1;
|
||||
if (0 != create_command_pool (init, data)) return -1;
|
||||
if (0 != create_command_buffers (init, data)) return -1;
|
||||
@ -466,9 +465,8 @@ int draw_frame (Init& init, RenderData& data) {
|
||||
|
||||
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
return recreate_swapchain (init, data);
|
||||
return 0;
|
||||
} else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) {
|
||||
std::cout << "failed to recreate swapchain. Error " << result << "\n";
|
||||
std::cout << "failed to acquire swapchain image. Error " << result << "\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -515,7 +513,6 @@ int draw_frame (Init& init, RenderData& data) {
|
||||
result = vkQueuePresentKHR (data.present_queue, &present_info);
|
||||
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
|
||||
return recreate_swapchain (init, data);
|
||||
return 0;
|
||||
} else if (result != VK_SUCCESS) {
|
||||
std::cout << "failed to present swapchain image\n";
|
||||
return -1;
|
||||
|
@ -1292,9 +1292,11 @@ VkExtent2D find_extent (
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
void destroy_swapchain (Swapchain const& swapchain) {
|
||||
if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE)
|
||||
void destroy_swapchain (Swapchain& swapchain) {
|
||||
if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE) {
|
||||
vkDestroySwapchainKHR (swapchain.device, swapchain.swapchain, swapchain.allocation_callbacks);
|
||||
swapchain.swapchain = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
SwapchainBuilder::SwapchainBuilder (Device const& device) {
|
||||
|
@ -528,7 +528,7 @@ struct Swapchain {
|
||||
void destroy_image_views (std::vector<VkImageView> const& image_views);
|
||||
};
|
||||
|
||||
void destroy_swapchain (Swapchain const& swapchain);
|
||||
void destroy_swapchain (Swapchain & swapchain);
|
||||
|
||||
class SwapchainBuilder {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user