| 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <proposal href="proposals/WEBGL_video_texture/"> |
| 3 | <name>WEBGL_video_texture</name> |
| 4 | |
| 5 | <contact> <a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL |
| 6 | working group</a> (public_webgl 'at' khronos.org) </contact> |
| 7 | |
| 8 | <contributors> |
| 9 | <contributor>Byungseon Shin (sun.shin 'at' lge.com)</contributor> |
| 10 | <contributor>Andrey Volykhin (andrey.volykhin 'at' lge.com)</contributor> |
| 11 | <contributor>Members of the WebGL working group</contributor> |
| 12 | </contributors> |
| 13 | |
| 14 | <number>NN</number> |
| 15 | |
| 16 | <depends> |
| 17 | <api version="1.0"/> |
| 18 | </depends> |
| 19 | |
| 20 | <overview> |
| 21 | <mirrors href="https://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt" |
| 22 | name="OES_EGL_image_external"> |
| 23 | <addendum>Defines a new texture target <code>TEXTURE_VIDEO_IMAGE</code>.</addendum> |
| 24 | <addendum>Provides a mechanism for binding <code>HTMLVideoElement</code> stream to video texture targets.</addendum> |
| 25 | <addendum>Provides time of frame, texture width and height of <code>HTMLVideoElement</code>'s texture binding.</addendum> |
| 26 | </mirrors> |
| 27 | |
| 28 | <features> |
| 29 | <feature>Add support for <code>WEBGL_video_texture</code> |
| 30 | binding of HTMLVideoElement.</feature> |
| 31 | |
| 32 | <glsl extname="WEBGL_video_texture"> |
| 33 | <stage type="fragment"/> |
| 34 | <type name="samplerVideoWEBGL"/> |
| 35 | |
| 36 | <function name="texture2D" type="vec4"> |
| 37 | <param name="sampler" type="samplerVideoWEBGL"/> |
| 38 | |
| 39 | <param name="coord" type="vec2"/> |
| 40 | </function> |
| 41 | |
| 42 | </glsl> |
| 43 | </features> |
| 44 | </overview> |
| 45 | |
| 46 | <idl xml:space="preserve"> |
| 47 | [NoInterfaceObject] |
| 48 | interface WebGLVideoFrameInfo { |
| 49 | readonly attribute double currentTime; |
| 50 | readonly attribute unsigned long textureWidth; |
| 51 | readonly attribute unsigned long textureHeight; |
| 52 | }; |
| 53 | |
| 54 | [NoInterfaceObject] |
| 55 | interface WEBGL_video_texture { |
| 56 | const GLenum TEXTURE_VIDEO_IMAGE = 0x851D; |
| 57 | const GLenum SAMPLER_VIDEO_IMAGE = 0x8B61; |
| 58 | |
| 59 | [RaisesException] WebGLVideoFrameInfo VideoElementTargetVideoTexture( |
| 60 | GLenum target, HTMLVideoElement video); |
| 61 | }; |
| 62 | </idl> |
| 63 | |
| 64 | <samplecode xml:space="preserve"> |
| 65 | |
| 66 | <p> This a fragment shader that samples a video texture.</p> |
| 67 | <pre> |
| 68 | #extension GL_WEBGL_video_texture : require |
| 69 | precision mediump float; |
| 70 | varying vec2 v_texCoord; |
| 71 | |
| 72 | uniform samplerVideoWEBGL uSampler; |
| 73 | |
| 74 | void main(void) { |
| 75 | gl_FragColor = texture2D(uSampler, v_texCoord); |
| 76 | } |
| 77 | </pre> |
| 78 | |
| 79 | <p> This shows application that renders video using proposed extension. </p> |
| 80 | <pre> |
| 81 | var videoElement = document.getElementById("video"); |
| 82 | var videoTexture = gl.createTexture(); |
| 83 | |
| 84 | function update() { |
| 85 | var ext = gl.getExtension('WEBGL_video_texture'); |
| 86 | if(ext !=== null){ |
| 87 | gl.bindTexture(ext.TEXTURE_VIDEO_IMAGE, videoTexture); |
| 88 | ext.VideoElementTargetVideoTexture(ext.TEXTURE_VIDEO_IMAGE, videoElement); |
| 89 | gl.bindTexture(ext.TEXTURE_VIDEO_IMAGE, null); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | function render() { |
| 94 | gl.clearColor(0.0, 0.0, 1.0, 1.0); |
| 95 | gl.clear(gl.COLOR_BUFFER_BIT); |
| 96 | |
| 97 | gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesBuffer); |
| 98 | gl.vertexAttribPointer(vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0); |
| 99 | |
| 100 | gl.activeTexture(gl.TEXTURE0); |
| 101 | gl.bindTexture(ext.TEXTURE_VIDEO_IMAGE, videoTexture); |
| 102 | gl.uniform1i(gl.getUniformLocation(shaderProgram, "uSampler"), 0); |
| 103 | |
| 104 | gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); |
| 105 | } |
| 106 | </pre> |
| 107 | |
| 108 | <p> Application renders each video frames into WebGL canvas based on game-loop pattern. </p> |
| 109 | <pre> |
| 110 | |
| 111 | while (true) { |
| 112 | update(); |
| 113 | processInput(); |
| 114 | render(); |
| 115 | } |
| 116 | </pre> |
| 117 | |
| 118 | </samplecode> |
| 119 | |
| 120 | <tests/> |
| 121 | |
| 122 | <issues/> |
| 123 | |
| 124 | <history> |
| 125 | <revision date="2016/11/05"> |
| 126 | <change>Initial revision.</change> |
| 127 | </revision> |
| 128 | <revision date="2017/01/10"> |
| 129 | <change>Change EGLImageTargetTexture2DOES to be called at every WebGL rendering cycle.</change> |
| 130 | <change>Add VideoFrameInfo interface.</change> |
| 131 | <change>Change EGLImageTargetTexture2DOES to return VideoFrameInfo as a currently mapped frame.</change> |
| 132 | </revision> |
| 133 | <revision date="2017/08/03"> |
| 134 | <change>Change Extension name to WEBGL_video_texture for abstracion of OES_EGL_image_external extension.</change> |
| 135 | <change>Define new sampler and texture type, TEXTURE_VIDEO_IMAGE and SAMPLER_VIDEO_IMAGE.</change> |
| 136 | <change>Change EGLImageTargetTexture2DOES to VideoElementTargetVideoTexture.</change> |
| 137 | </revision> |
| 138 | </history> |
| 139 | </proposal> |