idk wip
This commit is contained in:
@@ -3,7 +3,7 @@ use std::time::SystemTime;
|
||||
|
||||
use cgmath::{Matrix4, SquareMatrix};
|
||||
use dds::get_block_size;
|
||||
use vulkano::{buffer::{BufferUsage, CpuAccessibleBuffer}, command_buffer::{CommandBuffer, SubpassContents}, image::{ImageLayout, ImageUsage, MipmapsCount, immutable::SubImage}};
|
||||
use vulkano::{buffer::{BufferUsage, CpuAccessibleBuffer}, command_buffer::{CommandBuffer, SubpassContents}, image::{ImageAccess, ImageLayout, ImageUsage, MipmapsCount, immutable::SubImage}};
|
||||
use vulkano::command_buffer::{AutoCommandBuffer, AutoCommandBufferBuilder, DynamicState};
|
||||
use vulkano::descriptor::DescriptorSet;
|
||||
use vulkano::device::{Device, DeviceExtensions, Queue};
|
||||
@@ -23,7 +23,7 @@ use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit::window::{Window, WindowBuilder};
|
||||
|
||||
use mesh::CPUMesh;
|
||||
use pipelines::{Drawcall, LineShader};
|
||||
use pipelines::{Drawcall};
|
||||
use pipelines::line_vs::ty::LinePushConstants;
|
||||
use pipelines::DefaultShader;
|
||||
use pipelines::vs;
|
||||
@@ -69,15 +69,15 @@ pub trait Game {
|
||||
pub struct Mesh {
|
||||
pub vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
|
||||
pub index_buffer: Arc<CpuAccessibleBuffer<[u32]>>,
|
||||
pub original_path: String,
|
||||
pub original_path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MeshHandle {
|
||||
pub index: usize,
|
||||
pub diffuse_handle: TextureHandle,
|
||||
pub normal_handle: TextureHandle,
|
||||
pub original_path: String
|
||||
pub normal_handle: Option<TextureHandle>,
|
||||
pub original_path: Option<String>
|
||||
}
|
||||
|
||||
pub(crate) type TextureHandle = usize;
|
||||
@@ -411,7 +411,7 @@ impl VulkanRenderer {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn upload_mesh(self: &mut Self, mesh: CPUMesh, original_path: String) -> usize {
|
||||
pub fn upload_mesh(self: &mut Self, mesh: CPUMesh, original_path: Option<String>) -> usize {
|
||||
// let mut collision_mesh = mgf::Mesh::new();
|
||||
// mesh.vertices.iter().for_each(|v| {
|
||||
// collision_mesh.push_vert(v.position.into());
|
||||
@@ -438,12 +438,13 @@ impl VulkanRenderer {
|
||||
};
|
||||
|
||||
let layout = ImageLayout::ShaderReadOnlyOptimal;
|
||||
let mip_maps = if format == Format::R8Srgb { MipmapsCount::One } else { MipmapsCount::Log2 };
|
||||
|
||||
let (image_view, initializer) = ImmutableImage::uninitialized(
|
||||
device.clone(),
|
||||
dimensions,
|
||||
format,
|
||||
MipmapsCount::Log2,
|
||||
mip_maps,
|
||||
usage,
|
||||
layout,
|
||||
device.active_queue_families(),
|
||||
@@ -462,21 +463,14 @@ impl VulkanRenderer {
|
||||
|
||||
let mut offset = 0;
|
||||
|
||||
let block_bytes = get_block_size(format).expect(&format!("Unknown texture format {:?}!", format));
|
||||
|
||||
for i in 0..image_view.mipmap_levels() {
|
||||
let mip_size = dimensions.to_image_dimensions().mipmap_dimensions(i).unwrap().width_height_depth();
|
||||
|
||||
let mip_byte_size = (
|
||||
(u32::max(4, mip_size[0]) / 4)
|
||||
* (u32::max(4, mip_size[1]) / 4)
|
||||
* block_bytes) as usize;
|
||||
let block_bytes = get_block_size(format);
|
||||
|
||||
let mut upload_bytes = |data: &[u8], mip_index: u32, mip_size: [u32; 3]| {
|
||||
let source = CpuAccessibleBuffer::from_iter(
|
||||
device.clone(),
|
||||
BufferUsage::transfer_source(),
|
||||
false,
|
||||
bytes[offset..(offset + mip_byte_size)].iter().cloned(),
|
||||
data.iter().cloned(),
|
||||
).unwrap();
|
||||
|
||||
cbb.copy_buffer_to_image_dimensions(
|
||||
@@ -486,11 +480,26 @@ impl VulkanRenderer {
|
||||
mip_size,
|
||||
0,
|
||||
dimensions.array_layers_with_cube(),
|
||||
i,
|
||||
)
|
||||
.unwrap();
|
||||
mip_index,
|
||||
).unwrap();
|
||||
};
|
||||
|
||||
offset += mip_byte_size;
|
||||
if let Some(block_byte_size) = block_bytes {
|
||||
for i in 0..image_view.mipmap_levels() {
|
||||
|
||||
let mip_size = dimensions.to_image_dimensions().mipmap_dimensions(i).unwrap().width_height_depth();
|
||||
|
||||
let mip_byte_size = (
|
||||
(u32::max(4, mip_size[0]) / 4)
|
||||
* (u32::max(4, mip_size[1]) / 4)
|
||||
* block_byte_size) as usize;
|
||||
|
||||
let data = &bytes[offset..(offset + mip_byte_size)];
|
||||
upload_bytes(data, i, mip_size);
|
||||
offset += mip_byte_size;
|
||||
}
|
||||
} else {
|
||||
upload_bytes(bytes, 0, dimensions.to_image_dimensions().width_height_depth());
|
||||
}
|
||||
|
||||
let cb = cbb.build().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user