Render pass

Concept

It's time to start with the actual rendering. For this you will need a graphics pipeline which will utilize shaders and define what you can render with it. However before you can setup your graphics pipeline, a render pass needs to be created. But what is this render pass, you ask?

A render pass is a resource from Vulkan which will be abstracted by the VkCV framework as simple Pass handle. In Vulkan the render pass consists of different subpasses which define what the targets for our rendering are in form of attachments. Also you can define dependencies, binding points and other details but that's not important now. The VkCV framework simplifies those render passes massively but in most cases this won't matter at all.

Implementation

A Pass handle from the framework can be created by only defining the attachments via their individual formats in most cases. Including the header for the pass creation functions is necessary though.

#include <vkcv/Pass.hpp>
vkcv::PassHandle renderPass = vkcv::passSwapchain(
  core,                    // the core instance
  window.getSwapchain(),   // the swapchain from the window
  {
    vk::Format::eUndefined // the format of an attachment
  }
);

The VkCV framework gives you multiple functions to create such Pass handles. But in most cases you want to stick to the shown function. It will configure an attachment for each format in the provided vector but each vk::Format::eUndefined will be replaced by the format of the given swapchain during creation. So you don't need to store it anywhere.


You can also pass as boolean value whether you want the render pass to clear its attachments before writing to them or not. Additionally you can select a custom choice for multisampling as well. But given that our example will only have one render pass, the default values are just fine. So the attachments will be cleared as default. Keep that in mind if you add other passes which should not clear their attachments.


Depth attachment

You should notice that the example does't have any attachment for depth values. This is totally fine for the goal to draw a single triangle but in case you want to render multiple faces later on, you can adjust the code to add a depth buffer like this:

vkcv::PassHandle renderPass = vkcv::passSwapchain(
  core,                    // the core instance
  window.getSwapchain(),   // the swapchain from the window
  {
    vk::Format::eUndefined, // the format of the windows surface
    vk::Format::eD32Sfloat  // the format of some depth buffer
  }
);

Just remember that you will need a render target later on with the exact format to use as an attachment. Those targets won't be automatically created for you except the swapchain images to draw on your window's surface. But more about that in a different step.

Previous

Next

Popular posts from this blog

Introduction

Application development

First setup