summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-04-21 11:52:42 +1000
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-04-21 11:52:42 +1000
commitff923749ef298346c5448e90e8338bfc28e4f66b (patch)
tree4ce844e04984e1b55647886bd05779aa7dc8ea18 /src/renderer
parent374567ae4b18627f9ab410e7e5a38b1e7aeb04c5 (diff)
parentd8b564ffd1257152094966784a8db3d1396a8879 (diff)
Merge branch 'master' into cel-67-load-animation-data-from-gltf
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/render.c41
-rw-r--r--src/renderer/render.h7
-rw-r--r--src/renderer/render_types.h1
3 files changed, 39 insertions, 10 deletions
diff --git a/src/renderer/render.c b/src/renderer/render.c
index d9b45cf..83011f8 100644
--- a/src/renderer/render.c
+++ b/src/renderer/render.c
@@ -4,6 +4,7 @@
#include "animation.h"
#include "maths_types.h"
#include "mem.h"
+#include "transform_hierarchy.h"
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
@@ -113,7 +114,31 @@ void model_destroy(model* model) {
}
}
-void draw_model(renderer* ren, camera* camera, model* model, transform tf, scene* scene) {
+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;
mat4 proj;
@@ -136,11 +161,11 @@ void draw_model(renderer* ren, camera* camera, model* model, transform tf, scene
}
// TRACE("Drawing mesh %d", i);
material* mat = &model->materials->data[m->material_index];
- draw_mesh(ren, m, tf, mat, &view, &proj);
+ draw_mesh(ren, m, model_tf, mat, &view, &proj);
}
}
-void draw_mesh(renderer* ren, mesh* mesh, transform tf, material* mat, mat4* view, mat4* proj) {
+void draw_mesh(renderer* ren, mesh* mesh, mat4* model_tf, material* mat, mat4* view, mat4* proj) {
shader lighting_shader = ren->blinn_phong;
// bind buffer
@@ -152,12 +177,12 @@ void draw_mesh(renderer* ren, mesh* mesh, transform tf, material* mat, mat4* vie
uniform_f32(lighting_shader.program_id, "material.shininess", 32.);
// upload model transform
- mat4 trans = mat4_translation(tf.position);
- mat4 rot = mat4_rotation(tf.rotation);
- mat4 scale = mat4_scale(tf.scale);
- mat4 model_tf = mat4_mult(trans, mat4_mult(rot, scale));
+ // mat4 trans = mat4_translation(tf.position);
+ // mat4 rot = mat4_rotation(tf.rotation);
+ // mat4 scale = mat4_scale(tf.scale);
+ // mat4 model_tf = mat4_mult(trans, mat4_mult(rot, scale));
- uniform_mat4f(lighting_shader.program_id, "model", &model_tf);
+ uniform_mat4f(lighting_shader.program_id, "model", model_tf);
// upload view & projection matrices
uniform_mat4f(lighting_shader.program_id, "view", view);
uniform_mat4f(lighting_shader.program_id, "projection", proj);
diff --git a/src/renderer/render.h b/src/renderer/render.h
index ba2cbdc..31cf3b0 100644
--- a/src/renderer/render.h
+++ b/src/renderer/render.h
@@ -13,6 +13,7 @@
#include "camera.h"
#include "loaders.h"
#include "render_types.h"
+#include "transform_hierarchy.h"
// --- Lifecycle
/** @brief initialise the render system frontend */
@@ -32,8 +33,10 @@ void render_frame_draw(renderer* ren);
// --- models meshes
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 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);
void draw_skinned_model(renderer* ren, camera* cam, model* model, transform tf, scene* scene);
diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h
index bfed18d..6e69708 100644
--- a/src/renderer/render_types.h
+++ b/src/renderer/render_types.h
@@ -20,6 +20,7 @@ struct GLFWwindow;
#ifndef RESOURCE_HANDLE_DEFS
CORE_DEFINE_HANDLE(model_handle);
+#define ABSENT_MODEL_HANDLE 999999999
CORE_DEFINE_HANDLE(texture_handle);
#define RESOURCE_HANDLE_DEFS
#endif