Only load one solution— regl, or webgpu, not both. This requires dynamic import.

This commit is contained in:
Rezmason
2021-11-09 18:26:00 -08:00
parent 87c2093281
commit f0f422e933

View File

@@ -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);
};