1#ifndef VULKAN_ATTACHMENT
2#define VULKAN_ATTACHMENT
4#include <vulkan/vulkan.h>
16 std::same_as<T, AttachmentDescription> ||
17 std::same_as < T, std::pair<AttachmentDescription, VkImageLayout>> ||
18 std::same_as < T, std::pair<AttachmentDescription, AttachmentColorBlendingMode>>
19 || std::same_as < T, std::tuple<AttachmentDescription, VkImageLayout, AttachmentColorBlendingMode>>;
56 attachment.format = VK_FORMAT_B8G8R8A8_SRGB;
57 attachment.samples = VK_SAMPLE_COUNT_1_BIT;
58 attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
59 attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
60 attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
61 attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
62 attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
63 attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
66 attachmentReferenceLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
73 attachment.format = VK_FORMAT_D32_SFLOAT;
74 attachment.samples = VK_SAMPLE_COUNT_1_BIT;
75 attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
76 attachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
77 attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
78 attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
79 attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
80 attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
83 attachmentReferenceLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
99 AttachmentDescription(
const VkAttachmentDescription& baseAttachment,
AttachmentType type, VkImageLayout referenceLayout = VK_IMAGE_LAYOUT_UNDEFINED) : attachment{ baseAttachment }, attachmentReferenceLayout{ referenceLayout }, type{ type } {}
126 return attachmentReferenceLayout;
146 attachment{ attachment.attachment },
147 attachmentReference{}, type{ attachment.type },
148 colorBlendingMode{ colorBlendingMode } {
149 attachmentReference.attachment = index;
150 attachmentReference.layout = layout;
168 return attachmentReference.attachment;
188 return attachmentReference;
199 return colorBlendingMode;
201 throw VulkanException{
"This attachment is not a color attachment, therefore it hasn't got the color blending mode" };
205 VkAttachmentDescription attachment;
206 VkAttachmentReference attachmentReference;
223 std::vector<BoundAttachmentDescription> boundAttachments;
226 std::vector<std::tuple<AttachmentDescription, VkImageLayout, AttachmentColorBlendingMode>> attachmentLayoutColorBlendingModeTriplets;
227 (attachmentLayoutColorBlendingModeTriplets.push_back(parseAttachment(attachments)), ...);
230 for (
const auto& alp : attachmentLayoutColorBlendingModeTriplets) {
231 boundAttachments.emplace_back(std::get<0>(alp), boundAttachments.size(), std::get<1>(alp), std::get<2>(alp));
234 return boundAttachments;
241 static std::tuple<AttachmentDescription, VkImageLayout, AttachmentColorBlendingMode> parseAttachment(
const std::pair<AttachmentDescription, VkImageLayout>& attachment) {
245 return { attachment.first, attachment.second, AttachmentColorBlendingMode{} };
249 static std::tuple<AttachmentDescription, VkImageLayout, AttachmentColorBlendingMode> parseAttachment(
const AttachmentDescription& attachment) {
253 return { attachment, attachment.attachmentReferenceLayout, AttachmentColorBlendingMode{} };
257 static std::tuple<AttachmentDescription, VkImageLayout, AttachmentColorBlendingMode> parseAttachment(
const std::pair<AttachmentDescription, AttachmentColorBlendingMode>& attachment) {
258 return { attachment.first, attachment.first.attachmentReferenceLayout, attachment.second };
262 static std::tuple<AttachmentDescription, VkImageLayout, AttachmentColorBlendingMode> parseAttachment(
const std::tuple<AttachmentDescription, VkImageLayout, AttachmentColorBlendingMode>& attachment) {
267 VkAttachmentDescription attachment;
268 VkImageLayout attachmentReferenceLayout;
A AttachmentColorBlendingMode describes how a render Subpass will write to a color attachment.
Definition: AttachmentColorBlendingMode.h:20
A BoundAttachmentDescription is an AttachmentDescription which ir ready to be used in a RenderPass an...
Definition: Attachment.h:136
int getAttachmentReferenceIndex() const
Returns the index with which this attachment will be referenced by a render Subpass.
Definition: Attachment.h:167
BoundAttachmentDescription(const AttachmentDescription &attachment, int index, VkImageLayout layout, AttachmentColorBlendingMode colorBlendingMode)
Creates an object starting from an AttachmentDescription.
Definition: Attachment.h:145
AttachmentColorBlendingMode getColorBlendingMode() const
If this attachment is a color attachment, it returns the color blending mode.
Definition: Attachment.h:197
const VkAttachmentReference & getAttachmentReference() const
Returns the underlying VkAttachmentReference struct, which is the struct used by a render Subpass to ...
Definition: Attachment.h:187
const VkAttachmentDescription & operator+() const
Access to the underlying VkAttachmentDescription Vulkan object.
Definition: Attachment.h:157
const AttachmentType & getType() const
Returns the type of this attachment, namely how the attachment will be used by a render Subpass.
Definition: Attachment.h:177
An AttachmentDescription is basically the description of render target where the GPU will draw.
Definition: Attachment.h:43
VkImageLayout & getAttachmentReferenceLayout()
Returns a modifiable reference to the default VkImageLayout used during BoundAttachmentDescription cr...
Definition: Attachment.h:125
AttachmentDescription(PredefinedAttachment predefined=PredefinedAttachment::STANDARD_COLOR)
Generates an attachment based on some standard attachment models.
Definition: Attachment.h:52
AttachmentDescription(const VkAttachmentDescription &baseAttachment, AttachmentType type, VkImageLayout referenceLayout=VK_IMAGE_LAYOUT_UNDEFINED)
Creates the AttachmentDescription starting from its Vulkan underlying struct.
Definition: Attachment.h:99
VkAttachmentDescription & operator+()
Access to the underlying VkAttachmentDescription Vulkan object.
Definition: Attachment.h:105
static std::vector< BoundAttachmentDescription > prepareAttachments(A... attachments)
Prepares the attachments to be used into a RenderPass and its render Subpass(es), fixing a position f...
Definition: Attachment.h:222
AttachmentType & getType()
Returns a modifiable reference to the type of this attachment, namely how the attachment will be used...
Definition: Attachment.h:115
Generic runtime exception thrown by Vulkan-related functions.
Definition: VulkanException.h:13
Definition: Attachment.h:15
Definition: Attachment.h:11
AttachmentType
Each AttachmentDescription, based on his properties, can be used by a render Subpass in different way...
Definition: Attachment.h:32
PredefinedAttachment
Definition: Attachment.h:24