vOOlkan
An object oriented approach to Vulkan
RenderPass.h
Go to the documentation of this file.
1#ifndef VULKAN_RENDERPASS
2#define VULKAN_RENDERPASS
3
4#include <vulkan/vulkan.h>
5#include <vector>
6#include <concepts>
7
8#include "Attachment.h"
9#include "Subpass.h"
10#include "LogicalDevice.h"
11#include "VulkanException.h"
12
13
14namespace Vulkan::PipelineOptions { class RenderPass; }
15
16
21 public:
22
33 template<std::same_as<RenderPassOptions::Subpass>... S>
34 RenderPass(const LogicalDevice& virtualGpu, const std::vector<RenderPassOptions::AttachmentDescription::BoundAttachmentDescription>& attachments, const S&... subpasses) : virtualGpu{ virtualGpu } {
35 //create the VkAttachmentDescription array
36 std::vector<VkAttachmentDescription> attachmentDescriptions;
37 for (const auto& attachment : attachments) {
38 attachmentDescriptions.push_back(+attachment);
39 }
40 attachmentCount = attachmentDescriptions.size();
41
42 //create the VkSubpassDescription array and save the subpasses in the vector
43 std::vector<VkSubpassDescription> subpassesDescriptions;
44 ([&subpassesDescriptions, this](RenderPassOptions::Subpass subpass) {
45 subpassesDescriptions.push_back(+subpass);
46 this->subpasses.push_back(subpass);
47 }(subpasses), ...);
48
49 //struct with the options for this render pass
50 VkRenderPassCreateInfo renderPassInfo{};
51 renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
52 renderPassInfo.attachmentCount = attachmentDescriptions.size();
53 renderPassInfo.pAttachments = attachmentDescriptions.data();
54 renderPassInfo.subpassCount = subpassesDescriptions.size();
55 renderPassInfo.pSubpasses = subpassesDescriptions.data();
56
57 if (VkResult result = vkCreateRenderPass(+virtualGpu, &renderPassInfo, nullptr, &renderPass); result != VK_SUCCESS) {
58 throw VulkanException("Failed to create render pass!", result);
59 }
60 }
61
62 RenderPass(const RenderPass&) = delete;
64 RenderPass& operator=(const RenderPass&) = delete;
66
68 vkDestroyRenderPass(+virtualGpu, renderPass, nullptr);
69 }
70
71
77 const VkRenderPass& operator+() const {
78 return renderPass;
79 }
80
81
87 RenderPassOptions::Subpass getSubpass(unsigned int i) const {
88 return subpasses[i];
89 }
90
91 int getAttachmentCount() const {
92 return attachmentCount;
93 }
94
95 private:
96 VkRenderPass renderPass;
97 const LogicalDevice& virtualGpu;
98 std::vector<RenderPassOptions::Subpass> subpasses;
99 int attachmentCount;
100};
101
102
103#endif
104
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
A RenderPass is the set of attachments, the way they are used, and the rendering work that is perform...
Definition: RenderPass.h:20
RenderPassOptions::Subpass getSubpass(unsigned int i) const
Returns the subpasses of this render pass.
Definition: RenderPass.h:87
RenderPass(const LogicalDevice &virtualGpu, const std::vector< RenderPassOptions::AttachmentDescription::BoundAttachmentDescription > &attachments, const S &... subpasses)
Creates a RenderPass given its Subpass(es) and its BoundAttachmentDescription(s).
Definition: RenderPass.h:34
RenderPass & operator=(RenderPass &&)=delete
RenderPass & operator=(const RenderPass &)=delete
RenderPass(RenderPass &&)=delete
const VkRenderPass & operator+() const
Returns the underlying VkRenderPass object.
Definition: RenderPass.h:77
int getAttachmentCount() const
Definition: RenderPass.h:91
RenderPass(const RenderPass &)=delete
~RenderPass()
Definition: RenderPass.h:67
A Subpass is a step of a RenderPass.
Definition: Subpass.h:28
Generic runtime exception thrown by Vulkan-related functions.
Definition: VulkanException.h:13
Definition: Attachment.h:11