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

Draft
wants to merge 78 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
a3894e3
Update idea file
maxammann Jul 27, 2024
30aa187
Add some expect calls
maxammann Jul 27, 2024
4edde09
Correct comment in shell.nix
maxammann Jul 27, 2024
e74125b
Move tesselation code to vector module
maxammann Jul 27, 2024
3f6ad5b
Add basic SDF rendering
maxammann Jul 29, 2024
7c72070
Extract SDF rendering into a plugin
maxammann Aug 5, 2024
48dfc87
Add a translucent pass
maxammann Aug 5, 2024
de13788
Format
maxammann Aug 5, 2024
b213f6d
Disable fragment discarding
maxammann Aug 5, 2024
b8458e8
Fix rendering of labels and also handle eg spaces
maxammann Aug 5, 2024
078cad9
Fix rendering on web
maxammann Aug 5, 2024
157e88f
Add log env vars
maxammann Aug 6, 2024
2f7318d
Update nix channel for unstable
maxammann Aug 6, 2024
9ac7393
Fix duplicate condition
maxammann Aug 6, 2024
689298b
Fix compilation for headless
maxammann Aug 6, 2024
297a49d
Add criterion for benchmark to nix
maxammann Aug 6, 2024
8c7d706
Use places as test layer
maxammann Aug 8, 2024
c7eeb9c
Resolve unwrap with a trace message
maxammann Aug 8, 2024
3ae1538
Add FPS meter to debug plugin
maxammann Aug 8, 2024
fdbe884
Add render doc
maxammann Aug 8, 2024
acdafc4
Optimize which tiles are rendered by adding ViewStatePadding
maxammann Aug 8, 2024
12c5b26
Rename shader files
maxammann Aug 8, 2024
a732006
Add opacity shader property and transfer bbox to render thread
maxammann Aug 8, 2024
cd0e930
Set window size
maxammann Aug 8, 2024
b2823e2
reformat and add collision system
maxammann Aug 8, 2024
2d3a1ec
Add stage and system errors
maxammann Aug 8, 2024
68ae915
Add grid index from maplibre
maxammann Aug 9, 2024
ef5c247
Add comment to default style
maxammann Aug 15, 2024
776d89e
Use the term bucket
maxammann Aug 15, 2024
2dfc990
Add empty collision index
maxammann Aug 16, 2024
6312e56
Fill collision index
maxammann Aug 16, 2024
60b0978
First working version
maxammann Aug 19, 2024
9a15dc7
Remove comment
maxammann Aug 19, 2024
da49d44
translate more code
maxammann Aug 19, 2024
f1c2406
start translating shaping
maxammann Aug 19, 2024
d9c811f
fix sdf upload
maxammann Aug 20, 2024
5a76566
translate next batch
maxammann Aug 20, 2024
58d1ebd
fixup todo comments
maxammann Aug 20, 2024
84f31e8
Add shaping test
maxammann Aug 20, 2024
27644e7
Add tagged string test
maxammann Aug 20, 2024
ecd23aa
Move files around and fix coordinate units
maxammann Aug 21, 2024
722b4a0
moev file
maxammann Aug 21, 2024
b317e74
Add quads
maxammann Aug 21, 2024
8f3f34e
add next batch
maxammann Aug 21, 2024
89713a1
add next batch
maxammann Aug 22, 2024
cc55d6e
add next batch
maxammann Aug 22, 2024
daaaa76
add next batch
maxammann Aug 22, 2024
41ac369
add next batch
maxammann Aug 22, 2024
de45903
fix errors
maxammann Aug 23, 2024
4f09105
fix errors
maxammann Aug 23, 2024
111730c
fix errors
maxammann Aug 23, 2024
6bedd50
replace todo!() with dummy implementations. We will want to rollback …
maxammann Aug 25, 2024
70a5c3d
fix mutability issues (TODO verify these again)
maxammann Aug 25, 2024
6786186
format
maxammann Aug 25, 2024
eb83dae
fix
maxammann Aug 25, 2024
4328389
Remove allowsVerticalWritingMode from feature (unused)
maxammann Aug 29, 2024
4a8b820
fmt and fix tests
maxammann Aug 29, 2024
6212101
Fix benchmark
maxammann Sep 1, 2024
129ec48
Minor
maxammann Sep 24, 2024
99bd57b
start using new code
maxammann Oct 21, 2024
48bad01
Some updates
maxammann Oct 21, 2024
dddaa35
Rename GlyphAtlas
maxammann Nov 5, 2024
3f66796
First working POC for maplibre SDF rendering
maxammann Nov 8, 2024
f9d8f50
Format code
maxammann Nov 8, 2024
97f6824
Add origin comments
maxammann Nov 10, 2024
fa1dd8a
Move translated files to legacy
maxammann Nov 10, 2024
546970e
Fix imports after move to legacy dir
maxammann Nov 10, 2024
a1af58d
Format
maxammann Nov 10, 2024
3a4dfe4
Add ref comments to fns, structs, enums and types
maxammann Nov 10, 2024
f9281ac
Format
maxammann Nov 10, 2024
b1006ab
Run cargo fix
maxammann Nov 10, 2024
d96ba5f
Fix camelCase to camel_case using IDE
maxammann Nov 10, 2024
8c97683
Fix some more clippy warnings
maxammann Nov 10, 2024
b911b05
Update idea file
maxammann Nov 10, 2024
160994d
Fix web compilation temporary
maxammann Nov 10, 2024
24a33bf
Format
maxammann Nov 10, 2024
3fbe3c1
Move code to tessellation_new.rs
maxammann Nov 11, 2024
e684984
Fix compilation
maxammann Nov 11, 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.

