-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFramebuffer.cpp
55 lines (44 loc) · 1.67 KB
/
Framebuffer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "Framebuffer.hpp"
Framebuffer::Framebuffer(const std::vector<VkImageView>& swapchainImageViews,
const VkImageView& msaaImageView, const VkImageView& depthImageView,
const VkRenderPass& renderpass, const VkExtent2D& swapchainExtent,
const VkDevice& device)
:
device(device)
{
create(swapchainImageViews, msaaImageView, depthImageView, renderpass, swapchainExtent);
}
void Framebuffer::create(const std::vector<VkImageView>& swapchainImageViews,
const VkImageView& msaaImageView, const VkImageView& depthImageView,
const VkRenderPass& renderpass, const VkExtent2D& swapchainExtent)
{
swapchainFramebuffers.resize(swapchainImageViews.size());
for (size_t i = 0; i < swapchainFramebuffers.size(); i++) {
std::array<VkImageView, 3> attachments = {
msaaImageView,
depthImageView,
swapchainImageViews[i]
};
VkFramebufferCreateInfo framebufferInfo{};
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
framebufferInfo.renderPass = renderpass;
framebufferInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
framebufferInfo.pAttachments = attachments.data();
framebufferInfo.width = swapchainExtent.width;
framebufferInfo.height = swapchainExtent.height;
framebufferInfo.layers = 1;
if (vkCreateFramebuffer(this->device, &framebufferInfo, nullptr, &swapchainFramebuffers[i]) != VK_SUCCESS) {
throw std::runtime_error("failed to create framebuffer");
}
}
}
void Framebuffer::cleanup()
{
for (size_t i = 0; i < swapchainFramebuffers.size(); i++) {
vkDestroyFramebuffer(device, swapchainFramebuffers[i], nullptr);
}
}
const std::vector<VkFramebuffer>& Framebuffer::getSwapchainFramebuffers()
{
return swapchainFramebuffers;
}