Avoid VAO in ShadedMesh
use gl;
use crate::*;
-use crate::surface::*;
+use crate::core::buffer::{VertexBuffer, ElementBuffer, Attribute};
#[derive(Debug)]
pub enum Error {
@@ -22,16 +22,10 @@ impl From<buffer::Error> for Error {
}
}
-impl From<surface::Error> for Error {
- fn from(other: surface::Error) -> Self {
- Error::Surface(other)
- }
-}
-
pub struct ShadedMesh {
program: program::Program,
- model: surface::TriangleSurface,
- buffer: buffer::VertexBuffer,
+ vertex_buffer: buffer::VertexBuffer,
+ index_buffer: buffer::ElementBuffer,
pub color: Vec3,
pub texture: Option<texture::Texture2D>,
pub diffuse_intensity: f32,
@@ -46,10 +40,10 @@ impl ShadedMesh
let program = program::Program::from_source(&gl,
include_str!("shaders/mesh_shaded.vert"),
include_str!("shaders/shaded.frag"))?;
- let mut model = surface::TriangleSurface::new(gl, indices)?;
- let buffer = model.add_attributes(&program, attributes)?;
+ let vertex_buffer = VertexBuffer::new_from_attributes(gl, attributes)?;
+ let index_buffer = ElementBuffer::new_with(gl, indices)?;
- Ok(ShadedMesh { program, model, buffer, color: vec3(1.0, 1.0, 1.0), texture: None, diffuse_intensity: 0.5, specular_intensity: 0.2, specular_power: 5.0 })
+ Ok(ShadedMesh { program, index_buffer, vertex_buffer, color: vec3(1.0, 1.0, 1.0), texture: None, diffuse_intensity: 0.5, specular_intensity: 0.2, specular_power: 5.0 })
}
pub fn new_from_obj_source(gl: &gl::Gl, source: String) -> Result<ShadedMesh, Error>
@@ -91,7 +85,7 @@ impl ShadedMesh
pub fn update_attributes(&mut self, attributes: &[Attribute]) -> Result<(), Error>
{
- self.buffer.fill_from_attributes(attributes)?;
+ self.vertex_buffer.fill_from_attributes(attributes)?;
Ok(())
}
@@ -120,6 +114,10 @@ impl ShadedMesh
self.program.add_uniform_mat4("viewMatrix", camera.get_view()).unwrap();
self.program.add_uniform_mat4("projectionMatrix", camera.get_projection()).unwrap();
self.program.add_uniform_mat4("normalMatrix", &transformation.invert().unwrap().transpose()).unwrap();
- self.model.render().unwrap();
+
+ self.program.use_attribute_vec3_float(&self.vertex_buffer, "position", 0).unwrap();
+ self.program.use_attribute_vec3_float(&self.vertex_buffer, "normal", 1).unwrap();
+
+ self.program.draw_elements(&self.index_buffer);
}
}
