1 #include <kiba/renderer/vulkan/index_buffer.h>
4 #include <kiba/renderer/vulkan/buffer.h>
10 context->index_count = 0;
14 if (!filesystem_open(&file,
"./assets/models/viking_room_indices",
true,
FILE_MODE_READ)) {
15 KB_ERROR(
"could not open indices file");
20 KB_ASSERT(filesystem_size(&file, &file_size),
"must work");
22 VkDeviceSize size = file_size;
24 if (vulkan_buffer_create(context,
26 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
27 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
31 VK_CALL_B8(vkMapMemory(context->device.logical, staging.memory, 0, size, 0, &data));
32 if (filesystem_read_all(&file, file_size, data, &bytes_read)) {
33 if (vulkan_buffer_create(context,
35 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
36 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
37 &context->index_data)) {
38 ret = vulkan_buffer_copy(context, &staging, &context->index_data, size);
39 context->index_count = (u32) (bytes_read /
sizeof(u32));
42 vkUnmapMemory(context->device.logical, staging.memory);
43 vulkan_buffer_destroy(context, &staging);
45 filesystem_close(&file);
49 void vulkan_index_buffer_destroy(
vulkan_context *context) { vulkan_buffer_destroy(context, &context->index_data); }
Lightweight layer between platform and other engine components to enable tracing/monitoring.
Interface to access the platform's filesystem.
@ FILE_MODE_READ
Needed to be able to read from a file.
#define KB_ASSERT(expr,...)
Perform runtime assertion and log failures.
#define KB_ERROR(...)
Log entry with error log level.