71 lines
2.9 KiB
C++
71 lines
2.9 KiB
C++
|
|
#include "iwa/render_pass.hpp"
|
|
|
|
#include "iwa/device.hpp"
|
|
#include "iwa/image.hpp"
|
|
|
|
namespace iwa
|
|
{
|
|
RenderPass::RenderPass(ObjectPtr<Device> owner, const RenderPassCreationArgs& args) : super_t(std::move(owner))
|
|
{
|
|
std::vector<vk::SubpassDescription> vkSubpasses;
|
|
vkSubpasses.reserve(args.subpasses.size());
|
|
for (const SubpassDescription& subpass : args.subpasses)
|
|
{
|
|
MIJIN_ASSERT(subpass.resolveAttachments.empty() || subpass.resolveAttachments.size() == subpass.colorAttachments.size(),
|
|
"Number of resolve attachments must be either 0 or the same as color attachments.");
|
|
vkSubpasses.push_back({
|
|
.flags = subpass.flags,
|
|
.pipelineBindPoint = subpass.pipelineBindPoint,
|
|
.inputAttachmentCount = static_cast<std::uint32_t>(subpass.inputAttachments.size()),
|
|
.pInputAttachments = subpass.inputAttachments.data(),
|
|
.colorAttachmentCount = static_cast<std::uint32_t>(subpass.colorAttachments.size()),
|
|
.pColorAttachments = subpass.colorAttachments.data(),
|
|
.pResolveAttachments = subpass.resolveAttachments.data(),
|
|
.pDepthStencilAttachment = subpass.depthStencilAttachment.has_value() ? &subpass.depthStencilAttachment.value() : nullptr,
|
|
.preserveAttachmentCount = static_cast<std::uint32_t>(subpass.preserveAttachments.size()),
|
|
.pPreserveAttachments = subpass.preserveAttachments.data()
|
|
});
|
|
}
|
|
mHandle = getOwner()->getVkHandle().createRenderPass(vk::RenderPassCreateInfo{
|
|
.flags = args.flags,
|
|
.attachmentCount = static_cast<std::uint32_t>(args.attachments.size()),
|
|
.pAttachments = args.attachments.data(),
|
|
.subpassCount = static_cast<std::uint32_t>(vkSubpasses.size()),
|
|
.pSubpasses = vkSubpasses.data(),
|
|
.dependencyCount = static_cast<std::uint32_t>(args.dependencies.size()),
|
|
.pDependencies = args.dependencies.data()
|
|
});
|
|
}
|
|
|
|
RenderPass::~RenderPass() noexcept
|
|
{
|
|
IWA_DELETE_DEVICE_OBJECT(getOwner(), mHandle, destroyRenderPass);
|
|
}
|
|
|
|
Framebuffer::Framebuffer(ObjectPtr<Device> owner, const FramebufferCreationArgs& args)
|
|
: super_t(std::move(owner)), mImageViews(args.attachments)
|
|
{
|
|
std::vector<vk::ImageView> vkImageViews;
|
|
vkImageViews.reserve(mImageViews.size());
|
|
for (const ObjectPtr<ImageView>& imageView : mImageViews)
|
|
{
|
|
vkImageViews.push_back(*imageView);
|
|
}
|
|
mHandle = getOwner()->getVkHandle().createFramebuffer(vk::FramebufferCreateInfo{
|
|
.flags = args.flags,
|
|
.renderPass = *args.renderPass,
|
|
.attachmentCount = static_cast<std::uint32_t>(vkImageViews.size()),
|
|
.pAttachments = vkImageViews.data(),
|
|
.width = args.width,
|
|
.height = args.height,
|
|
.layers = args.layers
|
|
});
|
|
}
|
|
|
|
Framebuffer::~Framebuffer() noexcept
|
|
{
|
|
IWA_DELETE_DEVICE_OBJECT(getOwner(), mHandle, destroyFramebuffer);
|
|
}
|
|
} // namespace iwa
|