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

81 lines
3.7 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#include "Framebuffer.h"
2024-06-09 10:44:24 +02:00
#include "CRC.h"
2024-06-09 12:20:04 +02:00
#include "Enums.h"
#include "Graphics.h"
#include "RenderPass.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::RenderTargetLayout renderTargetLayout)
2024-06-09 12:20:04 +02:00
: graphics(graphics), layout(renderTargetLayout), renderPass(renderPass) {
2020-04-12 15:47:19 +02:00
FramebufferDescription description;
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;
2025-04-06 09:57:47 +02:00
uint32 layers = 0;
2024-06-09 12:20:04 +02:00
for (auto inputAttachment : layout.inputAttachments) {
PTextureView vkInputAttachment = inputAttachment.getTextureView();
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());
2025-04-06 09:57:47 +02:00
layers = std::max(layers, vkInputAttachment->getNumLayers());
2020-04-01 02:17:49 +02:00
}
2024-06-09 12:20:04 +02:00
for (auto colorAttachment : layout.colorAttachments) {
PTextureView vkColorAttachment = colorAttachment.getTextureView();
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());
2025-04-06 09:57:47 +02:00
layers = std::max(layers, vkColorAttachment->getNumLayers());
2020-04-01 02:17:49 +02:00
}
2024-06-09 12:20:04 +02:00
for (auto resolveAttachment : layout.resolveAttachments) {
PTextureView vkResolveAttachment = resolveAttachment.getTextureView();
2023-12-10 22:27:59 +01:00
attachments.add(vkResolveAttachment->getView());
description.resolveAttachments[description.numResolveAttachments++] = vkResolveAttachment->getView();
width = std::max(width, vkResolveAttachment->getWidth());
height = std::max(height, vkResolveAttachment->getHeight());
2025-04-06 09:57:47 +02:00
layers = std::max(layers, vkResolveAttachment->getNumLayers());
2023-12-10 22:27:59 +01:00
}
if (layout.depthAttachment.getTextureView() != nullptr) {
PTextureView vkDepthAttachment = layout.depthAttachment.getTextureView();
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());
2025-04-06 09:57:47 +02:00
layers = std::max(layers, vkDepthAttachment->getNumLayers());
2020-04-01 02:17:49 +02:00
}
if (layout.depthResolveAttachment.getTextureView() != nullptr) {
PTextureView vkDepthAttachment = layout.depthResolveAttachment.getTextureView();
2023-12-10 22:27:59 +01:00
attachments.add(vkDepthAttachment->getView());
description.depthResolveAttachment = vkDepthAttachment->getView();
width = std::max(width, vkDepthAttachment->getWidth());
height = std::max(height, vkDepthAttachment->getHeight());
2025-04-06 09:57:47 +02:00
layers = std::max(layers, vkDepthAttachment->getNumLayers());
2023-12-10 22:27:59 +01:00
}
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));
2025-04-11 21:02:52 +02:00
renderArea = VkRect2D{
.offset = {0, 0},
.extent = {width, height},
};
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
}
2024-06-09 12:20:04 +02:00
Framebuffer::~Framebuffer() {
2020-04-01 02:17:49 +02:00
vkDestroyFramebuffer(graphics->getDevice(), handle, nullptr);
2020-09-19 14:36:50 +02:00
graphics = nullptr;
2020-04-01 02:17:49 +02:00
}