@@ -20,6 +20,7 @@ VkSurfaceKHR surface;
2020VulkanSwapchain swapchain;
2121VkRenderPass renderPass;
2222std::vector<VulkanImage> depthBuffers;
23+ std::vector<VulkanImage> colorBuffers;
2324std::vector<VkFramebuffer> framebuffers;
2425VkCommandPool commandPools[FRAMES_IN_FLIGHT];
2526VkCommandBuffer commandBuffers[FRAMES_IN_FLIGHT];
@@ -84,19 +85,26 @@ void recreateRenderPass() {
8485 for (uint32_t i = 0 ; i < depthBuffers.size (); ++i) {
8586 destroyImage (context, &depthBuffers[i]);
8687 }
88+ for (uint32_t i = 0 ; i < colorBuffers.size (); ++i) {
89+ destroyImage (context, &colorBuffers[i]);
90+ }
8791 destroyRenderpass (context, renderPass);
8892 }
8993 framebuffers.clear ();
9094 depthBuffers.clear ();
95+ colorBuffers.clear ();
9196
92- renderPass = createRenderPass (context, swapchain.format );
97+ renderPass = createRenderPass (context, swapchain.format , VK_SAMPLE_COUNT_4_BIT );
9398 framebuffers.resize (swapchain.images .size ());
9499 depthBuffers.resize (swapchain.images .size ());
100+ colorBuffers.resize (swapchain.images .size ());
95101 for (uint32_t i = 0 ; i < swapchain.images .size (); ++i) {
96- createImage (context, &depthBuffers.data ()[i], swapchain.width , swapchain.height , VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
102+ createImage (context, &depthBuffers.data ()[i], swapchain.width , swapchain.height , VK_FORMAT_D32_SFLOAT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_SAMPLE_COUNT_4_BIT);
103+ createImage (context, &colorBuffers.data ()[i], swapchain.width , swapchain.height , swapchain.format , VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_SAMPLE_COUNT_4_BIT);
97104 VkImageView attachments[] = {
98- swapchain. imageViews [i],
105+ colorBuffers [i]. view ,
99106 depthBuffers[i].view ,
107+ swapchain.imageViews [i],
100108 };
101109 VkFramebufferCreateInfo createInfo = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO };
102110 createInfo.renderPass = renderPass;
@@ -536,6 +544,10 @@ void shutdownApplication() {
536544 for (uint32_t i = 0 ; i < depthBuffers.size (); ++i) {
537545 destroyImage (context, &depthBuffers[i]);
538546 }
547+ for (uint32_t i = 0 ; i < colorBuffers.size (); ++i) {
548+ destroyImage (context, &colorBuffers[i]);
549+ }
550+ colorBuffers.clear ();
539551 depthBuffers.clear ();
540552 destroyRenderpass (context, renderPass);
541553 destroySwapchain (context, &swapchain);
0 commit comments