Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDF text rendering plugin #314

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4798030
Update idea file
maxammann Jul 27, 2024
dca77c3
Add some expect calls
maxammann Jul 27, 2024
484dbdf
Correct comment in shell.nix
maxammann Jul 27, 2024
621371a
Move tesselation code to vector module
maxammann Jul 27, 2024
14213be
Add basic SDF rendering
maxammann Jul 29, 2024
cd218c3
Extract SDF rendering into a plugin
maxammann Aug 5, 2024
fdacced
Add a translucent pass
maxammann Aug 5, 2024
927c6a1
Format
maxammann Aug 5, 2024
2ef573d
Disable fragment discarding
maxammann Aug 5, 2024
a0acb93
Fix rendering of labels and also handle eg spaces
maxammann Aug 5, 2024
b5cd9d1
Fix rendering on web
maxammann Aug 5, 2024
a0153e8
Add log env vars
maxammann Aug 6, 2024
c4488c7
Update nix channel for unstable
maxammann Aug 6, 2024
b727611
Fix duplicate condition
maxammann Aug 6, 2024
bc03b83
Fix compilation for headless
maxammann Aug 6, 2024
946135f
Add criterion for benchmark to nix
maxammann Aug 6, 2024
1389f90
Use places as test layer
maxammann Aug 8, 2024
ab3793d
Resolve unwrap with a trace message
maxammann Aug 8, 2024
78ba91e
Add FPS meter to debug plugin
maxammann Aug 8, 2024
0af7a6c
Add render doc
maxammann Aug 8, 2024
c40bb43
Optimize which tiles are rendered by adding ViewStatePadding
maxammann Aug 8, 2024
bba27ae
Rename shader files
maxammann Aug 8, 2024
636ef34
Add opacity shader property and transfer bbox to render thread
maxammann Aug 8, 2024
b328f0e
Set window size
maxammann Aug 8, 2024
8d6456f
reformat and add collision system
maxammann Aug 8, 2024
5c0d023
Add stage and system errors
maxammann Aug 8, 2024
469a5e3
Add grid index from maplibre
maxammann Aug 9, 2024
a8d1535
Add comment to default style
maxammann Aug 15, 2024
4eadf6a
Use the term bucket
maxammann Aug 15, 2024
a885cdf
Add empty collision index
maxammann Aug 16, 2024
d5dd17a
Fill collision index
maxammann Aug 16, 2024
3fd232d
First working version
maxammann Aug 19, 2024
e17347b
Remove comment
maxammann Aug 19, 2024
f0c808d
translate more code
maxammann Aug 19, 2024
42f87b9
start translating shaping
maxammann Aug 19, 2024
6b79b03
fix sdf upload
maxammann Aug 20, 2024
3ef061b
translate next batch
maxammann Aug 20, 2024
8471271
fixup todo comments
maxammann Aug 20, 2024
0a416ce
Add shaping test
maxammann Aug 20, 2024
449770b
Add tagged string test
maxammann Aug 20, 2024
4b60445
Move files around and fix coordinate units
maxammann Aug 21, 2024
ac9081f
moev file
maxammann Aug 21, 2024
05f78db
Add quads
maxammann Aug 21, 2024
e284d65
add next batch
maxammann Aug 21, 2024
876dd29
add next batch
maxammann Aug 22, 2024
9bb487d
add next batch
maxammann Aug 22, 2024
e043d89
add next batch
maxammann Aug 22, 2024
d265afd
add next batch
maxammann Aug 22, 2024
0a24a3a
fix errors
maxammann Aug 23, 2024
4f1d54b
fix errors
maxammann Aug 23, 2024
53182a7
fix errors
maxammann Aug 23, 2024
2e2de4a
replace todo!() with dummy implementations. We will want to rollback …
maxammann Aug 25, 2024
ee58110
fix mutability issues (TODO verify these again)
maxammann Aug 25, 2024
89e5120
format
maxammann Aug 25, 2024
43abfd7
fix
maxammann Aug 25, 2024
6950d07
Remove allowsVerticalWritingMode from feature (unused)
maxammann Aug 29, 2024
5085420
fmt and fix tests
maxammann Aug 29, 2024
5f92e6a
Fix benchmark
maxammann Sep 1, 2024
ad77881
Minor
maxammann Sep 24, 2024
bec5a1f
start using new code
maxammann Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .idea/maplibre-rs.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/runConfigurations/Run_demo__debug_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/runConfigurations/Run_demo__debug_enable_tracing_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions .idea/runConfigurations/Run_demo__release_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/runConfigurations/Run_demo__release_enable_tracing_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ tokio = "1.32.0" # Individual features are customized in each crate
tokio-util = { version = "0.7.9", features = ["rt"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
tracing-tracy = "0.11.1"
tracing-tracy = "=0.10.5"
tracing-wasm = "0.2.1" # TODO: Low quality dependency (remove in a separate PR!)
walkdir = "2.4.0"
wasm-bindgen = "=0.2.92"
wasm-bindgen-futures = "0.4"
wasm-bindgen-test = "0.3"
web-sys = "0.3" # Individual features are customized in each crate
wgpu = "22.0.0"
wgpu = "22.1.0"
http-cache-reqwest = "0.14.0"
bitflags = "2.6.0"

[profile.release]
lto = true
Expand Down
8 changes: 2 additions & 6 deletions benchmarks/benches/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use maplibre::{
benchmarking::io::static_tile_fetcher::StaticTileFetcher,
coords::{TileCoords, ZoomLevel},
io::apc::{Context, IntoMessage, SendError},
style::source::TileAddressingScheme,
style::{source::TileAddressingScheme, Style},
vector::{
process_vector_tile, DefaultVectorTransferables, ProcessVectorContext, VectorTileRequest,
},
Expand Down Expand Up @@ -42,11 +42,7 @@ fn bench_process_vector_tile(c: &mut Criterion) {
coords: MUNICH_COORDS
.into_world_tile(TileAddressingScheme::XYZ)
.unwrap(),
layers: HashSet::from([
"transportation".to_owned(),
"water".to_owned(),
"building".to_owned(),
]),
layers: Style::default().layers.iter().cloned().collect(),
},
&mut ProcessVectorContext::<DefaultVectorTransferables, _>::new(DummyContext),
);
Expand Down
9 changes: 7 additions & 2 deletions benchmarks/benches/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ fn headless_render(c: &mut Criterion) {
Box::new(HeadlessPlugin::new(false)),
];

let map = HeadlessMap::new(style, renderer, kernel, plugins).unwrap();
let map = HeadlessMap::new(style.clone(), renderer, kernel, plugins).unwrap();

let tile = map
.fetch_tile(WorldTileCoords::from((0, 0, ZoomLevel::default())))
.await
.expect("Failed to fetch!");

let tile = map.process_tile(tile, &["water"]).await;
let water_layer = style
.layers
.iter()
.find(|layer| layer.source_layer == Some("water".to_string()))
.expect("water layer must exist");
let tile = map.process_tile(tile, water_layer).await;

(map, tile)
});
Expand Down
Binary file added data/0-255.pbf
Binary file not shown.
12 changes: 10 additions & 2 deletions maplibre-winit/src/noweb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use maplibre::{
style::Style,
window::{MapWindow, MapWindowConfig, PhysicalSize, WindowCreateError},
};
use winit::window::WindowAttributes;
use winit::{dpi::Size, window::WindowAttributes};

