| 692 | } |
| 693 | |
| 694 | VkResult CreateMainFrameBuffers(VulkanContext* context) |
| 695 | { |
| 696 | assert(context->m_SwapChain); |
| 697 | |
| 698 | // We need to create a framebuffer per swap chain image |
| 699 | // so that they can be used in different states in the rendering pipeline |
| 700 | context->m_MainFrameBuffers.SetCapacity(context->m_SwapChain->m_Images.Size()); |
| 701 | context->m_MainFrameBuffers.SetSize(context->m_SwapChain->m_Images.Size()); |
| 702 | |
| 703 | SwapChain* swapChain = context->m_SwapChain; |
| 704 | VkResult res; |
| 705 | |
| 706 | VulkanTexture* depth_stencil_texture = &context->m_MainTextureDepthStencil; |
| 707 | |
| 708 | for (uint8_t i=0; i < context->m_MainFrameBuffers.Size(); i++) |
| 709 | { |
| 710 | // All swap chain images can share the same depth buffer, |
| 711 | // that's why we create a single depth buffer at the start and reuse it. |
| 712 | // Same thing goes for the resolve buffer if we are rendering with |
| 713 | // multisampling enabled. |
| 714 | VkImageView& vk_image_view_swap = swapChain->m_ImageViews[i]; |
| 715 | VkImageView& vk_image_view_depth = depth_stencil_texture->m_Handle.m_ImageView; |
| 716 | VkImageView& vk_image_view_resolve = swapChain->m_ResolveTexture->m_Handle.m_ImageView; |
| 717 | VkImageView vk_image_attachments[3]; |
| 718 | uint8_t num_attachments; |
| 719 | |
| 720 | if (swapChain->HasMultiSampling()) |
| 721 | { |
| 722 | vk_image_attachments[0] = vk_image_view_resolve; |
| 723 | vk_image_attachments[1] = vk_image_view_depth; |
| 724 | vk_image_attachments[2] = vk_image_view_swap; |
| 725 | num_attachments = 3; |
| 726 | } |
| 727 | else |
| 728 | { |
| 729 | vk_image_attachments[0] = vk_image_view_swap; |
| 730 | vk_image_attachments[1] = vk_image_view_depth; |
| 731 | num_attachments = 2; |
| 732 | } |
| 733 | |
| 734 | res = CreateFramebuffer(context->m_LogicalDevice.m_Device, context->m_MainRenderPass, |
| 735 | swapChain->m_ImageExtent.width, swapChain->m_ImageExtent.height, |
| 736 | vk_image_attachments, num_attachments, &context->m_MainFrameBuffers[i]); |
| 737 | CHECK_VK_ERROR(res); |
| 738 | } |
| 739 | |
| 740 | return res; |
| 741 | } |
| 742 | |
| 743 | VkResult DestroyMainFrameBuffers(VulkanContext* context) |
| 744 | { |
no test coverage detected