Update documentation

This commit is contained in:
Maximilian Ammann 2022-09-24 17:10:15 +02:00
parent a36067d995
commit 1b30e4c8c3
3 changed files with 35 additions and 24 deletions

View File

@ -102,18 +102,35 @@ click on run. This will start the MacOS application.
## Web (WebGL, WebGPU)
If you have a browser which already supports a recent version of the WebGPU specification then you can start a
development server using the following commands.
You need to first build the library for WebGL or WebGPU. Optionally, you can also enabled multi-threading support,
which requires that the library is used in a secure environment:
[isSecureContext](https://developer.mozilla.org/en-US/docs/Web/API/isSecureContext)
and [crossOriginIsolated](https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated).
The demo runs this such an environment.
If you have a browser which already supports a recent version of the WebGPU specification then you can build the library
with WebGPU:
```bash
cd web
npm run start
just web-lib build # WebGPU
```
If you want to run maplibre-rs with WebGL which is supported on every major browser, then you have to use the following
command.
If not, then you must enable WebGL support:
```bash
just web-lib build --webgl # WebGL
just web-lib build --webgl --multithreaded # WebGL + multithreaded
```
Instead of building it is also possible to watch for changes. The same flags like with `web-lib build` are supported:
```bash
just web-lib watch --webgl
```
After building the library you can run the demo server:
```bash
just web-lib build
just web-demo start
```

View File

@ -1,9 +0,0 @@
export type WebWorkerMessageType = {
type: 'init',
memory: WebAssembly.Memory
} | {
type: 'fetch_tile',
threadLocalState: number,
url: string,
request_id: number,
}

View File

@ -63,15 +63,15 @@ impl SerializedMessageTag {
}
trait SerializableMessage {
fn serialize(self) -> &[u8];
fn serialize(&self) -> &[u8];
fn deserialize(tag: SerializedMessageTag, data: &[u8]) -> Message<UsedTransferables>;
fn deserialize(tag: SerializedMessageTag, data: Uint8Array) -> Message<UsedTransferables>;
fn tag(&self) -> u32;
fn tag(&self) -> SerializedMessageTag;
}
impl<T: Transferables> SerializableMessage for Message<T> {
fn serialize(self) -> &[u8] {
impl SerializableMessage for Message<LinearTransferables> {
fn serialize(&self) -> &[u8] {
match self {
Message::TileTessellated(data) => bytemuck::bytes_of(data),
Message::UnavailableLayer(data) => bytemuck::bytes_of(data),
@ -79,7 +79,7 @@ impl<T: Transferables> SerializableMessage for Message<T> {
}
}
fn deserialize(tag: SerializedMessageTag, data: &[u8]) -> Message<UsedTransferables> {
fn deserialize(tag: SerializedMessageTag, data: Uint8Array) -> Message<UsedTransferables> {
match tag {
SerializedMessageTag::TileTessellated => {
Message::<UsedTransferables>::TileTessellated(*bytemuck::from_bytes::<
@ -121,6 +121,9 @@ pub struct PassingContext {
impl Context<UsedTransferables, UsedHttpClient> for PassingContext {
fn send(&self, data: Message<UsedTransferables>) {
let tag = data.tag();
let serialized = data.serialize();
let serialized_array_buffer = js_sys::ArrayBuffer::new(serialized.len() as u32);
let serialized_array = js_sys::Uint8Array::new(&serialized_array_buffer);
unsafe {
@ -129,8 +132,8 @@ impl Context<UsedTransferables, UsedHttpClient> for PassingContext {
let global = js_sys::global().unchecked_into::<DedicatedWorkerGlobalScope>(); // FIXME (wasm-executor): Remove unchecked
let array = js_sys::Array::new();
array.push(&JsValue::from(data.tag() as u32));
array.push(&data.serialize());
array.push(&JsValue::from(tag as u32));
array.push(&serialized_array_buffer);
global.post_message(&array).unwrap(); // FIXME (wasm-executor) Remove unwrap
}