1#ifndef VULKAN_FRAMEBUFFER
2#define VULKAN_FRAMEBUFFER
4#include <vulkan/vulkan.h>
17namespace Vulkan {
class Framebuffer; }
25 template<std::same_as<ImageView>... IV>
27 std::vector<VkImageView> attachments;
28 (attachments.push_back(+imageViews), ...);
31 throw VulkanException(
"Failed to create framebuffer!",
"The number of attachments in the frame buffer must match the number of attachment descriptions in the render pass");
34 VkFramebufferCreateInfo framebufferInfo{};
35 framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
36 framebufferInfo.renderPass = +renderPass;
37 framebufferInfo.attachmentCount = attachments.size();
38 framebufferInfo.pAttachments = attachments.data();
39 framebufferInfo.width = resolution.first;
40 framebufferInfo.height = resolution.second;
41 framebufferInfo.layers = 1;
43 if (VkResult result = vkCreateFramebuffer(+virtualGpu, &framebufferInfo,
nullptr, &framebuffer); result != VK_SUCCESS) {
47 std::cout <<
"\n+ Framebuffer created";
54 Framebuffer(
Framebuffer&& movedFrom) noexcept : framebuffer{ movedFrom.framebuffer }, resolution{ movedFrom.resolution }, virtualGpu{ movedFrom.virtualGpu } {
55 movedFrom.framebuffer =
nullptr;
56 std::cout <<
"\n> Framebuffer moved";
63 vkDestroyFramebuffer(+virtualGpu, framebuffer,
nullptr);
64 std::cout <<
"\n- Framebuffer destroyed";
87 template<std::same_as<ImageView>... IV>
89 std::vector<Framebuffer> framebuffers;
92 for (
const auto& image : images) {
93 auto& imageViews = image.getImageViews();
94 for (
const auto& imageView : imageViews) {
95 framebuffers.emplace_back(virtualGpu, renderPass, swapchain.
getResolution(), imageView.second, otherAttachments...);
103 VkFramebuffer framebuffer;
105 std::pair<unsigned int, unsigned int> resolution;
A Framebuffer links toghether the real attachments (e.g. image views in the swapchain or depth buffer...
Definition: Framebuffer.h:22
Framebuffer(const LogicalDevice &virtualGpu, const PipelineOptions::RenderPass &renderPass, std::pair< unsigned int, unsigned int > resolution, const IV &... imageViews)
Definition: Framebuffer.h:26
Framebuffer & operator=(const Framebuffer &)=delete
Framebuffer(Framebuffer &&movedFrom) noexcept
Definition: Framebuffer.h:54
Framebuffer(const Framebuffer &)=delete
Framebuffer & operator=(Framebuffer &&)=default
const VkFramebuffer & operator+() const
Definition: Framebuffer.h:68
~Framebuffer()
Definition: Framebuffer.h:62
std::pair< unsigned int, unsigned int > getResolution() const
Definition: Framebuffer.h:73
static std::vector< Framebuffer > generateFramebufferForEachSwapchainImageView(const LogicalDevice &virtualGpu, const PipelineOptions::RenderPass &renderPass, const Swapchain &swapchain, const IV &... otherAttachments)
Creates a framebuffer for each image view in the specified swapchain. It also attaches the specified ...
Definition: Framebuffer.h:88
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
int getAttachmentCount() const
Definition: RenderPass.h:91
Object which holds images to be presented to the WindowSurface.
Definition: Swapchain.h:19
std::pair< unsigned int, unsigned int > getResolution() const
Returns the width and height of the images in this swapchain.
Definition: Swapchain.cpp:95
const std::vector< Image > & getImages() const
Returns the images of this swapchain.
Definition: Swapchain.cpp:90
Generic runtime exception thrown by Vulkan-related functions.
Definition: VulkanException.h:13
Types of queue families.
Definition: Animations.h:17