OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 --> | |
6 <!DOCTYPE html> | |
7 <html> | |
8 <head> | |
9 <meta charset="utf-8"> | |
10 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
11 <script src="../../resources/js-test-pre.js"></script> | |
12 <script src="../resources/webgl-test.js"></script> | |
13 <script src="../resources/webgl-test-utils.js"></script> | |
14 <script> | |
15 var wtu = WebGLTestUtils; | |
16 var gl = null; | |
17 var textureLoc = null; | |
18 var successfullyParsed = false; | |
19 | |
20 if (window.initNonKhronosFramework) { | |
21 window.initNonKhronosFramework(true); | |
22 } | |
23 | |
24 function init() | |
25 { | |
26 description('Verify texImage2D and texSubImage2D code paths taking Video Ele
ments'); | |
27 | |
28 var canvas = document.getElementById("example"); | |
29 gl = wtu.create3DContext(canvas); | |
30 var program = wtu.setupTexturedQuad(gl); | |
31 | |
32 gl.clearColor(0,0,0,1); | |
33 gl.clearDepth(1); | |
34 | |
35 textureLoc = gl.getUniformLocation(program, "tex"); | |
36 | |
37 var video = document.getElementById("vid"); | |
38 video.addEventListener( | |
39 "playing", function() { runTest(video); }, true); | |
40 video.loop = true; | |
41 video.play(); | |
42 } | |
43 | |
44 // These two declarations need to be global for "shouldBe" to see them | |
45 var buf = null; | |
46 var idx = 0; | |
47 var pixel = [0, 0, 0]; | |
48 var correctColor = null; | |
49 | |
50 function runOneIteration(videoElement, useTexSubImage2D, flipY, topColor, bottom
Color) | |
51 { | |
52 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + | |
53 ' with flipY=' + flipY); | |
54 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
55 // Disable any writes to the alpha channel | |
56 gl.colorMask(1, 1, 1, 0); | |
57 var texture = gl.createTexture(); | |
58 // Bind the texture to texture unit 0 | |
59 gl.bindTexture(gl.TEXTURE_2D, texture); | |
60 // Set up texture parameters | |
61 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | |
62 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | |
63 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
64 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
65 // Set up pixel store parameters | |
66 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | |
67 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | |
68 // Upload the videoElement into the texture | |
69 if (useTexSubImage2D) { | |
70 // Initialize the texture to black first | |
71 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, | |
72 videoElement.videoWidth, videoElement.videoHeight, 0, | |
73 gl.RGBA, gl.UNSIGNED_BYTE, null); | |
74 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, vide
oElement); | |
75 } else { | |
76 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, vide
oElement); | |
77 } | |
78 | |
79 var c = document.createElement("canvas"); | |
80 c.width = 16; | |
81 c.height = 16; | |
82 c.style.border = "1px solid black"; | |
83 var ctx = c.getContext("2d"); | |
84 ctx.drawImage(videoElement, 0, 0, 16, 16); | |
85 document.body.appendChild(c); | |
86 | |
87 // Point the uniform sampler to texture unit 0 | |
88 gl.uniform1i(textureLoc, 0); | |
89 // Draw the triangles | |
90 wtu.drawQuad(gl, [0, 0, 0, 255]); | |
91 // Check a few pixels near the top and bottom and make sure they have | |
92 // the right color. | |
93 debug("Checking lower left corner"); | |
94 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, | |
95 "shouldBe " + bottomColor); | |
96 debug("Checking upper left corner"); | |
97 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, | |
98 "shouldBe " + topColor); | |
99 } | |
100 | |
101 function runTest(videoElement) | |
102 { | |
103 var red = [255, 0, 0]; | |
104 var green = [0, 255, 0]; | |
105 runOneIteration(videoElement, false, true, red, green); | |
106 runOneIteration(videoElement, false, false, green, red); | |
107 runOneIteration(videoElement, true, true, red, green); | |
108 runOneIteration(videoElement, true, false, green, red); | |
109 | |
110 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); | |
111 finishTest(); | |
112 } | |
113 </script> | |
114 </head> | |
115 <body onload="init()"> | |
116 <canvas id="example" width="32px" height="32px"></canvas> | |
117 <div id="description"></div> | |
118 <div id="console"></div> | |
119 <video width="640" height="228" id="vid" controls> | |
120 <source src="../resources/red-green.mp4" type='video/mp4; codecs="avc1.42E01E
, mp4a.40.2"' /> | |
121 <source src="../resources/red-green.webmvp8.webm" type='video/webm; codecs="vp
8, vorbis"' /> | |
122 <source src="../resources/red-green.theora.ogv" type='video/ogg; codecs="theo
ra, vorbis"' /> | |
123 </video> | |
124 </body> | |
125 </html> | |
OLD | NEW |