| 295 | } |
| 296 | |
| 297 | void vkRenderer::createSwapChain() { |
| 298 | SwapChainSupportDetails swapChainSupport = querySwapChainSupport(physicalDevice); |
| 299 | |
| 300 | VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapChainSupport.formats); |
| 301 | VkPresentModeKHR presentMode = chooseSwapPresentMode(swapChainSupport.presentModes); |
| 302 | VkExtent2D extent = chooseSwapExtent(swapChainSupport.capabilities); |
| 303 | |
| 304 | uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1; |
| 305 | if (swapChainSupport.capabilities.maxImageCount > 0 && imageCount > swapChainSupport.capabilities.maxImageCount) { |
| 306 | imageCount = swapChainSupport.capabilities.maxImageCount; |
| 307 | } |
| 308 | |
| 309 | VkSwapchainCreateInfoKHR createInfo = {}; |
| 310 | createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 311 | createInfo.surface = surface; |
| 312 | |
| 313 | createInfo.minImageCount = imageCount; |
| 314 | createInfo.imageFormat = surfaceFormat.format; |
| 315 | createInfo.imageColorSpace = surfaceFormat.colorSpace; |
| 316 | createInfo.imageExtent = extent; |
| 317 | createInfo.imageArrayLayers = 1; |
| 318 | createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 319 | |
| 320 | QueueFamilyIndices indices = findQueueFamilies(physicalDevice); |
| 321 | uint32_t queueFamilyIndices[] = {(uint32_t) indices.graphicsFamily, (uint32_t) indices.presentFamily}; |
| 322 | |
| 323 | if (indices.graphicsFamily != indices.presentFamily) { |
| 324 | createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 325 | createInfo.queueFamilyIndexCount = 2; |
| 326 | createInfo.pQueueFamilyIndices = queueFamilyIndices; |
| 327 | } else { |
| 328 | createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 329 | } |
| 330 | |
| 331 | createInfo.preTransform = swapChainSupport.capabilities.currentTransform; |
| 332 | createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; |
| 333 | createInfo.presentMode = presentMode; |
| 334 | createInfo.clipped = VK_TRUE; |
| 335 | |
| 336 | if (vkCreateSwapchainKHR(device, &createInfo, nullptr, &swapChain) != VK_SUCCESS) { |
| 337 | throw std::runtime_error("failed to create swap chain!"); |
| 338 | } |
| 339 | |
| 340 | vkGetSwapchainImagesKHR(device, swapChain, &imageCount, nullptr); |
| 341 | swapChainImages.resize(imageCount); |
| 342 | vkGetSwapchainImagesKHR(device, swapChain, &imageCount, swapChainImages.data()); |
| 343 | |
| 344 | swapChainImageFormat = surfaceFormat.format; |
| 345 | swapChainExtent = extent; |
| 346 | } |
| 347 | |
| 348 | void vkRenderer::createImageViews() { |
| 349 | swapChainImageViews.resize(swapChainImages.size()); |
nothing calls this directly
no outgoing calls
no test coverage detected