entity spawning. great success

This commit is contained in:
2021-02-20 01:45:24 -08:00
parent a1305bed2d
commit c2b62a5f53
5 changed files with 276 additions and 225 deletions

View File

@@ -108,11 +108,10 @@ impl RenderState {
}
}
/// Create a bare vertex & indices buffer
/// TODO I really should remove this / consolidate it
/// Create a buffer for a mesh
fn create_buffer(
device: &wgpu::Device,
raw_mesh: RawMesh,
raw_mesh: &RawMesh,
) -> (Arc<Buffer>, Arc<Buffer>) {
let vertex_buf = Arc::new(
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
@@ -122,16 +121,6 @@ impl RenderState {
}),
);
//println!("{:x?}", raw_mesh.indices);
// let mut hack = Vec::<u32>::new();
// for ind_chunk in raw_mesh.indices {
// hack.push(ind_chunk[0]);
// hack.push(ind_chunk[1]);
// hack.push(ind_chunk[2]);
// }
let index_buf = Arc::new(
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("index-buffer"),
@@ -143,17 +132,12 @@ impl RenderState {
(vertex_buf, index_buf)
}
/// Take a meshes
pub fn upload_mesh_to_buffer(mesh: RawMesh) {
/// Take a meshes raw representation and upload it to a GPU buffer
pub fn upload_mesh_to_buffer(&mut self, mesh: &RawMesh, color: Option<wgpu::Color>) -> Result<Mesh, String> {
}
let index_count = mesh.indices.len() * 3; // TODO bad bad bad bad!
pub fn load_mesh_to_buffer(&self, filepath: &str, color: Option<wgpu::Color>) -> Result<Mesh, String> {
let raw_mesh = load_obj(filepath)?;
let index_count = raw_mesh.indices.len() * 3; // TODO bad bad bad bad!
let (vertex_buf, index_buf) = RenderState::create_buffer(&self.device, raw_mesh);
let (vertex_buf, index_buf) = RenderState::create_buffer(&self.device, mesh);
let uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
@@ -189,6 +173,12 @@ impl RenderState {
})
}
/// explicitly load from file, and upload to gpu the mesh
pub fn load_mesh_to_buffer(&mut self, filepath: &str, color: Option<wgpu::Color>) -> Result<Mesh, String> {
let raw_mesh = load_obj(filepath)?;
self.upload_mesh_to_buffer(&raw_mesh, color)
}
/// When creating a light we have to give it a target view to render to
/// This is major danger scary since we have a 10 light limit, and only
/// 2 views created at this moment, need to smarten this up