tex-image-and-sub-image-3d-with-image-bitmap-from-video.js (2713B)
1 /* 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 */ 6 7 function generateTest(internalFormat, pixelFormat, pixelType, prologue, resourcePath, defaultContextVersion) { 8 var wtu = WebGLTestUtils; 9 var tiu = TexImageUtils; 10 var gl = null; 11 var successfullyParsed = false; 12 13 var videos = [ 14 { src: resourcePath + "red-green.mp4" , type: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', }, 15 { src: resourcePath + "red-green.webmvp8.webm" , type: 'video/webm; codecs="vp8, vorbis"', }, 16 { src: resourcePath + "red-green.bt601.vp9.webm", type: 'video/webm; codecs="vp9"', }, 17 ]; 18 19 function init() 20 { 21 description('Verify texImage3D and texSubImage3D code paths taking ImageBitmap created from an HTMLVideoElement (' + internalFormat + '/' + pixelFormat + '/' + pixelType + ')'); 22 23 if(!window.createImageBitmap || !window.ImageBitmap) { 24 finishTest(); 25 return; 26 } 27 28 // Set the default context version while still allowing the webglVersion URL query string to override it. 29 wtu.setDefault3DContextVersion(defaultContextVersion); 30 gl = wtu.create3DContext("example"); 31 32 if (!prologue(gl)) { 33 finishTest(); 34 return; 35 } 36 37 gl.clearColor(0,0,0,1); 38 gl.clearDepth(1); 39 40 var videoNdx = 0; 41 var video; 42 function runNextVideo() { 43 if (video) { 44 video.pause(); 45 } 46 47 if (videoNdx == videos.length) { 48 finishTest(); 49 return; 50 } 51 52 var info = videos[videoNdx++]; 53 debug(""); 54 debug("testing: " + info.type); 55 video = document.createElement("video"); 56 video.muted = true; 57 var canPlay = true; 58 if (!video.canPlayType) { 59 testFailed("video.canPlayType required method missing"); 60 runNextVideo(); 61 return; 62 } 63 64 if(!video.canPlayType(info.type).replace(/no/, '')) { 65 debug(info.type + " unsupported"); 66 runNextVideo(); 67 return; 68 }; 69 70 document.body.appendChild(video); 71 video.type = info.type; 72 video.src = info.src; 73 wtu.startPlayingAndWaitForVideo(video, async function() { 74 await runImageBitmapTest(video, 1, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, true); 75 runNextVideo(); 76 }); 77 } 78 runNextVideo(); 79 } 80 81 return init; 82 }