Search code examples
vulkanframebuffer

Do I need a VkFramebuffer for each VkImageView?


I am following this tutorial to learn Vulkan: https://vulkan-tutorial.com .

I am at the Framebuffers section: https://vulkan-tutorial.com/en/Drawing_a_triangle/Drawing/Framebuffers.

It appears as if the author is binding a different VkFramebuffer per VkImageView previously created. He had created 3 VkImageViews so now he created 3 VkFramebuffers. Is this necessary?

The tutorials says this:

You can only use a framebuffer with the render passes that it is compatible with, which roughly means that they use the same number and type of attachments.

Does this mean I can create one VkFramebuffer which contains all created VkImageViews instead as long as I specify that in the renderpass?


Solution

  • Perhaps you are confused as to what the code is doing.

    To render to a VkFramebuffer means to starting a render pass using that framebuffer to provide the attachments for the render pass. All the attachments. If you have a framebuffer with 3 attachments, that means you have a render pass that has 3 attachments, and that you're rendering to all of them (during the render pass; individual subpass render to a subset of the attachments).

    But that's not what this code is doing. This code wants to render to different images at different times. So on one frame, it renders to one image, on the next frame, it renders to a different image, and so on.

    To do that, you need different VkFramebuffer objects.