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

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



On Tue, 18 Dec 2012, Gregg Tavares (社~T) wrote:
> 
> I'm lost. I'm in worker. I want to use WebGL to generate an image and 
> then send it to a server. I never need to see a canvas.

For 2D, the context itself can be used to get the image.

For 3D, I would propose having an object you can create in a worker that 
acts like a canvas for this purpose (we'll call it a DrawingBuffer so it's 
easier to compare to yours), as in:

    var db = new DrawingBuffer(512, 512, {alpha: false; antialias: true});
    var gl = new WebGLRenderingContext();
    db.setContext(gl);

    ...drawStuffUsingGL...
 
    var image = db.toDataURL();
    var xhr = new XMLHttpRequest();
    xhr.open('PUT', 'http://www.mysite.org/upload_image/', true);
    xhr.send(image);
 

> Now. expand that to 2 drawingbuffers

    var db1 = new DrawingBuffer(512, 512, {alpha: false; antialias: true});
    var db2 = new DrawingBuffer(256, 256, {alpha: true; antialias: true});
    var gl = new WebGLRenderingContext();

    db1.setContext(gl);
    ...drawStuffUsingGLWithoutTransparentParts...

    db2.setContext(gl);
    ...drawStuffUsingGLWithTransparentParts...
 
    var image = db1.toDataURL();
    var xhr = new XMLHttpRequest();
    xhr.open('PUT', 'http://www.mysite.org/upload_image_1/', true);
    xhr.send(image);

    var image = db2.toDataURL();
    var xhr = new XMLHttpRequest();
    xhr.open('PUT', 'http://www.mysite.org/upload_image_2/', true);
    xhr.send(image);

And then if you want to draw to a canvas instead of an off-screen buffer, 
you just use a Canvas instead of a DrawingBuffer.


> Why should you have to specify the settings every time?

I don't know why you have to specify them at all. :-)

Why would a canvas (not context, you've explained why a context may wish 
to paint to different surfaces differently, e.g. to have an area with AA 
and an area without or something) ever need to have its settings changed?


> Why conflate those 2 operations?
> (1) specifying settings
> (2) binding a context with a canvas

I'd be fine with not conflating them. If we introduce a middle man, 
though, it seems like they are still conflated, since the middle man is 
basically just a standin for the settings.

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