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

50 lines
2.0 KiB
C++
Raw Normal View History

2020-04-01 02:17:49 +02:00
#include "VulkanFramebuffer.h"
#include "VulkanGraphicsEnums.h"
#include "VulkanInitializer.h"
#include "VulkanRenderPass.h"
#include "VulkanGraphics.h"
using namespace Seele;
using namespace Seele::Vulkan;
Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::PRenderTargetLayout renderTargetLayout)
2020-05-05 01:51:13 +02: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;
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();
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();
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();
2020-04-01 02:17:49 +02:00
}
VkFramebufferCreateInfo createInfo =
init::FramebufferCreateInfo(
renderPass->getHandle(),
attachments.size(),
attachments.data(),
renderPass->getRenderArea().extent.width,
renderPass->getRenderArea().extent.height,
2020-04-12 15:47:19 +02:00
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
hash = memCrc32(&description, sizeof(FramebufferDescription));
2020-04-01 02:17:49 +02:00
}
Framebuffer::~Framebuffer()
{
vkDestroyFramebuffer(graphics->getDevice(), handle, nullptr);
}