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

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






On Tue, Dec 18, 2012 at 4:04 PM, Ian Hickson <ian@hixie.ch> wrote:
On Tue, 18 Dec 2012, Gregg Tavares (社ç~T¨) wrote:
> On Tue, Dec 18, 2012 at 3:30 AM, Ian Hickson <ian@hixie.ch> wrote:
> > On Mon, 17 Dec 2012, Gregg Tavares (社ç~T¨) wrote:
> > > On Fri, Dec 14, 2012 at 5:08 AM, Ian Hickson <ian@hixie.ch> wrote:
> > > > On Thu, 13 Dec 2012, Gregg Tavares (社ç~T¨) wrote:
> > > > > >
> > > > > > Is this something that would make sense as arguments to
> > > > > > setContext()?
> > > > >
> > > > > It doesn't seem like the appropriate place since they are
> > > > > "creation" parameters and since for an animated app with
> > > > > multiple canvases you're going to be calling setContext once per
> > > > > canvas per frame.
> > > >
> > > > They don't have to be creation, right? I mean, you have multiple
> > > > contexts and you have multiple canvases, you're not going to be
> > > > necessarily creating anything after that, just binding a context
> > > > to a canvas and drawing. If the settings are specific to a
> > > > particular context/canvas binding, then setContext() seems the
> > > > right place...
> > >
> > > How does this help us in workers where we also want to be able to
> > > create some object that represents what's being drawn to and we want
> > > to be able to create multiple of them, draw to them with 1 context,
> > > and have each have different attributes?
> >
> > setContext is on the CanvasProxy object you have in workers also.
>
> My understanding of CanvasProxy is it's something you create in the main
> thread from a Canvas. Not something the worker creates.

It's created for a specific canvas, then sent to the worker.


> We're asking for something a worker creates, no relation to the main
> page whatsoever.

I still don't see why the context can't do this, but ok.

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. I'll use drawingbuffer and then you can show me how I'd do this with CanvasProxy or whatever.

   var db = new DrawingBuffer({alpha: false; antialias: true});  // no need for alpha
   db.width = 512;  
   db.height = 512;
   var gl = new WebGLRenderingContext();
   gl.bindDrawingbuffer(db);

   ...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({alpha: false; antialias: true});  // no need for alpha
   var db2 = new DrawingBuffer({alpha: true; antialias: false);  // want alpha this time. Making a translucent image
   db1.width = 512;  
   db1.height = 512;
   db2.width = 256;  
   db2.height = 256;
   var gl = new WebGLRenderingContext();
   gl.bindDrawingbuffer(db1);
   ...drawStuffUsingGLWithoutTransparentParts...
   gl.bindDrawingbuffer(db2);
   ...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);

how does this work in the system you're suggesting? None of this connects with the main page at all so there are no canvases involved.
 

I really don't understand why, given that you have a scene graph object
and a place for the scene graph to be rendered to, you feel it's important
to have a middle-man object.

I understand that there is a concern that authors will accidentally change
the settings and that changing the settings used in a particular context/
canvas pair is expensive. But I don't see how a middleman object would
help. If an author could accidentally use different settings when binding
a context to a canvas, why couldn't an author accidentally use a different
middle man object?

If the settings are described by an object, why wouldn't the author pass
the same object each time to setContext()?

That is, instead of

   canvas1.setContext(webgl1, { setting1: 'a', setting2: 'a' });
   // ...
   canvas2.setContext(webgl1, { setting1: 'b', setting2: 'b' });
   // ...
   canvas1.setContext(webgl1, { setting1: 'a', setting2: 'b' }); // oops
   // ...
   canvas1.setContext(webgl2, { setting1: 'c', setting2: 'c' });
   // ...

...why wouldn't authors do:

   var canvas1webgl1 = { setting1: 'a', setting2: 'a' };
   var canvas2webgl1 = { setting1: 'b', setting2: 'b' };
   var canvas1webgl2 = { setting1: 'c', setting2: 'c' };
   canvas1.setContext(webgl1, canvas1webgl1);
   // ...
   canvas2.setContext(webgl1, canvas2webgl1);
   // ...
   canvas1.setContext(webgl1, canvas1webgl1);
   // ...
   canvas1.setContext(webgl2, canvas1webgl2);
   // ...

In fact, why would one canvas ever be used with two different contexts
with different settings? Can the settings just be put on the canvas (or
canvas proxy) directly?

Why should you have to specify the settings every time? Are they going
to be respected every time? If so that means every time setContext is 
called all of the settings need to be checked against previous settings 
and then reset the canvas if they change. That's both costly for checking 
and extremely costly if they change. If they aren't going to be respected
on a second call then why have them?

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

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