mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-14 12:29: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 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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user