Improve asmjs support, add wasm target.
authorBernie Innocenti <bernie@codewiz.org>
Sat, 22 Apr 2017 20:19:10 +0000 (16:19 -0400)
committerBernie Innocenti <bernie@codewiz.org>
Sat, 22 Apr 2017 20:19:10 +0000 (16:19 -0400)
Cargo.toml
README.md
main.rs
release_wasm.sh [new file with mode: 0755]

index 37d847a9826943d31464e03090f991e7b75a9d77..516775948420000cd8d0f28f9c56bbf18e89ee63 100644 (file)
@@ -11,7 +11,7 @@ license = "GPL-3.0+"
 [dependencies]
 cgmath = "*"
 glium = "0.15.0"
-glutin = "*"
+glutin = "0.6.2"
 genmesh = "0.4.1"
 image = "0.12.0"
 obj = { version = "0.5", features = ["usegenmesh"] }
index dd4f14a2343c90b47dda0a813a49b567fb6c0fa7..56b6c192f27cc4fa07d74aa4ecc735d3db8344bf 100644 (file)
--- a/README.md
+++ b/README.md
@@ -10,17 +10,59 @@ I wrote this hack to learn Rust & basic GLSL. Mind the mess.
 
 ## Building from source
 
+### Native
+
 Install cargo, then simply type:
 
 ```
 cargo run --release
 ```
 
+### asm.js
+
+Install emsdk 1.36.14:
+
+```
+cd ~
+curl -O https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz
+tar xf emsdk-portable.tar.gz
+source emsdk-portable/emsdk_env.sh
+emsdk install emscripten-1.37.9 --build=MinSizeRel
+emsdk activate emscripten-1.37.9 --build=MinSizeRel
+```
+
+Install rustc:
+
+```
+cd ~
+curl https://sh.rustup.rs -sSf | sh
+source ~/.cargo/env
+rustup toolchain install nightly
+rustup default nightly
+rustup target install asmjs-unknown-emscripten
+rustup target install wasm32-unknown-emscripten
+```
+
+Build and run mandelwow:
+
+```
+cd mandelwow
+./release.sh
+```
+
+Build the WebAssembly binary:
+
+```
+cd mandelwow
+./release_wasm.sh
+```
 
 ## Requirements
 
-Requires OpenGL 3.1. Should perform well on reasonably modern hardware.
-Tested on Linux with Intel HD Graphics 4000 (Ivy Bridge) and NVidia GTX 970.
+The native binary requires OpenGL 3.1. Should perform well on reasonably modern
+hardware. Tested on Linux with Intel HD Graphics 4000 (Ivy Bridge) and NVidia GTX 970.
+
+The asmjs and WebAssembly versions were tested on Chromium 57 and Firefox 53.
 
 ## License
 
diff --git a/main.rs b/main.rs
index 2d68c82622f6fb98b7caf70d89e0553e566b645f..d1582dc288c86ab54c6320a4fcde1363e43e22d4 100644 (file)
--- a/main.rs
+++ b/main.rs
@@ -63,7 +63,7 @@ fn main() {
     let _soundplayer = sound::start();
 
     let display = glutin::WindowBuilder::new()
-        .with_dimensions(1024, 768)
+        .with_dimensions(300, 300)
         //.with_fullscreen(glutin::get_primary_monitor())
         .with_depth_buffer(24)
         .with_vsync()
@@ -71,6 +71,13 @@ fn main() {
         .build_glium()
         .unwrap();
 
+    let version = *display.get_opengl_version();
+    let api = match version {
+        glium::Version(glium::Api::Gl, _, _) => "OpenGL",
+        glium::Version(glium::Api::GlEs, _, _) => "OpenGL ES"
+    };
+    println!("{} context verson: {}", api, display.get_opengl_version_string());
+
     let mandelwow_program = mandelwow::program(&display);
     let bounding_box_program = bounding_box::solid_fill_program(&display);
 
diff --git a/release_wasm.sh b/release_wasm.sh
new file mode 100755 (executable)
index 0000000..f09f623
--- /dev/null
@@ -0,0 +1,5 @@
+set -e
+cargo build --target wasm32-unknown-emscripten --release
+cp target/wasm32-unknown-emscripten/release/mandelwow.js .
+cp target/wasm32-unknown-emscripten/release/deps/mandelwow-*.wasm .
+emrun .