Skip to content

Platforms: Readd support for WebGL2#26

Open
leomeinel wants to merge 4 commits into
malbernaz:mainfrom
leomeinel:webgl
Open

Platforms: Readd support for WebGL2#26
leomeinel wants to merge 4 commits into
malbernaz:mainfrom
leomeinel:webgl

Conversation

@leomeinel

@leomeinel leomeinel commented Feb 10, 2026

Copy link
Copy Markdown

Purpose

This readds support for WebGL2 that has been removed in 124607d

Tested platforms

All examples have been tested and are working flawlessly on the following targets:

Bevy 0.18

I also have https://github.com/leomeinel/bevy_lit/tree/bevy-0-18-webgl which includes changes from #23 but I wanted this to not depend on it.

IVec2Uniform and UVec2Uniform are a simple wrappers for IVec2/UVec2
that ensure 16-byte alignment for use in uniform buffers.
This is required for WebGL2
@leomeinel

This comment was marked as resolved.

@leomeinel

leomeinel commented Feb 10, 2026

Copy link
Copy Markdown
Author

The stress_test not working as far as I can tell is because of issues in FpsOverlayPlugin. These have been resolved here: bevyengine/bevy#21885

When using https://github.com/leomeinel/bevy_lit/tree/bevy-0-18-webgl which uses Bevy 0.18 it is working on WebGL2:

example

@leomeinel leomeinel marked this pull request as ready for review February 10, 2026 10:30
@malbernaz

Copy link
Copy Markdown
Owner

Hey, thanks for pulling this off. And sorry for not taking a look at it sooner (life 🤷‍♂️). I'll be reviewing this soon.

@leomeinel

Copy link
Copy Markdown
Author

Hey, thanks for pulling this off. And sorry for not taking a look at it sooner (life 🤷‍♂️). I'll be reviewing this soon.

Perfect, I'll be fixing conflicts in a few days. I'm currently busy with something else. If you want to however you can also just do this on your own :)

I'm happy that you found the time to take a look at it. 👍

@leomeinel

leomeinel commented Jul 6, 2026

Copy link
Copy Markdown
Author

I'm currently testing the merge of main, but I'm pretty sure that it should work. I kind of forgot about this PR so I'm sorry that I didn't get to this sooner.

All examples are working and have been tested on

  • x86_64-unknown-linux-gnu
  • webgl2

Update

This is ready to be merged. All examples including stress_test work on webgl2 and x86_64-unknown-linux-gnu.

@malbernaz

Copy link
Copy Markdown
Owner

From a first glance this is looking good. Can you share your setup for testing the webgl2 target?

@leomeinel

leomeinel commented Jul 14, 2026

Copy link
Copy Markdown
Author

From a first glance this is looking good. Can you share your setup for testing the webgl2 target?

Repo changes

ℹ️ This is needed to run the examples because wasm needs a custom runner and because of wasm_js being required on wasm32-unknown-unknown

diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 0000000..bc39f05
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,2 @@
+[target.'cfg(all(target_family = "wasm", any(target_os = "unknown", target_os = "none")))']
+runner = "wasm-server-runner"
diff --git a/Cargo.toml b/Cargo.toml
index a5c09c2..352fc4f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,6 +27,9 @@ indexmap = "2"
 bevy = { version = "0.19.0", features = ["bevy_dev_tools"] }
 rand = { version = "0.10.1" }
 
+[target.'cfg(all(target_family = "wasm", any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
+getrandom =  { version = "0.4", features = ["wasm_js"] }
+
 [profile.dev]
 opt-level = 1

Testing environment

  • Browser: Ungoogled Chromium 150.0.7871.46
  • rustc: rustc 1.96.0 (ac68faa20 2026-05-25)

One also has to install wasm-server-runner on the machine.

Running the example

To run any example one can now just do:

cargo run --target wasm32-unknown-unknown --example texture_light

This should create a local http server listening on http://127.0.0.1:1334/. The ip and port will also be printed after executing cargo run [...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants