mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-18 14:19:30 -07:00
Only load one solution— regl, or webgpu, not both. This requires dynamic import.
This commit is contained in:
12
js/main.js
12
js/main.js
@@ -1,6 +1,4 @@
|
|||||||
import makeConfig from "./config.js";
|
import makeConfig from "./config.js";
|
||||||
import initWebGPU from "./webgpu/main.js";
|
|
||||||
import initREGL from "./regl/main.js";
|
|
||||||
|
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
document.body.appendChild(canvas);
|
document.body.appendChild(canvas);
|
||||||
@@ -8,12 +6,10 @@ document.addEventListener("touchmove", (e) => e.preventDefault(), {
|
|||||||
passive: false,
|
passive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
document.body.onload = () => {
|
document.body.onload = async () => {
|
||||||
const urlParams = Object.fromEntries(new URLSearchParams(window.location.search).entries());
|
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);
|
const config = makeConfig(urlParams);
|
||||||
if (navigator.gpu == null || ["webgl", "regl"].includes(urlParams.renderer?.toLowerCase())) {
|
(await solution).default(canvas, config);
|
||||||
initREGL(canvas, config);
|
|
||||||
} else {
|
|
||||||
initWebGPU(canvas, config);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user