mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Run rust formatter
This commit is contained in:
parent
bf48fd55b6
commit
05775e712e
16
build.rs
16
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();
|
||||
}
|
||||
|
||||
@ -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"));
|
||||
|
||||
@ -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<serde_json::Error> for Error {
|
||||
@ -25,26 +25,33 @@ impl From<io::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl From<rusqlite::Error> for Error {
|
||||
fn from(error: rusqlite::Error) -> Self {
|
||||
Error::IO(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract<P: AsRef<Path>, R: AsRef<Path>>(input_mbtiles: P,
|
||||
output_dir: R,
|
||||
z: u32,
|
||||
x_range: Range<u32>,
|
||||
y_range: Range<u32>) -> Result<(), Error> {
|
||||
pub fn extract<P: AsRef<Path>, R: AsRef<Path>>(
|
||||
input_mbtiles: P,
|
||||
output_dir: R,
|
||||
z: u32,
|
||||
x_range: Range<u32>,
|
||||
y_range: Range<u32>,
|
||||
) -> 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<P: AsRef<Path>, R: AsRef<Path>>(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<P: AsRef<Path>, R: AsRef<Path>>(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<String, String> = metadata.filter_map(|result| {
|
||||
match result {
|
||||
let metadata_map: HashMap<String, String> = metadata
|
||||
.filter_map(|result| match result {
|
||||
Ok(tuple) => Some(tuple),
|
||||
Err(_) => None,
|
||||
}
|
||||
}).collect::<HashMap<String, String>>();
|
||||
})
|
||||
.collect::<HashMap<String, String>>();
|
||||
|
||||
let json_string = serde_json::to_string(&metadata_map)?;
|
||||
let metadata_path = output_path.join("metadata.json");
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ use std::io::BufReader;
|
||||
use serde_json::Value;*/
|
||||
|
||||
fn generate_type_def() -> Option<u32> {
|
||||
/* 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<u32> {
|
||||
Some(5)
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
generate_type_def();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1 @@
|
||||
|
||||
@ -10,4 +10,4 @@ fn main() {
|
||||
.include("spec/2.1")
|
||||
.run()
|
||||
.expect("Codegen failed.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use std::io;
|
||||
use protobuf::ProtobufError;
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
|
||||
@ -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<P: AsRef<Path>>(path: P) -> Result<Tile, Error> {
|
||||
let f = File::open(path)?;
|
||||
@ -27,10 +27,9 @@ pub fn parse_tile<P: AsRef<Path>>(path: P) -> Result<Tile, Error> {
|
||||
}
|
||||
|
||||
pub fn parse_tile_reader<B: BufRead>(reader: &mut B) -> Result<Tile, Error> {
|
||||
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())
|
||||
}
|
||||
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
#[path = "vector_tile.rs"]
|
||||
pub mod vector_tile;
|
||||
pub mod vector_tile;
|
||||
|
||||
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,6 @@ impl Feature {
|
||||
self.internal.get_id()
|
||||
}
|
||||
|
||||
|
||||
pub fn geometry(&self) -> &Geometry {
|
||||
&self.geometry
|
||||
}
|
||||
|
||||
@ -79,4 +79,4 @@ pub fn validate_project_wgsl() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,2 +1 @@
|
||||
pub mod static_database;
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
mod fps_meter;
|
||||
mod platform;
|
||||
mod render;
|
||||
mod io;
|
||||
pub mod main_loop;
|
||||
mod platform;
|
||||
mod render;
|
||||
|
||||
@ -80,4 +80,4 @@ pub async fn setup(window: winit::window::Window, event_loop: EventLoop<()>) {
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
pub use std::time::Instant;
|
||||
|
||||
// Vulkan/OpenGL
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -0,0 +1 @@
|
||||
|
||||
@ -60,4 +60,3 @@ pub async fn run() {
|
||||
|
||||
super::setup::setup(window, event_loop).await;
|
||||
}
|
||||
|
||||
|
||||
@ -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<dyn FnMut(JsValue) + 'static> = Closure::wrap(Box::new(|value: JsValue| {
|
||||
info!("interval elapsed!");
|
||||
}) as Box<dyn FnMut(JsValue)>);
|
||||
web_window.fetch_with_str("http://localhost:5555/web/index.html").then(&cb);
|
||||
})
|
||||
as Box<dyn FnMut(JsValue)>);
|
||||
web_window
|
||||
.fetch_with_str("http://localhost:5555/web/index.html")
|
||||
.then(&cb);
|
||||
|
||||
cb.forget();
|
||||
}
|
||||
|
||||
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,9 @@ pub struct GlobalsUniform {
|
||||
|
||||
impl GlobalsUniform {
|
||||
pub fn new(camera_uniform: CameraUniform) -> Self {
|
||||
Self { camera: camera_uniform }
|
||||
Self {
|
||||
camera: camera_uniform,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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::<GpuVertexUniform>() 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::<GpuVertexUniform>() 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::<GpuVertexUniform>() 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::<GpuVertexUniform>() 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,
|
||||
}]);
|
||||
}
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
@ -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<GpuVertexUniform, IndexDataType> = 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<GpuVertexUniform, IndexDataType> = VertexBuffers::new();
|
||||
let mut tile_mask_geometry: VertexBuffers<GpuVertexUniform, IndexDataType> =
|
||||
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);
|
||||
|
||||
@ -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<OutputIndex: std::ops::Add> {
|
||||
fn tesselate_stroke(&self, buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>, prim_id: u32) -> Range<u32>;
|
||||
fn tesselate_fill(&self, buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>, prim_id: u32) -> Range<u32>;
|
||||
fn tesselate_stroke(
|
||||
&self,
|
||||
buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>,
|
||||
prim_id: u32,
|
||||
) -> Range<u32>;
|
||||
fn tesselate_fill(
|
||||
&self,
|
||||
buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>,
|
||||
prim_id: u32,
|
||||
) -> Range<u32>;
|
||||
|
||||
fn empty_range(&self, buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>,
|
||||
_prim_id: u32) -> Range<u32> {
|
||||
fn empty_range(
|
||||
&self,
|
||||
buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>,
|
||||
_prim_id: u32,
|
||||
) -> Range<u32> {
|
||||
let initial_indices_count = buffer.indices.len() as u32;
|
||||
initial_indices_count..initial_indices_count
|
||||
}
|
||||
@ -49,11 +60,7 @@ impl StrokeVertexConstructor<GpuVertexUniform> 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<OutputIndex: std::ops::Add + std::convert::From<lyon::lyon_tessellation::VertexId> + MaxIndex> Tesselated<OutputIndex> for Tile {
|
||||
impl<
|
||||
OutputIndex: std::ops::Add + std::convert::From<lyon::lyon_tessellation::VertexId> + MaxIndex,
|
||||
> Tesselated<OutputIndex> for Tile
|
||||
{
|
||||
fn tesselate_stroke(
|
||||
&self,
|
||||
buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>,
|
||||
@ -141,7 +151,11 @@ impl<OutputIndex: std::ops::Add + std::convert::From<lyon::lyon_tessellation::Ve
|
||||
initial_indices_count as u32..buffer.indices.len() as u32
|
||||
}
|
||||
|
||||
fn tesselate_fill(&self, buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>, prim_id: u32) -> Range<u32> {
|
||||
fn tesselate_fill(
|
||||
&self,
|
||||
buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>,
|
||||
prim_id: u32,
|
||||
) -> Range<u32> {
|
||||
let mut tesselator = FillTessellator::new();
|
||||
|
||||
let initial_indices_count = buffer.indices.len();
|
||||
@ -162,8 +176,15 @@ impl<OutputIndex: std::ops::Add + std::convert::From<lyon::lyon_tessellation::Ve
|
||||
|
||||
pub struct RustLogo();
|
||||
|
||||
impl<OutputIndex: std::ops::Add + std::convert::From<lyon::lyon_tessellation::VertexId> + MaxIndex> Tesselated<OutputIndex> for RustLogo {
|
||||
fn tesselate_stroke(&self, buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>, prim_id: u32) -> Range<u32> {
|
||||
impl<
|
||||
OutputIndex: std::ops::Add + std::convert::From<lyon::lyon_tessellation::VertexId> + MaxIndex,
|
||||
> Tesselated<OutputIndex> for RustLogo
|
||||
{
|
||||
fn tesselate_stroke(
|
||||
&self,
|
||||
buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>,
|
||||
prim_id: u32,
|
||||
) -> Range<u32> {
|
||||
let mut stroke_tess = StrokeTessellator::new();
|
||||
|
||||
let initial_indices_count = buffer.indices.len();
|
||||
@ -184,7 +205,11 @@ impl<OutputIndex: std::ops::Add + std::convert::From<lyon::lyon_tessellation::Ve
|
||||
initial_indices_count as u32..buffer.indices.len() as u32
|
||||
}
|
||||
|
||||
fn tesselate_fill(&self, buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>, prim_id: u32) -> Range<u32> {
|
||||
fn tesselate_fill(
|
||||
&self,
|
||||
buffer: &mut VertexBuffers<GpuVertexUniform, OutputIndex>,
|
||||
prim_id: u32,
|
||||
) -> Range<u32> {
|
||||
let mut fill_tess = FillTessellator::new();
|
||||
|
||||
let initial_indices_count = buffer.indices.len();
|
||||
@ -207,17 +232,24 @@ impl<OutputIndex: std::ops::Add + std::convert::From<lyon::lyon_tessellation::Ve
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const EXTENT: f32 = 4096.0;
|
||||
|
||||
pub struct TileMask();
|
||||
|
||||
impl Tesselated<u32> for TileMask {
|
||||
fn tesselate_stroke(&self, _buffer: &mut VertexBuffers<GpuVertexUniform, u32>, _prim_id: u32) -> Range<u32> {
|
||||
fn tesselate_stroke(
|
||||
&self,
|
||||
_buffer: &mut VertexBuffers<GpuVertexUniform, u32>,
|
||||
_prim_id: u32,
|
||||
) -> Range<u32> {
|
||||
0..0
|
||||
}
|
||||
|
||||
fn tesselate_fill(&self, buffer: &mut VertexBuffers<GpuVertexUniform, u32>, prim_id: u32) -> Range<u32> {
|
||||
fn tesselate_fill(
|
||||
&self,
|
||||
buffer: &mut VertexBuffers<GpuVertexUniform, u32>,
|
||||
prim_id: u32,
|
||||
) -> Range<u32> {
|
||||
let initial_indices_count = buffer.indices.len();
|
||||
|
||||
buffer.vertices = vec![
|
||||
@ -231,4 +263,4 @@ impl Tesselated<u32> for TileMask {
|
||||
|
||||
initial_indices_count as u32..buffer.indices.len() as u32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user