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

Re: [Public WebGL] double-buffering and back buffer preservation



You actually end up needing 3 buffers to have an explicit present on the desktop I think.

The reason is multisampling / anti-aliasing. WebGL has a antialias context creation attribute. In that case 2 buffers are currently created. A multisample draw buffer (MDB) and a resolved display buffer (RDB).  Anytime toDataURL, drawImage, readPixels or texImage2D is called where the contents of the draw buffer are needed we have to blit the MDB into the RDB before you can read the pixels out. Since present is implicit currently that's okay because the RDB is going to be used for rendering anyway when JS finally exits and will be over written.  If we changed to an explicit present then we'd need a 3rd work buffer anytime any of those 4 functions was called since we have to resolve the MDB and we can't use the RDB except for present.

Maybe that's ok. That 3rd buffer could be dynamically created and freed since none of those calls are expected to be that fast. I just thought I'd mention the added complication needed to support explicit present. I still like the idea of explicit present.

On the opposite side, A problem with the implicit present + implicit clear is offscreen rendering. If I make a canvas with the sole purpose of doing GPU computation or just making images that I'm going to use in a canvas2d drawImage call and my WebGL canvas isn't even connected to the DOM why should it be cleared when JS exits? With explicit present that problem would go away. (or without implicit clear as it is now that problem doesn't exist)