diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-11-23 12:38:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-23 12:38:17 +0100 |
commit | 50db0e66ac8c00f176c706cee0c3a5469453acce (patch) | |
tree | 8ef45399f10c32b5dad742cf30180b569519cb70 /platform/javascript/js/engine/utils.js | |
parent | 18023cc3ede6fd84842db77019085c383e807016 (diff) | |
parent | 4617a7fa9cea323978f14053ef2726c84e9bd267 (diff) | |
download | redot-engine-50db0e66ac8c00f176c706cee0c3a5469453acce.tar.gz |
Merge pull request #43747 from Faless/js/4.0_lint
[HTML5] Linting, fixes.
Diffstat (limited to 'platform/javascript/js/engine/utils.js')
-rw-r--r-- | platform/javascript/js/engine/utils.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/platform/javascript/js/engine/utils.js b/platform/javascript/js/engine/utils.js new file mode 100644 index 0000000000..d0fca4e1cb --- /dev/null +++ b/platform/javascript/js/engine/utils.js @@ -0,0 +1,56 @@ +const Utils = { // eslint-disable-line no-unused-vars + + createLocateRewrite: function (execName) { + function rw(path) { + if (path.endsWith('.worker.js')) { + return `${execName}.worker.js`; + } else if (path.endsWith('.audio.worklet.js')) { + return `${execName}.audio.worklet.js`; + } else if (path.endsWith('.js')) { + return `${execName}.js`; + } else if (path.endsWith('.wasm')) { + return `${execName}.wasm`; + } + return path; + } + return rw; + }, + + createInstantiatePromise: function (wasmLoader) { + let loader = wasmLoader; + function instantiateWasm(imports, onSuccess) { + loader.then(function (xhr) { + WebAssembly.instantiate(xhr.response, imports).then(function (result) { + onSuccess(result['instance'], result['module']); + }); + }); + loader = null; + return {}; + } + + return instantiateWasm; + }, + + findCanvas: function () { + const nodes = document.getElementsByTagName('canvas'); + if (nodes.length && nodes[0] instanceof HTMLCanvasElement) { + return nodes[0]; + } + return null; + }, + + isWebGLAvailable: function (majorVersion = 1) { + let testContext = false; + try { + const 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'); + } + } catch (e) { + // Not available + } + return !!testContext; + }, +}; |