Create typedef for IDs
There was a code, where id for something was u32, and u16 for other things. I have created a typedef to fix that Signed-off-by: Piotr Krygier <piotrkrygier@everyonecancode@xyz>
This commit is contained in:
@@ -54,7 +54,7 @@ rse_err_t descriptor_pool_initialize(struct graphics_context_t* context)
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
rse_err_t descriptor_create_new_set(struct graphics_context_t* context, uint32_t* set_id)
|
||||
rse_err_t descriptor_create_new_set(struct graphics_context_t* context, rse_id_t* set_id)
|
||||
{
|
||||
if (context->descriptor_data.descriptor_sets_count >= DESCRIPTOR_MAX_SETS) {
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_GPU, "Reached maximum number of available descriptor sets");
|
||||
@@ -83,7 +83,7 @@ rse_err_t descriptor_add_layout(struct descriptor_set_layout_bindings_t* layout_
|
||||
|
||||
rse_err_t descriptor_set_finish(struct graphics_context_t* context,
|
||||
struct descriptor_set_layout_bindings_t* layout_bindings,
|
||||
uint32_t set_id)
|
||||
rse_id_t set_id)
|
||||
{
|
||||
VkDescriptorSetLayoutCreateInfo create_info = {0};
|
||||
|
||||
@@ -137,8 +137,8 @@ rse_err_t descriptor_build_sets(struct graphics_context_t* context)
|
||||
}
|
||||
|
||||
rse_err_t descriptor_attach_images(struct graphics_context_t* context,
|
||||
uint32_t descriptor_set_id,
|
||||
uint16_t* texture_ids,
|
||||
rse_id_t descriptor_set_id,
|
||||
rse_id_t* texture_ids,
|
||||
size_t images_count,
|
||||
VkSampler sampler,
|
||||
uint32_t binding)
|
||||
@@ -169,7 +169,7 @@ rse_err_t descriptor_attach_images(struct graphics_context_t* context,
|
||||
}
|
||||
|
||||
rse_err_t descriptor_attach_buffer(struct graphics_context_t* context,
|
||||
uint32_t descriptor_set_id,
|
||||
rse_id_t descriptor_set_id,
|
||||
struct vulkan_buffer_t* buffer,
|
||||
uint32_t binding,
|
||||
VkDescriptorType type)
|
||||
|
||||
@@ -24,7 +24,7 @@ rse_err_t descriptor_pool_add_type(struct graphics_context_t* context, VkDescrip
|
||||
|
||||
rse_err_t descriptor_pool_initialize(struct graphics_context_t* context);
|
||||
|
||||
rse_err_t descriptor_create_new_set(struct graphics_context_t* context, uint32_t* set_id);
|
||||
rse_err_t descriptor_create_new_set(struct graphics_context_t* context, rse_id_t* set_id);
|
||||
|
||||
rse_err_t descriptor_add_layout(struct descriptor_set_layout_bindings_t* layout_bindings,
|
||||
uint32_t binding,
|
||||
@@ -34,7 +34,7 @@ rse_err_t descriptor_add_layout(struct descriptor_set_layout_bindings_t* layout_
|
||||
|
||||
rse_err_t descriptor_set_finish(struct graphics_context_t* context,
|
||||
struct descriptor_set_layout_bindings_t* layout_bindings,
|
||||
uint32_t set_id);
|
||||
rse_id_t set_id);
|
||||
|
||||
rse_err_t descriptor_build_sets(struct graphics_context_t* context);
|
||||
|
||||
@@ -55,17 +55,18 @@ rse_err_t descriptor_add_set(struct descriptor_set_handle_t* descriptor_set_hand
|
||||
VkShaderStageFlags shader_stages);
|
||||
|
||||
rse_err_t descriptor_attach_images(struct graphics_context_t* context,
|
||||
uint32_t descriptor_set_id,
|
||||
uint16_t* texture_ids,
|
||||
rse_id_t descriptor_set_id,
|
||||
rse_id_t* texture_ids,
|
||||
size_t images_count,
|
||||
VkSampler sampler,
|
||||
uint32_t binding);
|
||||
|
||||
rse_err_t descriptor_attach_buffer(struct graphics_context_t* context,
|
||||
uint32_t descriptor_set_id,
|
||||
rse_id_t descriptor_set_id,
|
||||
struct vulkan_buffer_t* buffer,
|
||||
uint32_t binding,
|
||||
VkDescriptorType type);
|
||||
|
||||
void destroy_descriptors(struct graphics_context_t* context);
|
||||
|
||||
#endif // !DESCRIPTOR_BUILDER_H
|
||||
|
||||
+16
-11
@@ -23,12 +23,12 @@
|
||||
|
||||
#include "freetype/freetype.h"
|
||||
#include "graphics_context.h"
|
||||
#include "mesh_controller.h"
|
||||
#include "src/vulkan_commons.h"
|
||||
#include "utilities/file_utils.h"
|
||||
#include "vulkan_image.h"
|
||||
#include "utilities/commons.h"
|
||||
#include "utilities/errors_common.h"
|
||||
#include "mesh_controller.h"
|
||||
#include "utilities/file_utils.h"
|
||||
#include "vulkan_image.h"
|
||||
|
||||
#define FONTS_START_CHARACTER_CODE (33U)
|
||||
|
||||
@@ -50,7 +50,7 @@ rse_err_t fonts_init(void)
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
rse_err_t fonts_load_from_file(struct graphics_context_t* context, const char* file_path, uint32_t* font_id)
|
||||
rse_err_t fonts_load_from_file(struct graphics_context_t* context, const char* file_path, rse_id_t* font_id)
|
||||
{
|
||||
FT_Error error = FT_Err_Ok;
|
||||
rse_err_t ret = RSE_ERROR_NO_ERROR;
|
||||
@@ -79,7 +79,7 @@ rse_err_t fonts_load_from_file(struct graphics_context_t* context, const char* f
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
rse_err_t fonts_set_font_size(struct graphics_context_t* context, const uint32_t font_id, const uint32_t font_size)
|
||||
rse_err_t fonts_set_font_size(struct graphics_context_t* context, const rse_id_t font_id, const uint32_t font_size)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
// size_t iter = 0U;
|
||||
@@ -94,9 +94,7 @@ rse_err_t fonts_set_font_size(struct graphics_context_t* context, const uint32_t
|
||||
assert(font_id < FONTS_MAX_COUNT);
|
||||
assert(g_font_faces[font_id] != NULL);
|
||||
|
||||
error = FT_Set_Pixel_Sizes(g_font_faces[font_id],
|
||||
0,
|
||||
font_size);
|
||||
error = FT_Set_Pixel_Sizes(g_font_faces[font_id], 0, font_size);
|
||||
|
||||
if (error != FT_Err_Ok) {
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Failed to set font size. Error code: %d", error);
|
||||
@@ -170,12 +168,18 @@ rse_err_t fonts_set_font_size(struct graphics_context_t* context, const uint32_t
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
rse_err_t print_debug_text(struct graphics_context_t* context, uint32_t font_id, char *text)
|
||||
rse_err_t print_debug_text(struct graphics_context_t* context, rse_id_t font_id, char* text)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
(void)text;
|
||||
|
||||
STATUS_CHECK(mesh_create_instance(context, context->fonts_data.fonts[font_id].font_characters[33].mesh_id, (struct instance_data_t){{0.0f, 0.0f, 2.4f}, {0.0f, 0.0f, 0.0}, 1.0f, context->fonts_data.fonts[font_id].font_characters[33].texture_id}));
|
||||
STATUS_CHECK(mesh_create_instance(
|
||||
context,
|
||||
context->fonts_data.fonts[font_id].font_characters[33].mesh_id,
|
||||
(struct instance_data_t){{0.0f, 0.0f, 2.4f},
|
||||
{0.0f, 0.0f, 0.0},
|
||||
1.0f,
|
||||
context->fonts_data.fonts[font_id].font_characters[33].texture_id}));
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -218,7 +222,8 @@ rse_err_t print_debug_text(struct graphics_context_t* context, uint32_t font_id,
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// STATUS_CHECK(texture_update_image(context, (unsigned char*)context->debug_overlay.pixels, width, height, context->debug_overlay.texture_id, VK_FORMAT_R8G8B8A8_UNORM));
|
||||
// STATUS_CHECK(texture_update_image(context, (unsigned char*)context->debug_overlay.pixels, width, height,
|
||||
// context->debug_overlay.texture_id, VK_FORMAT_R8G8B8A8_UNORM));
|
||||
//
|
||||
// return RSE_ERROR_NO_ERROR;
|
||||
// }
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include "graphics_context.h"
|
||||
|
||||
rse_err_t fonts_init(void);
|
||||
rse_err_t fonts_load_from_file(struct graphics_context_t* context, const char* file_path, uint32_t* font_id);
|
||||
rse_err_t fonts_set_font_size(struct graphics_context_t* context, const uint32_t font_id, const uint32_t font_size);
|
||||
rse_err_t print_debug_text(struct graphics_context_t* context, uint32_t font_id, char *text);
|
||||
rse_err_t fonts_load_from_file(struct graphics_context_t* context, const char* file_path, rse_id_t* font_id);
|
||||
rse_err_t fonts_set_font_size(struct graphics_context_t* context, const rse_id_t font_id, const uint32_t font_size);
|
||||
rse_err_t print_debug_text(struct graphics_context_t* context, rse_id_t font_id, char *text);
|
||||
|
||||
#endif /* FONT_MANAGER_H */
|
||||
|
||||
@@ -165,7 +165,7 @@ struct pipeline_t
|
||||
|
||||
struct pipeline_internal_t
|
||||
{
|
||||
uint32_t descriptor_set_ids[MAX_PIPELINE_COUNT];
|
||||
rse_id_t descriptor_set_ids[MAX_PIPELINE_COUNT];
|
||||
size_t pipelines_count;
|
||||
size_t pipeline_layouts_count;
|
||||
VkPipeline pipelines[MAX_PIPELINE_COUNT];
|
||||
@@ -234,14 +234,14 @@ struct mesh_data_t {
|
||||
|
||||
struct debug_overlay_t
|
||||
{
|
||||
uint16_t texture_id;
|
||||
rse_id_t texture_id;
|
||||
uint32_t* pixels;
|
||||
size_t pixels_size;
|
||||
struct vulkan_image_t image_handle;
|
||||
VkSampler sampler;
|
||||
};
|
||||
|
||||
typedef rse_err_t(*renderer_function_t)(struct graphics_context_t* context, uint32_t renderer_id);
|
||||
typedef rse_err_t(*renderer_function_t)(struct graphics_context_t* context, rse_id_t renderer_id);
|
||||
|
||||
struct renderer_t {
|
||||
renderer_function_t render_function;
|
||||
@@ -253,8 +253,8 @@ struct renderer_data_t {
|
||||
};
|
||||
|
||||
struct font_character_data_t {
|
||||
uint32_t mesh_id;
|
||||
uint16_t texture_id;
|
||||
rse_id_t mesh_id;
|
||||
rse_id_t texture_id;
|
||||
};
|
||||
|
||||
struct sized_font_data_t {
|
||||
|
||||
@@ -24,7 +24,7 @@ rse_err_t mesh_create(struct graphics_context_t* context,
|
||||
uint16_t* indices,
|
||||
size_t vertices_count,
|
||||
size_t indices_count,
|
||||
uint32_t* mesh_id)
|
||||
rse_id_t* mesh_id)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
rse_err_t mesh_create(struct graphics_context_t* context, struct vertex_t* vertices,
|
||||
uint16_t* indices,
|
||||
size_t vertices_count,
|
||||
size_t indices_count, uint32_t* mesh_id);
|
||||
size_t indices_count, rse_id_t* mesh_id);
|
||||
|
||||
/**
|
||||
* @brief Create a instance for the selected mesh. Instance can have its own location, rotation and scale
|
||||
@@ -47,15 +47,15 @@ rse_err_t mesh_create_instance(struct graphics_context_t* context, entity_t enti
|
||||
* @param mesh_id Mesh identifier
|
||||
* @return size_t Number of vertices
|
||||
*/
|
||||
size_t get_vertices_count(struct graphics_context_t* context, uint16_t mesh_id);
|
||||
// size_t get_vertices_count(struct graphics_context_t* context, rse_id_t mesh_id);
|
||||
|
||||
/**
|
||||
* @brief Get the index count for mesh with mesh_id ID
|
||||
*
|
||||
* @param mesh_id Mesh identifier
|
||||
w @param mesh_id Mesh identifier
|
||||
* @return size_t Number of indices
|
||||
*/
|
||||
size_t get_indices_count(struct graphics_context_t* context, uint16_t mesh_id);
|
||||
// size_t get_indices_count(struct graphics_context_t* context, rse_id_t mesh_id);
|
||||
|
||||
/**
|
||||
* @brief Get vertex offset in vertex buffer for selected mesh
|
||||
@@ -63,6 +63,6 @@ size_t get_indices_count(struct graphics_context_t* context, uint16_t mesh_id);
|
||||
* @param mesh_id Mesh identifies
|
||||
* @return size_t Offset
|
||||
*/
|
||||
size_t get_vertex_offset(struct graphics_context_t* context, uint16_t mesh_id);
|
||||
// size_t get_vertex_offset(struct graphics_context_t* context, rse_id_t mesh_id);
|
||||
|
||||
#endif /* MESH_CONTROLLER_H */
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#define MAX_BINDLESS_RESOURCES 1000
|
||||
|
||||
rse_err_t shader_create_module(struct graphics_context_t* context,
|
||||
uint16_t* shader_module_id,
|
||||
rse_id_t* shader_module_id,
|
||||
const char* shader_path,
|
||||
const VkShaderStageFlagBits shader_stage)
|
||||
{
|
||||
@@ -197,7 +197,7 @@ static rse_err_t pipeline_add_depth_stencil(struct pipeline_t* pipeline)
|
||||
|
||||
rse_err_t pipeline_add_descriptor_sets(struct graphics_context_t* context,
|
||||
struct pipeline_t* pipeline,
|
||||
uint32_t descriptor_set_id)
|
||||
rse_id_t descriptor_set_id)
|
||||
{
|
||||
VkPipelineLayoutCreateInfo create_info = {0};
|
||||
create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||
@@ -271,7 +271,7 @@ rse_err_t pipeline_builder_init(struct pipeline_t* pipeline)
|
||||
|
||||
rse_err_t pipeline_add_shader_stage(struct graphics_context_t* context,
|
||||
struct pipeline_t* pipeline,
|
||||
const uint32_t shader_id)
|
||||
const rse_id_t shader_id)
|
||||
{
|
||||
size_t i = 0;
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "utilities/commons.h"
|
||||
|
||||
rse_err_t shader_create_module(struct graphics_context_t* context,
|
||||
uint16_t* shader_module_id,
|
||||
rse_id_t* shader_module_id,
|
||||
const char* shader_path,
|
||||
const VkShaderStageFlagBits shader_stage);
|
||||
|
||||
@@ -42,7 +42,7 @@ rse_err_t pipeline_builder_init(struct pipeline_t* pipeline);
|
||||
*/
|
||||
rse_err_t pipeline_add_shader_stage(struct graphics_context_t* context,
|
||||
struct pipeline_t* pipeline,
|
||||
const uint32_t shader_id);
|
||||
const rse_id_t shader_id);
|
||||
|
||||
/**
|
||||
* @brief Add vertex input binding to pipeline
|
||||
|
||||
@@ -114,16 +114,16 @@ rse_err_t rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
struct graphics_context_t* context = rse_context->context;
|
||||
uint16_t textures[2] = {0};
|
||||
rse_id_t textures[2] = {0};
|
||||
struct pipeline_t pipeline;
|
||||
uint32_t descriptor_set_handle = 0;
|
||||
rse_id_t descriptor_set_handle = 0;
|
||||
struct descriptor_set_layout_bindings_t layout_bindings = {0};
|
||||
struct pipeline_infos_t pipeline_infos = {0};
|
||||
struct vulkan_buffer_t model_view_projection_buffer = {0};
|
||||
uint32_t mesh_id_1, mesh_id_2 = 0;
|
||||
uint32_t font_id = 0;
|
||||
uint32_t static_mesh_renderer = 0U;
|
||||
uint16_t vertex_shader_id, fragment_shader_id;
|
||||
rse_id_t mesh_id_1, mesh_id_2 = 0;
|
||||
rse_id_t font_id = 0;
|
||||
rse_id_t static_mesh_renderer = 0U;
|
||||
rse_id_t vertex_shader_id, fragment_shader_id;
|
||||
|
||||
texture_load_from_file(context, "../../test_image.jpg", &textures[0]);
|
||||
texture_load_from_file(context, "../../test_image_2.jpg", &textures[1]);
|
||||
|
||||
@@ -304,7 +304,7 @@ static rse_err_t create_textured_image(struct graphics_context_t* context,
|
||||
uint32_t height,
|
||||
VkFormat format,
|
||||
const unsigned char* pixels,
|
||||
uint16_t* texture_id)
|
||||
rse_id_t* texture_id)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
struct vulkan_buffer_t staging_buffer = {0};
|
||||
@@ -411,7 +411,7 @@ rse_err_t texture_update_image(struct graphics_context_t* context,
|
||||
const unsigned char* pixels,
|
||||
int width,
|
||||
int height,
|
||||
uint16_t texture_id,
|
||||
rse_id_t texture_id,
|
||||
VkFormat format)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
@@ -479,7 +479,7 @@ rse_err_t load_texture_from_bitmat(struct graphics_context_t* context,
|
||||
const unsigned char* pixel_buffer,
|
||||
int width,
|
||||
int height,
|
||||
uint16_t* texture_id,
|
||||
rse_id_t* texture_id,
|
||||
VkFormat color_format)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
@@ -490,7 +490,7 @@ rse_err_t load_texture_from_bitmat(struct graphics_context_t* context,
|
||||
return status;
|
||||
}
|
||||
|
||||
rse_err_t texture_load_from_file(struct graphics_context_t* context, const char* file_path, uint16_t* texture_id)
|
||||
rse_err_t texture_load_from_file(struct graphics_context_t* context, const char* file_path, rse_id_t* texture_id)
|
||||
{
|
||||
rse_err_t status = RSE_ERROR_NO_ERROR;
|
||||
int width = 0;
|
||||
@@ -548,7 +548,7 @@ void destroy_color_resource(struct graphics_context_t* context)
|
||||
vmaDestroyImage(context->vulkan_handles.allocator, context->color_image.image, context->color_image.allocation);
|
||||
}
|
||||
|
||||
uint8_t image_exists(struct graphics_context_t* context, uint8_t image_id)
|
||||
uint8_t image_exists(struct graphics_context_t* context, rse_id_t image_id)
|
||||
{
|
||||
return context->texture_images[image_id].id_taken == IMAGE_TAKEN;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ rse_err_t init_vulkan_images(struct graphics_context_t* context);
|
||||
* @return rse_err_t RSE_ERROR_NO_ERROR on success
|
||||
*/
|
||||
rse_err_t load_texture_from_bitmat(struct graphics_context_t* context, const unsigned char* pixel_buffer, int width,
|
||||
int height, uint16_t* texture_id, VkFormat color_format);
|
||||
int height, rse_id_t* texture_id, VkFormat color_format);
|
||||
|
||||
/**
|
||||
* @brief Loads image from file, for later to be used as a texture
|
||||
@@ -48,13 +48,13 @@ rse_err_t load_texture_from_bitmat(struct graphics_context_t* context, const uns
|
||||
* @param texture_id Texture ID will be set up here
|
||||
* @return rse_err_t RSE_ERROR_NO_ERROR on success
|
||||
*/
|
||||
rse_err_t texture_load_from_file(struct graphics_context_t* context, const char* file_path, uint16_t* texture_id);
|
||||
rse_err_t texture_load_from_file(struct graphics_context_t* context, const char* file_path, rse_id_t* texture_id);
|
||||
|
||||
rse_err_t texture_update_image(struct graphics_context_t* context,
|
||||
const unsigned char* pixels,
|
||||
int width,
|
||||
int height,
|
||||
uint16_t texture_id,
|
||||
rse_id_t texture_id,
|
||||
VkFormat format);
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ void destroy_textures(struct graphics_context_t* context);
|
||||
* @param image_id Image ID
|
||||
* @return uint8_t 1 on success, 0 on failure
|
||||
*/
|
||||
uint8_t image_exists(struct graphics_context_t* context, uint8_t image_id);
|
||||
uint8_t image_exists(struct graphics_context_t* context, rse_id_t image_id);
|
||||
|
||||
/**
|
||||
* @brief Returns number of loaded texture
|
||||
|
||||
@@ -45,4 +45,10 @@
|
||||
*/
|
||||
typedef uint32_t rse_err_t;
|
||||
|
||||
/**
|
||||
* @brief General type for ID use
|
||||
*
|
||||
*/
|
||||
typedef uint32_t rse_id_t;
|
||||
|
||||
#endif /* COMMONS_H */
|
||||
|
||||
Reference in New Issue
Block a user