1 #include <kiba/renderer/vulkan/vertex_buffer.h>
4 #include <kiba/renderer/vulkan/buffer.h>
22 if (!filesystem_open(&file,
"./assets/models/viking_room_vertices",
true,
FILE_MODE_READ)) {
23 KB_ERROR(
"could not open vertices file");
28 KB_ASSERT(filesystem_size(&file, &file_size),
"must work");
30 VkDeviceSize size = file_size;
32 if (vulkan_buffer_create(context,
34 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
35 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
39 VK_CALL_B8(vkMapMemory(context->device.logical, staging.memory, 0, size, 0, &data));
40 if (filesystem_read_all(&file, file_size, data, &bytes_read)) {
41 if (vulkan_buffer_create(context,
43 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
44 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
45 &context->vertex_data)) {
46 ret = vulkan_buffer_copy(context, &staging, &context->vertex_data, size);
49 vkUnmapMemory(context->device.logical, staging.memory);
50 vulkan_buffer_destroy(context, &staging);
52 filesystem_close(&file);
56 void vulkan_vertex_buffer_destroy(
vulkan_context *context) { vulkan_buffer_destroy(context, &context->vertex_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.