5 changes: 3 additions & 2 deletions .idea/runConfigurations/Run_Tests.xml

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

2 changes: 2 additions & 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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Mars, no water exists!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True! We must create water on mars first

let tile = map.process_tile(tile, water_layer).await;

(map, tile)
});
Expand Down
Binary file added data/0-255.pbf
Binary file not shown.
10 changes: 5 additions & 5 deletions maplibre-build-tools/src/wgsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ pub fn validate_project_wgsl() {
Ok(entry) => {
let path = entry.path();
if !path.is_dir() {
println!("cargo:rerun-if-changed={}", path.display().to_string());
match validate_wgsl(&mut validator, path) {
Ok(_) => {}
Err(err) => {
let path = path.strip_prefix(&root_dir).unwrap_or(path);
println!(
"cargo:warning={}{}",
panic!(
"{}{}",
path.to_str().unwrap(),
match err {
WgslError::ValidationErr(error) => format!(": {error:?}"),
WgslError::ValidationErr(error) => format!(": {error}"),
WgslError::ParserErr { error, location } =>
if let Some(SourceLocation {
line_number,
Expand All @@ -82,10 +83,9 @@ pub fn validate_project_wgsl() {
} else {
error
},
WgslError::IoErr(error) => format!(": {error:?}"),
WgslError::IoErr(error) => format!(": {error}"),
}
);
exit(1);
}
};
}
Expand Down
1 change: 1 addition & 0 deletions maplibre-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct Cli {
command: Commands,
}

#[allow(dead_code)]
fn parse_lat_long(env: &str) -> Result<LatLon, std::io::Error> {
let split = env.split(',').collect::<Vec<_>>();
if let (Some(latitude), Some(longitude)) = (split.first(), split.get(1)) {
Expand Down
2 changes: 1 addition & 1 deletion maplibre-winit/src/input/camera_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct CameraHandler {
}

impl UpdateState for CameraHandler {
fn update_state(&mut self, MapContext { view_state, .. }: &mut MapContext, dt: Duration) {
fn update_state(&mut self, MapContext { view_state, .. }: &mut MapContext, _dt: Duration) {
if !self.is_active {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion maplibre-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl<ET: 'static + PartialEq + Debug> EventLoop<ET> for WinitEventLoop<ET> {
}
}
}
WindowEvent::ScaleFactorChanged { inner_size_writer, scale_factor: new_scale_factor } => {
WindowEvent::ScaleFactorChanged { inner_size_writer: _, scale_factor: new_scale_factor } => {
if let Ok(map_context) = map.context_mut() {
log::info!("New scaling factor: {}", new_scale_factor);
scale_factor = *new_scale_factor;
Expand Down
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::*;
}
Loading
Loading