| 1 | <?xml version="1.0"?> |
| 2 | |
| 3 | <draft href="WEBGL_multiview/"> |
| 4 | <name>WEBGL_multiview</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>Olli Etuaho, NVIDIA</contributor> |
| 10 | <contributor>Members of the WebGL working group</contributor> |
| 11 | </contributors> |
| 12 | <number>36</number> |
| 13 | <depends> |
| 14 | <api version="1.0"/> |
| 15 | </depends> |
| 16 | <overview> |
| 17 | <mirrors href="https://www.opengl.org/registry/specs/OVR/multiview.txt" name="OVR_multiview"> |
| 18 | <addendum> |
| 19 | Calling <code>framebufferTextureMultiviewWEBGL</code> with a non-null <code>texture</code> parameter that does not identify a 2D array texture generates an <code>INVALID_OPERATION</code> error. |
| 20 | </addendum> |
| 21 | <addendum> |
| 22 | The values of <code>baseViewIndex</code> and <code>numViews</code> can result in an error only if the <code>texture</code> parameter is non-null. |
| 23 | </addendum> |
| 24 | <addendum> |
| 25 | If <code>baseViewIndex</code> is not the same for all framebuffer attachment points where the value of <code>FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE</code> is not <code>NONE</code> the framebuffer is considered incomplete. Calling <code>getFramebufferStatus</code> for a framebuffer in this state returns <code>FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR</code>. Other rules for framebuffer completeness from the OVR_multiview specification also apply. |
| 26 | </addendum> |
| 27 | <addendum> |
| 28 | Other web APIs may expose <i>opaque multiview framebuffers</i>. Opaque multiview framebuffers are <code>WebGLFramebuffer</code> objects that act as if they have multi-view attachments, but their attachments are not exposed as textures or renderbuffers and can not be changed. Opaque multiview framebuffers may have any combination of color, depth and stencil attachments. |
| 29 | </addendum> |
| 30 | <addendum> |
| 31 | Calling <code>framebufferRenderbuffer</code>, <code>framebufferTexture2D</code>, <code>framebufferTextureLayer</code>, <code>framebufferTextureMultiviewWEBGL</code>, or any other call that could change framebuffer attachments with an opaque multiview framebuffer bound to <code>target</code> generates an <code>INVALID_OPERATION</code> error. |
| 32 | </addendum> |
| 33 | <addendum> |
| 34 | If an opaque framebuffer is bound to <code>target</code> when calling <code>getFramebufferAttachmentParameter</code>, then <code>attachment</code> must be <code>BACK</code>, <code>DEPTH</code>, or <code>STENCIL</code>. |
| 35 | </addendum> |
| 36 | <addendum> |
| 37 | If an opaque framebuffer is bound to <code>target</code> when calling <code>getFramebufferAttachmentParameter</code>, then <code>pname</code> must not be <code>FRAMEBUFFER_ATTACHMENT_OBJECT_NAME</code>. |
| 38 | </addendum> |
| 39 | <addendum> |
| 40 | Querying <code>FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR</code> on an opaque multiview framebuffer attachment point that has attachments must return the number of views in the opaque multiview framebuffer. |
| 41 | </addendum> |
| 42 | <addendum> |
| 43 | Querying <code>FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR</code> on an opaque multiview framebuffer must return 0. |
| 44 | </addendum> |
| 45 | <addendum> |
| 46 | Querying <code>FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE</code> on an opaque multiview framebuffer must return <code>FRAMEBUFFER_DEFAULT</code>. |
| 47 | </addendum> |
| 48 | <addendum> |
| 49 | The number of views in an opaque multiview framebuffer may be greater than the maximum number of texture array views (the value of <code>MAX_VIEWS_OVR</code>). |
| 50 | </addendum> |
| 51 | <addendum> |
| 52 | Passing an opaque multiview framebuffer to <code>deleteFramebuffer</code> generates an <code>INVALID_OPERATION</code> error. |
| 53 | </addendum> |
| 54 | <addendum> |
| 55 | Although the extension name is prefixed with WEBGL the extension must be enabled with the |
| 56 | <code>#extension GL_OVR_multiview</code> directive, as shown in the sample code, to use |
| 57 | the extension in a shader. |
| 58 | |
| 59 | Likewise the shading language preprocessor <code>#define GL_OVR_multiview</code>, will be defined to 1 if the extension is supported. |
| 60 | </addendum> |
| 61 | <addendum> |
| 62 | This extension relaxes the restriction in OVR_multiview that only <code>gl_Position</code> can depend on ViewID in the vertex shader. With this change, view-dependent outputs like reflection vectors and similar are allowed. |
| 63 | </addendum> |
| 64 | <addendum> |
| 65 | When the number of views specified in the active program is one, <code>gl_ViewID_OVR</code> will always evaluate to zero. |
| 66 | </addendum> |
| 67 | <addendum> |
| 68 | When a shader written in OpenGL ES shading language version 1.00 enables or requires <code>GL_OVR_multiview</code> with an extension directive, <code>layout</code> is treated as a keyword rather than an identifier, and using a layout qualifier to specify <code>num_views</code> is allowed. Other uses of layout qualifiers are not allowed in OpenGL ES shading language 1.00. |
| 69 | </addendum> |
| 70 | <addendum> |
| 71 | In OpenGL ES shading language version 1.00 <code>gl_ViewID_OVR</code> has the type <code>int</code> as opposed to <code>uint</code>. |
| 72 | </addendum> |
| 73 | <addendum> |
| 74 | When a timer query is active and the number of views in the current draw framebuffer is greater than one, attempting to draw or calling <code>clear</code> generates an <code>INVALID_OPERATION</code> error. |
| 75 | </addendum> |
| 76 | <addendum> |
| 77 | When the number of views in the current draw framebuffer is greater than one and the active program does not declare a number of views, attempting to draw generates an <code>INVALID_OPERATION</code> error. |
| 78 | </addendum> |
| 79 | </mirrors> |
| 80 | <features> |
| 81 | <feature> |
| 82 | Adds support for rendering into multiple views simultaneously. This is supported for opaque multiview framebuffers starting from WebGL 1.0, and 2D texture arrays starting from WebGL 2.0. |
| 83 | </feature> |
| 84 | <feature> |
| 85 | When a shader enables, requires, or warns <code>GL_OVR_multiview</code> with an extension directive: |
| 86 | <ul> |
| 87 | <li><code>gl_ViewID_OVR</code> is a built-in input of the type uint.</li> |
| 88 | </ul> |
| 89 | </feature> |
| 90 | <feature> |
| 91 | The GLSL macro <code>GL_OVR_multiview</code> is defined as 1. |
| 92 | </feature> |
| 93 | </features> |
| 94 | </overview> |
| 95 | <idl xml:space="preserve"> |
| 96 | [NoInterfaceObject] |
| 97 | interface WEBGL_multiview { |
| 98 | const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR = 0x9630; |
| 99 | const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR = 0x9632; |
| 100 | const GLenum MAX_VIEWS_OVR = 0x9631; |
| 101 | const GLenum FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR = 0x9633; |
| 102 | |
| 103 | void framebufferTextureMultiviewWEBGL(GLenum target, GLenum attachment, WebGLTexture? texture, GLint level, GLint baseViewIndex, GLsizei numViews); |
| 104 | }; |
| 105 | </idl> |
| 106 | <newfun> |
| 107 | <function name="framebufferTextureMultiviewWEBGL" type="void"> |
| 108 | <param name="target" type="GLenum"/> |
| 109 | <param name="attachment" type="GLenum"/> |
| 110 | <param name="texture" type="GLuint"/> |
| 111 | <param name="level" type="GLint"/> |
| 112 | <param name="baseViewIndex" type="GLint"/> |
| 113 | <param name="numViews" type="GLsizei"/> |
| 114 | </function> |
| 115 | </newfun> |
| 116 | <newtok> |
| 117 | <function name="getParameter" type="any"> |
| 118 | <param name="pname" type="GLenum"/> |
| 119 | Calling with the <code>pname</code> set to <code>MAX_VIEWS_OVR</code> returns the maximum number of views. The implementation must support at least 2 views. |
| 120 | <br/> |
| 121 | |
| 122 | The return type depends on the parameter queried: |
| 123 | <table width="30%"> |
| 124 | <tr><th>pname</th><th>returned type</th></tr> |
| 125 | <tr><td>MAX_VIEWS_OVR</td><td>GLint</td></tr> |
| 126 | </table> |
| 127 | </function> |
| 128 | </newtok> |
| 129 | <newtok> |
| 130 | <function name="getFramebufferAttachmentParameter" type="any"> |
| 131 | <param name="target" type="GLenum"/> |
| 132 | <param name="attachment" type="GLenum"/> |
| 133 | <param name="pname" type="GLenum"/> |
| 134 | Calling with the <code>pname</code> parameter set to <code>FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR</code> returns the number of views of the framebuffer object attachment. |
| 135 | Calling with the <code>pname</code> parameter set to <code>FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR</code> returns the base view index of the framebuffer object attachment. |
| 136 | <br/> |
| 137 | |
| 138 | The return type depends on the parameter queried: |
| 139 | <table width="30%"> |
| 140 | <tr><th>pname</th><th>returned type</th></tr> |
| 141 | <tr><td>FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR</td><td>GLsizei</td></tr> |
| 142 | <tr><td>FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR</td><td>GLint</td></tr> |
| 143 | </table> |
| 144 | </function> |
| 145 | </newtok> |
| 146 | <errors> |
| 147 | <error> |
| 148 | The error <code>INVALID_OPERATION</code> is generated by calling <code>framebufferTextureMultiviewWEBGL</code> with a <code>texture</code> parameter that does not identify a 2D array texture. |
| 149 | </error> |
| 150 | <error> |
| 151 | The error <code>INVALID_OPERATION</code> is generated by calling <code>framebufferRenderbuffer</code>, <code>framebufferTexture2D</code>, <code>framebufferTextureLayer</code>, or <code>framebufferTextureMultiviewWEBGL</code> with a <code>target</code> parameter that identifies an opaque multiview framebuffer. |
| 152 | </error> |
| 153 | <error> |
| 154 | The error <code>INVALID_OPERATION</code> is generated by calling <code>deleteFramebuffer</code> with a <code>buffer</code> parameter that identifies an opaque multiview framebuffer. |
| 155 | </error> |
| 156 | <error> |
| 157 | The error <code>INVALID_ENUM</code> is generated by calling <code>getFramebufferAttachmentParameter</code> with an <code>attachment</code> parameter other than <code>BACK</code>, <code>DEPTH</code> or <code>STENCIL</code> when the <code>target</code> parameter identifies an opaque multiview framebuffer. |
| 158 | </error> |
| 159 | <error> |
| 160 | The error <code>INVALID_ENUM</code> is generated by calling <code>getFramebufferAttachmentParameter</code> with the <code>pname</code> parameter set to <code>FRAMEBUFFER_ATTACHMENT_OBJECT_NAME</code> when the <code>target</code> parameter identifies an opaque multiview framebuffer. |
| 161 | </error> |
| 162 | <error> |
| 163 | The error <code>INVALID_VALUE</code> is generated by calling <code>framebufferTextureMultiviewWEBGL</code> with a non-null <code>texture</code> in the following cases: |
| 164 | <ul> |
| 165 | <li>if <code>numViews</code> is less than one</li> |
| 166 | <li>if <code>numViews</code> is more than <code>MAX_VIEWS_OVR</code></li> |
| 167 | <li>with the parameters set so that <code>baseViewIndex</code> + <code>numViews</code> is larger than the value of <code>MAX_ARRAY_TEXTURE_LAYERS</code></li> |
| 168 | <li>if <code>baseViewIndex</code> is negative</li> |
| 169 | </ul> |
| 170 | </error> |
| 171 | <error> |
| 172 | The error <code>INVALID_FRAMEBUFFER_OPERATION</code> is generated by commands that read from the framebuffer such as <code>BlitFramebuffer</code>, <code>ReadPixels</code>, <code>CopyTexImage*</code>, and <code>CopyTexSubImage*</code>, if the number of views in the current read framebuffer is greater than one. |
| 173 | </error> |
| 174 | <error> |
| 175 | The error <code>INVALID_OPERATION</code> is generated by attempting to draw if the active program declares a number of views and the number of views in the draw framebuffer does not match the number of views declared in the active program. |
| 176 | </error> |
| 177 | <error> |
| 178 | The error <code>INVALID_OPERATION</code> is generated by attempting to draw if the number of views in the current draw framebuffer is greater than one and the active program does not declare a number of views. |
| 179 | </error> |
| 180 | <error> |
| 181 | The error <code>INVALID_OPERATION</code> is generated by attempting to draw if the number of views in the current draw framebuffer is greater than one and transform feedback is active. |
| 182 | </error> |
| 183 | <error> |
| 184 | The error <code>INVALID_OPERATION</code> is generated by attempting to draw or calling <code>clear</code> if the number of views in the current draw framebuffer is greater than one and a timer query is active. |
| 185 | </error> |
| 186 | </errors> |
| 187 | <samplecode xml:space="preserve"> |
| 188 | <pre> |
| 189 | var gl = document.createElement('canvas').getContext('webgl2'); |
| 190 | var ext = gl.getExtension('WEBGL_multiview'); |
| 191 | var fb = gl.createFramebuffer(); |
| 192 | gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fb); |
| 193 | var colorTex = gl.createTexture(); |
| 194 | gl.bindTexture(gl.TEXTURE_2D_ARRAY, colorTex); |
| 195 | gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.RGBA8, 512, 512, 2); |
| 196 | ext.framebufferTextureMultiviewWEBGL(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, colorTex, 0, 0, 2); |
| 197 | var depthStencilTex = gl.createTexture(); |
| 198 | gl.bindTexture(gl.TEXTURE_2D_ARRAY, depthStencilTex); |
| 199 | gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.DEPTH32F_STENCIL8, 512, 512, 2); |
| 200 | ext.framebufferTextureMultiviewWEBGL(gl.DRAW_FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, depthStencilTex, 0, 0, 2); |
| 201 | gl.drawElements(...); // draw will be broadcasted to the layers of colorTex and depthStencilTex. |
| 202 | </pre> |
| 203 | </samplecode> |
| 204 | <samplecode xml:space="preserve"> |
| 205 | <pre> |
| 206 | var gl = document.createElement('canvas').getContext('webgl'); |
| 207 | var ext = gl.getExtension('WEBGL_multiview'); |
| 208 | // ... obtain opaque multiview framebuffer "fb" from another web API here ... |
| 209 | gl.bindFramebuffer(gl.FRAMEBUFFER, fb); |
| 210 | gl.drawElements(...); // draw will be broadcasted to the views of the opaque multiview framebuffer. |
| 211 | // You can not call framebufferTextureMultiviewWEBGL to change the attachments of "fb", only draw to it. |
| 212 | </pre> |
| 213 | </samplecode> |
| 214 | <samplecode xml:space="preserve"> |
| 215 | <pre> |
| 216 | #version 300 es |
| 217 | #extension GL_OVR_multiview : require |
| 218 | precision mediump float; |
| 219 | layout (num_views = 2) in; |
| 220 | in vec4 inPos; |
| 221 | uniform mat4 u_viewMatrix0; |
| 222 | uniform mat4 u_viewMatrix1; |
| 223 | void main() { |
| 224 | if (gl_ViewID_OVR == 0u) { |
| 225 | gl_Position = u_viewMatrix0 * inPos; |
| 226 | } else { |
| 227 | gl_Position = u_viewMatrix1 * inPos; |
| 228 | } |
| 229 | } |
| 230 | </pre> |
| 231 | </samplecode> |
| 232 | <history> |
| 233 | <revision date="2016/11/11"> |
| 234 | <change>Initial revision.</change> |
| 235 | </revision> |
| 236 | |
| 237 | <revision date="2016/11/25"> |
| 238 | <change>Specified what happens when the number of views doesn't match or if the number of views is one.</change> |
| 239 | </revision> |
| 240 | ยด |
| 241 | <revision date="2016/12/21"> |
| 242 | <change>Specified what happens on invalid num_views declarations and if assignment to gl_Position.x is inside a larger expression.</change> |
| 243 | </revision> |
| 244 | |
| 245 | <revision date="2017/01/12"> |
| 246 | <change>Filled in getFramebufferAttachmentParameter and extension macro specs, formatted the documentation better, and added a simple API usage example.</change> |
| 247 | </revision> |
| 248 | |
| 249 | <revision date="2017/03/10"> |
| 250 | <change>Removed the core spec changes and made the specification follow the OVR_multiview specification more closely.</change> |
| 251 | </revision> |
| 252 | |
| 253 | <revision date="2017/05/19"> |
| 254 | <change>Introduced the concept of an opaque multiview framebuffer and fixed example code.</change> |
| 255 | </revision> |
| 256 | |
| 257 | <revision date="2017/05/23"> |
| 258 | <change>Made the extension compatible with WebGL 1.0 and fixed example shader code.</change> |
| 259 | </revision> |
| 260 | |
| 261 | <revision date="2017/07/21"> |
| 262 | <change>Specified some errors to be generated at draw time and made the extension compatible with emscripten.</change> |
| 263 | </revision> |
| 264 | |
| 265 | <revision date="2017/08/08"> |
| 266 | <change>Rolled back shader restrictions.</change> |
| 267 | </revision> |
| 268 | |
| 269 | <revision date="2017/08/17"> |
| 270 | <change>Required a multiview program to draw to a multiview framebuffer.</change> |
| 271 | </revision> |
| 272 | |
| 273 | <revision date="2017/10/26"> |
| 274 | <change>Took changes in the native OVR_multiview specification into account, added a more elaborate example including a depth/stencil texture, and an explicit mention that texture arrays are only supported in WebGL 2.0.</change> |
| 275 | </revision> |
| 276 | |
| 277 | <revision date="2018/01/03"> |
| 278 | <change>Moved to draft status.</change> |
| 279 | </revision> |
| 280 | |
| 281 | <revision date="2018/07/26"> |
| 282 | <change>Fixed off-by-one issue in validating baseViewIndex + numViews.</change> |
| 283 | </revision> |
| 284 | </history> |
| 285 | </draft> |