Add gltf loader

Added MIT licensed external library for loading gltf
files

Signed-off-by: Piotr Krygier <piotrkrygier@everyonecancode@xyz>
This commit is contained in:
Piotr Krygier
2026-03-12 13:21:24 +01:00
parent c6825caa69
commit dd70f5e5b0
7 changed files with 7289 additions and 6 deletions
BIN
View File
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
#include "utilities/commons.h"
rse_err_t object_load_gltf(const char* file_path)
{
}
+2 -2
View File
@@ -44,9 +44,9 @@ rse_err_t shader_create_module(struct graphics_context_t* context,
} }
/* Read shader file */ /* Read shader file */
file_read(shader_path, &buffer_size, NULL); file_read_bytes(shader_path, &buffer_size, NULL);
rse_malloc(buffer, buffer_size); rse_malloc(buffer, buffer_size);
file_read(shader_path, &buffer_size, buffer); file_read_bytes(shader_path, &buffer_size, buffer);
create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
create_info.pNext = NULL; create_info.pNext = NULL;
+7
View File
@@ -263,6 +263,13 @@ rse_err_t rse_graphics_main_loop(struct graphics_context_t* context)
return status; return status;
} }
// rse_err_t rse_graphics_load_model(struct graphics_context_t* context, const char* model_path, rse_id_t* model_id)
// {
// rse_err_t status = RSE_ERROR_NO_ERROR;
//
// return status;
// }
void rse_graphics_deinit(struct graphics_context_t* context) void rse_graphics_deinit(struct graphics_context_t* context)
{ {
vulkan_deinit(context); vulkan_deinit(context);
+7240
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -14,7 +14,7 @@
* @param bytes_count Returned bytes count * @param bytes_count Returned bytes count
* @param buffer Returned filled buffer * @param buffer Returned filled buffer
*/ */
rse_err_t file_read(const char* file_path, size_t* bytes_count, char* buffer); rse_err_t file_read_bytes(const char* file_path, size_t* bytes_count, char* buffer);
rse_err_t file_write(const char* file_name, size_t bytes_count, char* buffer); rse_err_t file_write(const char* file_name, size_t bytes_count, char* buffer);
@@ -22,5 +22,7 @@ rse_err_t file_load_pixels(const char* file_name, unsigned char* buffer, size_t*
rse_err_t file_append_full_path(char* file_path, size_t max_buffer_size); rse_err_t file_append_full_path(char* file_path, size_t max_buffer_size);
rse_err_t file_json_parser(const char* file_name);
#endif /* FILE_UTILS_H */ #endif /* FILE_UTILS_H */
+31 -3
View File
@@ -1,8 +1,14 @@
#include "file_utils.h" #include "file_utils.h"
#define CGLTF_IMPLEMENTATION
#include "cgltf.h"
#include <stddef.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <vulkan/vulkan_core.h>
#include "SDL3/SDL_log.h" #include "SDL3/SDL_log.h"
#include "commons.h" #include "commons.h"
@@ -151,7 +157,7 @@ rse_err_t file_load_pixels(const char* file_name, unsigned char* buffer, size_t*
return RSE_ERROR_INTERNAL_ERROR; return RSE_ERROR_INTERNAL_ERROR;
} }
image_buffer_size = *width * *height * 4; // TODO: "4" is very hardcoded value. Change this image_buffer_size = *width * *height * 4; // TODO: "4" is very hardcoded value. Change this
if ((buffer != NULL) && (image_buffer_size > *buffer_size)) { if ((buffer != NULL) && (image_buffer_size > *buffer_size)) {
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
@@ -176,7 +182,7 @@ image_free:
return ret; return ret;
} }
rse_err_t file_read(const char* file_name, size_t* bytes_count, char* buffer) rse_err_t file_read_bytes(const char* file_name, size_t* bytes_count, char* buffer)
{ {
rse_err_t ret = RSE_ERROR_NO_ERROR; rse_err_t ret = RSE_ERROR_NO_ERROR;
FILE* file = NULL; FILE* file = NULL;
@@ -238,5 +244,27 @@ rse_err_t file_write(const char* file_name, size_t bytes_count, char* buffer)
fwrite(buffer, bytes_count, 1, file); fwrite(buffer, bytes_count, 1, file);
fclose(file); fclose(file);
return RSE_ERROR_NO_ERROR; return ret;
}
rse_err_t file_load_gltf(const char* file_name)
{
char real_path[MAX_PATH_LENGTH] = {0};
rse_err_t ret = RSE_ERROR_NO_ERROR;
cgltf_options options = {0};
cgltf_data* data = NULL;
strncpy(real_path, file_name, MAX_PATH_LENGTH);
if ((ret = file_append_full_path(real_path, MAX_PATH_LENGTH)) != RSE_ERROR_NO_ERROR) {
return ret;
}
if (cgltf_parse_file(&options, real_path, &data) != cgltf_result_success) {
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Failed to parse GLTF data");
return RSE_ERROR_INTERNAL_ERROR;
}
cgltf_free(data);
return ret;
} }