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

Re: [Public WebGL] using the same context with multiple canvases



On Sat, 10 Nov 2012, Boris Zbarsky wrote:
> On 11/10/12 3:15 PM, Ian Hickson wrote:
> > > In the current model there is a one-to-many relationship between a 
> > > canvas and canvas contexts.  In particular, it's possible to grab 
> > > both a 2d context and a webgl context for the same canvas.
> > 
> > Not according to the spec, not for a long time. "webgl" and "2d" are 
> > marked as incompatible, so once you get one, you can never get the 
> > other for the same canvas element.
> 
> Oh, hmm.  I thought the spec said to throw away the binding to one 
> context and return a new one with a new backing store... That's 
> certainly what some UAs do last I tested, but maybe they've changed 
> since.

Chrome, Firefox, and Opera do what the spec says:

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1906
http://whatwg.org/html#dom-canvas-getcontext

(Note: single-page version currently has different text, it's the 
work-in-progress for the proposal I'm writing.)


> > Right now as far as I can tell you need two copies of the bitmap per 
> > canvas: one for drawing on, and one for painting to the screen, so 
> > that you don't get any flicker.
> 
> I don't believe this is true.  For example, if your canvas is bigger 
> than the viewport, then you only need one copy of the entire backing 
> store; the part that you have to put on the screen can be just the 
> smaller bit that fits inside the viewport.

Look at this test (warning, has a loop with 10000 getImageData/drawImage 
calls, so can take a long time to render):

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1908

Between the time that the timeout fires and the time the timeout ends, 
which should hopefully be noticeable unless your computer is quite new 
(in which case just up the iteration count, thanks!), you can see the 
canvas on the screen is still completely transparent, but the bitmap of 
the canvas/context itself (they're shared in this case) is clearly not 
showing the same thing, since after the loop has finished, you see two 
squares, despite only one having been drawn -- the second is a copy from 
this "off-screen" buffer to itself.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl
-----------------------------------------------------------