basic rendering for both opengl and vulkan
This commit is contained in:
parent
4b18afa040
commit
dadd2edaf1
29 changed files with 1140 additions and 38 deletions
48
rendering/vk/sync.c
Normal file
48
rendering/vk/sync.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* SPDX-License-Identifier:BSD-3-Clause */
|
||||
#include "sync.h"
|
||||
#include "../../core/log.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void vk_sync_init(struct renderer_context *context)
|
||||
{
|
||||
u32 count = context->swapchain.image_count;
|
||||
|
||||
context->image_available = malloc(sizeof(VkSemaphore) * count);
|
||||
context->render_finished = malloc(sizeof(VkSemaphore) * count);
|
||||
context->in_flight = malloc(sizeof(VkFence) * count);
|
||||
|
||||
VkSemaphoreCreateInfo semaphore_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO
|
||||
};
|
||||
|
||||
VkFenceCreateInfo fence_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
||||
.flags = VK_FENCE_CREATE_SIGNALED_BIT
|
||||
};
|
||||
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
if (vkCreateSemaphore(context->device, &semaphore_info, NULL, &context->image_available[i]) != VK_SUCCESS ||
|
||||
vkCreateSemaphore(context->device, &semaphore_info, NULL, &context->render_finished[i]) != VK_SUCCESS ||
|
||||
vkCreateFence(context->device, &fence_info, NULL, &context->in_flight[i]) != VK_SUCCESS) {
|
||||
fatal("Can't create sync objects.\n");
|
||||
}
|
||||
}
|
||||
|
||||
context->current_frame = 0;
|
||||
log_info("Sync objects created.\n");
|
||||
}
|
||||
|
||||
void vk_sync_deinit(struct renderer_context *context)
|
||||
{
|
||||
u32 count = context->swapchain.image_count;
|
||||
|
||||
for (u32 i = 0; i < count; i++) {
|
||||
vkDestroySemaphore(context->device, context->image_available[i], NULL);
|
||||
vkDestroySemaphore(context->device, context->render_finished[i], NULL);
|
||||
vkDestroyFence(context->device, context->in_flight[i], NULL);
|
||||
}
|
||||
|
||||
free(context->image_available);
|
||||
free(context->render_finished);
|
||||
free(context->in_flight);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue