Open JL102 opened 3 years ago
I edited glslCanvas myself to add that functionality, and it works quite well. Here's what I changed:
// Set framerate
if (canvas.hasAttribute('data-framerate')) {
this.framerate = parseInt(canvas.getAttribute('data-framerate'));
}
Changed RenderLoop:
function RenderLoop() {
if (sandbox.nMouse > 1) {
sandbox.setMouse(mouse);
}
if (sandbox.resize()) {
sandbox.forceRender = true;
}
sandbox.render();
if (sandbox.framerate) {
window.setTimeout(() => {
sandbox.animationFrameRequest = window.requestAnimationFrame(RenderLoop);
}, Math.floor(1000 / sandbox.framerate));
}
else {
sandbox.animationFrameRequest = window.requestAnimationFrame(RenderLoop);
}
}
With the framerate set to 30, there's not even a noticeable difference, and idle CPU usage is down to 2-3%! Others might like the functionality, if you want to add it to the source :)
Thanks, works like a charm! I think it would be a nice addition to the source :)
Hi,
I'm kinda surprised that having an idle animation with glslCanvas causes a non-negligible amount of CPU usage. When my animation is idle, it uses 6-7% of my CPU, and when I mouse over it, it uses ~15% of my CPU. I figure it would be less resource intensive if I force it to refresh at 30 frames per second instead of 60. Is there a simple way of doing that?