diff --git a/bin/boilerplate.rs b/bin/boilerplate.rs index 3f0e337..5fdc8e7 100644 --- a/bin/boilerplate.rs +++ b/bin/boilerplate.rs @@ -1,6 +1,6 @@ #![allow(clippy::single_match)] use vangers::{ - config::{settings::Terrain, Settings}, + config::Settings, render::{GraphicsContext, ScreenTargets, DEPTH_FORMAT}, }; diff --git a/bin/convert/level_obj.rs b/bin/convert/level_obj.rs index bf9ec86..f24dc2a 100644 --- a/bin/convert/level_obj.rs +++ b/bin/convert/level_obj.rs @@ -333,7 +333,7 @@ pub fn save(path: &Path, level: &Level, config: &Config) { { let diag_column = &c.face_columns[(dy - config.yr.start) as usize] [(dx - config.xr.start) as usize]; - column.add_faces(&diag_column, diagonal.corner); + column.add_faces(diag_column, diagonal.corner); } } @@ -441,7 +441,7 @@ pub fn save(path: &Path, level: &Level, config: &Config) { unit(num_tris), ); - let mut dest = BufWriter::new(File::create(&path).unwrap()); + let mut dest = BufWriter::new(File::create(path).unwrap()); bar.set_job_title("Vertices:"); for v in c.final_vertices { writeln!(dest, "v {} {} {}", v[0], v[1], v[2]).unwrap(); diff --git a/bin/convert/level_png.rs b/bin/convert/level_png.rs index 39c5549..af39c4a 100644 --- a/bin/convert/level_png.rs +++ b/bin/convert/level_png.rs @@ -31,7 +31,7 @@ pub fn save(path: &Path, layers: LevelLayers, palette: &[u8]) { { println!("\t\t{}...", mp.height); let file = File::create(path.with_file_name(mp.height)).unwrap(); - let mut encoder = png::Encoder::new(file, layers.size.0 as u32, layers.size.1 as u32); + let mut encoder = png::Encoder::new(file, layers.size.0, layers.size.1); encoder.set_color(png::ColorType::Rgb); data.clear(); for ((&h0, &h1), &delta) in layers.het0.iter().zip(&layers.het1).zip(&layers.delta) { @@ -46,7 +46,7 @@ pub fn save(path: &Path, layers: LevelLayers, palette: &[u8]) { { println!("\t\t{}...", mp.material_lo); let file = File::create(path.with_file_name(mp.material_lo)).unwrap(); - let mut encoder = png::Encoder::new(file, layers.size.0 as u32, layers.size.1 as u32); + let mut encoder = png::Encoder::new(file, layers.size.0, layers.size.1); encoder.set_color(png::ColorType::Indexed); encoder.set_palette(palette.to_vec()); encoder.set_depth(png::BitDepth::Four); @@ -59,7 +59,7 @@ pub fn save(path: &Path, layers: LevelLayers, palette: &[u8]) { { println!("\t\t{}...", mp.material_hi); let file = File::create(path.with_file_name(mp.material_hi)).unwrap(); - let mut encoder = png::Encoder::new(file, layers.size.0 as u32, layers.size.1 as u32); + let mut encoder = png::Encoder::new(file, layers.size.0, layers.size.1); encoder.set_color(png::ColorType::Indexed); encoder.set_palette(palette.to_vec()); encoder.set_depth(png::BitDepth::Four); diff --git a/bin/convert/main.rs b/bin/convert/main.rs index 7021aa8..c0b54c0 100644 --- a/bin/convert/main.rs +++ b/bin/convert/main.rs @@ -12,36 +12,36 @@ use std::{ pub fn save_tiff(path: &Path, layers: layers::LevelLayers) { let images = [ tiff::Image { - width: layers.size.0 as u32, - height: layers.size.1 as u32, + width: layers.size.0, + height: layers.size.1, bpp: 8, name: "h0", data: &layers.het0, }, tiff::Image { - width: layers.size.0 as u32, - height: layers.size.1 as u32, + width: layers.size.0, + height: layers.size.1, bpp: 8, name: "h1", data: &layers.het1, }, tiff::Image { - width: layers.size.0 as u32, - height: layers.size.1 as u32, + width: layers.size.0, + height: layers.size.1, bpp: 8, name: "del", data: &layers.delta, }, tiff::Image { - width: layers.size.0 as u32, - height: layers.size.1 as u32, + width: layers.size.0, + height: layers.size.1, bpp: 4, name: "m0", data: &layers.mat0, }, tiff::Image { - width: layers.size.0 as u32, - height: layers.size.1 as u32, + width: layers.size.0, + height: layers.size.1, bpp: 4, name: "m1", data: &layers.mat1, diff --git a/bin/convert/model_obj.rs b/bin/convert/model_obj.rs index 4603992..177ccb7 100644 --- a/bin/convert/model_obj.rs +++ b/bin/convert/model_obj.rs @@ -16,7 +16,7 @@ type RefModel = Model, Mesh>; type RefAnimatedMesh = AnimatedMesh; type DrawAnimatedMesh = AnimatedMesh>; -const MAT_NAME: &'static str = "object.mtl"; +const MAT_NAME: &str = "object.mtl"; pub fn export_m3d(full: FullModel, model_path: &Path) { const BODY_PATH: &str = "body.obj"; @@ -87,11 +87,11 @@ pub fn import_m3d(model_path: &Path) -> FullModel { let resolve_geom_draw = |name| -> Geometry { load_geometry(dir_path.join(name)) }; let resolve_geom_coll = |name| -> Geometry { load_geometry(dir_path.join(name)) }; - let resolve_mesh = |mesh: Mesh| mesh.map(&resolve_geom_draw); + let resolve_mesh = |mesh: Mesh| mesh.map(resolve_geom_draw); FullModel { - body: model.body.map(&resolve_geom_draw), - shape: model.shape.map(&resolve_geom_coll), + body: model.body.map(resolve_geom_draw), + shape: model.shape.map(resolve_geom_coll), bound: model.bound, color: model.color, wheels: model @@ -103,8 +103,8 @@ pub fn import_m3d(model_path: &Path) -> FullModel { .debris .into_iter() .map(|debrie| Debrie { - mesh: debrie.mesh.map(&resolve_geom_draw), - shape: debrie.shape.map(&resolve_geom_coll), + mesh: debrie.mesh.map(resolve_geom_draw), + shape: debrie.shape.map(resolve_geom_coll), }) .collect(), slots: Slot::map_all(model.slots, |mesh, _| resolve_mesh(mesh)), diff --git a/bin/level/app.rs b/bin/level/app.rs index 911a8b6..eb52170 100644 --- a/bin/level/app.rs +++ b/bin/level/app.rs @@ -142,7 +142,7 @@ impl LevelView { level, cam, input: Input::Empty, - ui: settings.ui.clone(), + ui: settings.ui, last_mouse_pos: cgmath::vec2(-1.0, -1.0), alt_button_pressed: false, mouse_button_pressed: false, diff --git a/bin/level/main.rs b/bin/level/main.rs index b790267..2a7dfa6 100644 --- a/bin/level/main.rs +++ b/bin/level/main.rs @@ -25,7 +25,7 @@ fn main() { } let path = matches.free.first(); - let app = app::LevelView::new(path.as_deref(), &settings, &harness.graphics_ctx); + let app = app::LevelView::new(path, &settings, &harness.graphics_ctx); harness.main_loop(app); } diff --git a/bin/road/game.rs b/bin/road/game.rs index d120c7f..c7c2f13 100644 --- a/bin/road/game.rs +++ b/bin/road/game.rs @@ -468,7 +468,7 @@ impl Game { level, agents, stats: Stats::default(), - ui: settings.ui.clone(), + ui: settings.ui, cam, cam_style: CameraStyle::new(&settings.game.camera), max_quant: settings.game.physics.max_quant, diff --git a/src/level/mod.rs b/src/level/mod.rs index 6d7cf72..4cb8e67 100644 --- a/src/level/mod.rs +++ b/src/level/mod.rs @@ -237,7 +237,7 @@ pub fn load_flood(config: &LevelConfig) -> Box<[u8]> { let size = (config.size.0.as_value(), config.size.1.as_value()); let flood_size = size.1 >> config.section.as_power(); - let vpr_file = match File::open(&config.path_data.with_extension("vpr")) { + let vpr_file = match File::open(config.path_data.with_extension("vpr")) { Ok(file) => file, Err(_) => return vec![0; flood_size as usize].into_boxed_slice(), }; @@ -297,7 +297,7 @@ impl LevelData { } Splay::write_trivial(&mut vmc); - assert_eq!(vmc.seek(SeekFrom::Current(0)).unwrap(), base_offset); + assert_eq!(vmc.stream_position().unwrap(), base_offset); self.height .chunks(self.size.0 as _) diff --git a/src/model.rs b/src/model.rs index f967bc5..61c24c3 100644 --- a/src/model.rs +++ b/src/model.rs @@ -6,7 +6,7 @@ use crate::render::{ use m3d; use wgpu::util::DeviceExt as _; -use std::{fs::File, mem, ops::Range, slice, sync::Arc}; +use std::{fs::File, ops::Range, slice, sync::Arc}; #[derive(Copy, Clone)] pub struct BoundingBox { @@ -127,7 +127,7 @@ pub fn load_c3d( ) -> Arc { let num_vertices = raw.geometry.polygons.len() * 3; debug!("\tGot {} GPU vertices...", num_vertices); - let vertex_size = mem::size_of::(); + let vertex_size = size_of::(); let vertex_buf = device.create_buffer(&wgpu::BufferDescriptor { label: Some("C3D"), size: (num_vertices * vertex_size) as wgpu::BufferAddress, @@ -251,7 +251,7 @@ pub fn load_c3d_shape( let vertex_buf = device.create_buffer(&wgpu::BufferDescriptor { label: Some("Shape"), - size: (raw.geometry.positions.len() * mem::size_of::()) as wgpu::BufferAddress, + size: (raw.geometry.positions.len() * size_of::()) as wgpu::BufferAddress, usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::STORAGE, mapped_at_creation: true, }); diff --git a/src/render/debug.rs b/src/render/debug.rs index 238a5fc..bbe34e9 100644 --- a/src/render/debug.rs +++ b/src/render/debug.rs @@ -11,7 +11,7 @@ use crate::{ use bytemuck::{Pod, Zeroable}; use wgpu::util::DeviceExt as _; -use std::{collections::HashMap, mem, num::NonZeroU64}; +use std::{collections::HashMap, num::NonZeroU64}; const BLEND_FRONT: wgpu::BlendComponent = wgpu::BlendComponent::REPLACE; const BLEND_BEHIND: wgpu::BlendComponent = wgpu::BlendComponent { @@ -157,7 +157,7 @@ impl Context { ]), usage: wgpu::BufferUsages::UNIFORM, }); - let locals_size = mem::size_of::() as wgpu::BufferAddress; + let locals_size = size_of::() as wgpu::BufferAddress; let bind_group_line = device.create_bind_group(&wgpu::BindGroupDescriptor { label: Some("Debug line"), layout: &bind_group_layout, @@ -242,7 +242,7 @@ impl Context { entry_point: "main_vs", buffers: &[ wgpu::VertexBufferLayout { - array_stride: mem::size_of::() as wgpu::BufferAddress, + array_stride: size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, attributes: &[wgpu::VertexAttribute { offset: 0, @@ -251,7 +251,7 @@ impl Context { }], }, wgpu::VertexBufferLayout { - array_stride: mem::size_of::() as wgpu::BufferAddress, + array_stride: size_of::() as wgpu::BufferAddress, step_mode: color_rate, attributes: &[wgpu::VertexAttribute { offset: 0, @@ -327,14 +327,14 @@ impl Context { //TODO: this is broken - both regular rendering and debug one // require instancing now, one has to yield and be refactored. - let instance_offset = instance_id * mem::size_of::(); + let instance_offset = instance_id * size_of::(); pass.set_bind_group(2, shape_bg, &[]); pass.set_vertex_buffer(0, shape.polygon_buf.slice(..)); pass.set_vertex_buffer( 1, instance_buf.slice( instance_offset as wgpu::BufferAddress - ..mem::size_of::() as wgpu::BufferAddress, + ..size_of::() as wgpu::BufferAddress, ), ); diff --git a/src/render/global.rs b/src/render/global.rs index c075056..3237533 100644 --- a/src/render/global.rs +++ b/src/render/global.rs @@ -1,6 +1,5 @@ use crate::{config::settings, space::Camera}; use bytemuck::{Pod, Zeroable}; -use std::mem; #[repr(C)] #[derive(Clone, Copy)] @@ -91,7 +90,7 @@ impl Context { }); let uniform_buf = gfx.device.create_buffer(&wgpu::BufferDescriptor { label: Some("Uniform"), - size: mem::size_of::() as wgpu::BufferAddress, + size: size_of::() as wgpu::BufferAddress, usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); diff --git a/src/render/mod.rs b/src/render/mod.rs index 23db4ea..ec3d7c5 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -11,7 +11,6 @@ use std::{ collections::HashMap, fs::File, io::{BufReader, Error as IoError, Read}, - mem, ops::Range, path::PathBuf, sync::Arc, @@ -89,7 +88,7 @@ impl ShapeVertexDesc { pub fn buffer_desc(&self) -> wgpu::VertexBufferLayout<'_> { wgpu::VertexBufferLayout { - array_stride: mem::size_of::() as wgpu::BufferAddress, + array_stride: size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Instance, attributes: &self.attributes, } @@ -462,7 +461,7 @@ impl Render { 0, &self.global.uniform_buf, 0, - mem::size_of::() as wgpu::BufferAddress, + size_of::() as wgpu::BufferAddress, ); self.terrain.prepare_shadow( @@ -518,7 +517,7 @@ impl Render { 0, &self.global.uniform_buf, 0, - mem::size_of::() as wgpu::BufferAddress, + size_of::() as wgpu::BufferAddress, ); self.terrain.prepare( @@ -528,7 +527,7 @@ impl Render { &self.fog_config, level.geometry.height, cam, - viewport.unwrap_or_else(|| Rect { + viewport.unwrap_or(Rect { x: 0, y: 0, w: self.screen_size.width as u16, diff --git a/src/render/object.rs b/src/render/object.rs index 51f81c0..c82e590 100644 --- a/src/render/object.rs +++ b/src/render/object.rs @@ -8,7 +8,7 @@ use crate::{ use bytemuck::{Pod, Zeroable}; use m3d::NUM_COLOR_IDS; -use std::{mem, slice}; +use std::slice; pub const COLOR_TABLE: [[u8; 2]; NUM_COLOR_IDS as usize] = [ [0, 0], // reserved @@ -109,7 +109,7 @@ impl InstanceDesc { pub fn buffer_desc(&self) -> wgpu::VertexBufferLayout<'_> { wgpu::VertexBufferLayout { - array_stride: mem::size_of::() as wgpu::BufferAddress, + array_stride: size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Instance, attributes: &self.attributes, } @@ -133,7 +133,7 @@ impl Context { front_face: wgpu::FrontFace, ) -> PipelineSet { let vertex_descriptor = wgpu::VertexBufferLayout { - array_stride: mem::size_of::() as wgpu::BufferAddress, + array_stride: size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array![0 => Sint8x4, 1 => Uint32, 2 => Snorm8x4], }; diff --git a/src/render/terrain.rs b/src/render/terrain.rs index 742ea0f..445f4ee 100644 --- a/src/render/terrain.rs +++ b/src/render/terrain.rs @@ -10,7 +10,7 @@ use crate::{ use bytemuck::{Pod, Zeroable}; use wgpu::util::DeviceExt as _; -use std::{mem, ops::Range}; +use std::ops::Range; const SCATTER_GROUP_SIZE: [u32; 3] = [16, 16, 1]; // Has to agree with the shader @@ -334,7 +334,7 @@ impl Context { module: &shader, entry_point: "main", buffers: &[wgpu::VertexBufferLayout { - array_stride: mem::size_of::() as wgpu::BufferAddress, + array_stride: size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, attributes: &[wgpu::VertexAttribute { offset: 0, @@ -437,12 +437,12 @@ impl Context { label: Some("terrain-ray-voxel"), layout: Some(pipeline_layout), vertex: wgpu::VertexState { - module: &draw_shader, + module: draw_shader, entry_point: "main", buffers: &[], }, fragment: Some(wgpu::FragmentState { - module: &draw_shader, + module: draw_shader, entry_point: "draw_depth", targets: &[], }), @@ -859,13 +859,13 @@ impl Context { let surface_uni_buf = gfx.device.create_buffer(&wgpu::BufferDescriptor { label: Some("surface-uniforms"), - size: mem::size_of::() as _, + size: size_of::() as _, usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); let uniform_buf = gfx.device.create_buffer(&wgpu::BufferDescriptor { label: Some("Terrain uniforms"), - size: mem::size_of::() as wgpu::BufferAddress, + size: size_of::() as wgpu::BufferAddress, usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); @@ -980,7 +980,7 @@ impl Context { ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: true, - min_binding_size: wgpu::BufferSize::new(mem::size_of::< + min_binding_size: wgpu::BufferSize::new(size_of::< BakeConstants, >( ) @@ -1037,7 +1037,7 @@ impl Context { ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, - min_binding_size: wgpu::BufferSize::new(mem::size_of::< + min_binding_size: wgpu::BufferSize::new(size_of::< VoxelConstants, >( ) @@ -1105,7 +1105,7 @@ impl Context { .min(grid_extent.depth_or_array_layers) .leading_zeros(); - assert_eq!(mem::size_of::(), 16); + assert_eq!(size_of::(), 16); let mut header = VoxelHeader { lod_count: mip_level_count, pad: [0; 3], @@ -1136,7 +1136,7 @@ impl Context { let grid = gfx.device.create_buffer(&wgpu::BufferDescriptor { label: Some("Grid"), - size: (mem::size_of::() + data_offset_in_words as usize * 4) as _, + size: (size_of::() + data_offset_in_words as usize * 4) as _, usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); @@ -1145,7 +1145,7 @@ impl Context { let constant_buffer = gfx.device.create_buffer(&wgpu::BufferDescriptor { label: Some("Voxel constants"), - size: mem::size_of::() as _, + size: size_of::() as _, usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); @@ -1165,7 +1165,7 @@ impl Context { }); let max_update_rects = 10usize; - assert!(mem::size_of::() <= MAXIMUM_UNIFORM_BUFFER_ALIGNMENT); + assert!(size_of::() <= MAXIMUM_UNIFORM_BUFFER_ALIGNMENT); let update_buffer = gfx.device.create_buffer(&wgpu::BufferDescriptor { label: Some("Bake constants"), size: (MAXIMUM_UNIFORM_BUFFER_ALIGNMENT * max_update_rects) @@ -1202,7 +1202,7 @@ impl Context { resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { buffer: &update_buffer, offset: 0, - size: wgpu::BufferSize::new(mem::size_of::() as _), + size: wgpu::BufferSize::new(size_of::() as _), }), }, wgpu::BindGroupEntry { @@ -1554,7 +1554,7 @@ impl Context { 0, &self.surface_uni_buf, 0, - mem::size_of::() as _, + size_of::() as _, ); // Update acceleration structures self.dirty_rects.push(super::DirtyRect { @@ -1711,10 +1711,10 @@ impl Context { for i in 0..update_buffer_contents.len() { encoder.copy_buffer_to_buffer( &staging_buf, - (i * mem::size_of::()) as _, + (i * size_of::()) as _, update_buffer, (i * MAXIMUM_UNIFORM_BUFFER_ALIGNMENT) as _, - mem::size_of::() as _, + size_of::() as _, ); } @@ -1855,7 +1855,7 @@ impl Context { 0, &self.uniform_buf, 0, - mem::size_of::() as _, + size_of::() as _, ); } @@ -1887,7 +1887,7 @@ impl Context { 0, constant_buffer, 0, - mem::size_of::() as _, + size_of::() as _, ); } Kind::Paint { @@ -1972,48 +1972,45 @@ impl Context { 0, &self.uniform_buf, 0, - mem::size_of::() as wgpu::BufferAddress, + size_of::() as wgpu::BufferAddress, ); } - match self.shadow_kind { - ShadowKind::InheritRayVoxel { + if let ShadowKind::InheritRayVoxel { max_outer_steps, max_inner_steps, .. - } => match self.kind { - Kind::RayVoxel { - ref constant_buffer, + } = self.shadow_kind { match self.kind { + Kind::RayVoxel { + ref constant_buffer, + voxel_size, + debug_alpha, + .. + } => { + let constants = VoxelConstants { voxel_size, + pad: 0, + max_depth: cam.depth_range().end, debug_alpha, - .. - } => { - let constants = VoxelConstants { - voxel_size, - pad: 0, - max_depth: cam.depth_range().end, - debug_alpha, - max_outer_steps, - max_inner_steps, - }; - let constant_update = - device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("ray-voxel shadow constants"), - contents: bytemuck::bytes_of(&constants), - usage: wgpu::BufferUsages::COPY_SRC, - }); - encoder.copy_buffer_to_buffer( - &constant_update, - 0, - constant_buffer, - 0, - mem::size_of::() as _, - ); - } - _ => unreachable!(), - }, - _ => {} - } + max_outer_steps, + max_inner_steps, + }; + let constant_update = + device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("ray-voxel shadow constants"), + contents: bytemuck::bytes_of(&constants), + usage: wgpu::BufferUsages::COPY_SRC, + }); + encoder.copy_buffer_to_buffer( + &constant_update, + 0, + constant_buffer, + 0, + size_of::() as _, + ); + } + _ => unreachable!(), + } } } pub fn draw<'a>(&'a self, pass: &mut wgpu::RenderPass<'a>) { @@ -2111,34 +2108,31 @@ impl Context { } pub fn draw_ui(&mut self, ui: &mut egui::Ui) { - match self.kind { - Kind::RayVoxel { + if let Kind::RayVoxel { ref mut max_outer_steps, ref mut max_inner_steps, ref mut debug_alpha, ref mut debug_render, .. - } => { - ui.add(egui::Slider::new(max_outer_steps, 0..=100).text("Max outer steps")); - ui.add(egui::Slider::new(max_inner_steps, 0..=100).text("Max inner steps")); - ui.add(egui::Slider::new(debug_alpha, 0.0..=1.0).text("Debug alpha")); - if let Some(ref mut debug) = *debug_render { - let mut debug_voxels = debug.lod_range.is_some(); - ui.checkbox(&mut debug_voxels, "Debug voxels"); - let mut lod_start = debug.lod_range.clone().map_or(4, |r| r.start); - let mut lod_count = debug.lod_range.clone().map_or(1, |r| r.end - r.start); - ui.add_enabled_ui(debug_voxels, |ui| { - ui.add(egui::Slider::new(&mut lod_start, 1..=8).text("LOD start")); - ui.add(egui::Slider::new(&mut lod_count, 1..=8).text("LOD count")); - }); - debug.lod_range = if debug_voxels { - Some(lod_start..lod_start + lod_count) - } else { - None - }; - } + } = self.kind { + ui.add(egui::Slider::new(max_outer_steps, 0..=100).text("Max outer steps")); + ui.add(egui::Slider::new(max_inner_steps, 0..=100).text("Max inner steps")); + ui.add(egui::Slider::new(debug_alpha, 0.0..=1.0).text("Debug alpha")); + if let Some(ref mut debug) = *debug_render { + let mut debug_voxels = debug.lod_range.is_some(); + ui.checkbox(&mut debug_voxels, "Debug voxels"); + let mut lod_start = debug.lod_range.clone().map_or(4, |r| r.start); + let mut lod_count = debug.lod_range.clone().map_or(1, |r| r.end - r.start); + ui.add_enabled_ui(debug_voxels, |ui| { + ui.add(egui::Slider::new(&mut lod_start, 1..=8).text("LOD start")); + ui.add(egui::Slider::new(&mut lod_count, 1..=8).text("LOD count")); + }); + debug.lod_range = if debug_voxels { + Some(lod_start..lod_start + lod_count) + } else { + None + }; } - _ => {} } } } diff --git a/src/render/water.rs b/src/render/water.rs index 4ec9b09..1265477 100644 --- a/src/render/water.rs +++ b/src/render/water.rs @@ -4,7 +4,7 @@ use crate::{ space::Camera, }; use bytemuck::{Pod, Zeroable}; -use std::{mem, ops}; +use std::ops; use wgpu::util::DeviceExt as _; #[repr(C)] @@ -33,7 +33,7 @@ impl Context { color_format: wgpu::TextureFormat, ) -> wgpu::RenderPipeline { let vertex_descriptor = wgpu::VertexBufferLayout { - array_stride: mem::size_of::() as wgpu::BufferAddress, + array_stride: size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Sint32], }; @@ -90,7 +90,7 @@ impl Context { let max_vertices = 1000; let vertex_buf = device.create_buffer(&wgpu::BufferDescriptor { label: Some("water-vertex"), - size: (max_vertices * mem::size_of::()) as wgpu::BufferAddress, + size: (max_vertices * size_of::()) as wgpu::BufferAddress, usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); @@ -162,7 +162,7 @@ impl Context { contents: bytemuck::cast_slice(&self.vertices), usage: wgpu::BufferUsages::COPY_SRC | wgpu::BufferUsages::MAP_WRITE, }); - let total_size = self.vertices.len() * mem::size_of::(); + let total_size = self.vertices.len() * size_of::(); encoder.copy_buffer_to_buffer( &staging, 0,