[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Public WebGL] Event on SwapBuffers
- To: public webgl <firstname.lastname@example.org>
- Subject: [Public WebGL] Event on SwapBuffers
- From: Brandon Jones <email@example.com>
- Date: Tue, 24 Jan 2012 14:47:45 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=p9o/m7jXG2UrIVs7Pa0kckdZwRsi6utEWWcBF/mZyBk=; b=NuTJgd/oK8Zfb0lAZ9TsC6/ZH63gwsMGQA/ZVrNWJUfgo65PWvCDnmpimKnKZrYU81 kOmuWzChIpKL4WlTu2uH10QroFKXFYI8LKKsJixw6cTflU9j0saS+CD5bMnRCcVOcC3n 59qBcbvWcRkMB5+O33AhXTzTrH1jMiHRUT65U=
- List-id: Public WebGL Mailing List <public_webgl.khronos.org>
- Sender: firstname.lastname@example.org
Forgive me if this has been brought up before, I'm fairly new to the mailing list.
I've been experimenting with the idea of creating a browser extension that would allow users to inject limited post-process effects into any WebGL canvas. Essentially the extension would work by redirecting gl.bindFramebuffer to force scenes to render into a texture, then just before end-of-frame render that texture with an arbitrary effect shader. The target effect would be FXAA
but any image-based effect would work (greyscale, edge detection, etc.)
The catch to this whole thing is that you have to accurately detect when the frame is done rendering or, more accurately, when the backbuffer is going to be flipped. Unfortunately as WebGL handles that for you automatically it can be difficult to determine. My current hack of a solution is to also override requestAnimationFrame and setTimeout/Interval, detect if glDrawArrays/Elements is called within the callback of those methods, and if so perform my post process step before relinquishing control back to the browser. As you can imagine, however, this is a messy processes and is imperfect since it's possible to have applications that render outside the "expected" draw loop. For example, a paint application may render within the mouseMove event. Of course best practices would dictate otherwise, but we all know how often the web follows best practices in their development.
What really surprised me, however, was that upon looking at the code for Ben Vanik's WebGL Inspector
I found a very similar procedure
to my own, complete with the same concerns voiced in the comments. This leads me to believe that although the average WebGL developer will probably never need to know the details of when a buffer swap is going to happen, such information would be valuable to those writing tools or other "non-typical" applications.
As such, I would like to suggest that an API be made available for monitoring when SwapBuffers (or the platform's equivalent function) is called. For the use cases that I have seen a callback or an event that occurs just before the buffers are swapped, allowing developers to inject last-second draw calls for tool overlays or post-process effects as I described above. It may also be useful to allow the swap to be canceled from this event, though I can't think of a use case for it at the moment. It would also be useful to have an event that fires after the swap has occurred. I would imagine this would be used for performance profiling and statistics generation more than anything else.
Not being terribly familiar with the various browser's code bases I'm not sure if there are any practical matters that would prevent such an API from being implemented, but I'm certain that the development community could make good use of them should they be made available!