Skip to content

Commit e4ef29e

Browse files
authored
Merge pull request #1096 from pacmancoder/feat/wgpu-webgl
Experimental WebGL wgpu backend support
2 parents c75ed37 + 6f604ab commit e4ef29e

90 files changed

Lines changed: 768 additions & 3901 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ jobs:
3737
run: cargo build --package tour --target wasm32-unknown-unknown
3838
- name: Check compilation of `todos` example
3939
run: cargo build --package todos --target wasm32-unknown-unknown
40+
- name: Check compilation of `integration_wgpu` example
41+
run: cargo build --package integration_wgpu --target wasm32-unknown-unknown

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pkg/
33
**/*.rs.bk
44
Cargo.lock
55
.cargo/
6+
dist/

Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ categories = ["gui"]
1313
resolver = "2"
1414

1515
[features]
16-
default = ["wgpu", "default_system_font"]
16+
default = ["wgpu"]
1717
# Enables the `iced_wgpu` renderer
1818
wgpu = ["iced_wgpu"]
1919
# Enables the `Image` widget
@@ -58,7 +58,6 @@ members = [
5858
"lazy",
5959
"native",
6060
"style",
61-
"web",
6261
"wgpu",
6362
"winit",
6463
"examples/bezier_tool",
@@ -94,16 +93,16 @@ members = [
9493
[dependencies]
9594
iced_core = { version = "0.4", path = "core" }
9695
iced_futures = { version = "0.3", path = "futures" }
96+
iced_winit = { version = "0.3", path = "winit" }
97+
iced_glutin = { version = "0.2", path = "glutin", optional = true }
98+
iced_glow = { version = "0.2", path = "glow", optional = true }
9799
thiserror = "1.0"
98100

99101
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
100-
iced_winit = { version = "0.3", path = "winit" }
101-
iced_glutin = { version = "0.2", path = "glutin", optional = true }
102102
iced_wgpu = { version = "0.4", path = "wgpu", optional = true }
103-
iced_glow = { version = "0.2", path = "glow", optional = true}
104103

105104
[target.'cfg(target_arch = "wasm32")'.dependencies]
106-
iced_web = { version = "0.4", path = "web" }
105+
iced_wgpu = { version = "0.4", path = "wgpu", features = ["webgl"], optional = true }
107106

108107
[package.metadata.docs.rs]
109108
rustdoc-args = ["--cfg", "docsrs"]

core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ bitflags = "1.2"
1313
[dependencies.palette]
1414
version = "0.5"
1515
optional = true
16+
17+
[target.'cfg(target_arch = "wasm32")'.dependencies]
18+
wasm-timer = { version = "0.2" }

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
pub mod alignment;
1818
pub mod keyboard;
1919
pub mod mouse;
20+
pub mod time;
2021

2122
mod background;
2223
mod color;

core/src/time.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Keep track of time, both in native and web platforms!
2+
3+
#[cfg(target_arch = "wasm32")]
4+
pub use wasm_timer::Instant;
5+
6+
#[cfg(not(target_arch = "wasm32"))]
7+
pub use std::time::Instant;
8+
9+
pub use std::time::Duration;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.wasm
2+
*.js

examples/integration_wgpu/Cargo.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,16 @@ publish = false
77

88
[dependencies]
99
iced_winit = { path = "../../winit" }
10-
iced_wgpu = { path = "../../wgpu", features = ["spirv"] }
10+
iced_wgpu = { path = "../../wgpu", features = ["webgl"] }
1111
env_logger = "0.8"
12+
13+
[target.'cfg(target_arch = "wasm32")'.dependencies]
14+
console_error_panic_hook = "0.1.7"
15+
console_log = "0.2.0"
16+
log = "0.4"
17+
wasm-bindgen = "0.2"
18+
web-sys = { version = "0.3", features = ["Element", "HtmlCanvasElement", "Window", "Document"] }
19+
# This dependency a little bit quirky, it is deep in the tree and without `js` feature it
20+
# refuses to work with `wasm32-unknown-unknown target`. Unfortunately, we need this patch
21+
# to make it work
22+
getrandom = { version = "0.2", features = ["js"] }

examples/integration_wgpu/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,22 @@ You can run it with `cargo run`:
1515
cargo run --package integration
1616
```
1717

18+
### How to run this example with WebGL backend
19+
NOTE: Currently, WebGL backend is is still experimental, so expect bugs.
20+
21+
```sh
22+
# 0. Install prerequisites
23+
cargo install wasm-bindgen-cli https
24+
# 1. cd to the current folder
25+
# 2. Compile wasm module
26+
cargo build -p integration_wgpu --target wasm32-unknown-unknown
27+
# 3. Invoke wasm-bindgen
28+
wasm-bindgen ../../target/wasm32-unknown-unknown/debug/integration_wgpu.wasm --out-dir . --target web --no-typescript
29+
# 4. run http server
30+
http
31+
# 5. Open 127.0.0.1:8000 in browser
32+
```
33+
34+
1835
[`main`]: src/main.rs
1936
[`wgpu`]: https://github.com/gfx-rs/wgpu
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5+
<title>Iced - wgpu + WebGL integration</title>
6+
</head>
7+
<body>
8+
<h1>integration_wgpu</h1>
9+
<canvas id="iced_canvas"></canvas>
10+
<script type="module">
11+
import init from "./integration_wgpu.js";
12+
init('./integration_wgpu_bg.wasm');
13+
</script>
14+
<style>
15+
body {
16+
width: 100%;
17+
text-align: center;
18+
}
19+
</style>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)