summaryrefslogtreecommitdiff
path: root/src/renderer/backends
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer/backends')
-rw-r--r--src/renderer/backends/backend_vulkan.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c
index 88cc87b..6e80861 100644
--- a/src/renderer/backends/backend_vulkan.c
+++ b/src/renderer/backends/backend_vulkan.c
@@ -75,6 +75,15 @@ typedef struct vulkan_renderpass {
vulkan_renderpass_state state;
} vulkan_renderpass;
+typedef struct vulkan_framebuffer {
+ VkFramebuffer handle;
+ u32 attachment_count;
+ VkImageView* attachments;
+ vulkan_renderpass* renderpass;
+} vulkan_framebuffer;
+
+KITC_DECL_TYPED_ARRAY(vulkan_framebuffer)
+
typedef struct vulkan_swapchain {
VkSurfaceFormatKHR image_format;
u8 max_frames_in_flight;
@@ -83,6 +92,7 @@ typedef struct vulkan_swapchain {
VkImage* images;
VkImageView* views;
vulkan_image depth_attachment;
+ vulkan_framebuffer_darray* framebuffers;
} vulkan_swapchain;
typedef enum vulkan_command_buffer_state {
@@ -122,10 +132,6 @@ typedef struct vulkan_context {
#endif
} vulkan_context;
-typedef struct vulkan_framebuffer {
- // TODO: struct members
-} vulkan_framebuffer;
-
static vulkan_context context;
/** @brief Internal backend state */
@@ -385,6 +391,36 @@ void vulkan_image_create(vulkan_context* context, VkImageType image_type, u32 wi
// TODO: vulkan_image_destroy
+void vulkan_framebuffer_create(
+ vulkan_context* context,
+ vulkan_renderpass* renderpass,
+ u32 width, u32 height,
+ u32 attachment_count,
+ VkImageView* attachments,
+ vulkan_framebuffer* out_framebuffer
+) {
+ out_framebuffer->attachments = malloc(sizeof(VKImageView) * attachment_count);
+ for (u32 i = 0; i < attachment_count; i++) {
+ out_framebuffer->attachments[i] = attachments[i];
+ }
+ out_framebuffer->attachment_count = attachment_count;
+ out_framebuffer->renderpass = renderpass;
+
+ VkFramebufferCreateInfo framebuffer_create_info = {}; // TODO
+
+ framebuffer_create_info.renderPass = renderpass->handle;
+ // TODO: fill out info - https://youtu.be/Is6CwlsaCFE?si=86ZGxU7S8licijCD&t=252
+
+ vkCreateFramebuffer(
+ context->device.logical_device,
+ &framebuffer_create_info,
+ context->allocator,
+ &out_framebuffer->handle
+ );
+}
+
+// TODO: vulkan_framebuffer_destroy
+
void vulkan_command_buffer_allocate(vulkan_context* context, VkCommandPool pool, bool is_primary,
vulkan_command_buffer* out_command_buffer) {
VkCommandBufferAllocateInfo allocate_info = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO };
@@ -716,6 +752,20 @@ void create_command_buffers(renderer* ren) {
}
}
+void regenerate_framebuffers(renderer* ren, vulkan_swapchain* swapchain, vulkan_renderpass* renderpass) {
+ for (u32 i = 0; i < swapchain->image_count; i++) {
+ u32 attachment_count = 2; // one for depth, one for colour
+
+ VkImageView attachments[2] = {
+ swapchain->views[i],
+ swapchain->depth_attachment
+ };
+
+ vulkan_framebuffer_create(context,
+ renderpass, context.framebuffer_width, context.framebuffer_height, 2, attachments, swapchain->framebuffers->data[i]);
+ }
+}
+
bool gfx_backend_init(renderer* ren) {
INFO("loading Vulkan backend");
@@ -838,6 +888,10 @@ bool gfx_backend_init(renderer* ren) {
vec4(0, 0, context.framebuffer_width, context.framebuffer_height),
vec4(0.0, 0.0, 0.2, 1.0), 1.0, 0);
+ // Framebiffers creation
+ context.swapchain.framebuffers = vulkan_framebuffer_darray_new(context.swapchain.image_count);
+ regenerate_framebuffers(ren, &context.swapchain, &context.main_renderpass);
+
// Command buffers creation
create_command_buffers(ren);