Clearing render pass attachments
There are situations in which we cannot rely only on implicit attachment clearings performed as initial render pass operations, and we need to clear attachments explicitly in one of the sub-passes. We can do this by calling a vkCmdClearAttachments()
function.
How to do it...
- Take a command buffer that is in a recording state and store its handle in a variable of type
VkCommandBuffer
namedcommand_buffer
. - Create a vector variable of type
std::vector<VkClearAttachment>
namedattachments
. For eachframebuffer
attachment that should be cleared inside a current sub-pass of a render pass, add an element to the vector and initialize it with the following values:- The attachment's aspect (color, depth, or stencil) for
aspectMask
- If
aspectMask
is set toVK_IMAGE_ASPECT_COLOR_BIT
, specify an index of a color attachment in the current sub-pass forcolorAttachment
; otherwise, this parameter is ignored - A desired clear value for a color, depth, or stencil aspect for
clearValue...
- The attachment's aspect (color, depth, or stencil) for