WebGL
Khronos
 

WebGL WEBGL_multiview Extension Proposed Specification

DO NOT IMPLEMENT!!!

Name

WEBGL_multiview

Contact

WebGL working group (public_webgl 'at' khronos.org)

Contributors

Olli Etuaho, NVIDIA

Members of the WebGL working group

Version

Last modified date: October 26, 2017
Revision: 11

Number

WebGL extension #NN

Dependencies

Written against the WebGL API 1.0 specification.

Overview

This extension exposes the OVR_multiview functionality to WebGL.

The following WebGL-specific behavioral changes apply:

Consult the above extension for documentation, issues and new functions and enumerants.

When this extension is enabled:

IDL

[NoInterfaceObject]
interface WEBGL_multiview {
    const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR = 0x9630;
    const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR = 0x9632;
    const GLenum MAX_VIEWS_OVR = 0x9631;
    const GLenum FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR = 0x9633;

    void framebufferTextureMultiviewWEBGL(GLenum target, GLenum attachment, WebGLTexture? texture, GLint level, GLint baseViewIndex, GLsizei numViews);
};
  

New Functions

void framebufferTextureMultiviewWEBGL(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint baseViewIndex, GLsizei numViews)

New Tokens

any getParameter(GLenum pname)
Calling with the pname set to MAX_VIEWS_OVR returns the maximum number of views. The implementation must support at least 2 views.
The return type depends on the parameter queried:
pnamereturned type
MAX_VIEWS_OVRGLint
any getFramebufferAttachmentParameter(GLenum target, GLenum attachment, GLenum pname)
Calling with the pname parameter set to FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR returns the number of views of the framebuffer object attachment. Calling with the pname parameter set to FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR returns the base view index of the framebuffer object attachment.
The return type depends on the parameter queried:
pnamereturned type
FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVRGLsizei
FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVRGLint

Errors

The error INVALID_OPERATION is generated by calling framebufferTextureMultiviewWEBGL with a texture parameter that does not identify a 2D array texture.
The error INVALID_OPERATION is generated by calling framebufferRenderbuffer, framebufferTexture2D, framebufferTextureLayer, or framebufferTextureMultiviewWEBGL with a target parameter that identifies an opaque multiview framebuffer.
The error INVALID_OPERATION is generated by calling deleteFramebuffer with a buffer parameter that identifies an opaque multiview framebuffer.
The error INVALID_ENUM is generated by calling getFramebufferAttachmentParameter with an attachment parameter other than BACK, DEPTH or STENCIL when the target parameter identifies an opaque multiview framebuffer.
The error INVALID_ENUM is generated by calling getFramebufferAttachmentParameter with the pname parameter set to FRAMEBUFFER_ATTACHMENT_OBJECT_NAME when the target parameter identifies an opaque multiview framebuffer.
The error INVALID_VALUE is generated by calling framebufferTextureMultiviewWEBGL with a non-null texture in the following cases:
The error INVALID_FRAMEBUFFER_OPERATION is generated by commands that read from the framebuffer such as BlitFramebuffer, ReadPixels, CopyTexImage*, and CopyTexSubImage*, if the number of views in the current read framebuffer is greater than one.
The error INVALID_OPERATION 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.
The error INVALID_OPERATION 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.
The error INVALID_OPERATION 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.
The error INVALID_OPERATION is generated by attempting to draw or calling clear if the number of views in the current draw framebuffer is greater than one and a timer query is active.

Sample Code

    var gl = document.createElement('canvas').getContext('webgl2');
    var ext = gl.getExtension('WEBGL_multiview');
    var fb = gl.createFramebuffer();
    gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fb);
    var colorTex = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D_ARRAY, colorTex);
    gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.RGBA8, 512, 512, 2);
    ext.framebufferTextureMultiviewWEBGL(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, colorTex, 0, 0, 2);
    var depthStencilTex = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D_ARRAY, depthStencilTex);
    gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 1, gl.DEPTH32F_STENCIL8, 512, 512, 2);
    ext.framebufferTextureMultiviewWEBGL(gl.DRAW_FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, depthStencilTex, 0, 0, 2);
    gl.drawElements(...);  // draw will be broadcasted to the layers of colorTex and depthStencilTex.
    
    var gl = document.createElement('canvas').getContext('webgl');
    var ext = gl.getExtension('WEBGL_multiview');
    // ... obtain opaque multiview framebuffer "fb" from another web API here ...
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
    gl.drawElements(...);  // draw will be broadcasted to the views of the opaque multiview framebuffer.
    // You can not call framebufferTextureMultiviewWEBGL to change the attachments of "fb", only draw to it.
    
    #version 300 es
    #extension GL_OVR_multiview : require
    precision mediump float;
    layout (num_views = 2) in;
    in vec4 inPos;
    uniform mat4 u_viewMatrix0;
    uniform mat4 u_viewMatrix1;
    void main() {
      if (gl_ViewID_OVR == 0u) {
        gl_Position = u_viewMatrix0 * inPos;
      } else {
        gl_Position = u_viewMatrix1 * inPos;
      }
    }
    

Revision History

Revision 1, 2016/11/11

Revision 2, 2016/11/25

Revision 3, 2016/12/21

Revision 4, 2017/01/12

Revision 5, 2017/03/10

Revision 6, 2017/05/19

Revision 7, 2017/05/23

Revision 8, 2017/07/21

Revision 9, 2017/08/08

Revision 10, 2017/08/17

Revision 11, 2017/10/26