Skip to content

Commit

Permalink
Use web-sys for web backend (#444)
Browse files Browse the repository at this point in the history
A small step for #446 🕸️ Web support, use web-sys to interface to the web.
Previously, we would try to use glutin on the web, which is not supported;
now glutin is only used on native: fixes #171 could not find Context in platform_impl.

winit is still used on both, but the GL context is created with web-sys and glow
(on the web), and created with glutin and used with glow (on native). stdweb is
no longer used, being replaced by web-sys.

Substantial refactoring to allow reusing the code between web/native:

* settings: use VirtualKeyCode from winit, not reexported from glutin
* std_or_web: remove broken localstoragefs/stdweb, add File placeholder
* render: disable skin_thread on wasm since we don't have threads

* gl: use glow types in gl wrapper (integers in native, but Web*Key in web)
* gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't
* gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web
* gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper

* glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2

* shaders: add explicit float/int type conversions, required for WebGL
* shaders: specify mediump precision, required for WebGL
* shaders: specify fragment shader output locations for WebGL

* main: refactor handle_window_event to take a winit window, not glutin context
* main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this)
* main: use winit events in handle_window_event not reexported glutin events
* main: refactor game loop handling into tick_all()
* main: create winit window for WebGL, and use winit_window from glutin
* main: restore console_error_panic_hook,  mistakingly removed in (#260)
* main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web

* www: index.js: fix wasm import path
* www: npm update, npm audit fix
* www: update readme to link to status on #446 🕸️ Web support
  • Loading branch information
iceiix authored Dec 26, 2020
1 parent 0aa062f commit 3692f7a
Show file tree
Hide file tree
Showing 24 changed files with 688 additions and 1,019 deletions.
175 changes: 19 additions & 156 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ opt-level = 1
[dependencies]
cfg-if = "1.0.0"
wasm-bindgen = "0.2.69"
glutin = "0.26.0"
glow = { git = "https://github.com/iceiix/glow", rev = "45c808678735e03737d5e1b9d6ed0e21070edcd9" }
winit = { version = "0.24.0", features = [ "web-sys" ]}
glow = { git = "https://github.com/iceiix/glow", rev = "b354346dee69ff0ca7ccef67f7580dfbb697423b" }
byteorder = "1.3.4"
serde = "1.0.118"
serde_json = "1.0.60"
Expand All @@ -42,10 +42,11 @@ clipboard = "0.5.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
reqwest = { version = "0.10.10", features = [ "blocking" ]}
glutin = "0.26.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
stdweb = "0.4.20"
winit = { version = "0.24.0", features = [ "stdweb" ]}
console_error_panic_hook = "0.1.6"
web-sys = "0.3.46"

[dependencies.steven_resources]
path = "./resources"
Expand Down
Loading

0 comments on commit 3692f7a

Please sign in to comment.