[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] More predictable behavior for !preserveDrawingBuffer





On Mon, Jun 4, 2012 at 4:39 PM, Glenn Maynard <glenn@zewt.org> wrote:
I started writing this in more depth, but noticed that it might simply not be implementable, so I'll just start with a basic description.

When preserveDrawingBuffer is false, the buffer is cleared when it's actually composited.  Would it be possible to clear the buffer as soon as the JS code returns to the browser, rather than waiting for compositing, so the time of compositing can't affect script behavior?

These times aren't quite the same.  For instance:

<!DOCTYPE html>
<canvas></canvas>
<script>
var ctx = document.querySelector('canvas').getContext('2d');
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 100, 100);
window.setTimeout(function() {
  ctx.fillStyle = "blue";
  ctx.fillRect(0, 0, 100, 100);
  window.alert("hi");
  ctx.fillStyle = "green";
  ctx.fillRect(0, 0, 100, 100);
}, 1000);
</script>

(test is with 2d canvas since it's a lot easier to create a testcase, but the issue is the same with WebGL.)

On this test case, while the modal dialog is open I see a blue square in the most recent versions of Chrome and Firefox, indicating that the browser did in fact composite even though the anonymous function has not yet returned control to the browser and the task queue is suspended.  You'll have to pretty carefully define when exactly you want the clearing to happen to make this proposal well-defined.

- James

 

This would be efficient with triple-buffering--you just flip the backbuffers--but I don't know if that can be done on more restricted implementations, especially ES ones.

--
Glenn Maynard