2020-11-19 16:54:07 +01:00
|
|
|
var Utils = { // eslint-disable-line no-unused-vars
|
2020-01-19 11:44:19 +01:00
|
|
|
|
|
|
|
createLocateRewrite: function(execName) {
|
|
|
|
function rw(path) {
|
|
|
|
if (path.endsWith('.worker.js')) {
|
|
|
|
return execName + '.worker.js';
|
2020-11-03 17:18:02 +01:00
|
|
|
} else if (path.endsWith('.audio.worklet.js')) {
|
|
|
|
return execName + '.audio.worklet.js';
|
2020-01-19 11:44:19 +01:00
|
|
|
} else if (path.endsWith('.js')) {
|
|
|
|
return execName + '.js';
|
|
|
|
} else if (path.endsWith('.wasm')) {
|
|
|
|
return execName + '.wasm';
|
|
|
|
}
|
2020-11-19 16:54:07 +01:00
|
|
|
return path;
|
2020-01-19 11:44:19 +01:00
|
|
|
}
|
|
|
|
return rw;
|
|
|
|
},
|
|
|
|
|
|
|
|
createInstantiatePromise: function(wasmLoader) {
|
2020-11-19 16:54:07 +01:00
|
|
|
let loader = wasmLoader;
|
2020-01-19 11:44:19 +01:00
|
|
|
function instantiateWasm(imports, onSuccess) {
|
2020-11-19 16:54:07 +01:00
|
|
|
loader.then(function(xhr) {
|
2020-01-19 11:44:19 +01:00
|
|
|
WebAssembly.instantiate(xhr.response, imports).then(function(result) {
|
|
|
|
onSuccess(result['instance'], result['module']);
|
|
|
|
});
|
|
|
|
});
|
2020-11-19 16:54:07 +01:00
|
|
|
loader = null;
|
2020-01-19 11:44:19 +01:00
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
|
|
|
return instantiateWasm;
|
|
|
|
},
|
|
|
|
|
|
|
|
findCanvas: function() {
|
|
|
|
var nodes = document.getElementsByTagName('canvas');
|
|
|
|
if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {
|
|
|
|
return nodes[0];
|
|
|
|
}
|
2020-11-19 16:54:07 +01:00
|
|
|
return null;
|
2020-01-19 11:44:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
isWebGLAvailable: function(majorVersion = 1) {
|
|
|
|
|
|
|
|
var testContext = false;
|
|
|
|
try {
|
|
|
|
var testCanvas = document.createElement('canvas');
|
|
|
|
if (majorVersion === 1) {
|
|
|
|
testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
|
|
|
|
} else if (majorVersion === 2) {
|
|
|
|
testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
|
|
|
|
}
|
2020-11-19 16:54:07 +01:00
|
|
|
} catch (e) {
|
|
|
|
// Not available
|
|
|
|
}
|
2020-01-19 11:44:19 +01:00
|
|
|
return !!testContext;
|
|
|
|
}
|
|
|
|
};
|