Book Image

Learning Vulkan

By : Parminder Singh
Book Image

Learning Vulkan

By: Parminder Singh

Overview of this book

Vulkan, the next generation graphics and compute API, is the latest offering by Khronos. This API is the successor of OpenGL and unlike OpenGL, it offers great flexibility and high performance capabilities to control modern GPU devices. With this book, you'll get great insights into the workings of Vulkan and how you can make stunning graphics run with minimum hardware requirements. We begin with a brief introduction to the Vulkan system and show you its distinct features with the successor to the OpenGL API. First, you will see how to establish a connection with hardware devices to query the available queues, memory types, and capabilities offered. Vulkan is verbose, so before diving deep into programing, you’ll get to grips with debugging techniques so even first-timers can overcome error traps using Vulkan’s layer and extension features. You’ll get a grip on command buffers and acquire the knowledge to record various operation commands into command buffer and submit it to a proper queue for GPU processing. We’ll take a detailed look at memory management and demonstrate the use of buffer and image resources to create drawing textures and image views for the presentation engine and vertex buffers to store geometry information. You'll get a brief overview of SPIR-V, the new way to manage shaders, and you'll define the drawing operations as a single unit of work in the Render pass with the help of attachments and subpasses. You'll also create frame buffers and build a solid graphics pipeline, as well as making use of the synchronizing mechanism to manage GPU and CPU hand-shaking. By the end, you’ll know everything you need to know to get your hands dirty with the coolest Graphics API on the block.
Table of Contents (18 chapters)
Learning Vulkan
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface

Rendering an indexed geometry


In this section, you will learn to use the vkCmdDrawIndexed() draw command. This command is used for drawing the index geometry.The vkCmdDrawIndexed() API is an index buffer's draw command. In an index buffer, each vertex is represented using an index number. This fashion of representing mesh data requires less memory and storage space to represent connected meshes when the mesh has shared vertices (such as enclosed shapes).

For example, a square geometry rendered using two triangles shares two common vertices as shown in the following example; as you can see, the first and third vertices are repeated:

static const VertexWithColor squareData[] = 
{ 
  { -0.5f,  0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0 }, 
  {  0.5f,  0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0 }, 
  {  0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0 }, 
  { -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0 }, 
}; 
 
uint16_t squareIndices[] = { 0,3,1, 3,2,1 }; ...