| 1 | <?xml version="1.0"?> |
| 2 | |
| 3 | <rejected href="rejected/WEBGL_get_buffer_sub_data_async/"> |
| 4 | <name>WEBGL_get_buffer_sub_data_async</name> |
| 5 | <contact> |
| 6 | <a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL working group</a> (public_webgl 'at' khronos.org) |
| 7 | </contact> |
| 8 | <contributors> |
| 9 | <contributor>Kai Ninomiya, Google Inc.</contributor> |
| 10 | <contributor>Members of the WebGL working group</contributor> |
| 11 | </contributors> |
| 12 | <number>34</number> |
| 13 | <depends> |
| 14 | <api version="2.0"/> |
| 15 | </depends> |
| 16 | <overview> |
| 17 | <p> |
| 18 | This extension allows asynchronous buffer readback in WebGL 2.0. |
| 19 | </p> |
| 20 | <features> |
| 21 | <feature> |
| 22 | This extension exposes an asynchronous buffer readback entry point for |
| 23 | non-blocking readbacks from WebGL buffers. It is equivalent to |
| 24 | <code>getBufferSubData</code> but returns a <code>Promise</code> |
| 25 | instead of an immediate readback result. |
| 26 | </feature> |
| 27 | </features> |
| 28 | </overview> |
| 29 | |
| 30 | <idl xml:space="preserve"> |
| 31 | [NoInterfaceObject] |
| 32 | interface WEBGL_get_buffer_sub_data_async { |
| 33 | // Asynchronous version of getBufferSubData which fulfills the returned promise when the data becomes available. |
| 34 | Promise<ArrayBuffer> getBufferSubDataAsync(GLenum target, GLintptr srcByteOffset, ArrayBufferView dstBuffer, |
| 35 | optional GLuint dstOffset = 0, optional GLuint length = 0); // May throw DOMException |
| 36 | }; |
| 37 | </idl> |
| 38 | |
| 39 | <newfun> |
| 40 | <function name="getBufferSubDataAsync" type="Promise<ArrayBuffer>"> |
| 41 | <param name="target" type="GLenum"/> |
| 42 | <param name="srcByteOffset" type="GLintptr"/> |
| 43 | <param name="dstBuffer" type="ArrayBufferView"/> |
| 44 | <param name="dstOffset" type="optional GLuint"/> |
| 45 | <param name="length" type="optional GLuint"/> |
| 46 | Reads back data asynchronously from the bound WebGLBuffer into <code>dstBuffer</code>. |
| 47 | <br/><br/> |
| 48 | Let <code>buf</code> be the buffer bound to <code>target</code> at the time |
| 49 | <code>getBufferSubDataAsync</code> is called. |
| 50 | If <code>length</code> is 0, let <code>copyLength</code> be |
| 51 | <code>dstBuffer.length - dstOffset</code>; otherwise, let |
| 52 | <code>copyLength</code> be <code>length</code>. |
| 53 | <br/><br/> |
| 54 | If <code>copyLength</code> is greater than zero, |
| 55 | copy <code>copyLength</code> typed elements (each of size <code>dstBuffer.BYTES_PER_ELEMENT</code>) |
| 56 | from <code>buf</code> into <code>dstBuffer</code>, |
| 57 | reading <code>buf</code> starting at byte index <code>srcByteOffset</code> and |
| 58 | writing into <code>dstBuffer</code> starting at element index <code>dstOffset</code>. |
| 59 | If <code>copyLength</code> is 0, no data is written to <code>dstBuffer</code>, but |
| 60 | this does not cause a GL error to be generated. |
| 61 | <ul> |
| 62 | <li>If no WebGLBuffer is bound to <code>target</code>, |
| 63 | an <code>INVALID_OPERATION</code> error is generated. |
| 64 | </li> |
| 65 | <li>If <code>target</code> is <code>TRANSFORM_FEEDBACK_BUFFER</code>, |
| 66 | and any transform feedback object is currently active, |
| 67 | an <code>INVALID_OPERATION</code> error is generated. |
| 68 | </li> |
| 69 | <li>If <code>dstOffset</code> is greater than <code>dstBuffer.length</code>, |
| 70 | an <code>INVALID_VALUE</code> error is generated. |
| 71 | </li> |
| 72 | <li>If <code>dstOffset + copyLength</code> is greater than <code>dstBuffer.length</code>, |
| 73 | an <code>INVALID_VALUE</code> error is generated. |
| 74 | </li> |
| 75 | <li>If <code>srcByteOffset</code> is less than zero, |
| 76 | an <code>INVALID_VALUE</code> error is generated. |
| 77 | </li> |
| 78 | <li>If <code>srcByteOffset + copyLength*dstBuffer.BYTES_PER_ELEMENT</code> |
| 79 | is larger than the length of <code>buf</code>, |
| 80 | an <code>INVALID_OPERATION</code> is generated. |
| 81 | </li> |
| 82 | </ul> |
| 83 | When invoked, <code>getBufferSubDataAsync</code> must run these steps: |
| 84 | <ul> |
| 85 | <li>Let <code>promise</code> be a Promise to be returned. |
| 86 | </li> |
| 87 | <li>Check for the errors defined above. If there are any errors, generate the GL error |
| 88 | synchronously and |
| 89 | <a href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise">reject</a> |
| 90 | <code>promise</code> with an <code>InvalidStateError</code>. |
| 91 | </li> |
| 92 | <li>Insert a readback of <code>buf</code> into the GL command stream, using the range |
| 93 | defined above. |
| 94 | </li> |
| 95 | <li>Return <code>promise</code>, but continue running these steps in parallel. |
| 96 | </li> |
| 97 | <li>Upon completion of the readback, queue a task performing the following steps: |
| 98 | <ul> |
| 99 | <li>If the context has been lost, or if <code>dstBuffer</code> has been neutered, |
| 100 | <a href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise">reject</a> |
| 101 | <code>promise</code> with an <code>InvalidStateError</code>. In this case, no GL |
| 102 | error is generated. |
| 103 | </li> |
| 104 | <li>Write the readback result into <code>dstBuffer</code>, using the range defined |
| 105 | above. |
| 106 | </li> |
| 107 | <li><a href="https://www.w3.org/2001/tag/doc/promises-guide/#resolve-promise">Resolve</a> |
| 108 | <code>promise</code> with <code>dstBuffer</code>. |
| 109 | </li> |
| 110 | </ul> |
| 111 | The task source for this task is the <a href="#WEBGLCONTEXTEVENT">WebGL task source</a>. |
| 112 | </li> |
| 113 | </ul> |
| 114 | If the returned Promise is rejected, no data is written to <code>dstBuffer</code>. |
| 115 | |
| 116 | <div class="note"> |
| 117 | Even if <code>getBufferSubDataAsync</code> is called multiple times in a row with the same |
| 118 | <code>dstBuffer</code>, <code>then</code> callbacks added synchronously will never see |
| 119 | results of subsequent <code>getBufferSubDataAsync</code> calls. |
| 120 | </div> |
| 121 | |
| 122 | <div class="note rationale"> |
| 123 | Compared to the synchronous version of <code>getBufferSubData</code>, this version may |
| 124 | impose less overhead on applications. Intended use cases include reading pixels into a |
| 125 | pixel buffer object and examining that data on the CPU. It does not force the graphics |
| 126 | pipeline to be stalled as <code>getBufferSubData</code> does. |
| 127 | </div> |
| 128 | </function> |
| 129 | </newfun> |
| 130 | |
| 131 | <history> |
| 132 | <revision date="2016/12/13"> |
| 133 | <change>Initial revision.</change> |
| 134 | </revision> |
| 135 | <revision date="2018/05/04"> |
| 136 | <change>Set status to rejected following the working group's decision to |
| 137 | allow optimizations of the existing getBufferSubData API instead of |
| 138 | exposing a new one.</change> |
| 139 | </revision> |
| 140 | </history> |
| 141 | </rejected> |