summaryrefslogtreecommitdiff
path: root/src/renderer/render.c
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-17 17:03:33 +1100
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-17 17:03:33 +1100
commit9ef22d2af0001bbc402454c8d605339ec6a428ae (patch)
tree748f5abb86edd255015647a7d414a725e2d2e76e /src/renderer/render.c
parent8c331ac497d6e6705cde5e292538d4ab7d9a16ec (diff)
draw_scene that uses transform hierarchy to draw all models
Diffstat (limited to 'src/renderer/render.c')
-rw-r--r--src/renderer/render.c27
1 files changed, 27 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;