Create frame buffers
With the backbuffers, depth render target and render pass in order, we will now create the framebuffers. Rendertargets in Vulkan are not set independently, but are instead grouped into framebuffers. This collection of render targets is static, allowing the driver implementation to make more assumptions in optimization.
The only render targets we have in this application are those associated with the back buffer and a single depth render target. Since every backbuffer image is a separate image view, we need to create a framebuffer per backbuffer. If we were to have more than one render pass or any other deviation, we would also need to create backbuffers for that combination.
for ( uint32_t i = 0; i < FRAME_BUFFER_COUNT; i++ )
{
result = vkCreateFramebuffer (
renderer->device,
&(VkFramebufferCreateInfo){
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
.pNext = NULL,
.renderPass = renderer->renderPass,
.attachmentCount = 2,
.pAttachments = (VkImageView[2]){
renderer->frameBuffers[i].imageView,
renderer->depthImageView,
},
.width = newWidth,
.height = newHeight,
.layers = 1,
},
NULL,
&renderer->frameBuffers[i].framebuffer
);
if ( result != VK_SUCCESS )
RETURN_ERROR(-1, "vkCreateFramebuffer failed (0x%08X)", (uint32_t)result);
}