3 <draft href="WEBGL_shared_resources/">
4 <name>WEBGL_shared_resources</name>
6 <a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL working group</a> (public_webgl 'at' khronos.org)
9 <contributor>Members of the WebGL working group</contributor>
17 This extension exposes the ability to share WebGL resources with multiple WebGLRenderingContexts.
23 The OpenGL ES spec defines that you can share a resource (texture, buffer, shader, program,
24 renderbuffer) with 2 or more GL contexts but with some caveats. To guarantee you'll see a
25 change made in one context in other context requires calling glFinish on the context that
26 made the change and call glBind on the context that wants to see the change.
29 Not calling glFinish and/or glBind does not guarantee you won't see the results which means
30 that users may do neither and their app might just happen to work on some platforms and
31 mysteriously have glitches, rendering corruption, gl errors or program failure on others.
34 WebGL must present consistent behavior for sharing and so this extension provides
35 an API so that implementions can enforce and optimize these requirements.
39 <p>Adds a new context creation parameter:</p>
41 <dt><span class="prop-value">shareGroup</span></dt>
43 <em>Default: undefined</em>. If the value is set to the <code>group</code>
44 attribute from the <code>WEBGL_shared_resources</code> object from an existing context
45 then resources from the existing context are shared with the newly created context.
49 var canvas1 = document.createElement("canvas");
50 var canvas2 = document.createElement("canvas");
51 var ctx1 = canvas1.getContext("webgl");
52 var sharedResourcesExtension = ctx1.getExtension("WEBGL_shared_resources");
53 var ctx2 = canvas2.getContext("webgl", {
54 shareGroup: sharedResourcesExtension.group
60 In order for a context to use a resouce it must first acquire it.
61 Contexts can make a request to acquire a resource by calling acquireSharedResource
62 in one of 2 modes, EXCLUSIVE or READ_ONLY. A resource may be acquired by multiple
63 contexts in READ_ONLY mode. The resource may only be acquired by one context
64 if the mode is EXCLUSIVE. acquireSharedResource returns an id you can use to cancel the acquire
65 by calling cancelAcquireSharedResource.
66 When the resource is available in the requested mode the callback
67 will be invoked. Resources start their life as acquired in EXCLUSIVE mode in the context
68 in which they are created.
71 To release a resource so it may be acquired by another context call releaseSharedResource and
72 pass it the resource to be released.
77 After a resource is acquired it must be bound before it is used. Binding
78 means for buffers calling bindBuffer, for textures either bindTexture or
79 framebufferTexture2D, for renderbuffers either bindRenderbuffer or framebufferRenderbuffer,
80 for shaders attachShader, for programs useProgram. Binding once is sufficient to satisfy
81 this requirement. In other words, if you have a texture attached to more than one texture
82 unit the texture only needs to be re-bound to 1 texture unit. Attemping to use a resource
83 which has not been bound since it was acquired generates INVALID_OPERATION.
86 Bind Requirement Algorithm:
89 Each resource has a per-context bound flag. When a resource is acquired in a context its
90 bound flag for that context is set to false. If one of the functions listed above
91 is called the bound flag for that context is set to true. Drawing and reading functions,
92 clear, drawArrays, drawElements, readPixels, that would access a resource whose bound flag
93 for that context is false generate INVALID_FRAMEBUFFER_OPERATION. All other functions that
94 use a resource whose bound flag for that context is false generate INVALID_OPERATION.
97 Note: In the specific case of programs, it is not an error to call draw with a program
98 or call useProgram for a program which has shaders that have
99 been acquired but not re-attached. Nor it is an error to draw with or call useProgram
100 for a program which has shaders that have not been acquired. It is an error to call linkProgram
101 for a program that is using shaders that have been acquired but not re-attached.
106 When an attempt is made to use a resource that is not acquired in the current context
107 the implementation must generate the error INVALID_OPERATION or INVALID_FRAMEBUFFER_OPRATION.
108 This includes all gl calls
109 that would access the given resource directly or indirectly. For example, a
110 draw call must fail if any of the resources it would access is not acquired in the
111 correct mode for the call. In other words, if the draw call would read from a buffer
112 or texture and that buffer or texture is not acquired for READ_ONLY or EXCLUSIVE mode the draw
113 must fail with INVALID_FRAMEBUFFER_OPERATION. If the draw would render to a texture or renderbuffer
114 that is not acquired for EXCLUSIVE mode the draw must fail and generate INVALID_FRAMEBUFFER_OPERATION.
115 If a program used in the draw is not acquired for READ_ONLY or EXCLUSIVE mode the draw or clear must fail
116 and generate INVALID_FRAMEBUFFER_OPERATION.
119 For buffers not acquired this includes but is not limited to
128 getParameter with parameter (BUFFER_SIZE or BUFFER_USAGE)
133 For a buffer acquired in READ_ONLY mode this includes but is not limited to
140 For programs not acquired this includes but is not limited to
160 For programs acquired in READ_ONLY mode includes but is not limited to
168 For renderbuffers not acquired this includes but is not limited to
176 framebufferRenderbuffer
181 For renderbuffers acquired in READ_ONLY mode this includes
191 For shaders not acquired this includes but is not limited to
203 For shaders acquired in READ_ONLY mode this includes but is not limited to
211 For textures not acquired this includes but is not limited to
217 compressedTexSubImage2D
231 For textures acquired in READ_ONLY mode this includes but is not limited to
236 compressedTexSubImage2D
247 The term "not limited to" is intended to point out that extension may enable
248 other functions to which these rule should apply. For example drawArraysInstancedANGLE
249 must follow the same rules as drawArrays.
254 Calling checkFramebufferStatus with the argument FRAMEBUFFER or DRAW_FRAMEBUFFER must
255 return FRAMEBUFFER_INCOMPLETE_ATTACHMENT if any of the resources referenced by the currently
256 bound framebuffer are not acquired for EXCLUSIVE access.
257 Calling checkFramebufferStatus with the argument READ_FRAMEBUFFER will return
258 FRAMEBUFFER_INCOMPLETE_ATTACHMENT if any of the resources referenced by the currently bound
259 framebuffer are not acquired for EXCLUSIVE or READ_ONLY access.
262 Note: This extension exposes the constants READ_FRAMEBUFFER and DRAW_FRAMEBUFFER only for
263 the purpose of calling checkFramebufferStatus. In particular, this extension does not enable
264 calling bindFramebuffer with either constant.
269 A context that is deleted automatically releases all resources it has acquired. Note that
270 currently there is no way to explicitly delete a context. Contexts are deleted through
276 Note that implementing this extension changes the base class of the sharable resources.
277 Specifically: WebGLBuffer, WebGLProgram, WebGLRenderbuffer, WebGLShader, and WebGLTexture
278 change their base class from WebGLObject to WebGLSharedObject.
287 Q: What happens if one context deletes a resource another context is attempting to acquire?
290 A: Nothing special. The acquire will succeed when the context that currently has the resource
291 releases it. The context that acquires the resource can use the WebGLSharedObject
292 (buffer, texture, etc...) and will get the normal WebGL behavior associated with using
298 Q: Can you attach a resources that you have not acquired to a container?
301 A: No. An attachment can remain attached while it is released but it must be acquired
303 In particular a framebuffer attachment may not be attached to a framebuffer unless
304 the attachment is acquired. A shader may not be attached to a program unless the
305 shader is acquired. A buffer may not be attached to an attibute, vertexAttribPointer,
306 unless the buffer is acquired.
311 Q: What happens if you try to acquire a resource you already have acquired?
314 A: It will generate INVALID_OPERATION
319 <idl xml:space="preserve">
321 interface WEBGL_shared_resources {
322 const GLenum READ_ONLY = 0x0001;
323 const GLenum EXCLUSIVE = 0x0004;
325 const GLenum READ_FRAMEBUFFER = 0x8CA8;
326 const GLenum DRAW_FRAMEBUFFER = 0x8CA9;
328 readonly attribute WebGLShareGroup group;
330 long acquireSharedResource(
331 WebGLSharedObject resource,
333 AcquireResourcesCallback callback);
334 void releaseSharedResource(
335 WebGLSharedObject resource);
336 void cancelAcquireSharedResource(long id);
339 callback AcquireSharedResourcesCallback = void ();
342 interface WebGLShareGroup {
345 interface WebGLSharedObject : WebGLObject {
348 interface WebGLBuffer : WebGLSharedObject {
351 interface WebGLProgram : WebGLSharedObject {
354 interface WebGLRenderbuffer : WebGLSharedObject {
357 interface WebGLShader : WebGLSharedObject {
360 interface WebGLTexture : WebGLSharedObject {
364 <revision date="2012/02/06">
365 <change>Initial revision.</change>
367 <revision date="2013/05/14">
368 <change>Moved to draft after agreement in working group.</change>
370 <revision date="2014/07/15">
371 <change>Added NoInterfaceObject extended attribute to extension interface and WebGLShareGroup.</change>