Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-ll] Emscripten support with WebGL 2.0 #1681

Merged
merged 2 commits into from Dec 19, 2017

Conversation

@kvark
Copy link
Member

commented Dec 19, 2017

Fixes #641. It has more things, so we'll create extra issues as we go forward.

The support is limited, but it works. Unexpected limitations:

  • GetActiveUniformsiv is missing, so constant_buffer_supported = false
  • glClearBufferiv is missing, so clear_buffer_supported = false.
  • glutin dependency is switched to GitHub until rust-windowing/glutin#962 is published
  • winit doesn't provide the proper window size, so I have to work around by calling emscripten's C API directly, see rust-windowing/winit#370

For missing GL exports, it appears to have a trivial fix: emscripten-core/emscripten#5951 . Hopefully, we'll run more examples after this is merged ;)

Screenshot

gfx-wasm-triangle

Status of the examples

  • triangle works 🎉
  • flowmap and blend produce ICE in the fastcomp code
  • instancing fails because it wants to map a buffer
  • mipmap, gamma, and performance I haven't tried
  • others use constant buffers, which are not yet supported (see above)

How to run and test yourself

You'll need Rust-1.22 or newer as well as Emscripten SDK installed. In Emscripten configuration, set USE_WEBGL2=1. I did it by just modifying "emscripten/src/settings.js" directly (from where it's installed). Hopefully, we'll be able to pass the linker parameters to emcc via cargo one day.

rustup target add wasm32-unknown-emscripten
cargo build --example triangle --feature wasm32-unknown-emscripten
ls target/wasm32-unknown-emscripten/debug/examples # find the "example-XXX" name
edit emscripten.html # put the example name in
firefox emscripten.html # open in the browser
@msiglreith
Copy link
Member

left a comment

Great work! 👏
bors r+

bors bot added a commit that referenced this pull request Dec 19, 2017

Merge #1681
1681: [pre-ll] Emscripten support with WebGL 2.0 r=msiglreith a=kvark

Fixes #641. It has more things, so we'll create extra issues as we go forward.

The support is limited, but it works. Unexpected limitations: `constant_buffer_supported` and `clear_buffer_supported` have to be OFF. Emscripten doesn't hook those GL functions, even though they are technically a part of GLES 3.0 standard. Also, the `glutin` dependency is switched to GitHub until the next version is published.

![gfx-wasm-triangle](https://user-images.githubusercontent.com/107301/34141203-af58b9a0-e44d-11e7-926c-933662420689.png)

## Status of the examples
  - `triangle` works 🎉 
  - `flowmap` and `blend` produce ICE in the [fastcomp](https://github.com/kripken/emscripten-fastcomp) code
  - `instancing` fails because it wants to map a buffer
  - `mipmap`, `gamma`, and `performance` I haven't tried
  - others use constant buffers, which are not yet supported (see above)

## How to run and test yourself

You'll need Rust-1.22 or newer as well as Emscripten SDK installed. In Emscripten configuration, set `USE_WEBGL2=1`. I did it by just modifying "emscripten/src/settings.js" directly (from where it's installed). Hopefully, we'll be able to pass the linker parameters to `emcc` via `cargo` one day.

```bash
rustup target add wasm32-unknown-emscripten
cargo build --example triangle --feature wasm32-unknown-emscripten
ls target/wasm32-unknown-emscripten/debug/examples # find the "example-XXX" name
edit emscripten.html # put the example name in
firefox emscripten.html # open in the browser
```
</script>
<canvas id="canvas" style="width:100%; height:100%"></canvas>
</body>
</html>

This comment has been minimized.

Copy link
@msiglreith

msiglreith Dec 19, 2017

Member

nit: newline

@bors

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2017

@bors bors bot merged commit 68f451e into gfx-rs:pre-ll Dec 19, 2017

3 checks passed

bors Build succeeded
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kvark kvark referenced this pull request Dec 29, 2017

Merged

More Emscripten support #1706

bors bot added a commit that referenced this pull request Dec 29, 2017

Merge #1706
1706: More Emscripten support r=msiglreith a=kvark

## Intro
This is a big follow-up to #1681 and #1685

After being blocked by rust-lang/rust#47023, I got stuff building in release, so continued porting the examples over. Note: there is a lot of shader code duplication, we need some (simple) templating/preprocessor there.

## Environment

OS: Linux + Firefox Nightly,

Emscripten: built from source with the following changes:
  - integrated emscripten-core/emscripten#5951
  - `USE_WEBGL2=1` is forcefully set in "settings.js"

## Status

🎉 Work 🎉 : triangle, cube, flowmap, blend, gamma, terrain, ubo_tilemap

Almost works: mipmap - see #1704

Not tested: deferred (too many shaders!), performance

Blocked by the lack of buffer mapping: instancing

Blocked by the lack of geometry/tessellation shader support: particle, render_target, terrain_tessellated

Fail to run: shadow, skybox - see #1705

## Proof
![gfx-emscripten-ubo_tilemap](https://user-images.githubusercontent.com/107301/34429974-5e6678d8-ec2d-11e7-91c7-2e4f3746e416.png)

@kvark kvark referenced this pull request Jan 22, 2018

Open

asm.js/wasm support #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.