From d435684b264419ec4d8fa5770ce7a15207a67c70 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Sat, 22 Apr 2017 16:19:10 -0400 Subject: [PATCH] Improve asmjs support, add wasm target. --- Cargo.toml | 2 +- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++-- main.rs | 9 ++++++++- release_wasm.sh | 5 +++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100755 release_wasm.sh diff --git a/Cargo.toml b/Cargo.toml index 37d847a..5167759 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/README.md b/README.md index dd4f14a..56b6c19 100644 --- 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 2d68c82..d1582dc 100644 --- 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 index 0000000..f09f623 --- /dev/null +++ b/release_wasm.sh @@ -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 . -- 2.25.1