diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-03-17 17:03:33 +1100 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-03-17 17:03:33 +1100 |
commit | 9ef22d2af0001bbc402454c8d605339ec6a428ae (patch) | |
tree | 748f5abb86edd255015647a7d414a725e2d2e76e /src/renderer | |
parent | 8c331ac497d6e6705cde5e292538d4ab7d9a16ec (diff) |
draw_scene that uses transform hierarchy to draw all models
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/render.c | 27 | ||||
-rw-r--r-- | src/renderer/render.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/renderer/render.c b/src/renderer/render.c index ca625ed..043a1fc 100644 --- a/src/renderer/render.c +++ b/src/renderer/render.c @@ -1,3 +1,6 @@ +#include <stdlib.h> +#include "mem.h" +#include "transform_hierarchy.h" #define STB_IMAGE_IMPLEMENTATION #include <stb_image.h> @@ -80,6 +83,30 @@ void default_material_init() { texture_data_upload(&DEFAULT_MATERIAL.specular_texture); } +typedef struct draw_ctx { + model_darray* models; + renderer* ren; + camera* cam; + scene* scene; +} draw_ctx; +bool draw_scene_node(transform_node* node, void* ctx_data) { + if (!node || !node->parent) return true; + draw_ctx* ctx = ctx_data; + model* m = &ctx->models->data[node->model.raw]; + draw_model(ctx->ren, ctx->cam, m, &node->world_matrix_tf, ctx->scene); + return true; +} + +void draw_scene(arena* frame, model_darray* models, renderer* ren, camera* camera, + transform_hierarchy* tfh, scene* scene) { + draw_ctx* ctx = arena_alloc(frame, sizeof(draw_ctx)); + ctx->models = models; + ctx->ren = ren; + ctx->cam = camera; + ctx->scene = scene; + transform_hierarchy_dfs(transform_hierarchy_root_node(tfh), draw_scene_node, true, ctx); +} + void draw_model(renderer* ren, camera* camera, model* model, mat4* model_tf, scene* scene) { // TRACE("Drawing model: %s", model->name); mat4 view; diff --git a/src/renderer/render.h b/src/renderer/render.h index 61dda75..bcdeb78 100644 --- a/src/renderer/render.h +++ b/src/renderer/render.h @@ -3,6 +3,7 @@ #include "camera.h" #include "loaders.h" #include "render_types.h" +#include "transform_hierarchy.h" // --- Lifecycle /** @brief initialise the render system frontend */ @@ -19,6 +20,7 @@ void render_frame_end(renderer* ren); void model_upload_meshes(renderer* ren, model* model); void draw_model(renderer* ren, camera* camera, model* model, mat4* tf, scene* scene); void draw_mesh(renderer* ren, mesh* mesh, mat4* tf, material* mat, mat4* view, mat4* proj); +void draw_scene(arena* frame, model_darray* models, renderer* ren, camera* camera, transform_hierarchy *tfh, scene* scene); // --- texture texture_data_load(const char* path, bool invert_y); // #frontend |