Files
Seele/src/Engine/Graphics/Vulkan/Framebuffer.cpp
T

63 lines
2.4 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#include "Framebuffer.h"
#include "Enums.h"
#include "Initializer.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)
: 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;
2021-09-23 10:10:39 +02:00
uint32 sizeX = 0;
uint32 sizeY = 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 00:06:00 +01:00
sizeX = std::max(sizeX, vkInputAttachment->getWidth());
sizeY = std::max(sizeY, 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 00:06:00 +01:00
sizeX = std::max(sizeX, vkColorAttachment->getWidth());
sizeY = std::max(sizeY, vkColorAttachment->getHeight());
2020-04-01 02:17:49 +02:00
}
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 00:06:00 +01:00
sizeX = std::max(sizeX, vkDepthAttachment->getWidth());
sizeY = std::max(sizeY, vkDepthAttachment->getHeight());
2020-04-01 02:17:49 +02:00
}
VkFramebufferCreateInfo createInfo =
init::FramebufferCreateInfo(
renderPass->getHandle(),
2021-03-31 12:18:16 +02:00
(uint32)attachments.size(),
2020-04-01 02:17:49 +02:00
attachments.data(),
2021-09-23 10:10:39 +02:00
sizeX,
sizeY,
2020-04-12 15:47:19 +02:00
1);
2020-10-03 11:00:10 +02:00
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
}