Add basic loader for gltf

Added loading of avocado. Something is still wrong though,
becaus I cannot see the seed. But basic functionality is there.
This commit is contained in:
Piotr Krygier
2026-03-19 21:00:39 +01:00
parent 984a56a8e8
commit 99fb36d9fd
14 changed files with 186 additions and 32 deletions
+34 -19
View File
@@ -116,7 +116,7 @@ rse_err_t rse_graphics_init(struct graphics_context_t* context)
return status;
}
#define TEXTURES_COUNT (2U)
#define TEXTURES_COUNT (3U)
rse_err_t rse_graphics_test_function(struct graphics_context_t* context)
{
rse_err_t status = RSE_ERROR_NO_ERROR;
@@ -125,28 +125,35 @@ rse_err_t rse_graphics_test_function(struct graphics_context_t* context)
rse_id_t descriptor_set_handle = 0;
struct descriptor_set_layout_bindings_t layout_bindings = {0};
struct pipeline_infos_t pipeline_infos = {0};
rse_id_t mesh_id_1, mesh_id_2 = 0;
rse_id_t font_id = 0;
rse_id_t mesh_id_1 = 0;
rse_id_t mesh_id_2 = 0;
rse_id_t avocado_id = 0;
// rse_id_t font_id = 0;
rse_id_t static_mesh_renderer = 0U;
rse_id_t vertex_shader_id, fragment_shader_id;
STATUS_CHECK(texture_load_from_file(context, "../../test_image.jpg", &textures[0]));
STATUS_CHECK(texture_load_from_file(context, "../../test_image_2.jpg", &textures[1]));
STATUS_CHECK(texture_load_from_file(context, "../../Avocado_baseColor.png", &textures[2]));
STATUS_CHECK(fonts_init());
STATUS_CHECK(fonts_load_from_file(context, "../../NotoSansMono-Regular.ttf", &font_id));
STATUS_CHECK(fonts_set_font_size(context, font_id, 16));
// STATUS_CHECK(fonts_init());
// STATUS_CHECK(fonts_load_from_file(context, "../../NotoSansMono-Regular.ttf", &font_id));
// STATUS_CHECK(fonts_set_font_size(context, font_id, 16));
// FIXME: Temporary array of vertices, for testing purposes
struct vertex_t vertices[] = {{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}};
struct vertex_t vertices[] = {
{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
};
struct vertex_t vertices2[] = {{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}};
struct vertex_t vertices_2[] = {
{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
{{0.2f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
{{0.2f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
};
// FIXME: Temporary array of vertices, for testing purposes
uint16_t indices[] = {0, 1, 2, 2, 3, 0};
@@ -155,7 +162,7 @@ rse_err_t rse_graphics_test_function(struct graphics_context_t* context)
if (RSE_ERROR_NO_ERROR !=
mesh_create_instance(context,
mesh_id_1,
(struct instance_data_t){{0.0f, 0.0f, 2.4f}, {0.0f, 0.0f, 0.0}, 1.0f, textures[1]})) {
(struct instance_data_t){{0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0}, 1.0f, textures[0]})) {
exit(1);
}
@@ -163,17 +170,25 @@ rse_err_t rse_graphics_test_function(struct graphics_context_t* context)
mesh_create_instance(
context,
mesh_id_1,
(struct instance_data_t){{-0.5f, 0.0f, -1.0f}, {0.0f, 0.0f, glm_rad(10.0f)}, 1.0f, textures[0]})) {
(struct instance_data_t){{-0.5f, 0.0f, -1.0f}, {0.0f, 0.0f, glm_rad(10.0f)}, 1.0f, textures[1]})) {
exit(1);
}
STATUS_CHECK(mesh_create(context, vertices2, indices, 4, 6, &mesh_id_2));
STATUS_CHECK(mesh_create(context, vertices_2, indices, 4, 6, &mesh_id_2));
if (RSE_ERROR_NO_ERROR !=
mesh_create_instance(
context,
mesh_id_2,
(struct instance_data_t){{1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, glm_rad(0.0f)}, 1.0f, textures[0]})) {
(struct instance_data_t){{0.5f, 0.0f, -1.0f}, {0.0f, 0.0f, glm_rad(0.0f)}, 1.0f, textures[1]})) {
exit(1);
}
mesh_create_from_file(context, "../../Avocado.glb", &avocado_id);
if (RSE_ERROR_NO_ERROR !=
mesh_create_instance(
context,
avocado_id,
(struct instance_data_t){{0.0f, 0.0f, -4.0f}, {0.0f, glm_rad(130.0f), 0.0f}, 2.0f, textures[2]})) {
exit(1);
}