Search code examples
vulkanframebuffer

How, when to capture image to file from framebuffer in Vulkan


Working on Vulkan triangle render code, where I want to save rendered image to file instead of rendering to window. So when should I read the framebuffer and how to write in file. I guess need to convert pixels which are in raw RGBA format to some known BMP or PNG format.


Solution

  • After the render pass you can copy the rendered image from the framebuffer image to a VkBuffer in RGBA format which you can then map and read on the CPU.

    How to encode the image into BMP or PNG is outside the scope of Vulkan. Though for BMP you only need to create the correct header and then you can put the raw data right after it.