@@ -130,9 +130,9 @@ running at once. The depth image will again require the trifecta of resources:
130130image, memory and image view.
131131
132132``` c++
133- VDeleter< VkImage> depthImage{device, vkDestroyImage} ;
134- VDeleter< VkDeviceMemory > depthImageMemory{device, vkFreeMemory} ;
135- VDeleter< VkImageView > depthImageView{device, vkDestroyImageView} ;
133+ VkImage depthImage;
134+ VkDeviceMemory depthImageMemory;
135+ VkImageView depthImageView;
136136```
137137
138138Create a new function ` createDepthResources ` to set up these resources:
@@ -272,15 +272,15 @@ We now have all the required information to invoke our `createImage` and
272272
273273``` c++
274274createImage (swapChainExtent.width, swapChainExtent.height, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, depthImage, depthImageMemory);
275- createImageView(depthImage, depthFormat, depthImageView );
275+ depthImageView = createImageView(depthImage, depthFormat);
276276```
277277
278278However, the `createImageView` function currently assumes that the subresource
279279is always the `VK_IMAGE_ASPECT_COLOR_BIT`, so we will need to turn that field
280280into a parameter:
281281
282282```c++
283- void createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, VDeleter<VkImageView>& imageView ) {
283+ VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags) {
284284 ...
285285 viewInfo.subresourceRange.aspectMask = aspectFlags;
286286 ...
@@ -290,11 +290,11 @@ void createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFl
290290Update all calls to this function to use the right aspect:
291291
292292``` c++
293- createImageView (swapChainImages[ i] , swapChainImageFormat, VK_IMAGE_ASPECT_COLOR_BIT, swapChainImageViews [ i ] );
293+ swapChainImageViews[i] = createImageView(swapChainImages[i], swapChainImageFormat, VK_IMAGE_ASPECT_COLOR_BIT);
294294...
295- createImageView(depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, depthImageView );
295+ depthImageView = createImageView(depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT);
296296...
297- createImageView(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT, textureImageView );
297+ textureImageView = createImageView(textureImage, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT);
298298```
299299
300300That's it for creating the depth image. We don't need to map it or copy another
@@ -396,7 +396,7 @@ buffers.
396396std::array<VkAttachmentDescription, 2 > attachments = {colorAttachment, depthAttachment};
397397VkRenderPassCreateInfo renderPassInfo = {};
398398renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
399- renderPassInfo.attachmentCount = attachments.size();
399+ renderPassInfo.attachmentCount = static_cast<uint32_t>( attachments.size() );
400400renderPassInfo.pAttachments = attachments.data();
401401renderPassInfo.subpassCount = 1;
402402renderPassInfo.pSubpasses = &subpass;
@@ -422,7 +422,7 @@ std::array<VkImageView, 2> attachments = {
422422VkFramebufferCreateInfo framebufferInfo = {};
423423framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
424424framebufferInfo.renderPass = renderPass;
425- framebufferInfo.attachmentCount = attachments.size();
425+ framebufferInfo.attachmentCount = static_cast<uint32_t>( attachments.size() );
426426framebufferInfo.pAttachments = attachments.data();
427427framebufferInfo.width = swapChainExtent.width;
428428framebufferInfo.height = swapChainExtent.height;
@@ -456,7 +456,7 @@ std::array<VkClearValue, 2> clearValues = {};
456456clearValues[0 ].color = {0.0f, 0.0f, 0.0f, 1.0f};
457457clearValues[ 1] .depthStencil = {1.0f, 0};
458458
459- renderPassInfo.clearValueCount = clearValues.size();
459+ renderPassInfo.clearValueCount = static_cast<uint32_t>( clearValues.size() );
460460renderPassInfo.pClearValues = clearValues.data();
461461```
462462
@@ -548,6 +548,18 @@ void recreateSwapChain() {
548548}
549549```
550550
551+ The cleanup operations should happen in the swap chain cleanup function:
552+
553+ ``` c++
554+ void cleanupSwapChain () {
555+ vkDestroyImageView (device, depthImageView, nullptr);
556+ vkDestroyImage(device, depthImage, nullptr);
557+ vkFreeMemory(device, depthImageMemory, nullptr);
558+
559+ ...
560+ }
561+ ```
562+
551563Congratulations, your application is now finally ready to render arbitrary 3D
552564geometry and have it look right. We're going to try this out in the next chapter
553565by drawing a textured model!
0 commit comments