dds import WIP

This commit is contained in:
2021-03-11 01:34:51 +01:00
parent 31cdfa1885
commit 9848fbc183
3 changed files with 38 additions and 19 deletions

View File

@@ -1,4 +1,6 @@
use std::{convert::TryInto, io::Read, time::SystemTime};
use cgmath::{Deg, InnerSpace, Quaternion, Rotation3};
use winit::event::Event;
@@ -125,7 +127,7 @@ impl TestGame {
let mut mesh_handles = Vec::new();
// Load file
let (meshes, textures) = mesh::load_mesh(gltf_path, self.log_config.mesh_load_info).unwrap();
let (meshes, document) = mesh::load_mesh(gltf_path, self.log_config.mesh_load_info).unwrap();
for cpu_mesh in meshes.into_iter() {
// Convert file texture id to game texture id
@@ -143,10 +145,36 @@ impl TestGame {
mesh_handles.push(mesh_handle);
}
textures.iter().for_each(|tex| {
renderer.upload_texture(tex, renderer.device.clone());
for doc_image in document.images()
{
let texture_start_time = SystemTime::now();
// Load file
let mut tex_file = std::fs::File::open(format!("models/textures/{}.dds", doc_image.name().unwrap())).unwrap();
let mut tex_bytes: Vec<u8> = vec![];
tex_file.read_to_end(&mut tex_bytes).unwrap();
// Parse DDS
let tex_height = u32::from_ne_bytes(tex_bytes[12..16].try_into().unwrap());
let tex_width = u32::from_ne_bytes(tex_bytes[16..20].try_into().unwrap());
let tex_byte_count = u32::from_ne_bytes(tex_bytes[20..24].try_into().unwrap());
let pixel_format_flags = u32::from_ne_bytes(tex_bytes[80..84].try_into().unwrap());
let pixel_format_name: [u8; 4] = tex_bytes[84..88].try_into().unwrap();
let is_dxt1 = pixel_format_name == [0x44, 0x58, 0x54, 0x31]; // [D,X,T,1]
assert!(pixel_format_flags == 0x00000004);
assert!(is_dxt1);
println!("Texture width: {}, height: {}, bytes: {}", tex_width, tex_height, tex_byte_count);
let data_start: usize = 124;
let data_end: usize = data_start + tex_byte_count as usize;
renderer.upload_texture(&tex_bytes[data_start..data_end], tex_width, tex_height, vulkano::format::Format::BC1_RGBASrgbBlock, renderer.device.clone());
self.texture_index_counter += 1;
});
if self.log_config.mesh_load_info {
println!("Uploading texture took {:?}s", texture_start_time.elapsed().unwrap().as_secs());
}
}
mesh_handles
}