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

Re: [Public WebGL] Shared resources between contexts



On Thu, Jan 5, 2012 at 2:15 PM, Kenneth Russell <kbr@google.com> wrote:
> Figuring out how to define resource sharing between WebGL contexts is
> the next important step forward. Florian, as you point out, drawing
> the same content to multiple canvases can be implemented by the
> application if resource sharing is supported, so I don't think this
> should be explicitly added to the Canvas or WebGL APIs.

I'll make a first-pass proposal. ÂFirst, an invariant: if an implementation supports shared contexts, creating a context which shares resources with another is a requirement.

A code sample:

ctx1 = canvas1.getContext("webgl");
if(ctx1.getExtension("WEBGL_shared_contexts") == null)
 Âthrow "Shared contexts are not supported";
ctx2 = canvas2.getContext("webgl", { sharedContext: ctx1 });
// ctx1 and ctx2 are now on the same OpenGL share list; the rest is defined by ES

Querying the extension WEBGL_shared_contexts is required to enable resource sharing with that context, for the usual reasons.

If WEBGL_shared_contexts is supported, then the sharedContext parameter to getContext must always be honored, like premultipliedAlpha and preserveDrawingBuffer. ÂIt is *not* a hint like depth or stencil.

(I'd go further, and require that if WEBGL_shared_contexts is supported by one context, it must be supported by all contexts. Never expose it on one but not another.)

If the extension hasn't been enabled, then sharedContext is ignored. ÂIt shouldn't cause an error: not loading an extension should have the same behavior as if the implementation doesn't know about the extension at all. ÂImplementations would probably want to print a warning, though.

Note that the value of sharedContext is *not* present in WebGLContextAttributes. ÂThis would cause GC exposure issues (which I'll explain if requested), and since sharedContext isn't a hint, you don't need to be able to test whether it was honored or not. ÂIf an attribute like this is wanted anyway, it should be a boolean, not the actual context.

--
Glenn Maynard