Combine render functions into single gpu_render()

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-04 11:51:53 +01:00
1 parent bf2e49a1eb
commit e7f4f4b51d
3 files changed
+62 -74

No files matched your search

+33 -34
View File
@@ -52,13 +52,10 @@ int main(int argc, char *argv[])
// Initialise GPU and load model
gpu_ctx_t gpu;
gpu_model_t gpu_model1, gpu_model2;
gpu_model_t gpu_models[2];
gpu_init(&gpu, window, "Foo");
gpu_model_load(&gpu, &model, &gpu_model1);
gpu_model_load(&gpu, &model, &gpu_model2);
// Initialise animation
animation_state_t anim = animation_init(&model);
gpu_model_load(&gpu, &model, gpu_models + 0);
gpu_model_load(&gpu, &model, gpu_models + 1);
const vec3_t cam = { 0, 4, -8 };
const vec3_t tgt = { 0, 0, 0 };
@@ -66,46 +63,48 @@ int main(int argc, char *argv[])
.view = mat4_lookat(cam, tgt, (vec3_t) { 0, 1, 0 }),
.proj = mat4_perspective((float)W / H, PI / 8, 0.1, 100.0),
};
mat4_t transform1 = mat4_mul(
MAT4_TRANSLATE(1, 0, 0),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
});
mat4_t transform2 = mat4_mul(
MAT4_TRANSLATE(2, 0, 0),
mat4_mul(
MAT4_ROTATE_Y(PI),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
}));
mat4_t transforms[] = {
mat4_mul(
MAT4_TRANSLATE(1, 0, 0),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
}),
mat4_mul(
MAT4_TRANSLATE(2, 0, 0),
mat4_mul(
MAT4_ROTATE_Y(PI),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
})),
};
const mat4_t rot1 = MAT4_ROTATE_Y(PI / 170);
const mat4_t rot2 = MAT4_ROTATE_Y(-PI / 340);
// Set up animation
animation_state_t anim = animation_init(&model);
animation_start(&anim, &model, 0);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
transform1 = mat4_mul(rot1, transform1);
transform2 = mat4_mul(rot2, transform2);
transforms[0] = mat4_mul(MAT4_ROTATE_Y(PI / 170), transforms[0]);
transforms[1] = mat4_mul(MAT4_ROTATE_Y(-PI / 340), transforms[1]);
animation_update(&anim, &model, DT);
gpu_render_begin(&gpu, vp);
gpu_render_model(&gpu, &gpu_model1, anim.bone_matrices, transform1);
gpu_render_model(&gpu, &gpu_model2, anim.bone_matrices, transform2);
gpu_render_submit(&gpu);
const mat4_t *bone_matrices[]
= { anim.bone_matrices, anim.bone_matrices };
gpu_render(&gpu, vp, 2, gpu_models, bone_matrices, transforms);
}
// Clean up
animation_cleanup(&anim);
gpu_model_cleanup(&gpu, &gpu_model1);
gpu_model_cleanup(&gpu, &gpu_model2);
gpu_model_cleanup(&gpu, gpu_models + 0);
gpu_model_cleanup(&gpu, gpu_models + 1);
gpu_cleanup(&gpu);
model_cleanup(&model);
glfwDestroyWindow(window);