refactor: replace manual VAO draws with recursive scene graph draw function

This commit is contained in:
2025-10-02 10:21:02 +02:00
parent ac1368c509
commit 6e53caae56

View File

@@ -127,6 +127,21 @@ unsafe fn create_vao(vertices: &Vec<f32>, normals: &Vec<f32>, colors: &Vec<f32>,
vao_id
}
// Scene graph drawing function
unsafe fn draw_scene(node: &scene_graph::SceneNode, transform_loc: i32, view_projection: &glm::Mat4, transform_so_far: &glm::Mat4) {
// Draw this node if drawable
if node.index_count > 0 {
let model_transform = view_projection * *transform_so_far;
gl::UniformMatrix4fv(transform_loc, 1, gl::FALSE, model_transform.as_ptr());
gl::BindVertexArray(node.vao_id);
gl::DrawElements(gl::TRIANGLES, node.index_count, gl::UNSIGNED_INT, ptr::null());
}
// Recurse to children
for &child in &node.children {
draw_scene(&*child, transform_loc, view_projection, transform_so_far);
}
}
fn main() {
// Set up the necessary objects to deal with windows and event handling
let el = glutin::event_loop::EventLoop::new();