Came up with some performance improvements. Hopefully this will help it run better on more machines leading up to the sequel coming out.

This commit is contained in:
Rezmason
2021-07-11 18:18:13 -07:00
parent d094f7e0b7
commit 6708ab03a7
8 changed files with 40 additions and 24 deletions

View File

@@ -43,6 +43,8 @@ const resize = () => {
window.onresize = resize;
resize();
const dimensions = { width: 1, height: 1 };
document.body.onload = async () => {
// All this takes place in a full screen quad.
const fullScreenQuad = makeFullScreenQuad(regl);
@@ -64,9 +66,20 @@ document.body.onload = async () => {
await Promise.all(pipeline.map(({ ready }) => ready));
const tick = regl.frame(({ viewportWidth, viewportHeight }) => {
// tick.cancel();
pipeline.forEach(({ resize }) => resize(viewportWidth, viewportHeight));
if (
dimensions.width !== viewportWidth ||
dimensions.height !== viewportHeight
) {
dimensions.width = viewportWidth;
dimensions.height = viewportHeight;
for (const pass of pipeline) {
pass.resize(viewportWidth, viewportHeight);
}
}
fullScreenQuad(() => {
pipeline.forEach(({ render }) => render());
for (const pass of pipeline) {
pass.render();
}
drawToScreen();
});
});