Lesson 6 text and code mismatch
I'll try to keep this in some kind of order but it's not always easy when you have to bounce around between sections to make sense of the text.
BTW this program makes a seg fault when it closes.
Checking for Swap Chain Support
The text calls it "deviceExtension", the code calls it "requiredDeviceExtension". I think this mismatch actuallys goes back to a prior lesson.
Enabling Device Extensions
Mismatch with what's in "createLogicalDevice()". Also, there is no change here from the code in previous lessons, this section feels vestigial.
Querying details of swap chain support
Another instance of what seems like vestigial references to the C API.
This function takes the specified VkPhysicalDevice and VkSurfaceKHR window surface into account when determining the supported capabilities. All the support querying functions have these two as first parameters because they are the core components of the swap chain.
But the actual call is the C++ version:
auto surfaceCapabilities = physicalDevice.getSurfaceCapabilitiesKHR( surface );
I believe lesson 4 had a similar C/C++ mismatch but I forgot to make a note.
Eventually I get to draw some triangles, right? I kid I kid.
Also this section is hard to follow. We're being told about a bunch of function calls and definitions we could/should make but in isolation, and only in the last half of lesson do we get told how it comes together. So if I'm sitting here trying to follow along in my own code, I don't know what goes where and I have to keep peeking ahead. Only by scrolling halfway through do I find that the above line goes in a function called "createSwapChain()" I need to write.
The earlier lessons had the better approach IMO: fill out skeletons with empty function bodies and then fill in details as you go. Here it's hard to "follow along" because I basically have to look at the completed code to know where the code snippets I'm typing ought to go. I hope I'm not being too harsh or belaboring the point here.
Also this sentence:
Make sure that the vector is resized to hold all the available formats.
About this line:
std::vector<vk::SurfaceFormatKHR> availableFormats = physicalDevice.getSurfaceFormatsKHR( surface );
I'm not clear what I'm being told to do here. Does .getSurfaceFormatsKHR not return a fully-instantiated vector?
Creating the swap chain
It's almost to the end where we actually declare the member object. This is minor, but previous lessons would have you create the relevant object as a class member near the beginning of the lesson. Just like with the code-skeleton-gradually-filled-in approach, I like it because you see the building process and I think you learn it better. Doing things out of order kind of feels like following instructions to build a pyramid that starts with the top stone. A practical reason for doing this is that towards the very end of this section, we're told:
Now run the application to ensure that the swap chain is created successfully!
Before we're told to add class members like std::vector<vk::Image> swapChainImages that allow the code to compile in the next section. While we're at it, the code adds a class member std::vector<vk::raii::ImageView> swapChainImageViews; which isn't mentioned in the text or used at all elsewhere in the code. I assume it's vestigial or explained in a future lesson?
Also the tutorial mentions a .oldSwapChain in the swapChainCreateInfo struct, but the code doesn't. Is it still important to have?
Another C API reference, to the enum VK_IMAGE_USAGE_TRANSFER_DST_BIT with no C++ equivalent listed. There are others too (search for "VK_").
The code block in the text that starts with...
uint32_t queueFamilyIndices[] = {graphicsFamily, presentFamily};
...isn't present in the code. Also, in this part of the text the references to "createInfo" seem to be for what is "swapChainCreateInfo" in the code. And this one in particular:
createInfo.presentMode = presentMode;
Doesn't match what is in the code, which is:
...
.presentMode = chooseSwapPresentMode(physicalDevice.getSurfacePresentModesKHR( surface )),
...
More language referring to the C API:
The parameters are the logical device, swap chain creation info, optional custom allocators and a pointer to the variable to store the handle in.
The function "chooseSwapSurfaceFormat" is completely different in the code than in the text (including return type). Also in the code it's static, might want to explain why. Same goes for "chooseSwapPresentMode".
It was during this lesson that I noticed the body of the function debugCallback changed from what I had copied from the text, before I started looking for discrepancies. Don't know if it's my error or not, too lazy to go look.
Retrieving the swap chain images
The last two lines of the last code block are different from what's in the code.