@@ -170,17 +170,17 @@ class HelloTriangleApplication {
170170
171171 VkCommandPool commandPool;
172172
173- VkImage colorImage ;
174- VkDeviceMemory colorImageMemory ;
175- VkImageView colorImageView ;
173+ std::vector< VkImage> colorImages ;
174+ std::vector< VkDeviceMemory> colorImagesMemory ;
175+ std::vector< VkImageView> colorImageViews ;
176176
177- VkImage depthMsaaImage ;
178- VkDeviceMemory depthMsaaImageMemory ;
179- VkImageView depthMsaaImageView ;
177+ std::vector< VkImage> depthMsaaImages ;
178+ std::vector< VkDeviceMemory> depthMsaaImagesMemory ;
179+ std::vector< VkImageView> depthMsaaImagesView ;
180180
181- VkImage depthImage ;
182- VkDeviceMemory depthImageMemory ;
183- VkImageView depthImageView ;
181+ std::vector< VkImage> depthImages ;
182+ std::vector< VkDeviceMemory> depthImagesMemory ;
183+ std::vector< VkImageView> depthImagesView ;
184184
185185 uint32_t mipLevels;
186186 VkImage textureImage;
@@ -263,15 +263,17 @@ class HelloTriangleApplication {
263263 }
264264
265265 void cleanupSwapChain () {
266- vkDestroyImageView (device, colorImageView, nullptr );
267- vkDestroyImage (device, colorImage, nullptr );
268- vkFreeMemory (device, colorImageMemory, nullptr );
269- vkDestroyImageView (device, depthMsaaImageView, nullptr );
270- vkDestroyImage (device, depthMsaaImage, nullptr );
271- vkFreeMemory (device, depthMsaaImageMemory, nullptr );
272- vkDestroyImageView (device, depthImageView, nullptr );
273- vkDestroyImage (device, depthImage, nullptr );
274- vkFreeMemory (device, depthImageMemory, nullptr );
266+ for (size_t i = 0 ; i < swapChainImages.size (); i++) {
267+ vkDestroyImageView (device, colorImageViews[i], nullptr );
268+ vkDestroyImage (device, colorImages[i], nullptr );
269+ vkFreeMemory (device, colorImagesMemory[i], nullptr );
270+ vkDestroyImageView (device, depthMsaaImagesView[i], nullptr );
271+ vkDestroyImage (device, depthMsaaImages[i], nullptr );
272+ vkFreeMemory (device, depthMsaaImagesMemory[i], nullptr );
273+ vkDestroyImageView (device, depthImagesView[i], nullptr );
274+ vkDestroyImage (device, depthImages[i], nullptr );
275+ vkFreeMemory (device, depthImagesMemory[i], nullptr );
276+ }
275277
276278 for (auto framebuffer : swapChainFramebuffers) {
277279 vkDestroyFramebuffer (device, framebuffer, nullptr );
@@ -778,10 +780,10 @@ class HelloTriangleApplication {
778780
779781 for (size_t i = 0 ; i < swapChainImageViews.size (); i++) {
780782 std::array<VkImageView, 4 > attachments = {
781- colorImageView ,
782- depthMsaaImageView ,
783+ colorImageViews[i] ,
784+ depthMsaaImagesView[i] ,
783785 swapChainImageViews[i],
784- depthImageView
786+ depthImagesView[i]
785787 };
786788
787789 VkFramebufferCreateInfo framebufferInfo = {};
@@ -814,24 +816,39 @@ class HelloTriangleApplication {
814816 void createColorResources () {
815817 VkFormat colorFormat = swapChainImageFormat;
816818
817- createImage (swapChainExtent.width , swapChainExtent.height , 1 , msaaSamples, colorFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, colorImage, colorImageMemory);
818- colorImageView = createImageView (colorImage, colorFormat, VK_IMAGE_ASPECT_COLOR_BIT, 1 );
819+ colorImages.resize (swapChainImages.size ());
820+ colorImagesMemory.resize (swapChainImages.size ());
821+ colorImageViews.resize (swapChainImages.size ());
822+
823+ for (size_t i = 0 ; i < swapChainImageViews.size (); i++) {
824+ createImage (swapChainExtent.width , swapChainExtent.height , 1 , msaaSamples, colorFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, colorImages[i], colorImagesMemory[i]);
825+ colorImageViews[i] = createImageView (colorImages[i], colorFormat, VK_IMAGE_ASPECT_COLOR_BIT, 1 );
819826
820- transitionImageLayout (colorImage, colorFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1 );
827+ transitionImageLayout (colorImages[i], colorFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1 );
828+ }
821829 }
822830
823831 void createDepthResources () {
824832 VkFormat depthFormat = findDepthFormat ();
825833
826- createImage (swapChainExtent.width , swapChainExtent.height , 1 , VK_SAMPLE_COUNT_1_BIT, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, depthImage, depthImageMemory);
827- depthImageView = createImageView (depthImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, 1 );
834+ depthImages.resize (swapChainImages.size ());
835+ depthImagesMemory.resize (swapChainImages.size ());
836+ depthImagesView.resize (swapChainImages.size ());
837+ depthMsaaImages.resize (swapChainImages.size ());
838+ depthMsaaImagesMemory.resize (swapChainImages.size ());
839+ depthMsaaImagesView.resize (swapChainImages.size ());
840+
841+ for (size_t i = 0 ; i < swapChainImageViews.size (); i++) {
842+ createImage (swapChainExtent.width , swapChainExtent.height , 1 , VK_SAMPLE_COUNT_1_BIT, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, depthImages[i], depthImagesMemory[i]);
843+ depthImagesView[i] = createImageView (depthImages[i], depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, 1 );
828844
829- transitionImageLayout (depthImage , depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1 );
845+ transitionImageLayout (depthImages[i] , depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1 );
830846
831- createImage (swapChainExtent.width , swapChainExtent.height , 1 , msaaSamples, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, depthMsaaImage, depthMsaaImageMemory );
832- depthMsaaImageView = createImageView (depthMsaaImage , depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, 1 );
847+ createImage (swapChainExtent.width , swapChainExtent.height , 1 , msaaSamples, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, depthMsaaImages[i], depthMsaaImagesMemory[i] );
848+ depthMsaaImagesView[i] = createImageView (depthMsaaImages[i] , depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, 1 );
833849
834- transitionImageLayout (depthMsaaImage, depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1 );
850+ transitionImageLayout (depthMsaaImages[i], depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1 );
851+ }
835852 }
836853
837854 VkFormat findSupportedFormat (const std::vector<VkFormat>& candidates, VkImageTiling tiling, VkFormatFeatureFlags features) {
0 commit comments