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.
10 <meta charset=
"utf-8">
11 <title>Stresses the camera-to-texture upload path.
</title>
12 <link rel=
"stylesheet" href=
"../resources/js-test-style.css"/>
13 <script src=
"../js/js-test-pre.js"></script>
14 <script src=
"../js/webgl-test-utils.js"> </script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"canvas" width=
"640" height=
"360">
25 debug("Repeatedly uploads from a camera video element to a texture, many times per frame.")
27 const wtu
= WebGLTestUtils
;
28 const gl
= wtu
.create3DContext(document
.getElementById('canvas'));
29 const video
= document
.createElement('video');
33 video
.setAttribute('playsinline', '');
35 const program
= wtu
.setupTexturedQuad(gl
);
36 const textureLoc
= gl
.getUniformLocation(program
, "tex");
37 gl
.uniform1i(textureLoc
, 0);
39 const texture
= gl
.createTexture();
40 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
41 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
42 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
43 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
44 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
45 gl
.pixelStorei(gl
.UNPACK_FLIP_Y_WEBGL
, true);
47 navigator
.mediaDevices
.getUserMedia({
50 facingMode
: 'environment',
55 .then(mediaStream
=> {
56 video
.srcObject
= mediaStream
;
57 video
.onloadedmetadata
= () => {
58 wtu
.startPlayingAndWaitForVideo(video
, startTestLoop
);
62 const urlOptions
= wtu
.getUrlOptions();
63 const uploadsPerFrame
= urlOptions
.uploadsPerFrame
? urlOptions
.uploadsPerFrame
: 400;
65 debug(`Testing with ${uploadsPerFrame} uploads per frame`);
67 function startTestLoop() {
68 requestAnimationFrame(startTestLoop
);
69 for (let i
= 0; i
< uploadsPerFrame
; ++i
) {
70 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGB
, gl
.RGB
, gl
.UNSIGNED_BYTE
, video
);
72 wtu
.clearAndDrawUnitQuad(gl
);
75 var successfullyParsed
= true;