From 9aafb51e0be1720019db1c3d0a294ce9a42653df Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 2 Nov 2023 20:22:33 +0100 Subject: feat(engine): add texturing --- engine/src/renderer/mod.rs | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'engine/src/renderer/mod.rs') diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index 6c56964..3691f76 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -116,23 +116,33 @@ pub fn render<'obj>( apply_transformation_matrices(obj, camera, window_size); - obj.renderable().vertex_arr.bind(|vert_arr_curr_bound| { - if let Some(index_info) = &obj.renderable().index_info { - VertexArray::draw_elements( - &vert_arr_curr_bound, - PrimitiveKind::Triangles, - 0, - index_info.cnt, - ); - } else { - VertexArray::draw_arrays( - &vert_arr_curr_bound, - PrimitiveKind::Triangles, - 0, - 3, - ); - } - }); + let draw = || { + obj.renderable().vertex_arr.bind(|vert_arr_curr_bound| { + if let Some(index_info) = &obj.renderable().index_info { + VertexArray::draw_elements( + &vert_arr_curr_bound, + PrimitiveKind::Triangles, + 0, + index_info.cnt, + ); + } else { + VertexArray::draw_arrays( + &vert_arr_curr_bound, + PrimitiveKind::Triangles, + 0, + 3, + ); + } + }); + }; + + if let Some(texture) = obj.texture() { + texture.inner().bind(|_| { + draw(); + }); + } else { + draw(); + } } } -- cgit v1.2.3-18-g5258