7 changed files with 183 additions and 26 deletions
@ -0,0 +1,86 @@ |
|||||
|
// 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 |
||||
|
) |
||||
|
: m_context(&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(*this, other); |
||||
|
} |
||||
|
|
||||
|
Framebuffer::~Framebuffer() noexcept { |
||||
|
if(!is_null()) |
||||
|
destroy(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
Framebuffer& Framebuffer::operator=(Framebuffer&& other) noexcept { |
||||
|
swap(*this, 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; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,74 @@ |
|||||
|
// Copyright 2022 Simon Boyé
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <core/utils.h> |
||||
|
|
||||
|
#include <vk/forward.h> |
||||
|
|
||||
|
#include <vulkan/vulkan.h> |
||||
|
|
||||
|
|
||||
|
namespace vk { |
||||
|
|
||||
|
|
||||
|
class Framebuffer { |
||||
|
public: |
||||
|
Framebuffer() noexcept; |
||||
|
Framebuffer( |
||||
|
Context& context, |
||||
|
VkRenderPass render_pass, |
||||
|
Array<VkImageView> attachments, |
||||
|
uint32_t width, uint32_t height, uint32_t layers=1 |
||||
|
); |
||||
|
Framebuffer( |
||||
|
Context& context, |
||||
|
VkRenderPass render_pass, |
||||
|
Array<VkImageView> attachments, |
||||
|
VkExtent2D extent, uint32_t layers=1 |
||||
|
); |
||||
|
Framebuffer(const Framebuffer&) = delete; |
||||
|
Framebuffer(Framebuffer&& other) noexcept; |
||||
|
~Framebuffer() noexcept; |
||||
|
|
||||
|
Framebuffer& operator=(const Framebuffer&) = delete; |
||||
|
Framebuffer& operator=(Framebuffer&& other) noexcept; |
||||
|
|
||||
|
explicit inline operator bool() const noexcept { |
||||
|
return !is_null(); |
||||
|
} |
||||
|
|
||||
|
inline bool is_null() const noexcept { |
||||
|
return m_framebuffer == VK_NULL_HANDLE; |
||||
|
} |
||||
|
|
||||
|
inline const Context* context() const noexcept { |
||||
|
return m_context; |
||||
|
} |
||||
|
|
||||
|
inline Context* context() noexcept { |
||||
|
return m_context; |
||||
|
} |
||||
|
|
||||
|
inline operator VkFramebuffer() noexcept { |
||||
|
return m_framebuffer; |
||||
|
} |
||||
|
|
||||
|
inline VkFramebuffer framebuffer() noexcept { |
||||
|
return m_framebuffer; |
||||
|
} |
||||
|
|
||||
|
friend inline void swap(Framebuffer& framebuffer_0, Framebuffer& framebuffer_1) noexcept { |
||||
|
using std::swap; |
||||
|
swap(framebuffer_0.m_context, framebuffer_1.m_context); |
||||
|
swap(framebuffer_0.m_framebuffer, framebuffer_1.m_framebuffer); |
||||
|
} |
||||
|
|
||||
|
void destroy() noexcept; |
||||
|
|
||||
|
private: |
||||
|
Context* m_context = nullptr; |
||||
|
VkFramebuffer m_framebuffer = VK_NULL_HANDLE; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue