mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 23:24:34 +00:00
Added new constructor to SwapchainBuilder
It is now possible to pass in a vkb::Device and a VkSurfaceKHR handle into the swapchain builder, and it will correctly get the queue indexes necessary to create a swapchain. This solved the 'delayed surface initialization' problem
This commit is contained in:
parent
ace1ccf854
commit
d99c378eea
@ -233,6 +233,8 @@ const char* to_string (DeviceError err) {
|
|||||||
}
|
}
|
||||||
const char* to_string (SwapchainError err) {
|
const char* to_string (SwapchainError err) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
|
case SwapchainError::surface_handle_not_provided:
|
||||||
|
return "surface_handle_not_provided";
|
||||||
case SwapchainError::failed_query_surface_support_details:
|
case SwapchainError::failed_query_surface_support_details:
|
||||||
return "failed_query_surface_support_details";
|
return "failed_query_surface_support_details";
|
||||||
case SwapchainError::failed_create_swapchain:
|
case SwapchainError::failed_create_swapchain:
|
||||||
@ -1191,6 +1193,18 @@ SwapchainBuilder::SwapchainBuilder (Device const& device) {
|
|||||||
info.graphics_queue_index = present.value ();
|
info.graphics_queue_index = present.value ();
|
||||||
info.present_queue_index = graphics.value ();
|
info.present_queue_index = graphics.value ();
|
||||||
}
|
}
|
||||||
|
SwapchainBuilder::SwapchainBuilder (Device const& device, VkSurfaceKHR const surface) {
|
||||||
|
info.device = device.device;
|
||||||
|
info.physical_device = device.physical_device.physical_device;
|
||||||
|
info.surface = surface;
|
||||||
|
Device temp_device = device;
|
||||||
|
temp_device.surface = surface;
|
||||||
|
auto present = temp_device.get_queue_index (QueueType::present);
|
||||||
|
auto graphics = temp_device.get_queue_index (QueueType::graphics);
|
||||||
|
// TODO: handle error of queue's not available
|
||||||
|
info.graphics_queue_index = present.value ();
|
||||||
|
info.present_queue_index = graphics.value ();
|
||||||
|
}
|
||||||
|
|
||||||
SwapchainBuilder::SwapchainBuilder (
|
SwapchainBuilder::SwapchainBuilder (
|
||||||
VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface) {
|
VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface) {
|
||||||
@ -1211,6 +1225,10 @@ detail::Expected<Swapchain, detail::Error<SwapchainError>> SwapchainBuilder::bui
|
|||||||
}
|
}
|
||||||
detail::Expected<Swapchain, detail::Error<SwapchainError>> SwapchainBuilder::build (
|
detail::Expected<Swapchain, detail::Error<SwapchainError>> SwapchainBuilder::build (
|
||||||
VkSwapchainKHR old_swapchain) const {
|
VkSwapchainKHR old_swapchain) const {
|
||||||
|
if (info.surface == VK_NULL_HANDLE) {
|
||||||
|
return detail::Error<SwapchainError>{ SwapchainError::surface_handle_not_provided };
|
||||||
|
}
|
||||||
|
|
||||||
auto desired_formats = info.desired_formats;
|
auto desired_formats = info.desired_formats;
|
||||||
if (desired_formats.size () == 0) add_desired_formats (desired_formats);
|
if (desired_formats.size () == 0) add_desired_formats (desired_formats);
|
||||||
auto desired_present_modes = info.desired_present_modes;
|
auto desired_present_modes = info.desired_present_modes;
|
||||||
|
@ -125,6 +125,7 @@ enum class DeviceError {
|
|||||||
failed_create_device,
|
failed_create_device,
|
||||||
};
|
};
|
||||||
enum class SwapchainError {
|
enum class SwapchainError {
|
||||||
|
surface_handle_not_present,
|
||||||
failed_query_surface_support_details,
|
failed_query_surface_support_details,
|
||||||
failed_create_swapchain,
|
failed_create_swapchain,
|
||||||
failed_get_swapchain_images,
|
failed_get_swapchain_images,
|
||||||
@ -523,6 +524,7 @@ void destroy_swapchain (Swapchain const& swapchain);
|
|||||||
class SwapchainBuilder {
|
class SwapchainBuilder {
|
||||||
public:
|
public:
|
||||||
SwapchainBuilder (Device const& device);
|
SwapchainBuilder (Device const& device);
|
||||||
|
SwapchainBuilder (Device& device, VkSurfaceKHR const surface);
|
||||||
SwapchainBuilder (VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface);
|
SwapchainBuilder (VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface);
|
||||||
|
|
||||||
detail::Expected<Swapchain, detail::Error<SwapchainError>> build () const;
|
detail::Expected<Swapchain, detail::Error<SwapchainError>> build () const;
|
||||||
|
Loading…
Reference in New Issue
Block a user