regl icon indicating copy to clipboard operation
regl copied to clipboard

[Q] How to prevent drawing of duplicate frames?

Open tim-steg opened this issue 3 years ago • 2 comments

Hi,

I am currently developing a video player in Regl that allows the user to zoom and pan whilst playing a live video feed. In an effort to reduce system resource consumption, I would like to make sure a frame is not drawn to the screen if nothing has changed from the last frame (which I have successfully kept track of), but is there a way to keep the old frame around and temporarily not draw anything in the regl.frame() loop?

Would something like this work?:

regl.frame(() => {
  if (dontDraw() === true) {
    return;
  }

  drawVideoShader({
     // shader params go here
  });
});

Thank you!

tim-steg avatar Mar 14 '22 14:03 tim-steg

Yes, the above should work just fine! Come to think of it, I don't know exactly what triggers this mechanism, but since WebGL uses double-buffering, if you don't draw anything the image should stay on the screen.

rreusser avatar Mar 14 '22 16:03 rreusser

Ah, maybe this is roughly what triggers it. I'd just always taken it for granted and hadn't thought about how it works: https://stackoverflow.com/questions/33327585/why-webgl-clear-draw-to-front-buffer

Anytime you do anything that effects the WebGL drawingBuffer (think "backbuffer) it gets marked to swap/copy.

rreusser avatar Mar 14 '22 16:03 rreusser