This commit is contained in:
2021-08-11 20:00:46 +02:00
parent b933a6dd35
commit c619f945a3
9 changed files with 96 additions and 37 deletions

View File

@@ -23,7 +23,7 @@ pub struct GameObject {
impl GameObject {
pub fn new(mesh: MeshHandle) -> GameObject {
GameObject { mesh_index: mesh.index, texture_index: mesh.diffuse_handle, normal_map_index: mesh.normal_handle, position: Vector3::new(0.0, 0.0, 0.0),
GameObject { mesh_index: mesh.index, texture_index: mesh.diffuse_handle, normal_map_index: mesh.normal_handle.unwrap_or(0), position: Vector3::new(0.0, 0.0, 0.0),
rotation: Quaternion::new(1.0, 0.0, 0.0, 0.0), scale: Vector3::new(1.0, 1.0, 1.0), children: vec![],
descriptor_sets: vec![], is_selected: false }
}

View File

@@ -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();

View File

@@ -204,7 +204,7 @@ pub struct LineShader {
}
impl LineShader {
pub fn new(device: Arc<Device>, render_pass: RP, vertex_buffer: Arc<vulkano::buffer::CpuAccessibleBuffer<[LinePoint]>>) -> Self {
pub fn _new(device: Arc<Device>, render_pass: RP, vertex_buffer: Arc<vulkano::buffer::CpuAccessibleBuffer<[LinePoint]>>) -> Self {
LineShader {
pipeline: Self::create_pipeline(device, render_pass),
vertex_buffer