Drawing an indexed geometry
Quite often it is more convenient to reuse vertices stored in a vertex buffer. Like the corners of a cube which belong to multiple sides, vertices in arbitrary geometry may belong to many parts of the whole model. Drawing the object one vertex after another would require us to store the same vertex (along with all its attributes) multiple times. A better solution is to indicate which vertices should be used for drawing, no matter how they are ordered in the vertex buffer. For this purpose, indexed drawing was introduced in the Vulkan API. To draw geometry using indices stored in an index buffer, we need to call the vkCmdDrawIndexed()
function.
How to do it...
- Create a variable of type
VkCommandBuffer
namedcommand_buffer
, in which store the handle of a command buffer. Make sure the command buffer is in the recording state. - Initialize a variable of type
uint32_t
namedindex_count
with the number of indices (and vertices) that should be drawn. - Use the number of instances...