summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/renderer/render.c27
-rw-r--r--src/renderer/render.h2
-rw-r--r--src/transform_hierarchy.c9
3 files changed, 34 insertions, 4 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
diff --git a/src/transform_hierarchy.c b/src/transform_hierarchy.c
index a8b3df1..a36b8ef 100644
--- a/src/transform_hierarchy.c
+++ b/src/transform_hierarchy.c
@@ -7,11 +7,11 @@
#include <stdlib.h>
#include <string.h>
+#include "core.h"
#include "log.h"
#include "maths.h"
#include "maths_types.h"
#include "render_types.h"
-#include "core.h"
struct transform_hierarchy {
transform_node root;
@@ -50,7 +50,8 @@ void transform_hierarchy_free(transform_hierarchy* tfh) {
transform_node* transform_hierarchy_root_node(transform_hierarchy* tfh) { return &tfh->root; }
-transform_node* transform_hierarchy_add_node(transform_node* parent, model_handle model, transform tf) {
+transform_node* transform_hierarchy_add_node(transform_node* parent, model_handle model,
+ transform tf) {
if (!parent) {
WARN("You tried to add a node to a bad parent (NULL?)");
return NULL;
@@ -163,14 +164,14 @@ bool print_node(transform_node* node, void* ctx_data) {
return true;
}
- // Grab the model
+ // Grab the model
model m = ctx->core->models->data[node->model.raw];
for (int i = 0; i < ctx->indentation_lvl; i++) {
printf(" ");
}
printf("Node %s\n", m.name.buf);
ctx->indentation_lvl++;
-
+
return true;
}