From f0f422e933a393df4e9f789d0438fc4ac167500d Mon Sep 17 00:00:00 2001 From: Rezmason Date: Tue, 9 Nov 2021 18:26:00 -0800 Subject: [PATCH] =?UTF-8?q?Only=20load=20one=20solution=E2=80=94=20regl,?= =?UTF-8?q?=20or=20webgpu,=20not=20both.=20This=20requires=20dynamic=20imp?= =?UTF-8?q?ort.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/main.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/js/main.js b/js/main.js index 35c86be..723b020 100644 --- a/js/main.js +++ b/js/main.js @@ -1,6 +1,4 @@ import makeConfig from "./config.js"; -import initWebGPU from "./webgpu/main.js"; -import initREGL from "./regl/main.js"; const canvas = document.createElement("canvas"); document.body.appendChild(canvas); @@ -8,12 +6,10 @@ document.addEventListener("touchmove", (e) => e.preventDefault(), { passive: false, }); -document.body.onload = () => { +document.body.onload = async () => { const urlParams = Object.fromEntries(new URLSearchParams(window.location.search).entries()); + const useREGL = navigator.gpu == null || ["webgl", "regl"].includes(urlParams.renderer?.toLowerCase()); + const solution = import(`./${useREGL ? "regl" : "webgpu"}/main.js`); const config = makeConfig(urlParams); - if (navigator.gpu == null || ["webgl", "regl"].includes(urlParams.renderer?.toLowerCase())) { - initREGL(canvas, config); - } else { - initWebGPU(canvas, config); - } + (await solution).default(canvas, config); };