diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-13 22:55:56 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-13 22:55:56 +0200 |
commit | cfa73b1ea42fa491ff9e00bb5efb5e5a5d860578 (patch) | |
tree | 95af08ec7e9598daef6a740ce3494c4e0f1c645d /engine/src/renderer/mod.rs | |
parent | 25b5ca97c5e5597570360c37d7452662e0118a00 (diff) |
refactor(engine): add OpenGL object currently bound guards
Diffstat (limited to 'engine/src/renderer/mod.rs')
-rw-r--r-- | engine/src/renderer/mod.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index 364b7f4..a23d5a0 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -45,7 +45,9 @@ pub fn render<'renderable>(renderables: impl IntoIterator<Item = &'renderable Re for renderable in renderables { renderable.shader_program.activate(); - renderable.vertex_arr.draw(PrimitiveKind::Triangles, 0, 3); + renderable.vertex_arr.bind(|vert_arr_curr_bound| { + VertexArray::draw(&vert_arr_curr_bound, PrimitiveKind::Triangles, 0, 3); + }); } } @@ -64,14 +66,15 @@ impl Renderable pub fn new(shader_program: crate::shader::Program, vertices: &[Vertex]) -> Self { let vertex_arr = VertexArray::new(); - - vertex_arr.bind(); - let vertex_buffer = VertexBuffer::new(); - vertex_buffer.store(vertices, BufferUsage::Static); + vertex_arr.bind(|vert_arr_curr_bound| { + vertex_buffer.bind(|vert_buf_curr_bound| { + VertexBuffer::store(&vert_buf_curr_bound, vertices, BufferUsage::Static); - VertexArray::configure_attrs(); + VertexArray::configure_attrs(&vert_arr_curr_bound, &vert_buf_curr_bound); + }); + }); Self { shader_program, |