2023-10-26 18:37:29 +02:00
|
|
|
#include "Framebuffer.h"
|
|
|
|
|
#include "Enums.h"
|
|
|
|
|
#include "RenderPass.h"
|
|
|
|
|
#include "Graphics.h"
|
|
|
|
|
#include "Texture.h"
|
2020-04-01 02:17:49 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
using namespace Seele::Vulkan;
|
|
|
|
|
|
|
|
|
|
Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::PRenderTargetLayout renderTargetLayout)
|
2021-11-14 20:36:53 +01:00
|
|
|
: graphics(graphics)
|
|
|
|
|
, layout(renderTargetLayout)
|
|
|
|
|
, renderPass(renderPass)
|
2020-04-01 02:17:49 +02:00
|
|
|
{
|
2020-04-12 15:47:19 +02:00
|
|
|
FramebufferDescription description;
|
|
|
|
|
std::memset(&description, 0, sizeof(FramebufferDescription));
|
2020-04-01 02:17:49 +02:00
|
|
|
Array<VkImageView> attachments;
|
2023-11-15 17:42:57 +01:00
|
|
|
uint32 width = 0;
|
|
|
|
|
uint32 height = 0;
|
2020-04-12 15:47:19 +02:00
|
|
|
for (auto inputAttachment : layout->inputAttachments)
|
2020-04-01 02:17:49 +02:00
|
|
|
{
|
2020-04-12 15:47:19 +02:00
|
|
|
PTexture2D vkInputAttachment = inputAttachment->getTexture().cast<Texture2D>();
|
2020-04-01 02:17:49 +02:00
|
|
|
attachments.add(vkInputAttachment->getView());
|
2020-04-12 15:47:19 +02:00
|
|
|
description.inputAttachments[description.numInputAttachments++] = vkInputAttachment->getView();
|
2023-11-15 17:42:57 +01:00
|
|
|
width = std::max(width, vkInputAttachment->getWidth());
|
|
|
|
|
height = std::max(height, vkInputAttachment->getHeight());
|
2020-04-01 02:17:49 +02:00
|
|
|
}
|
2020-04-12 15:47:19 +02:00
|
|
|
for (auto colorAttachment : layout->colorAttachments)
|
2020-04-01 02:17:49 +02:00
|
|
|
{
|
2020-04-12 15:47:19 +02:00
|
|
|
PTexture2D vkColorAttachment = colorAttachment->getTexture().cast<Texture2D>();
|
2020-04-01 02:17:49 +02:00
|
|
|
attachments.add(vkColorAttachment->getView());
|
2020-04-12 15:47:19 +02:00
|
|
|
description.colorAttachments[description.numColorAttachments++] = vkColorAttachment->getView();
|
2023-11-15 17:42:57 +01:00
|
|
|
width = std::max(width, vkColorAttachment->getWidth());
|
|
|
|
|
height = std::max(height, vkColorAttachment->getHeight());
|
2020-04-01 02:17:49 +02:00
|
|
|
}
|
2023-12-10 22:27:59 +01:00
|
|
|
for (auto resolveAttachment : layout->resolveAttachments)
|
|
|
|
|
{
|
|
|
|
|
PTexture2D vkResolveAttachment = resolveAttachment->getTexture().cast<Texture2D>();
|
|
|
|
|
attachments.add(vkResolveAttachment->getView());
|
|
|
|
|
description.resolveAttachments[description.numResolveAttachments++] = vkResolveAttachment->getView();
|
|
|
|
|
width = std::max(width, vkResolveAttachment->getWidth());
|
|
|
|
|
height = std::max(height, vkResolveAttachment->getHeight());
|
|
|
|
|
}
|
2020-04-12 15:47:19 +02:00
|
|
|
if (layout->depthAttachment != nullptr)
|
2020-04-01 02:17:49 +02:00
|
|
|
{
|
2020-04-12 15:47:19 +02:00
|
|
|
PTexture2D vkDepthAttachment = layout->depthAttachment->getTexture().cast<Texture2D>();
|
2020-04-01 02:17:49 +02:00
|
|
|
attachments.add(vkDepthAttachment->getView());
|
2020-04-12 15:47:19 +02:00
|
|
|
description.depthAttachment = vkDepthAttachment->getView();
|
2023-11-15 17:42:57 +01:00
|
|
|
width = std::max(width, vkDepthAttachment->getWidth());
|
|
|
|
|
height = std::max(height, vkDepthAttachment->getHeight());
|
2020-04-01 02:17:49 +02:00
|
|
|
}
|
2023-12-10 22:27:59 +01:00
|
|
|
if (layout->depthResolveAttachment != nullptr)
|
|
|
|
|
{
|
|
|
|
|
PTexture2D vkDepthAttachment = layout->depthResolveAttachment->getTexture().cast<Texture2D>();
|
|
|
|
|
attachments.add(vkDepthAttachment->getView());
|
|
|
|
|
description.depthResolveAttachment = vkDepthAttachment->getView();
|
|
|
|
|
width = std::max(width, vkDepthAttachment->getWidth());
|
|
|
|
|
height = std::max(height, vkDepthAttachment->getHeight());
|
|
|
|
|
}
|
2023-11-15 17:42:57 +01:00
|
|
|
VkFramebufferCreateInfo createInfo = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
|
|
|
|
.pNext = nullptr,
|
|
|
|
|
.flags = 0,
|
|
|
|
|
.renderPass = renderPass->getHandle(),
|
|
|
|
|
.attachmentCount = (uint32)attachments.size(),
|
|
|
|
|
.pAttachments = attachments.data(),
|
|
|
|
|
.width = width,
|
|
|
|
|
.height = height,
|
|
|
|
|
.layers = 1,
|
|
|
|
|
};
|
2020-04-01 02:17:49 +02:00
|
|
|
VK_CHECK(vkCreateFramebuffer(graphics->getDevice(), &createInfo, nullptr, &handle));
|
2020-04-12 15:47:19 +02:00
|
|
|
|
2022-11-22 22:11:37 +01:00
|
|
|
hash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
|
2020-04-01 02:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Framebuffer::~Framebuffer()
|
|
|
|
|
{
|
|
|
|
|
vkDestroyFramebuffer(graphics->getDevice(), handle, nullptr);
|
2020-09-19 14:36:50 +02:00
|
|
|
graphics = nullptr;
|
2020-04-01 02:17:49 +02:00
|
|
|
}
|