diff --git a/build.rs b/build.rs index f6b45809..19abc227 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,5 @@ -use std::{env, fs}; use std::path::{Path, PathBuf}; +use std::{env, fs}; use mapr_utils::mbtiles::extract; use wgsl_validate::validate_project_wgsl; @@ -17,10 +17,12 @@ fn main() { let source = Path::new(&root_dir).join("test-data/munich-12.mbtiles"); // Pack tiles around Maxvorstadt (100 tiles in each direction) - extract(source, - out, - 12, - (2179 - 100)..(2179 + 100), - (1421 - 100)..(1421 + 100), - ).unwrap(); + extract( + source, + out, + 12, + (2179 - 100)..(2179 + 100), + (1421 - 100)..(1421 + 100), + ) + .unwrap(); } diff --git a/examples/desktop.rs b/examples/desktop.rs index cde866a4..99d562e4 100644 --- a/examples/desktop.rs +++ b/examples/desktop.rs @@ -1,6 +1,6 @@ +use mapr::main_loop; use winit::event_loop::EventLoop; use winit::window::WindowBuilder; -use mapr::main_loop; fn main() { env_logger::init_from_env(env_logger::Env::default().default_filter_or("info")); diff --git a/libs/mapr_utils/src/mbtiles.rs b/libs/mapr_utils/src/mbtiles.rs index ff21bc39..3d475ea2 100644 --- a/libs/mapr_utils/src/mbtiles.rs +++ b/libs/mapr_utils/src/mbtiles.rs @@ -1,16 +1,16 @@ -use std::{fs, io}; use std::collections::HashMap; use std::fs::File; use std::io::Write; use std::ops::Range; use std::path::Path; +use std::{fs, io}; use flate2::bufread::GzDecoder; -use rusqlite::{Connection, params, Row}; +use rusqlite::{params, Connection, Row}; #[derive(Debug)] pub enum Error { - IO(String) + IO(String), } impl From for Error { @@ -25,26 +25,33 @@ impl From for Error { } } - impl From for Error { fn from(error: rusqlite::Error) -> Self { Error::IO(error.to_string()) } } -pub fn extract, R: AsRef>(input_mbtiles: P, - output_dir: R, - z: u32, - x_range: Range, - y_range: Range) -> Result<(), Error> { +pub fn extract, R: AsRef>( + input_mbtiles: P, + output_dir: R, + z: u32, + x_range: Range, + y_range: Range, +) -> Result<(), Error> { let input_path = input_mbtiles.as_ref().to_path_buf(); if !input_path.is_file() { - return Err(Error::IO(format!("Input file {:?} is not a file", input_path))); + return Err(Error::IO(format!( + "Input file {:?} is not a file", + input_path + ))); } let output_path = output_dir.as_ref().to_path_buf(); if output_path.exists() { - return Err(Error::IO(format!("Output directory {:?} already exists", output_path))); + return Err(Error::IO(format!( + "Output directory {:?} already exists", + output_path + ))); } let connection = Connection::open(input_path)?; @@ -53,17 +60,20 @@ pub fn extract, R: AsRef>(input_mbtiles: P, extract_metadata(&connection, &output_path)?; // language=SQL - let mut prepared_statement = connection - .prepare("SELECT zoom_level, tile_column, tile_row, tile_data + let mut prepared_statement = connection.prepare( + "SELECT zoom_level, tile_column, tile_row, tile_data FROM tiles WHERE (zoom_level = ?1) AND (tile_column BETWEEN ?2 AND ?3) AND - (tile_row BETWEEN ?4 AND ?5);")?; + (tile_row BETWEEN ?4 AND ?5);", + )?; let mut tiles_rows = prepared_statement.query(params![ z, - x_range.start, x_range.end, - flip_vertical_axis(z, y_range.end), flip_vertical_axis(z, y_range.start) // in mbtiles it is stored flipped + x_range.start, + x_range.end, + flip_vertical_axis(z, y_range.end), + flip_vertical_axis(z, y_range.start) // in mbtiles it is stored flipped ])?; while let Ok(Some(tile)) = tiles_rows.next() { @@ -73,17 +83,16 @@ pub fn extract, R: AsRef>(input_mbtiles: P, Ok(()) } - -fn flip_vertical_axis(zoom: u32, value: u32)-> u32 { +fn flip_vertical_axis(zoom: u32, value: u32) -> u32 { 2u32.pow(zoom) - 1 - value } -fn extract_tile(tile: &Row, - output_path: &Path) - -> Result<(), Error> { - let (z, x, mut y): (u32, u32, u32) = (tile.get::<_, u32>(0)?, - tile.get::<_, u32>(1)?, - tile.get::<_, u32>(2)?); +fn extract_tile(tile: &Row, output_path: &Path) -> Result<(), Error> { + let (z, x, mut y): (u32, u32, u32) = ( + tile.get::<_, u32>(0)?, + tile.get::<_, u32>(1)?, + tile.get::<_, u32>(2)?, + ); // Flip vertical axis y = flip_vertical_axis(z, y); @@ -101,23 +110,19 @@ fn extract_tile(tile: &Row, Ok(()) } -fn extract_metadata(connection: &Connection, - output_path: &Path) - -> Result<(), Error> { +fn extract_metadata(connection: &Connection, output_path: &Path) -> Result<(), Error> { // language=SQL - let mut prepared_statement = connection - .prepare("SELECT name, value FROM metadata;")?; - let metadata = prepared_statement - .query_map([], |row| { - Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?)) - })?; + let mut prepared_statement = connection.prepare("SELECT name, value FROM metadata;")?; + let metadata = prepared_statement.query_map([], |row| { + Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?)) + })?; - let metadata_map: HashMap = metadata.filter_map(|result| { - match result { + let metadata_map: HashMap = metadata + .filter_map(|result| match result { Ok(tuple) => Some(tuple), Err(_) => None, - } - }).collect::>(); + }) + .collect::>(); let json_string = serde_json::to_string(&metadata_map)?; let metadata_path = output_path.join("metadata.json"); diff --git a/libs/mapr_utils/src/tile_downloader.rs b/libs/mapr_utils/src/tile_downloader.rs index 6fd0f68c..4c60bebe 100644 --- a/libs/mapr_utils/src/tile_downloader.rs +++ b/libs/mapr_utils/src/tile_downloader.rs @@ -1,7 +1,7 @@ +use reqwest::Client; use std::fs::File; use std::io::copy; use std::path::Path; -use reqwest::Client; use vector_tile::grid::*; @@ -14,9 +14,7 @@ pub async fn download_tiles() { y = y, ); println!("{}", target); - let client = Client::builder() - .gzip(true) - .build().unwrap(); + let client = Client::builder().gzip(true).build().unwrap(); let response = client.get(target).send().await.unwrap(); if response.status().is_success() { @@ -25,7 +23,7 @@ pub async fn download_tiles() { Path::new(".").join(format!("test-data/{z}-{x}-{y}.pbf", z = z, x = x, y = y,)); File::create(fname).unwrap() }; - copy(&mut response.bytes().await.unwrap().as_ref(), &mut dest).unwrap(); + copy(&mut response.bytes().await.unwrap().as_ref(), &mut dest).unwrap(); } } } diff --git a/libs/style_spec/build.rs b/libs/style_spec/build.rs index d29b3365..24436b69 100644 --- a/libs/style_spec/build.rs +++ b/libs/style_spec/build.rs @@ -3,7 +3,7 @@ use std::io::BufReader; use serde_json::Value;*/ fn generate_type_def() -> Option { -/* let f = File::open("style-spec-v8.json").unwrap(); + /* let f = File::open("style-spec-v8.json").unwrap(); let mut reader = BufReader::new(f); let result = serde_json::from_reader::<_, Value>(&mut reader).unwrap(); @@ -20,7 +20,6 @@ fn generate_type_def() -> Option { Some(5) } - fn main() { generate_type_def(); -} \ No newline at end of file +} diff --git a/libs/style_spec/src/lib.rs b/libs/style_spec/src/lib.rs index e69de29b..8b137891 100644 --- a/libs/style_spec/src/lib.rs +++ b/libs/style_spec/src/lib.rs @@ -0,0 +1 @@ + diff --git a/libs/vector_tile/build.rs b/libs/vector_tile/build.rs index 8f055319..44c80676 100644 --- a/libs/vector_tile/build.rs +++ b/libs/vector_tile/build.rs @@ -10,4 +10,4 @@ fn main() { .include("spec/2.1") .run() .expect("Codegen failed."); -} \ No newline at end of file +} diff --git a/libs/vector_tile/src/error.rs b/libs/vector_tile/src/error.rs index 2ca627d3..2087a8d8 100644 --- a/libs/vector_tile/src/error.rs +++ b/libs/vector_tile/src/error.rs @@ -1,5 +1,5 @@ -use std::io; use protobuf::ProtobufError; +use std::io; #[derive(Debug)] pub enum Error { diff --git a/libs/vector_tile/src/lib.rs b/libs/vector_tile/src/lib.rs index be0052a8..a8892991 100644 --- a/libs/vector_tile/src/lib.rs +++ b/libs/vector_tile/src/lib.rs @@ -1,6 +1,6 @@ use std::fs::File; use std::io::{BufRead, BufReader}; -use std::path::{Path}; +use std::path::Path; use protobuf::Message; @@ -15,10 +15,10 @@ mod protos; #[cfg(test)] mod tests; -pub mod geometry; -pub mod tile; -pub mod grid; pub mod error; +pub mod geometry; +pub mod grid; +pub mod tile; pub fn parse_tile>(path: P) -> Result { let f = File::open(path)?; @@ -27,10 +27,9 @@ pub fn parse_tile>(path: P) -> Result { } pub fn parse_tile_reader(reader: &mut B) -> Result { - if reader.fill_buf()?.is_empty() { - return Err(Error::Generic("input must not be empty".to_string())); - } + if reader.fill_buf()?.is_empty() { + return Err(Error::Generic("input must not be empty".to_string())); + } let proto_tile = TileProto::parse_from_reader(reader)?; Ok(proto_tile.decode()) } - diff --git a/libs/vector_tile/src/protos/mod.rs b/libs/vector_tile/src/protos/mod.rs index cc69ffdd..f1d07d73 100644 --- a/libs/vector_tile/src/protos/mod.rs +++ b/libs/vector_tile/src/protos/mod.rs @@ -1,2 +1,2 @@ #[path = "vector_tile.rs"] -pub mod vector_tile; \ No newline at end of file +pub mod vector_tile; diff --git a/libs/vector_tile/src/tests.rs b/libs/vector_tile/src/tests.rs index 89949cda..e6a71b8e 100644 --- a/libs/vector_tile/src/tests.rs +++ b/libs/vector_tile/src/tests.rs @@ -5,8 +5,8 @@ use protobuf::Message; use crate::encoding::Decode; use crate::grid::{google_mercator, tile_coordinates_bavaria}; -use crate::{parse_tile, parse_tile_reader}; use crate::protos::vector_tile::Tile; +use crate::{parse_tile, parse_tile_reader}; #[test] fn test_parsing_europe_pbf() { @@ -21,4 +21,4 @@ fn test_tile_coordinates_bavaria() { #[test] fn test_empty_fail() { assert!(parse_tile_reader(&mut Cursor::new(&[])).is_err()) -} \ No newline at end of file +} diff --git a/libs/vector_tile/src/tile.rs b/libs/vector_tile/src/tile.rs index 4ab9febf..a68cf57f 100644 --- a/libs/vector_tile/src/tile.rs +++ b/libs/vector_tile/src/tile.rs @@ -53,7 +53,6 @@ impl Feature { self.internal.get_id() } - pub fn geometry(&self) -> &Geometry { &self.geometry } diff --git a/libs/wgsl_validate/src/lib.rs b/libs/wgsl_validate/src/lib.rs index 7bead26f..c1ffe35b 100644 --- a/libs/wgsl_validate/src/lib.rs +++ b/libs/wgsl_validate/src/lib.rs @@ -79,4 +79,4 @@ pub fn validate_project_wgsl() { } } } -} \ No newline at end of file +} diff --git a/src/io/mod.rs b/src/io/mod.rs index d1b50b2d..d8ac86a4 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -1,2 +1 @@ pub mod static_database; - diff --git a/src/io/static_database.rs b/src/io/static_database.rs index 315050d2..b63f7fcf 100644 --- a/src/io/static_database.rs +++ b/src/io/static_database.rs @@ -1,7 +1,7 @@ use std::concat; use std::env; -use include_dir::{Dir, File, include_dir}; +use include_dir::{include_dir, Dir, File}; static TILES: Dir = include_dir!("$OUT_DIR/extracted-tiles"); @@ -21,7 +21,7 @@ mod tests { #[test] fn test_tiles_available() { - assert!(get_tile(0,0,0).is_none()); // World overview - assert!(get_tile(2179, 1421,12).is_some()); // Maxvorstadt Munich + assert!(get_tile(0, 0, 0).is_none()); // World overview + assert!(get_tile(2179, 1421, 12).is_some()); // Maxvorstadt Munich } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 92f4f8b9..cb5e3065 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ mod fps_meter; -mod platform; -mod render; mod io; pub mod main_loop; +mod platform; +mod render; diff --git a/src/main_loop.rs b/src/main_loop.rs index 254abcfb..13f8e586 100644 --- a/src/main_loop.rs +++ b/src/main_loop.rs @@ -80,4 +80,4 @@ pub async fn setup(window: winit::window::Window, event_loop: EventLoop<()>) { _ => {} } }); -} \ No newline at end of file +} diff --git a/src/platform/generic.rs b/src/platform/generic.rs index c6264e5a..53d12ff5 100644 --- a/src/platform/generic.rs +++ b/src/platform/generic.rs @@ -1,4 +1,3 @@ - pub use std::time::Instant; // Vulkan/OpenGL diff --git a/src/platform/mod.rs b/src/platform/mod.rs index c52efca1..b2c945d0 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -7,7 +7,6 @@ mod apple; #[cfg(target_os = "android")] mod android; - #[cfg(not(any( target_os = "android", all(target_arch = "aarch64", not(target_os = "android")), @@ -31,7 +30,6 @@ pub use android::*; )))] pub use generic::*; - // FIXME: This limit is enforced by WebGL. Actually this makes sense! // FIXME: This can also be achieved by _pad attributes in shader_ffi.rs pub const MIN_BUFFER_SIZE: u64 = 32; diff --git a/src/platform/web/io.rs b/src/platform/web/io.rs index e69de29b..8b137891 100644 --- a/src/platform/web/io.rs +++ b/src/platform/web/io.rs @@ -0,0 +1 @@ + diff --git a/src/platform/web/mod.rs b/src/platform/web/mod.rs index 489eea61..152abee3 100644 --- a/src/platform/web/mod.rs +++ b/src/platform/web/mod.rs @@ -60,4 +60,3 @@ pub async fn run() { super::setup::setup(window, event_loop).await; } - diff --git a/src/platform/web/wasm_experiment.rs b/src/platform/web/wasm_experiment.rs index 9ba5d3b9..c8fe8812 100644 --- a/src/platform/web/wasm_experiment.rs +++ b/src/platform/web/wasm_experiment.rs @@ -1,16 +1,19 @@ use log::info; use wasm_bindgen::closure::Closure; +use wasm_bindgen::prelude::*; use wasm_bindgen::JsValue; use web_sys::MessageEvent; use web_sys::Window; -use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn test_fetch(web_window: &Window) { let cb: Closure = Closure::wrap(Box::new(|value: JsValue| { info!("interval elapsed!"); - }) as Box); - web_window.fetch_with_str("http://localhost:5555/web/index.html").then(&cb); + }) + as Box); + web_window + .fetch_with_str("http://localhost:5555/web/index.html") + .then(&cb); cb.forget(); } diff --git a/src/render/camera.rs b/src/render/camera.rs index d063c69d..af7f9305 100644 --- a/src/render/camera.rs +++ b/src/render/camera.rs @@ -166,9 +166,9 @@ impl CameraController { // I'm assuming a line is about 100 pixels winit::event::MouseScrollDelta::LineDelta(_, scroll) => scroll * 100.0, winit::event::MouseScrollDelta::PixelDelta(winit::dpi::PhysicalPosition { - y: scroll, - .. - }) => *scroll as f32, + y: scroll, + .. + }) => *scroll as f32, }; } diff --git a/src/render/mod.rs b/src/render/mod.rs index 4c271426..7361483b 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1,8 +1,8 @@ +mod camera; mod piplines; mod shader_ffi; mod tesselation; mod texture; -mod camera; -pub mod state; mod shaders; +pub mod state; diff --git a/src/render/piplines.rs b/src/render/piplines.rs index ff7f1ffc..289e494a 100644 --- a/src/render/piplines.rs +++ b/src/render/piplines.rs @@ -43,7 +43,7 @@ pub fn create_map_render_pipeline_description<'a>( pass_op: wgpu::StencilOperation::Keep, } }; - + wgpu::RenderPipelineDescriptor { label: None, layout: Some(pipeline_layout), @@ -56,7 +56,7 @@ pub fn create_map_render_pipeline_description<'a>( strip_index_format: None, cull_mode: None, // TODO Maps look the same from he bottom and above conservative: false, - unclipped_depth: false + unclipped_depth: false, }, depth_stencil: Some(wgpu::DepthStencilState { format: DEPTH_TEXTURE_FORMAT, @@ -75,6 +75,6 @@ pub fn create_map_render_pipeline_description<'a>( mask: !0, alpha_to_coverage_enabled: false, }, - multiview: None + multiview: None, } } diff --git a/src/render/shader_ffi.rs b/src/render/shader_ffi.rs index 0f8bce7a..9543ebf8 100644 --- a/src/render/shader_ffi.rs +++ b/src/render/shader_ffi.rs @@ -38,7 +38,9 @@ pub struct GlobalsUniform { impl GlobalsUniform { pub fn new(camera_uniform: CameraUniform) -> Self { - Self { camera: camera_uniform } + Self { + camera: camera_uniform, + } } } diff --git a/src/render/shaders/mod.rs b/src/render/shaders/mod.rs index 12f5258c..5daeecd6 100644 --- a/src/render/shaders/mod.rs +++ b/src/render/shaders/mod.rs @@ -1,4 +1,6 @@ -use wgpu::{ColorTargetState, Device, FragmentState, ShaderModule, VertexBufferLayout, VertexState}; +use wgpu::{ + ColorTargetState, Device, FragmentState, ShaderModule, VertexBufferLayout, VertexState, +}; pub struct FragmentShaderState { source: &'static str, @@ -21,15 +23,12 @@ impl FragmentShaderState { } } - pub fn create_fragment_state( - &mut self, device: &Device, - ) -> FragmentState { + pub fn create_fragment_state(&mut self, device: &Device) -> FragmentState { self.module = Some(device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("fragment shader"), source: wgpu::ShaderSource::Wgsl(self.source.into()), })); - wgpu::FragmentState { module: self.module.as_ref().unwrap(), entry_point: "main", @@ -39,8 +38,10 @@ impl FragmentShaderState { } impl VertexShaderState { - pub const fn new(source: &'static str, - buffers: &'static [VertexBufferLayout<'static>]) -> Self { + pub const fn new( + source: &'static str, + buffers: &'static [VertexBufferLayout<'static>], + ) -> Self { Self { source, buffers, @@ -66,10 +67,11 @@ pub mod tile { use crate::platform::COLOR_TEXTURE_FORMAT; use crate::render::shader_ffi::GpuVertexUniform; - use super::{VertexShaderState, FragmentShaderState}; + use super::{FragmentShaderState, VertexShaderState}; pub const VERTEX: VertexShaderState = VertexShaderState::new( - include_str!("tile.vertex.wgsl"), &[wgpu::VertexBufferLayout { + include_str!("tile.vertex.wgsl"), + &[wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as u64, step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ @@ -93,7 +95,8 @@ pub mod tile { ); pub const FRAGMENT: FragmentShaderState = FragmentShaderState::new( - include_str!("tile.fragment.wgsl"), &[wgpu::ColorTargetState { + include_str!("tile.fragment.wgsl"), + &[wgpu::ColorTargetState { format: COLOR_TEXTURE_FORMAT, blend: None, write_mask: wgpu::ColorWrites::ALL, @@ -101,51 +104,53 @@ pub mod tile { ); } - pub mod tile_mask { + use super::{FragmentShaderState, VertexShaderState}; use crate::platform::COLOR_TEXTURE_FORMAT; use crate::render::shader_ffi::GpuVertexUniform; - use super::{VertexShaderState, FragmentShaderState}; pub const VERTEX: VertexShaderState = VertexShaderState::new( - include_str!("tile_mask.vertex.wgsl"), &[wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as u64, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[ - wgpu::VertexAttribute { - offset: 0, - format: wgpu::VertexFormat::Float32x2, - shader_location: 0, - }, - wgpu::VertexAttribute { - offset: wgpu::VertexFormat::Float32x2.size(), - format: wgpu::VertexFormat::Float32x2, - shader_location: 1, - }, - wgpu::VertexAttribute { - offset: 2 * wgpu::VertexFormat::Float32x2.size(), - format: wgpu::VertexFormat::Uint32, - shader_location: 2, - }, - ], - }, + include_str!("tile_mask.vertex.wgsl"), + &[ wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as u64, - step_mode: wgpu::VertexStepMode::Instance, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, format: wgpu::VertexFormat::Float32x2, - shader_location: 4, + shader_location: 0, + }, + wgpu::VertexAttribute { + offset: wgpu::VertexFormat::Float32x2.size(), + format: wgpu::VertexFormat::Float32x2, + shader_location: 1, + }, + wgpu::VertexAttribute { + offset: 2 * wgpu::VertexFormat::Float32x2.size(), + format: wgpu::VertexFormat::Uint32, + shader_location: 2, }, ], - }], + }, + wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::() as u64, + step_mode: wgpu::VertexStepMode::Instance, + attributes: &[wgpu::VertexAttribute { + offset: 0, + format: wgpu::VertexFormat::Float32x2, + shader_location: 4, + }], + }, + ], ); pub const FRAGMENT: FragmentShaderState = FragmentShaderState::new( - include_str!("tile_mask.fragment.wgsl"), &[wgpu::ColorTargetState { + include_str!("tile_mask.fragment.wgsl"), + &[wgpu::ColorTargetState { format: COLOR_TEXTURE_FORMAT, blend: None, write_mask: wgpu::ColorWrites::ALL, - }]); -} \ No newline at end of file + }], + ); +} diff --git a/src/render/state.rs b/src/render/state.rs index 7ec4bc0c..15dc3639 100644 --- a/src/render/state.rs +++ b/src/render/state.rs @@ -4,25 +4,27 @@ use std::ops::Range; use log::warn; use lyon::tessellation::VertexBuffers; -use wgpu::{Limits}; use wgpu::util::DeviceExt; +use wgpu::Limits; use winit::dpi::PhysicalSize; -use winit::event::{DeviceEvent, ElementState, KeyboardInput, MouseButton, TouchPhase, WindowEvent}; +use winit::event::{ + DeviceEvent, ElementState, KeyboardInput, MouseButton, TouchPhase, WindowEvent, +}; use winit::window::Window; use vector_tile::parse_tile_reader; use crate::fps_meter::FPSMeter; use crate::io::static_database; -use crate::render::{camera, shaders}; use crate::render::camera::CameraController; use crate::render::tesselation::TileMask; +use crate::render::{camera, shaders}; use super::piplines::*; -use crate::platform::{COLOR_TEXTURE_FORMAT, MIN_BUFFER_SIZE}; use super::shader_ffi::*; use super::tesselation::Tesselated; use super::texture::Texture; +use crate::platform::{COLOR_TEXTURE_FORMAT, MIN_BUFFER_SIZE}; pub struct SceneParams { stroke_width: f32, @@ -129,7 +131,6 @@ impl SceneParams { cpu_primitives[MASK_FILL_PRIM_ID as usize] = PrimitiveUniform::new([0.0, 0.0, 1.0, 1.0], [0.0, 0.0], 0, 1.0, 0.0, 1.0); - Self { cpu_primitives, ..SceneParams::default() @@ -150,9 +151,17 @@ impl State { let mut geometry: VertexBuffers = VertexBuffers::new(); - println!("Using static database from {}", static_database::get_source_path()); + println!( + "Using static database from {}", + static_database::get_source_path() + ); - let tile = parse_tile_reader(&mut Cursor::new(static_database::get_tile(2179, 1421, 12).unwrap().contents())).expect("failed to load tile"); + let tile = parse_tile_reader(&mut Cursor::new( + static_database::get_tile(2179, 1421, 12) + .unwrap() + .contents(), + )) + .expect("failed to load tile"); let (tile_stroke_range, tile_fill_range) = ( tile.tesselate_stroke(&mut geometry, STROKE_PRIM_ID), //tile.empty_range(&mut geometry, STROKE_PRIM_ID), @@ -160,7 +169,12 @@ impl State { ); // tile right to it - let tile = parse_tile_reader(&mut Cursor::new(static_database::get_tile(2180, 1421, 12).unwrap().contents())).expect("failed to load tile"); + let tile = parse_tile_reader(&mut Cursor::new( + static_database::get_tile(2180, 1421, 12) + .unwrap() + .contents(), + )) + .expect("failed to load tile"); let (tile2_stroke_range, tile2_fill_range) = ( tile.tesselate_stroke(&mut geometry, SECOND_TILE_STROKE_PRIM_ID), //tile.empty_range(&mut geometry, STROKE_PRIM_ID), @@ -223,7 +237,8 @@ impl State { usage: wgpu::BufferUsages::INDEX, }); - let mut tile_mask_geometry: VertexBuffers = VertexBuffers::new(); + let mut tile_mask_geometry: VertexBuffers = + VertexBuffers::new(); let tile_mask = TileMask(); let tile_mask_range = tile_mask.tesselate_fill(&mut tile_mask_geometry, MASK_FILL_PRIM_ID); let tile_mask_vertex_uniform_buffer = @@ -245,12 +260,11 @@ impl State { GpuVertexUniform::new([4096.0, 0.0], [0.0, 0.0], 0), ]; - let tile_mask_instances = - device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: None, - contents: bytemuck::cast_slice(&instances), - usage: wgpu::BufferUsages::VERTEX, - }); + let tile_mask_instances = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: None, + contents: bytemuck::cast_slice(&instances), + usage: wgpu::BufferUsages::VERTEX, + }); let prim_buffer_byte_size = cmp::max( MIN_BUFFER_SIZE, @@ -474,7 +488,10 @@ impl State { DeviceEvent::MouseMotion { delta } => { if self.mouse_pressed { warn!("mouse {}", delta.0); - self.camera_controller.process_mouse(delta.0 / window.scale_factor(), delta.1 / window.scale_factor()); + self.camera_controller.process_mouse( + delta.0 / window.scale_factor(), + delta.1 / window.scale_factor(), + ); } true } @@ -486,11 +503,11 @@ impl State { match event { WindowEvent::KeyboardInput { input: - KeyboardInput { - state, - virtual_keycode: Some(key), - .. - }, + KeyboardInput { + state, + virtual_keycode: Some(key), + .. + }, .. } => match key { winit::event::VirtualKeyCode::Z => { @@ -512,7 +529,10 @@ impl State { if let Some(start) = self.scene.last_touch { let delta_x = start.0 - touch.location.x; let delta_y = start.1 - touch.location.y; - self.camera_controller.process_touch(delta_x / window.scale_factor(), delta_y / window.scale_factor()); + self.camera_controller.process_touch( + delta_x / window.scale_factor(), + delta_y / window.scale_factor(), + ); } self.scene.last_touch = Some((touch.location.x, touch.location.y)) @@ -520,7 +540,6 @@ impl State { TouchPhase::Cancelled => {} } - true } WindowEvent::MouseWheel { delta, .. } => { @@ -621,10 +640,7 @@ impl State { { pass.set_pipeline(&self.render_pipeline); pass.set_stencil_reference(2); - pass.set_index_buffer( - self.indices_uniform_buffer.slice(..), - INDEX_FORMAT, - ); + pass.set_index_buffer(self.indices_uniform_buffer.slice(..), INDEX_FORMAT); pass.set_vertex_buffer(0, self.vertex_uniform_buffer.slice(..)); if !self.tile_fill_range.is_empty() { pass.draw_indexed(self.tile_fill_range.clone(), 0, 0..1); @@ -634,10 +650,7 @@ impl State { { pass.set_pipeline(&self.render_pipeline); pass.set_stencil_reference(1); - pass.set_index_buffer( - self.indices_uniform_buffer.slice(..), - INDEX_FORMAT, - ); + pass.set_index_buffer(self.indices_uniform_buffer.slice(..), INDEX_FORMAT); pass.set_vertex_buffer(0, self.vertex_uniform_buffer.slice(..)); if !self.tile2_fill_range.is_empty() { pass.draw_indexed(self.tile2_fill_range.clone(), 0, 0..1); diff --git a/src/render/tesselation.rs b/src/render/tesselation.rs index 3e349200..896ce025 100644 --- a/src/render/tesselation.rs +++ b/src/render/tesselation.rs @@ -3,11 +3,11 @@ use std::ops::Range; use lyon::extra::rust_logo::build_logo_path; use lyon::lyon_tessellation::{FillTessellator, StrokeTessellator}; use lyon::tessellation; +use lyon::tessellation::geometry_builder::MaxIndex; use lyon::tessellation::{ BuffersBuilder, FillOptions, FillVertexConstructor, StrokeOptions, StrokeVertexConstructor, VertexBuffers, }; -use lyon::tessellation::geometry_builder::MaxIndex; use lyon_path::builder::SvgPathBuilder; use lyon_path::Path; @@ -19,11 +19,22 @@ use super::shader_ffi::GpuVertexUniform; const DEFAULT_TOLERANCE: f32 = 0.02; pub trait Tesselated { - fn tesselate_stroke(&self, buffer: &mut VertexBuffers, prim_id: u32) -> Range; - fn tesselate_fill(&self, buffer: &mut VertexBuffers, prim_id: u32) -> Range; + fn tesselate_stroke( + &self, + buffer: &mut VertexBuffers, + prim_id: u32, + ) -> Range; + fn tesselate_fill( + &self, + buffer: &mut VertexBuffers, + prim_id: u32, + ) -> Range; - fn empty_range(&self, buffer: &mut VertexBuffers, - _prim_id: u32) -> Range { + fn empty_range( + &self, + buffer: &mut VertexBuffers, + _prim_id: u32, + ) -> Range { let initial_indices_count = buffer.indices.len() as u32; initial_indices_count..initial_indices_count } @@ -49,11 +60,7 @@ impl StrokeVertexConstructor for WithId { } } - -fn build_path( - tile: &Tile, - fill: bool -) -> Path { +fn build_path(tile: &Tile, fill: bool) -> Path { let mut tile_builder = Path::builder().with_svg(); for layer in tile.layers() { @@ -118,7 +125,10 @@ fn build_path( tile_builder.build() } -impl + MaxIndex> Tesselated for Tile { +impl< + OutputIndex: std::ops::Add + std::convert::From + MaxIndex, + > Tesselated for Tile +{ fn tesselate_stroke( &self, buffer: &mut VertexBuffers, @@ -141,7 +151,11 @@ impl, prim_id: u32) -> Range { + fn tesselate_fill( + &self, + buffer: &mut VertexBuffers, + prim_id: u32, + ) -> Range { let mut tesselator = FillTessellator::new(); let initial_indices_count = buffer.indices.len(); @@ -162,8 +176,15 @@ impl + MaxIndex> Tesselated for RustLogo { - fn tesselate_stroke(&self, buffer: &mut VertexBuffers, prim_id: u32) -> Range { +impl< + OutputIndex: std::ops::Add + std::convert::From + MaxIndex, + > Tesselated for RustLogo +{ + fn tesselate_stroke( + &self, + buffer: &mut VertexBuffers, + prim_id: u32, + ) -> Range { let mut stroke_tess = StrokeTessellator::new(); let initial_indices_count = buffer.indices.len(); @@ -184,7 +205,11 @@ impl, prim_id: u32) -> Range { + fn tesselate_fill( + &self, + buffer: &mut VertexBuffers, + prim_id: u32, + ) -> Range { let mut fill_tess = FillTessellator::new(); let initial_indices_count = buffer.indices.len(); @@ -207,17 +232,24 @@ impl for TileMask { - fn tesselate_stroke(&self, _buffer: &mut VertexBuffers, _prim_id: u32) -> Range { + fn tesselate_stroke( + &self, + _buffer: &mut VertexBuffers, + _prim_id: u32, + ) -> Range { 0..0 } - fn tesselate_fill(&self, buffer: &mut VertexBuffers, prim_id: u32) -> Range { + fn tesselate_fill( + &self, + buffer: &mut VertexBuffers, + prim_id: u32, + ) -> Range { let initial_indices_count = buffer.indices.len(); buffer.vertices = vec![ @@ -231,4 +263,4 @@ impl Tesselated for TileMask { initial_indices_count as u32..buffer.indices.len() as u32 } -} \ No newline at end of file +}