Book Image

Vulkan Cookbook

By : Pawel Lapinski
Book Image

Vulkan Cookbook

By: Pawel Lapinski

Overview of this book

Vulkan is the next generation graphics API released by the Khronos group. It is expected to be the successor to OpenGL and OpenGL ES, which it shares some similarities with such as its cross-platform capabilities, programmed pipeline stages, or nomenclature. Vulkan is a low-level API that gives developers much more control over the hardware, but also adds new responsibilities such as explicit memory and resources management. With it, though, Vulkan is expected to be much faster. This book is your guide to understanding Vulkan through a series of recipes. We start off by teaching you how to create instances in Vulkan and choose the device on which operations will be performed. You will then explore more complex topics such as command buffers, resources and memory management, pipelines, GLSL shaders, render passes, and more. Gradually, the book moves on to teach you advanced rendering techniques, how to draw 3D scenes, and how to improve the performance of your applications. By the end of the book, you will be familiar with the latest advanced techniques implemented with the Vulkan API, which can be used on a wide range of platforms.
Table of Contents (13 chapters)

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...

  1. Create a variable of type VkCommandBuffer named command_buffer, in which store...