diff options
author | HampusM <hampus@hampusmat.com> | 2025-01-15 14:43:44 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-01-15 14:43:44 +0100 |
commit | e893a733008561b41a25a3fcc8909071d2d3ba85 (patch) | |
tree | 0e9b6cfec9ba3d8d1051fbb097c484b0ba5ba26f /engine/src | |
parent | 6c2fde864b9c6a5a00209f36e92f2b93a21e9764 (diff) |
fix(engine): draw all vertices when not using indexed drawing
Diffstat (limited to 'engine/src')
-rw-r--r-- | engine/src/renderer/opengl.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs index a41f61a..7220ddc 100644 --- a/engine/src/renderer/opengl.rs +++ b/engine/src/renderer/opengl.rs @@ -276,9 +276,9 @@ fn draw_mesh(gl_objects: &GlObjects) gl_objects.vertex_arr.bind(); if gl_objects.index_buffer.is_some() { - VertexArray::draw_elements(PrimitiveKind::Triangles, 0, gl_objects.index_cnt); + VertexArray::draw_elements(PrimitiveKind::Triangles, 0, gl_objects.element_cnt); } else { - VertexArray::draw_arrays(PrimitiveKind::Triangles, 0, 3); + VertexArray::draw_arrays(PrimitiveKind::Triangles, 0, gl_objects.element_cnt); } } @@ -365,7 +365,7 @@ struct GlObjects /// Vertex and index buffer has to live as long as the vertex array vertex_buffer: Buffer<Vertex>, index_buffer: Option<Buffer<u32>>, - index_cnt: u32, + element_cnt: u32, vertex_arr: VertexArray, } @@ -420,7 +420,10 @@ impl GlObjects return Self { vertex_buffer, index_buffer: Some(index_buffer), - index_cnt: indices.len().try_into().unwrap(), + element_cnt: indices + .len() + .try_into() + .expect("Mesh index count does not fit into a 32-bit unsigned int"), vertex_arr, }; } @@ -428,7 +431,11 @@ impl GlObjects Self { vertex_buffer, index_buffer: None, - index_cnt: 0, + element_cnt: mesh + .vertices() + .len() + .try_into() + .expect("Mesh vertex count does not fit into a 32-bit unsigned int"), vertex_arr, } } @@ -444,7 +451,7 @@ impl GlObjects // SAFETY: The index buffer will never become dropped (NeverDrop ensures // it) .map(|index_buffer| unsafe { index_buffer.clone_weak() }), - index_cnt: self.index_cnt, + element_cnt: self.element_cnt, // SAFETY: The vertex array will never become dropped (NeverDrop ensures it) vertex_arr: unsafe { self.vertex_arr.clone_unsafe() }, }) |