Always draw indexed
@@ -32,8 +32,7 @@ impl From<mesh::Error> for Error {
pub struct TriangleSurface {
gl: gl::Gl,
id: gl::types::GLuint,
- count: usize,
- indexed: bool
+ count: usize
}
impl TriangleSurface
@@ -51,20 +50,13 @@ impl TriangleSurface
unsafe {
gl.GenVertexArrays(1, &mut id);
}
- let model;
- match mesh.indices {
- Some(ref indices) => {
- model = TriangleSurface { gl: gl.clone(), id, indexed: true, count: indices.len() };
+
+ let indices = mesh.indices();
+ let model = TriangleSurface { gl: gl.clone(), id, count: indices.len() };
model.bind();
let index_buffer = buffer::ElementBuffer::create(&gl)?;
- index_buffer.fill_with(&indices);
- },
- None => {
- model = TriangleSurface { gl: gl.clone(), id, indexed: false, count: mesh.no_vertices() };
- model.bind();
- }
- }
+ index_buffer.fill_with(indices);
Ok(model)
}
@@ -86,8 +78,6 @@ impl TriangleSurface
pub fn render(&self) -> Result<(), Error>
{
self.bind();
- match self.indexed {
- true => {
unsafe {
self.gl.DrawElements(
gl::TRIANGLES, // mode
@@ -96,25 +86,12 @@ impl TriangleSurface
std::ptr::null() // starting index in the enabled arrays
);
}
- },
- false => {
- unsafe {
- self.gl.DrawArrays(
- gl::TRIANGLES, // mode
- 0,
- self.count as i32 // number of vertices to be rendered
- );
- }
- }
- }
Ok(())
}
pub fn render_instances(&self, no_instances: usize) -> Result<(), Error>
{
self.bind();
- match self.indexed {
- true => {
unsafe {
self.gl.DrawElementsInstanced(
gl::TRIANGLES, // mode
@@ -124,18 +101,6 @@ impl TriangleSurface
no_instances as i32
);
}
- },
- false => {
- unsafe {
- self.gl.DrawArraysInstanced(
- gl::TRIANGLES, // mode
- 0,
- self.count as i32, // number of vertices to be rendered
- no_instances as i32
- );
- }
- }
- }
Ok(())
}
