-
Notifications
You must be signed in to change notification settings - Fork 4
/
loader.js
39 lines (31 loc) · 1.29 KB
/
loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var script = document.createElement('script');
script.src = "./../wasm_exec.js";
script.onload = function () {
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
let mod, inst;
WebAssembly.instantiateStreaming(fetch("./fx.wasm"), go.importObject).then((result) => {
mod = result.module;
inst = result.instance;
run();
}).catch(reason => {
var status = document.querySelector('#status');
status.innerHTML = reason;
});
async function run() {
console.clear();
await go.run(inst);
inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
}
var canvas = document.querySelector('#canvas-container');
canvas.requestFullScreen = canvas.webkitRequestFullScreen || canvas.msRequestFullscreen ||
canvas.mozRequestFullScreen || canvas.requestFullScreen;
canvas.cancelFullScreen = canvas.webkitCancelFullScreen || canvas.msCancelFullscreen ||
canvas.mozCancelFullScreen || canvas.cancelFullScreen;
};
document.head.appendChild(script);