summaryrefslogtreecommitdiff
path: root/render/vulkan/framebuffer.c
blob: 36d90c06539eadff162c8a7e544641808eaf16d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "framebuffer.h"
#include "vkassert.h"
#include <rune/core/alloc.h>
#include <rune/core/logging.h>

struct vkframebuffer* create_vkframebuffer(struct vkdev *dev, struct vkrendpass *rendpass, uint32_t width, uint32_t height, uint32_t at_count, VkImageView *at) {
        struct vkframebuffer *ret = rune_alloc(sizeof(struct vkframebuffer));
        ret->at_count = at_count;
        ret->attachments = rune_alloc(sizeof(VkImageView) * at_count);
        for (uint32_t i = 0; i < at_count; i++)
                ret->attachments[i] = at[i];
        ret->rendpass = rendpass;
        
        VkFramebufferCreateInfo fbinfo;
        fbinfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
        fbinfo.pNext = NULL;
        fbinfo.flags = 0;
        fbinfo.renderPass = rendpass->handle;
        fbinfo.attachmentCount = ret->at_count;
        fbinfo.pAttachments = ret->attachments;
        fbinfo.width = width;
        fbinfo.height = height;
        fbinfo.layers = 1;
        vkassert(vkCreateFramebuffer(dev->ldev, &fbinfo, NULL, &ret->handle), "Failed to create Vulkan framebuffer");

        return ret;
}

void destroy_vkframebuffer(struct vkframebuffer *framebuffer, struct vkdev *dev) {
        vkDestroyFramebuffer(dev->ldev, framebuffer->handle, NULL);
        if (framebuffer->attachments)
                rune_free(framebuffer->attachments);
        rune_free(framebuffer);
}