Skip to content

Commit

Permalink
Fix wasm build
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximkaaa committed Jan 29, 2024
1 parent 4e50e3c commit 7ff4173
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 130 deletions.
3 changes: 3 additions & 0 deletions galileo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ exclude = [
"examples",
]

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["wgpu", "tokio", "image", "serde"]
web = ["wasm-bindgen-futures", "serde", "byte-conversion", "js-sys"]
Expand Down
110 changes: 0 additions & 110 deletions galileo/examples/data/points.rs

This file was deleted.

2 changes: 1 addition & 1 deletion galileo/examples/georust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn load_points() -> Vec<Disambig<geo_types::Point, GeoSpace2d>> {
pub async fn run(builder: MapBuilder) {
let point_layer = FeatureLayer::new(
load_points(),
ImagePointSymbol::from_file(
ImagePointSymbol::from_path(
"galileo/examples/data/pin-yellow.png",
Vector2::new(0.5, 1.0),
0.5,
Expand Down
4 changes: 2 additions & 2 deletions galileo/src/layer/feature_layer/symbol/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct ImagePointSymbol {
}

impl ImagePointSymbol {
pub fn from_file(path: &str, offset: Vector2<f32>, scale: f32) -> Result<Self, GalileoError> {
pub fn from_path(path: &str, offset: Vector2<f32>, scale: f32) -> Result<Self, GalileoError> {
let image = image::io::Reader::open(path)?.decode()?;
let dimensions = image.dimensions();

Expand Down Expand Up @@ -95,7 +95,7 @@ mod tests {

#[test]
fn image_symbol_from_file() {
let symbol = ImagePointSymbol::from_file(
let symbol = ImagePointSymbol::from_path(
"examples/data/pin-yellow.png",
Vector2::new(0.5, 1.0),
1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn store_vector_tile(
let packed = renderer
.read()
.unwrap()
.pack_bundle(RenderBundle::Tessellating(bundle));
.pack_bundle(&RenderBundle::Tessellating(bundle));
store.insert(
index,
TileState::Loaded(VectorTile {
Expand Down
51 changes: 35 additions & 16 deletions galileo/src/render/render_bundle/tessellating/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::render::render_bundle::tessellating::{
use lyon::lyon_tessellation::VertexBuffers;
use serde::{Deserialize, Serialize};
use std::mem::size_of;
use std::sync::Arc;

#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct TessellatingRenderBundleBytes {
Expand All @@ -13,13 +14,14 @@ pub(crate) struct TessellatingRenderBundleBytes {
pub screen_ref: ScreenRefVertexBuffersBytes,
pub images: Vec<ImageBytes>,
pub primitives: Vec<PrimitiveInfo>,
pub image_store: Vec<(u32, u32, Vec<u8>)>,
pub clip_area: Option<PolyVertexBuffersBytes>,
pub bundle_size: usize,
}

#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct ImageBytes {
image_bytes: Vec<u8>,
dimensions: (u32, u32),
image_index: usize,
vertices: Vec<u32>,
}

Expand Down Expand Up @@ -87,14 +89,19 @@ impl TessellatingRenderBundle {
images: self
.images
.into_iter()
.map(|(image, vertices)| ImageBytes {
image_bytes: bytemuck::cast_vec(image.bytes),
dimensions: image.dimensions,
.map(|(image_index, vertices)| ImageBytes {
image_index,
vertices: bytemuck::cast_vec(vertices.to_vec()),
})
.collect(),
primitives: self.primitives,
image_store: self
.image_store
.into_iter()
.map(|image| (image.dimensions.0, image.dimensions.1, image.bytes.clone()))
.collect(),
clip_area: self.clip_area.map(|v| v.into()),
bundle_size: self.buffer_size,
};

converted
Expand All @@ -108,20 +115,32 @@ impl TessellatingRenderBundle {
images: bundle
.images
.into_iter()
.map(|v| {
let decoded_image = DecodedImage {
bytes: v.image_bytes,
dimensions: v.dimensions,
};
let vertices = bytemuck::cast_vec(v.vertices)
.try_into()
.expect("invalid vector length");

(decoded_image, vertices)
})
.map(
|ImageBytes {
image_index,
vertices,
}| {
let vertices = bytemuck::cast_vec(vertices)
.try_into()
.expect("invalid vector length");

(image_index, vertices)
},
)
.collect(),
primitives: bundle.primitives,
image_store: bundle
.image_store
.into_iter()
.map(|(width, height, bytes)| {
Arc::new(DecodedImage {
bytes,
dimensions: (width, height),
})
})
.collect(),
clip_area: bundle.clip_area.map(|v| v.into_typed_unchecked()),
buffer_size: bundle.bundle_size,
}
}
}

0 comments on commit 7ff4173

Please sign in to comment.