|
3 | 3 | #include <quark/vk/presentation/presenter_bundle.hpp> |
4 | 4 | #include <quark/vk/surface_source.hpp> |
5 | 5 |
|
6 | | -#include <exception> |
7 | | - |
8 | 6 | namespace quark::vk { |
9 | 7 |
|
10 | 8 | namespace { |
@@ -53,52 +51,43 @@ util::Status PresenterBundle::create(const CreateInfo &ci) { |
53 | 51 |
|
54 | 52 | QUARK_TRY_ASSIGN(surface_, create_surface(ci.instance, ci.window)); |
55 | 53 |
|
56 | | - auto swapchain_res = create_swapchain_(VK_NULL_HANDLE); |
57 | | - if (!swapchain_res) { |
| 54 | + Swapchain::CreateInfo sci{}; |
| 55 | + sci.physical_device = ci.physical_device; |
| 56 | + sci.device = ci.device; |
| 57 | + sci.surface = surface_; |
| 58 | + sci.graphics_queue_family_index = ci.graphics_queue_family_index; |
| 59 | + sci.present_queue_family_index = ci.present_queue_family_index; |
| 60 | + sci.window = ci.window; |
| 61 | + sci.old_swapchain = VK_NULL_HANDLE; |
| 62 | + sci.preferred_present_mode = ci.preferred_present_mode; |
| 63 | + sci.preferred_format = ci.preferred_format; |
| 64 | + sci.preferred_color_space = ci.preferred_color_space; |
| 65 | + |
| 66 | + if (auto res = swapchain_.create(sci); !res) { |
58 | 67 | destroy_surface(ci.instance, surface_); |
59 | | - return util::unexpected(std::move(swapchain_res.error())); |
| 68 | + return util::unexpected(std::move(res.error())); |
60 | 69 | } |
61 | 70 |
|
62 | | - swapchain_ = std::move(swapchain_res.value()); |
63 | 71 | QUARK_OK(); |
64 | 72 | } |
65 | 73 |
|
66 | | -util::Result<Swapchain> |
67 | | -PresenterBundle::create_swapchain_(VkSwapchainKHR old_swapchain) const { |
68 | | - QUARK_ENSURE( |
69 | | - surface_ != VK_NULL_HANDLE, |
70 | | - QUARK_ERR(util::Errc::InvalidState, "presenter surface is null")); |
71 | | - |
72 | | - Swapchain swapchain; |
73 | | - Swapchain::CreateInfo ci{}; |
74 | | - ci.physical_device = create_info_.physical_device; |
75 | | - ci.device = create_info_.device; |
76 | | - ci.surface = surface_; |
77 | | - ci.graphics_queue_family_index = create_info_.graphics_queue_family_index; |
78 | | - ci.present_queue_family_index = create_info_.present_queue_family_index; |
79 | | - ci.window = create_info_.window; |
80 | | - ci.old_swapchain = old_swapchain; |
81 | | - ci.preferred_present_mode = create_info_.preferred_present_mode; |
82 | | - ci.preferred_format = create_info_.preferred_format; |
83 | | - ci.preferred_color_space = create_info_.preferred_color_space; |
84 | | - |
85 | | - try { |
86 | | - swapchain.create(ci); |
87 | | - } catch (const std::exception &e) { |
88 | | - QUARK_FAIL(QUARK_ERR(util::Errc::ApiError, |
89 | | - "PresenterBundle::create_swapchain_ failed: {}", |
90 | | - e.what())); |
91 | | - } |
92 | | - |
93 | | - return swapchain; |
94 | | -} |
95 | | - |
96 | 74 | util::Status PresenterBundle::recreate_swapchain() { |
97 | | - auto *old_swapchain = swapchain_.handle(); |
| 75 | + VkSwapchainKHR old_handle = swapchain_.handle(); |
| 76 | + |
| 77 | + Swapchain::CreateInfo sci{}; |
| 78 | + sci.physical_device = create_info_.physical_device; |
| 79 | + sci.device = create_info_.device; |
| 80 | + sci.surface = surface_; |
| 81 | + sci.graphics_queue_family_index = create_info_.graphics_queue_family_index; |
| 82 | + sci.present_queue_family_index = create_info_.present_queue_family_index; |
| 83 | + sci.window = create_info_.window; |
| 84 | + sci.old_swapchain = old_handle; |
| 85 | + sci.preferred_present_mode = create_info_.preferred_present_mode; |
| 86 | + sci.preferred_format = create_info_.preferred_format; |
| 87 | + sci.preferred_color_space = create_info_.preferred_color_space; |
98 | 88 |
|
99 | 89 | Swapchain next_swapchain; |
100 | | - QUARK_TRY_ASSIGN(next_swapchain, create_swapchain_(old_swapchain)); |
101 | | - |
| 90 | + QUARK_TRY_STATUS(next_swapchain.create(sci)); |
102 | 91 | swapchain_ = std::move(next_swapchain); |
103 | 92 | QUARK_OK(); |
104 | 93 | } |
|
0 commit comments