multi threaded image load
This commit is contained in:
parent
c7538869b4
commit
fddd4576bd
22
src/main.rs
22
src/main.rs
@ -97,10 +97,18 @@ impl GraphicsData {
|
|||||||
|
|
||||||
//idk how to do this gooder lol
|
//idk how to do this gooder lol
|
||||||
let mut double_map=std::collections::HashMap::<u32,u32>::new();
|
let mut double_map=std::collections::HashMap::<u32,u32>::new();
|
||||||
let mut texture_views:Vec<wgpu::TextureView>=Vec::with_capacity(indexed_models.textures.len());
|
let mut texture_loading_threads=Vec::new();
|
||||||
for (i,t) in indexed_models.textures.iter().enumerate(){
|
for (i,t) in indexed_models.textures.iter().enumerate(){
|
||||||
if let Ok(mut file) = std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",t))){
|
if let Ok(mut file) = std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",t))){
|
||||||
let image = ddsfile::Dds::read(&mut file).unwrap();
|
double_map.insert(i as u32, texture_loading_threads.len() as u32);
|
||||||
|
texture_loading_threads.push(std::thread::spawn(move ||{
|
||||||
|
(i,ddsfile::Dds::read(&mut file).unwrap())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let texture_views:Vec<wgpu::TextureView>=texture_loading_threads.into_iter().map(|t|{
|
||||||
|
let (i,image)=t.join().unwrap();
|
||||||
|
|
||||||
let (mut width,mut height)=(image.get_width(),image.get_height());
|
let (mut width,mut height)=(image.get_width(),image.get_height());
|
||||||
|
|
||||||
@ -141,15 +149,13 @@ impl GraphicsData {
|
|||||||
},
|
},
|
||||||
&image.data,
|
&image.data,
|
||||||
);
|
);
|
||||||
|
texture.create_view(&wgpu::TextureViewDescriptor {
|
||||||
double_map.insert(i as u32, texture_views.len() as u32);
|
|
||||||
texture_views.push(texture.create_view(&wgpu::TextureViewDescriptor {
|
|
||||||
label: Some(format!("Texture{} View",i).as_str()),
|
label: Some(format!("Texture{} View",i).as_str()),
|
||||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
dimension: Some(wgpu::TextureViewDimension::D2),
|
||||||
..wgpu::TextureViewDescriptor::default()
|
..wgpu::TextureViewDescriptor::default()
|
||||||
}));
|
})
|
||||||
}
|
}).collect();
|
||||||
}
|
|
||||||
let indexed_models_len=indexed_models.models.len();
|
let indexed_models_len=indexed_models.models.len();
|
||||||
//split groups with different textures into separate models
|
//split groups with different textures into separate models
|
||||||
//the models received here are supposed to be tightly packed, i.e. no code needs to check if two models are using the same groups.
|
//the models received here are supposed to be tightly packed, i.e. no code needs to check if two models are using the same groups.
|
||||||
|
Loading…
Reference in New Issue
Block a user