WebGL
Khronos
 

WebGL WEBGL_video_texture Extension Proposed Specification

DO NOT IMPLEMENT!!!

Name

WEBGL_video_texture

Contact

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

Contributors

Byungseon Shin (sun.shin 'at' lge.com)

Andrey Volykhin (andrey.volykhin 'at' lge.com)

Members of the WebGL working group

Version

Last modified date: May 13, 2020
Revision: 7

Number

WebGL extension #NN

Dependencies

Written against the WebGL API 1.0 specification.

Overview

This extension exposes the OES_EGL_image_external 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

[Exposed=(Window,Worker), LegacyNoInterfaceObject]
interface WebGLVideoFrameInfo {
  readonly attribute double currentTime;
  readonly attribute unsigned long textureWidth;
  readonly attribute unsigned long textureHeight;
};

[Exposed=(Window,Worker), LegacyNoInterfaceObject]
interface WEBGL_video_texture {
    const GLenum TEXTURE_VIDEO_IMAGE_WEBGL             = 0x9248;
    const GLenum SAMPLER_VIDEO_IMAGE_WEBGL             = 0x9249;

    [RaisesException] WebGLVideoFrameInfo shareVideoImageWEBGL(
      GLenum target, HTMLVideoElement video);
    [RaiseException] undefined releaseVideoImageWEBGL(GLenum target);
};
  

Sample Code

This a fragment shader that samples a video texture.

    #extension GL_WEBGL_video_texture : require
    precision mediump float;
    varying vec2 v_texCoord;

    uniform samplerVideoWEBGL uSampler;

    void main(void) {
      gl_FragColor = textureVideoWEBGL(uSampler, v_texCoord);
    }
    

This shows application that renders video using proposed extension.

    var videoElement = document.getElementById("video");
    var videoTexture = gl.createTexture();

    function update() {
        var ext = gl.getExtension('WEBGL_video_texture');
        if(ext !=== null){
            gl.bindTexture(ext.TEXTURE_VIDEO_IMAGE_WEBGL, videoTexture);
            ext.shareVideoImageWEBGL(ext.TEXTURE_VIDEO_IMAGE_WEBGL, videoElement);
            ext.releaseVideoImageWEBGL(ext.TEXTURE_VIDEO_IMAGE_WEBGL);
            gl.bindTexture(ext.TEXTURE_VIDEO_IMAGE_WEBGL, null);
        }
    }

    function render() {
        gl.clearColor(0.0, 0.0, 1.0, 1.0);
        gl.clear(gl.COLOR_BUFFER_BIT);

        gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesBuffer);
        gl.vertexAttribPointer(vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0);

        gl.activeTexture(gl.TEXTURE0);
        gl.bindTexture(ext.TEXTURE_VIDEO_IMAGE_WEBGL, videoTexture);
        gl.uniform1i(gl.getUniformLocation(shaderProgram, "uSampler"), 0);

        gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

        ext.releaseVideoImageWEBGL(ext.TEXTURE_VIDEO_IMAGE_WEBGL);
    }
    

Application renders each video frames into WebGL canvas based on game-loop pattern.


    while (true) {
       update();
       processInput();
       render();
    }
    

Conformance Tests

Issues

Revision History

Revision 1, 2016/11/05

Revision 2, 2017/01/10

Revision 3, 2017/08/03

Revision 4, 2019/04/10

Revision 5, 2019/10/25

Revision 6, 2019/10/29

Revision 7, 2020/05/13