2019-01-11 20:14:37 +00:00
|
|
|
// Library
|
|
|
|
use gfx::{
|
|
|
|
self,
|
|
|
|
traits::FactoryExt,
|
|
|
|
};
|
2019-01-07 21:10:31 +00:00
|
|
|
|
|
|
|
// Local
|
2019-01-11 20:14:37 +00:00
|
|
|
use super::{
|
|
|
|
mesh::Mesh,
|
|
|
|
Pipeline,
|
|
|
|
gfx_backend,
|
|
|
|
};
|
2019-01-07 21:10:31 +00:00
|
|
|
|
|
|
|
/// Represents a mesh that has been sent to the CPU
|
|
|
|
pub struct Model<P: Pipeline> {
|
2019-01-11 20:14:37 +00:00
|
|
|
pub vbuf: gfx::handle::Buffer<gfx_backend::Resources, P::Vertex>,
|
|
|
|
pub slice: gfx::Slice<gfx_backend::Resources>,
|
2019-01-07 21:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<P: Pipeline> Model<P> {
|
2019-01-11 20:14:37 +00:00
|
|
|
pub fn new(
|
|
|
|
factory: &mut gfx_backend::Factory,
|
|
|
|
mesh: &Mesh<P>,
|
|
|
|
) -> Self {
|
2019-01-07 21:10:31 +00:00
|
|
|
Self {
|
2019-01-11 20:14:37 +00:00
|
|
|
vbuf: factory.create_vertex_buffer(mesh.vertices()),
|
|
|
|
slice: gfx::Slice {
|
|
|
|
start: 0,
|
|
|
|
end: mesh.vertices().len() as u32,
|
|
|
|
base_vertex: 0,
|
|
|
|
instances: None,
|
|
|
|
buffer: gfx::IndexBuffer::Auto,
|
|
|
|
},
|
2019-01-07 21:10:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|