mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-17 05:49:30 -07:00
Testing hot-swapping renderers, which requires destroying and rebuilding the canvas after all. Fixed a few other related bugs and moved the imports into "bundle-contents.js".
This commit is contained in:
@@ -75,6 +75,9 @@ export const init = async (canvas) => {
|
||||
};
|
||||
|
||||
export const formulate = async (rain, config) => {
|
||||
if (rain.destroyed) {
|
||||
throw new Error("Cannot formulate a destroyed rain instance.");
|
||||
}
|
||||
const { resize, canvas, cache, canvasContext, adapter, device } = rain;
|
||||
rain.resolution = config.resolution;
|
||||
resize();
|
||||
@@ -197,10 +200,18 @@ export const formulate = async (rain, config) => {
|
||||
rain.renderLoop = renderLoop;
|
||||
};
|
||||
|
||||
export const destroy = ({ device, resize, doubleClick, cache, canvas }) => {
|
||||
export const destroy = (rain) => {
|
||||
if (rain.destroyed) {
|
||||
return;
|
||||
}
|
||||
const { device, resize, doubleClick, cache, canvas, renderLoop } = rain;
|
||||
window.removeEventListener("resize", resize);
|
||||
window.removeEventListener("dblclick", doubleClick);
|
||||
cache.clear();
|
||||
tick.cancel(); // stop RAF
|
||||
cancelAnimationFrame(renderLoop); // stop RAF
|
||||
// TODO: destroy WebGPU resources
|
||||
device.destroy();
|
||||
rain.destroyed = true;
|
||||
};
|
||||
|
||||
export const type = "webgpu";
|
||||
|
||||
@@ -29,7 +29,6 @@ const makeConfigBuffer = (device, configUniforms, config, density, gridSize, gly
|
||||
};
|
||||
// console.table(configData);
|
||||
|
||||
console.log(configUniforms, configData);
|
||||
return makeUniformBuffer(device, configUniforms, configData);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user