Crealned up some TODOs, FIXMEs etc. Added better error handling. Looks better, feels better.
109 lines
2.7 KiB
C
109 lines
2.7 KiB
C
#ifndef RSE_VULKAN_BUFFERS_H
|
|
#define RSE_VULKAN_BUFFERS_H
|
|
|
|
#include "vulkan_commons.h"
|
|
#include "utilities/rse_commons.h"
|
|
|
|
#include "vk_mem_alloc.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#define MAX_MESH_NUMBER 256
|
|
|
|
/**
|
|
* @brief Represents data within vertex or instance buffer.
|
|
*
|
|
*/
|
|
struct rse_buffer_data_t
|
|
{
|
|
size_t count;
|
|
size_t buffer_offset;
|
|
};
|
|
|
|
/**
|
|
* @brief Create buffers needed by vulkan pipeline
|
|
*
|
|
* @return rse_err_t RSE_ERROR_NO_ERROR on success
|
|
*/
|
|
rse_err_t create_buffers();
|
|
|
|
/**
|
|
* @brief Update uniform buffers
|
|
*
|
|
*/
|
|
void update_uniform_buffers();
|
|
|
|
/**
|
|
* @brief Add vertices and indices to vulkan buffers
|
|
*
|
|
* @param vertices Vertices to add
|
|
* @param indices Indices to add
|
|
* @param vertex_data Mutable vertex data. Count will be read and buffer offset will be set
|
|
* @param index_data Mutable index data. Count will be read and buffer offset will be set
|
|
* @return rse_err_t RSE_ERROR_NO_ERROR on success
|
|
*/
|
|
rse_err_t rse_add_vertices(uint16_t mesh_id,
|
|
const struct rse_vertex_t* vertices,
|
|
const uint16_t* indices,
|
|
struct rse_buffer_data_t* vertex_data,
|
|
struct rse_buffer_data_t* index_data);
|
|
|
|
/**
|
|
* @brief Add instance data to vulkan buffers
|
|
*
|
|
* @param mesh_id Mesh ID
|
|
* @param instance_data Instance data
|
|
* @return rse_err_t RSE_ERROR_NO_ERROR on success
|
|
*/
|
|
rse_err_t update_mesh_instances(uint16_t mesh_id, struct rse_instance_data_t* instance_data);
|
|
|
|
/**
|
|
* @brief Record commands for given image index
|
|
*
|
|
* @param vulkan_state
|
|
* @param imageIndex
|
|
* @return rse_err_t RSE_ERROR_NO_ERROR on success
|
|
*/
|
|
rse_err_t record_command_buffer(uint32_t imageIndex);
|
|
|
|
/**
|
|
* @brief Reset command buffer for current frame.
|
|
*
|
|
* @param vulkan_state
|
|
*/
|
|
void reset_command_buffer();
|
|
|
|
/**
|
|
* @brief Destroy ALL previously allocated buffers
|
|
*
|
|
* @param vulkan_state
|
|
*/
|
|
void destroy_buffers();
|
|
|
|
|
|
/**
|
|
* @brief Helper function. Creates a buffer object
|
|
*
|
|
* @param size Size of the target buffer
|
|
* @param buffer_usage Buffer usage flags
|
|
* @param memory_usage memory usage flags (mostly VMA_MEMORY_USAGE_AUTO)
|
|
* @param allocation_flags VMA allocation flags
|
|
* @param buffer Buffer, that will be allocated
|
|
* @return rse_err_t RSE_ERROR_NO_ERROR on success. Possible errors:
|
|
* VULKAN_ERROR_COMMAND_BUFFER_ALLOCATION_FAILED
|
|
*/
|
|
rse_err_t create_buffer(const VkDeviceSize size,
|
|
VkBufferUsageFlags buffer_usage,
|
|
VmaMemoryUsage memory_usage,
|
|
const VmaAllocationCreateFlags allocation_flags,
|
|
struct rse_vulkan_buffer_t* buffer);
|
|
|
|
|
|
/**
|
|
* @brief Destroy provided buffer
|
|
*
|
|
* @param buffer buffer to destroy
|
|
*/
|
|
void destroy_buffer(struct rse_vulkan_buffer_t* buffer);
|
|
|
|
#endif /* RSE_VULKAN_BUFFERS_H */ |