You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.7 KiB
86 lines
1.7 KiB
// Copyright 2022 Simon Boyé
|
|
|
|
#include <vk/Framebuffer.h>
|
|
#include <vk/Context.h>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
namespace vk {
|
|
|
|
|
|
Framebuffer::Framebuffer() noexcept {
|
|
}
|
|
|
|
Framebuffer::Framebuffer(
|
|
Context& context,
|
|
VkRenderPass render_pass,
|
|
Array<VkImageView> attachments,
|
|
uint32_t width, uint32_t height, uint32_t layers
|
|
)
|
|
: Wrapper(context)
|
|
{
|
|
assert(m_context);
|
|
assert(render_pass);
|
|
|
|
VkFramebufferCreateInfo create_info {
|
|
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
|
.renderPass = render_pass,
|
|
.attachmentCount = uint32_t(attachments.size()),
|
|
.pAttachments = attachments.data(),
|
|
.width = width,
|
|
.height = height,
|
|
.layers = layers,
|
|
};
|
|
if(vkCreateFramebuffer(
|
|
context.device(),
|
|
&create_info,
|
|
nullptr,
|
|
&m_framebuffer
|
|
) != VK_SUCCESS)
|
|
throw std::runtime_error("failed to create framebuffer");
|
|
}
|
|
|
|
Framebuffer::Framebuffer(
|
|
Context& context,
|
|
VkRenderPass render_pass,
|
|
Array<VkImageView> attachments,
|
|
VkExtent2D extent, uint32_t layers
|
|
)
|
|
: Framebuffer(context, render_pass, attachments, extent.width, extent.height, layers)
|
|
{}
|
|
|
|
Framebuffer::Framebuffer(Framebuffer&& other) noexcept
|
|
{
|
|
swap(other);
|
|
}
|
|
|
|
Framebuffer::~Framebuffer() noexcept {
|
|
if(!is_null())
|
|
destroy();
|
|
}
|
|
|
|
|
|
Framebuffer& Framebuffer::operator=(Framebuffer&& other) noexcept {
|
|
swap(other);
|
|
if(other)
|
|
other.destroy();
|
|
return *this;
|
|
}
|
|
|
|
|
|
void Framebuffer::destroy() noexcept {
|
|
assert(!is_null());
|
|
assert(m_context);
|
|
|
|
vkDestroyFramebuffer(
|
|
m_context->device(),
|
|
m_framebuffer,
|
|
nullptr
|
|
);
|
|
|
|
m_framebuffer = nullptr;
|
|
}
|
|
|
|
|
|
}
|
|
|