mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-21 23:39:29 -07:00
Code intended to leverage imports in the load functions.
This commit is contained in:
@@ -59,7 +59,7 @@ export const init = async (canvas) => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const regl = createREGL({ canvas, pixelRatio: 1, extensions, optionalExtensions });
|
const regl = createREGL({ canvas, pixelRatio: 1, extensions, optionalExtensions });
|
||||||
const cache = new Map();
|
const cache = new Map(inclusions);
|
||||||
const rain = { canvas, resize, doubleClick, cache, regl, resolution: 1 };
|
const rain = { canvas, resize, doubleClick, cache, regl, resolution: 1 };
|
||||||
|
|
||||||
window.addEventListener("dblclick", doubleClick);
|
window.addEventListener("dblclick", doubleClick);
|
||||||
|
|||||||
@@ -59,7 +59,13 @@ const loadImage = (cache, regl, url, mipmap) => {
|
|||||||
if (url != null) {
|
if (url != null) {
|
||||||
const data = new Image();
|
const data = new Image();
|
||||||
data.crossOrigin = "anonymous";
|
data.crossOrigin = "anonymous";
|
||||||
data.src = url;
|
let imageURL;
|
||||||
|
if (typeof cache.get(`import::${url}`) === "function") {
|
||||||
|
imageURL = (await cache.get(`import::${url}`)()).default;
|
||||||
|
} else {
|
||||||
|
imageURL = url;
|
||||||
|
}
|
||||||
|
data.src = imageURL;
|
||||||
await data.decode();
|
await data.decode();
|
||||||
loaded = true;
|
loaded = true;
|
||||||
if (mipmap) {
|
if (mipmap) {
|
||||||
@@ -97,7 +103,13 @@ const loadText = (cache, url) => {
|
|||||||
},
|
},
|
||||||
loaded: (async () => {
|
loaded: (async () => {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
text = await (await fetch(url)).text();
|
let textURL;
|
||||||
|
if (typeof cache.get(`import::${url}`) === "function") {
|
||||||
|
textURL = (await cache.get(`import::${url}`)()).default;
|
||||||
|
} else {
|
||||||
|
textURL = url;
|
||||||
|
}
|
||||||
|
text = await (await fetch(textURL)).text();
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export const init = async (canvas) => {
|
|||||||
const adapter = await navigator.gpu.requestAdapter();
|
const adapter = await navigator.gpu.requestAdapter();
|
||||||
const device = await adapter.requestDevice();
|
const device = await adapter.requestDevice();
|
||||||
|
|
||||||
const cache = new Map();
|
const cache = new Map(inclusions);
|
||||||
const rain = {
|
const rain = {
|
||||||
canvas,
|
canvas,
|
||||||
resize,
|
resize,
|
||||||
|
|||||||
@@ -16,7 +16,14 @@ const loadTexture = async (device, cache, url) => {
|
|||||||
GPUTextureUsage.RENDER_ATTACHMENT,
|
GPUTextureUsage.RENDER_ATTACHMENT,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const response = await fetch(url);
|
let imageURL;
|
||||||
|
if (typeof cache.get(`import::${url}`) === "function") {
|
||||||
|
imageURL = (await cache.get(`import::${url}`)()).default;
|
||||||
|
} else {
|
||||||
|
imageURL = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(imageURL);
|
||||||
const data = await response.blob();
|
const data = await response.blob();
|
||||||
const source = await createImageBitmap(data);
|
const source = await createImageBitmap(data);
|
||||||
const size = [source.width, source.height, 1];
|
const size = [source.width, source.height, 1];
|
||||||
@@ -67,7 +74,13 @@ const loadShader = async (device, cache, url) => {
|
|||||||
if (cache.has(key)) {
|
if (cache.has(key)) {
|
||||||
return cache.get(key);
|
return cache.get(key);
|
||||||
}
|
}
|
||||||
const response = await fetch(url);
|
let textURL;
|
||||||
|
if (typeof cache.get(`import::${url}`) === "function") {
|
||||||
|
textURL = (await cache.get(`import::${url}`)()).default;
|
||||||
|
} else {
|
||||||
|
textURL = url;
|
||||||
|
}
|
||||||
|
const response = await fetch(textURL);
|
||||||
const code = await response.text();
|
const code = await response.text();
|
||||||
return {
|
return {
|
||||||
code,
|
code,
|
||||||
|
|||||||
Reference in New Issue
Block a user