dds import WIP
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use gltf::Error;
|
||||
use gltf::{Document, Error};
|
||||
use gltf::mesh::util::{ReadJoints, ReadNormals, ReadPositions, ReadTangents, ReadTexCoords, ReadWeights};
|
||||
|
||||
use crate::vulkan::mesh::LoadError::{GltfError, MeshDataMissing, NoIndices};
|
||||
@@ -34,7 +34,7 @@ pub struct CPUMesh {
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
pub fn load_mesh(mesh_path: &str, print_status: bool) -> Result<(Vec<CPUMesh>, Vec<gltf::image::Data>), LoadError> {
|
||||
pub fn load_mesh(mesh_path: &str, print_status: bool) -> Result<(Vec<CPUMesh>, Document), LoadError> {
|
||||
let mut start_time = None;
|
||||
let mut total_vertices = 0;
|
||||
let mut total_indices = 0;
|
||||
@@ -92,7 +92,7 @@ pub fn load_mesh(mesh_path: &str, print_status: bool) -> Result<(Vec<CPUMesh>, V
|
||||
println!("Finished loading file, total vertices: {}, total indices: {}", total_vertices, total_indices);
|
||||
}
|
||||
|
||||
Ok((meshes, textures))
|
||||
Ok((meshes, document))
|
||||
}
|
||||
|
||||
fn create_vertices(positions: Option<ReadPositions>,
|
||||
|
||||
@@ -433,20 +433,11 @@ impl VulkanRenderer {
|
||||
self.game_data.meshes.len() - 1
|
||||
}
|
||||
|
||||
pub fn upload_texture(self: &mut Self, texture_data: &gltf::image::Data, device: Arc<Device>) {
|
||||
pub fn upload_texture(self: &mut Self, bytes: &[u8], width: u32, height: u32, format: Format, device: Arc<Device>) {
|
||||
// Format buffer on cpu for upload
|
||||
let buffer: ImageBuffer<Rgb<u8>, Vec<u8>> = image::ImageBuffer::from_raw(texture_data.width, texture_data.height, texture_data.pixels.clone()).unwrap();
|
||||
let new_buffer: ImageBuffer<Rgba<u8>, Vec<u8>> = buffer.convert();
|
||||
let dimensions = Dimensions::Dim2d { width: texture_data.width, height: texture_data.height };
|
||||
let dimensions = Dimensions::Dim2d { width, height };
|
||||
|
||||
let source = CpuAccessibleBuffer::from_iter(
|
||||
self.device.clone(),
|
||||
BufferUsage::transfer_source(),
|
||||
false,
|
||||
new_buffer.iter().cloned(),
|
||||
).unwrap();
|
||||
|
||||
let (image_view, future) = ImmutableImage::from_buffer(source.clone(), dimensions, MipmapsCount::Log2, Format::R8G8B8A8Unorm, self.queue.clone()).unwrap();
|
||||
let (image_view, future) = ImmutableImage::from_iter(bytes.iter().cloned(), dimensions, MipmapsCount::One, format, self.queue.clone()).unwrap();
|
||||
future.flush().unwrap();
|
||||
|
||||
let sampler = Sampler::new(device.clone(), Filter::Linear, Filter::Linear,
|
||||
|
||||
Reference in New Issue
Block a user