Files
Gryphn/projects/apis/vulkan/src/framebuffers/vulkan_framebuffer.c
2025-08-03 15:45:45 -04:00

33 lines
1.3 KiB
C

#include "vulkan_framebuffer.h"
#include "textures/vulkan_texture.h"
#include "renderpass/vulkan_render_pass_descriptor.h"
#include "output_device/vulkan_output_devices.h"
#include "vulkan_result_converter.h"
gnReturnCode createFramebuffer(gnFramebuffer framebuffer, gnDevice device, gnFramebufferInfo info) {
framebuffer->framebuffer = malloc(sizeof(struct gnPlatformFramebuffer_t));
VkImageView* attachments = malloc(sizeof(VkImageView) * info.attachmentCount);
for (uint32_t i = 0; i < info.attachmentCount; i++)
attachments[i] = info.attachments[i]->texture->image.imageView;
VkFramebufferCreateInfo framebufferInfo = {
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
.renderPass = info.renderPassDescriptor->renderPassDescriptor->renderPass,
.attachmentCount = info.attachmentCount,
.pAttachments = attachments,
.width = info.size.x,
.height = info.size.y,
.layers = 1
};
VkResult res = vkCreateFramebuffer(device->outputDevice->device, &framebufferInfo, NULL, &framebuffer->framebuffer->framebuffer);
free(attachments);
return VkResultToGnReturnCode(res);
}
void destroyFramebuffer(gnFramebuffer framebuffer) {
vkDestroyFramebuffer(framebuffer->device->outputDevice->device, framebuffer->framebuffer->framebuffer, NULL);
free(framebuffer->framebuffer);
}