summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/src/renderer/opengl.rs19
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() },
})