From 9baff5661f2ba8b57e1b0794e490e239b7ef80ca Mon Sep 17 00:00:00 2001 From: omnisci3nce <17525998+omnisci3nce@users.noreply.github.com> Date: Thu, 4 Apr 2024 22:53:13 +1100 Subject: loading animation data - step 1 --- src/renderer/backends/backend_opengl.c | 4 +--- src/renderer/render.c | 16 ++++++++++++++++ src/renderer/render.h | 2 ++ src/renderer/render_types.h | 12 ++++++++++-- 4 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src/renderer') diff --git a/src/renderer/backends/backend_opengl.c b/src/renderer/backends/backend_opengl.c index 8df0933..b769002 100644 --- a/src/renderer/backends/backend_opengl.c +++ b/src/renderer/backends/backend_opengl.c @@ -42,9 +42,7 @@ bool gfx_backend_init(renderer *ren) { return true; } -void gfx_backend_draw_frame(renderer* ren, camera* cam, mat4 model, texture* tex) { - -} +void gfx_backend_draw_frame(renderer *ren, camera *cam, mat4 model, texture *tex) {} void gfx_backend_shutdown(renderer *ren) {} diff --git a/src/renderer/render.c b/src/renderer/render.c index 2993225..2f5e553 100644 --- a/src/renderer/render.c +++ b/src/renderer/render.c @@ -1,3 +1,4 @@ +#include "mem.h" #define STB_IMAGE_IMPLEMENTATION #include @@ -88,6 +89,21 @@ void default_material_init() { texture_data_upload(&DEFAULT_MATERIAL.specular_texture); } +void model_destroy(model* model) { + arena_free_all(&model->animation_data_arena); + arena_free_storage(&model->animation_data_arena); + mesh_darray_free(model->meshes); + material_darray_free(model->materials); + if (model->is_uploaded) { + // Delete gpu buffer data + for (u32 i = 0; i < mesh_darray_len(model->meshes); i++) { + // FIXME: dont leak Opengl + glDeleteBuffers(1, &model->meshes->data[i].vbo); + glDeleteVertexArrays(1, &model->meshes->data[i].vao); + } + } +} + void draw_model(renderer* ren, camera* camera, model* model, transform tf, scene* scene) { // TRACE("Drawing model: %s", model->name); mat4 view; diff --git a/src/renderer/render.h b/src/renderer/render.h index b6dad00..f0118b6 100644 --- a/src/renderer/render.h +++ b/src/renderer/render.h @@ -35,5 +35,7 @@ void model_upload_meshes(renderer* ren, model* model); void draw_model(renderer* ren, camera* camera, model* model, transform tf, scene* scene); void draw_mesh(renderer* ren, mesh* mesh, transform tf, material* mat, mat4* view, mat4* proj); +void model_destroy(model* model); + // --- texture texture_data_load(const char* path, bool invert_y); // #frontend diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h index 80e1372..8d12183 100644 --- a/src/renderer/render_types.h +++ b/src/renderer/render_types.h @@ -7,6 +7,7 @@ */ #pragma once +#include "animation.h" #include "darray.h" #include "maths.h" #include "maths_types.h" @@ -52,8 +53,8 @@ typedef struct renderer { typedef struct texture { u32 texture_id; char name[MAX_TEXTURE_NAME_LEN]; - void* image_data; - void* backend_data; + void *image_data; + void *backend_data; u32 width; u32 height; u8 channel_count; @@ -84,6 +85,11 @@ KITC_DECL_TYPED_ARRAY(material) // creates "material_darray" #define TYPED_MATERIAL_ARRAY #endif +#ifndef TYPED_ANIMATION_CLIP_ARRAY +KITC_DECL_TYPED_ARRAY(animation_clip) // creates "material_darray" +#define TYPED_ANIMATION_CLIP_ARRAY +#endif + // lights typedef struct point_light { vec3 position; @@ -137,6 +143,8 @@ typedef struct model { mesh_darray *meshes; aabb_3d bbox; material_darray *materials; + animation_clip_darray *animations; + arena animation_data_arena; bool is_loaded; bool is_uploaded; } model; -- cgit v1.2.3-70-g09d2