MCPcopy Create free account
hub / github.com/PacktPublishing/3D-Graphics-Rendering-Cookbook / createSwapchain

Function createSwapchain

shared/UtilsVulkan.cpp:485–513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

483}
484
485VkResult createSwapchain(VkDevice device, VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t graphicsFamily, uint32_t width, uint32_t height, VkSwapchainKHR* swapchain, bool supportScreenshots)
486{
487 auto swapchainSupport = querySwapchainSupport(physicalDevice, surface);
488 auto surfaceFormat = chooseSwapSurfaceFormat(swapchainSupport.formats);
489 auto presentMode = chooseSwapPresentMode(swapchainSupport.presentModes);
490
491 const VkSwapchainCreateInfoKHR ci =
492 {
493 .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
494 .flags = 0,
495 .surface = surface,
496 .minImageCount = chooseSwapImageCount(swapchainSupport.capabilities),
497 .imageFormat = surfaceFormat.format,
498 .imageColorSpace = surfaceFormat.colorSpace,
499 .imageExtent = {.width = width, .height = height },
500 .imageArrayLayers = 1,
501 .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | (supportScreenshots ? VK_IMAGE_USAGE_TRANSFER_SRC_BIT : 0u),
502 .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
503 .queueFamilyIndexCount = 1,
504 .pQueueFamilyIndices = &graphicsFamily,
505 .preTransform = swapchainSupport.capabilities.currentTransform,
506 .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
507 .presentMode = presentMode,
508 .clipped = VK_TRUE,
509 .oldSwapchain = VK_NULL_HANDLE
510 };
511
512 return vkCreateSwapchainKHR(device, &ci, nullptr, swapchain);
513}
514
515size_t createSwapchainImages(
516 VkDevice device, VkSwapchainKHR swapchain,

Calls 4

querySwapchainSupportFunction · 0.85
chooseSwapSurfaceFormatFunction · 0.85
chooseSwapPresentModeFunction · 0.85
chooseSwapImageCountFunction · 0.85

Tested by

no test coverage detected