use super::WinitMapWindow;
use crate::{WinitEnvironment, WinitEventLoop};
Expand Down Expand Up @@ -87,7 +87,12 @@ impl<ET: 'static + Clone> MapWindowConfig for WinitMapWindowConfig<ET> {
.map_err(|_| WindowCreateError::EventLoop)?;

let window = raw_event_loop
.create_window(WindowAttributes::new().with_title(&self.title))
.create_window(
WindowAttributes::new()
.with_title(&self.title)
// TODO make window size configurable
.with_inner_size(Size::Logical(winit::dpi::LogicalSize::new(800.0, 800.0))),
)
.map_err(|_| WindowCreateError::Window)?;

Ok(Self::MapWindow {
Expand Down Expand Up @@ -136,6 +141,9 @@ pub fn run_headed_map<P>(
Box::new(maplibre::vector::VectorPlugin::<
maplibre::vector::DefaultVectorTransferables,
>::default()),
Box::new(maplibre::sdf::SdfPlugin::<
maplibre::vector::DefaultVectorTransferables,
>::default()),
// Box::new(maplibre::raster::RasterPlugin::<
// maplibre::raster::DefaultRasterTransferables,
// >::default()),
Expand Down
9 changes: 9 additions & 0 deletions maplibre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,14 @@ smallvec.workspace = true
png = { workspace = true, optional = true }
image = { workspace = true, optional = true }

# Text/glyphs
prost = "0.13.1"

# Symbols
bitflags = { workspace = true }
widestring = "1.1.0"
guillotiere = "0.6.2"

[build-dependencies]
maplibre-build-tools = { path = "../maplibre-build-tools", version = "0.1.0" }
prost-build = "0.13.1"
20 changes: 20 additions & 0 deletions maplibre/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! This script is built and executed just before building the package.
//! It will validate the WGSL (WebGPU Shading Language) shaders and embed static files.

use std::{fs, path::PathBuf};

use maplibre_build_tools::wgsl::validate_project_wgsl;

#[cfg(feature = "embed-static-tiles")]
Expand Down Expand Up @@ -50,9 +52,27 @@ fn embed_tiles_statically() {
}
}

fn generate_protobuf() {
let proto_paths = fs::read_dir("./proto")
.unwrap()
.filter_map(|entry| {
let entry = entry.ok()?;
println!(
"cargo:rerun-if-changed={}",
entry.path().display().to_string()
);
Some(entry.path())
})
.collect::<Vec<_>>();

prost_build::compile_protos(&proto_paths, &[PathBuf::from("./proto/")]).unwrap();
}

fn main() {
validate_project_wgsl();

#[cfg(feature = "embed-static-tiles")]
embed_tiles_statically();

generate_protobuf();
}
34 changes: 34 additions & 0 deletions maplibre/proto/glyphs.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Protocol Version 1
// Adapted from https://github.com/maplibre/maplibre-native/blob/2e3538c2fe9bcf2e3961971a0807c2d2c17a3f06/misc/proto/glyphs.proto#L4

package glyphs;

option optimize_for = LITE_RUNTIME;

// Stores a glyph with metrics and optional SDF bitmap information.
message glyph {
required uint32 id = 1;

// A signed distance field of the glyph with a border of 3 pixels.
optional bytes bitmap = 2;

// Glyph metrics.
required uint32 width = 3;
required uint32 height = 4;
required sint32 left = 5;
required sint32 top = 6;
required uint32 advance = 7;
}

// Stores fontstack information and a list of faces.
message fontstack {
required string name = 1;
required string range = 2;
repeated glyph glyphs = 3;
}

message glyphs {
repeated fontstack stacks = 1;

extensions 16 to 8191;
}
2 changes: 1 addition & 1 deletion maplibre/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub mod io {

/// Re-export of the tessellation module.
pub mod tessellation {
pub use crate::tessellation::*;
pub use crate::vector::tessellation::*;
}
17 changes: 9 additions & 8 deletions maplibre/src/coords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use bytemuck_derive::{Pod, Zeroable};
use cgmath::{AbsDiffEq, Matrix4, Point3, Vector3};
use cgmath::{AbsDiffEq, Matrix4, Point3, Vector3, Vector4};
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -21,6 +21,9 @@ use crate::{
pub const EXTENT_UINT: u32 = 4096;
pub const EXTENT_SINT: i32 = EXTENT_UINT as i32;
pub const EXTENT: f64 = EXTENT_UINT as f64;
const TOP_LEFT_EXTENT: Vector4<f64> = Vector4::new(0.0, 0.0, 0.0, 1.0);
const BOTTOM_RIGHT_EXTENT: Vector4<f64> = Vector4::new(EXTENT, EXTENT, 0.0, 1.0);

pub const TILE_SIZE: f64 = 512.0;
pub const MAX_ZOOM: usize = 32;

Expand Down Expand Up @@ -723,24 +726,22 @@ impl Display for WorldCoords {

#[cfg(test)]
mod tests {
use cgmath::{Point2, Vector4};
use cgmath::Point2;

use crate::{
coords::{
Quadkey, TileCoords, ViewRegion, WorldCoords, WorldTileCoords, Zoom, ZoomLevel, EXTENT,
Quadkey, TileCoords, ViewRegion, WorldCoords, WorldTileCoords, Zoom, ZoomLevel,
BOTTOM_RIGHT_EXTENT, TOP_LEFT_EXTENT,
},
render::tile_view_pattern::DEFAULT_TILE_SIZE,
style::source::TileAddressingScheme,
util::math::Aabb2,
};

const TOP_LEFT: Vector4<f64> = Vector4::new(0.0, 0.0, 0.0, 1.0);
const BOTTOM_RIGHT: Vector4<f64> = Vector4::new(EXTENT, EXTENT, 0.0, 1.0);

fn to_from_world(tile: (i32, i32, ZoomLevel), zoom: Zoom) {
let tile = WorldTileCoords::from(tile);
let p1 = tile.transform_for_zoom(zoom) * TOP_LEFT;
let p2 = tile.transform_for_zoom(zoom) * BOTTOM_RIGHT;
let p1 = tile.transform_for_zoom(zoom) * TOP_LEFT_EXTENT;
let p2 = tile.transform_for_zoom(zoom) * BOTTOM_RIGHT_EXTENT;
println!("{p1:?}\n{p2:?}");

assert_eq!(
Expand Down
13 changes: 10 additions & 3 deletions maplibre/src/debug/cleanup_system.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use crate::{context::MapContext, debug::TileDebugItem, render::render_phase::RenderPhase};
use crate::{
context::MapContext,
debug::TileDebugItem,
render::render_phase::RenderPhase,
tcs::system::{SystemError, SystemResult},
};

pub fn cleanup_system(MapContext { world, .. }: &mut MapContext) {
pub fn cleanup_system(MapContext { world, .. }: &mut MapContext) -> SystemResult {
let Some(debug_tile_phase) = world
.resources
.query_mut::<&mut RenderPhase<TileDebugItem>>()
else {
return;
return Err(SystemError::Dependencies);
};

debug_tile_phase.clear();

Ok(())
}
15 changes: 15 additions & 0 deletions maplibre/src/debug/fps_system.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::{
context::MapContext,
tcs::system::{SystemError, SystemResult},
util::FPSMeter,
};

pub fn fps_system(MapContext { world, .. }: &mut MapContext) -> SystemResult {
let Some(fps_meter) = world.resources.get_mut::<FPSMeter>() else {
return Err(SystemError::Dependencies);
};

fps_meter.update_and_print();

Ok(())
}
Loading
Loading