Swapchains

Swapchains manage the set of images which will be presented to the surface

In OpenGL ES, the process of rendering onscreen starts with acquiring the device context associated with the window. This is then followed by defining how to present the image on the screen, including finding out the format of the window and what capabilities it supports. Finally, a rendering context is created and activated.

In Vulkan, the process is slightly different. After creating an instance and selecting a physical and logical device, a swapchain must be created. A swapchain contains a collection of framebuffers, called images, that can be thought of as the individual frames of the application. The application retrieves these images, renders to them, and then returns them to their place in the swapchain.

Creating a swapchain

Like other Vulkan objects, a swapchain need to be setup in advance, with its features specified in an info struct. These include properties like the size of its images, the format of its images, the presentation mode, and so on. The presentation mode of the swapchain is very important as it determines the order in which the images will be presented to the surface.

The swapchain cannot be modified on-the-fly, so if, for example, the surface size is changed during runtime, the swapchain needs to be destroyed and recreated.

It is important to note again that a Vulkan application may not even need to render anything at all, so would not require a surface or any images. It is for this reason a swapchain functionality is found in an extension (VK_KHR_swapchain).