mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[rs] Update README.md for running examples on the web (#275)
* [readme] add details for running on wasm32 target * [readme] update * [readme] [web] Running instruction on webgpu.io
This commit is contained in:
parent
e0ec201ee5
commit
e8244ae5e3
@ -35,6 +35,8 @@ cargo run --example hello-compute 1 2 3 4
|
||||
|
||||
#### Run Examples on the Web (`wasm32-unknown-unknown`)
|
||||
|
||||
Running on the web is still work-in-progress. You may need to enable experimental flags on your browser. Check browser implementation status on [webgpu.io](https://webgpu.io).
|
||||
|
||||
To run examples on the `wasm32-unknown-unknown` target, first build the example as usual, then run `wasm-bindgen`:
|
||||
|
||||
```bash
|
||||
@ -46,6 +48,27 @@ RUSTFLAGS=--cfg=web_sys_unstable_apis cargo build --target wasm32-unknown-unknow
|
||||
wasm-bindgen --out-dir target/generated --web target/wasm32-unknown-unknown/debug/examples/hello-triangle.wasm
|
||||
```
|
||||
|
||||
Create an `index.html` file into `target/generated` directory and add the following code:
|
||||
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="google" content="notranslate">
|
||||
<title>hello-triangle</title>
|
||||
</head>
|
||||
<body>
|
||||
<script type="module">
|
||||
import init from "./hello-triangle.js";
|
||||
init();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
Now run a web server locally inside the `target/generated` directory to see the `hello-triangle` in the browser.
|
||||
|
||||
## Friends
|
||||
|
||||
Shout out to the following projects that work best with wgpu-rs:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user