Added handle system and improve resource management.

This commit is contained in:
2025-12-31 23:50:22 +09:00
parent 5c988108ef
commit acaaa2a86e
33 changed files with 998 additions and 915 deletions

View File

@@ -2,8 +2,9 @@
#define GEOMETRY_UTILITIES_H
#include "Triangle.h"
#include "../Material/Material.h"
inline void quad_create(vec3s center, vec3s forward, vec3s up, float size, uint8_t material_id, triangle_collection_t* collection)
inline void quad_create(vec3s center, vec3s forward, vec3s up, float size, material_handle_t material, triangle_list_t* list)
{
float half_size = size / 2.0f;
vec3s right = glms_vec3_cross(forward, up);
@@ -37,8 +38,28 @@ inline void quad_create(vec3s center, vec3s forward, vec3s up, float size, uint8
vertex_t vertex_2 = {.position = bottom_right, .normal = forward, .tangent = tangent, .uv = {1.0f, 1.0f}};
vertex_t vertex_3 = {.position = bottom_left, .normal = forward, .tangent = tangent, .uv = {0.0f, 1.0f}};
triangle_create(vertex_0, vertex_1, vertex_3, material_id, collection);
triangle_create(vertex_1, vertex_2, vertex_3, material_id, collection);
triangle_create(vertex_0, vertex_1, vertex_3, material, list);
triangle_create(vertex_1, vertex_2, vertex_3, material, list);
}
inline void cube_create(vec3s center, float size, material_handle_t material, triangle_list_t* list)
{
vec3s forward = {0.0f, 0.0f, 1.0f};
vec3s up = {0.0f, 1.0f, 0.0f};
float half_size = size / 2.0f;
// Front face
quad_create(glms_vec3_add(center, (vec3s){0.0f, 0.0f, half_size}), forward, up, size, material, list);
// Back face
quad_create(glms_vec3_sub(center, (vec3s){0.0f, 0.0f, half_size}), glms_vec3_negate(forward), up, size, material, list);
// Left face
quad_create(glms_vec3_sub(center, (vec3s){half_size, 0.0f, 0.0f}), glms_vec3_negate(glms_vec3_cross(forward, up)), up, size, material, list);
// Right face
quad_create(glms_vec3_add(center, (vec3s){half_size, 0.0f, 0.0f}), glms_vec3_cross(forward, up), up, size, material, list);
// Top face
quad_create(glms_vec3_add(center, (vec3s){0.0f, half_size, 0.0f}), up, glms_vec3_negate(forward), size, material, list);
// Bottom face
quad_create(glms_vec3_sub(center, (vec3s){0.0f, half_size, 0.0f}), glms_vec3_negate(up), forward, size, material, list);
}
#endif // GEOMETRY_UTILITIES_H