Skip to content

Add WebGL support to web builds#52

Merged
melody-rs merged 9 commits intoAstrabit-ST:devfrom
white-axe:webgl
Nov 23, 2023
Merged

Add WebGL support to web builds#52
melody-rs merged 9 commits intoAstrabit-ST:devfrom
white-axe:webgl

Conversation

@white-axe
Copy link
Copy Markdown
Collaborator

wgpu doesn't have support yet for having both WebGPU and WebGL support in the same binary (see gfx-rs/wgpu#2804) so I added the WebGL support behind a webgl Cargo feature. To build with WebGL support using Trunk, add --features webgl to the Trunk command.

I also added a feature detection for WebGPU support in assets/main.js, which will always load from luminol.js and luminol_bg.wasm if WebGPU is available, and will load from luminol_webgl.js and luminol_webgl_bg.wasm if WebGPU is not supported. If luminol_webgl.js is not detected on the server, it will use luminol.js and luminol_bg.wasm even if WebGPU is not supported so that you can test with trunk serve --features webgl without having to rename the output files.

If the web autobuild (once we have one) needs to build with both WebGPU and WebGL support, it can first build for WebGL, then move luminol.js and luminol_bg.wasm to a temporary location, then build for WebGPU and finally move those files back after renaming them to luminol_webgl.js and luminol_webgl_bg.wasm.

@melody-rs melody-rs added this to the v1.0 milestone Oct 16, 2023
@melody-rs
Copy link
Copy Markdown
Member

@somedevfox do you think you could add an autobuild action to luminol-website?

wgpu doesn't allow supporting both WebGL and WebGPU in the same binary
yet so we have to decide at compile time which one to use.

(cherry picked from commit ac4d0d9)
This is to avoid clogging the console with useless messages.

(cherry picked from commit cc857b2)
It's not supported in WebGL and probably also not supported in OpenGL.

(cherry picked from commit f951d14)
(cherry picked from commit 858fcb0)
Firefox Nightly apparently only supports WebGPU on the main thread and
not in a web worker where we need it, so the test for WebGPU support now
runs in a worker thread.

(cherry picked from commit 5d6bbb2)
@melody-rs melody-rs merged commit 41a7125 into Astrabit-ST:dev Nov 23, 2023
@white-axe white-axe deleted the webgl branch November 23, 2023 16:28
@white-axe white-axe added enhancement New feature or request webassembly and removed enhancement New feature or request labels Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants