@@ -85,7 +85,7 @@ Enabling the extension just requires a small change to the logical device
8585creation structure:
8686
8787``` c++
88- createInfo.enabledExtensionCount = deviceExtensions.size();
88+ createInfo.enabledExtensionCount = static_cast < uint32_t >( deviceExtensions.size() );
8989createInfo.ppEnabledExtensionNames = deviceExtensions.data();
9090```
9191
@@ -531,26 +531,32 @@ be specified in this field. This is a complex topic that we'll learn more about
531531in [ a future chapter] ( !Drawing_a_triangle/Swap_chain_recreation ) . For now we'll
532532assume that we'll only ever create one swap chain.
533533
534- Now add a class member to store the ` VkSwapchainKHR ` object with a proper
535- deleter. Make sure to add it after ` device ` so that it gets cleaned up before
536- the logical device is.
534+ Now add a class member to store the ` VkSwapchainKHR ` object:
537535
538536``` c++
539- VDeleter< VkSwapchainKHR> swapChain{device, vkDestroySwapchainKHR} ;
537+ VkSwapchainKHR swapChain;
540538```
541539
542- Now creating the swap chain is as simple as calling `vkCreateSwapchainKHR`:
540+ Creating the swap chain is now as simple as calling ` vkCreateSwapchainKHR ` :
543541
544542``` c++
545- if (vkCreateSwapchainKHR(device, &createInfo, nullptr, swapChain.replace() ) != VK_SUCCESS) {
543+ if (vkCreateSwapchainKHR(device, &createInfo, nullptr , & swapChain) != VK_SUCCESS) {
546544 throw std::runtime_error("failed to create swap chain!");
547545}
548546```
549547
550548The parameters are the logical device, swap chain creation info, optional custom
551549allocators and a pointer to the variable to store the handle in. No surprises
552- there. Now run the application to ensure that the swap chain is created
553- successfully!
550+ there. It should be cleaned up using ` vkDestroySwapchainKHR ` before the device:
551+
552+ ``` c++
553+ void cleanup () {
554+ vkDestroySwapchainKHR (device, swapChain, nullptr);
555+ ...
556+ }
557+ ```
558+
559+ Now run the application to ensure that the swap chain is created successfully!
554560
555561Try removing the ` createInfo.imageExtent = extent; ` line with validation layers
556562enabled. You'll see that one of the validation layers immediately catches the
@@ -570,7 +576,7 @@ std::vector<VkImage> swapChainImages;
570576
571577The images were created by the implementation for the swap chain and they will
572578be automatically cleaned up once the swap chain has been destroyed, therefore we
573- don't need a deleter here .
579+ don't need to add any cleanup code .
574580
575581I'm adding the code to retrieve the handles to the end of the ` createSwapChain `
576582function, right after the ` vkCreateSwapchainKHR ` call. Retrieving them is very
@@ -593,7 +599,7 @@ One last thing, store the format and extent we've chosen for the swap chain
593599images in member variables. We'll need them in future chapters.
594600
595601```c++
596- VDeleter< VkSwapchainKHR> swapChain{device, vkDestroySwapchainKHR} ;
602+ VkSwapchainKHR swapChain;
597603std::vector<VkImage> swapChainImages;
598604VkFormat swapChainImageFormat;
599605VkExtent2D swapChainExtent;
@@ -605,7 +611,8 @@ swapChainExtent = extent;
605611```
606612
607613We now have a set of images that can be drawn onto and can be presented to the
608- window. The next two chapters will cover how we can set up the images as render
609- targets and then we start looking into the actual drawing commands!
614+ window. The next chapter will begin to cover how we can set up the images as
615+ render targets and then we start looking into the actual graphics pipeline and
616+ drawing commands!
610617
611618[ C++ code] ( /code/swap_chain_creation.cpp )
0 commit comments