OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2010 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 <html> | |
7 <head> | |
8 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
9 <script src="../../resources/js-test-pre.js"></script> | |
10 <script src="../resources/webgl-test.js"></script> | |
11 <script src="../resources/webgl-test-utils.js"></script> | |
12 <script> | |
13 var wtu = WebGLTestUtils; | |
14 var gl = null; | |
15 var textureLoc = null; | |
16 var successfullyParsed = false; | |
17 | |
18 if (window.initNonKhronosFramework) { | |
19 window.initNonKhronosFramework(true); | |
20 } | |
21 | |
22 function init() | |
23 { | |
24 description('Verify npot video'); | |
25 | |
26 var canvas = document.getElementById("example"); | |
27 gl = wtu.create3DContext(canvas); | |
28 var program = wtu.setupTexturedQuad(gl); | |
29 | |
30 gl.clearColor(0,0,0,1); | |
31 gl.clearDepth(1); | |
32 | |
33 textureLoc = gl.getUniformLocation(program, "tex"); | |
34 | |
35 var video = document.getElementById("vid"); | |
36 video.addEventListener( | |
37 "playing", function() { runTest(video); }, true); | |
38 video.loop = true; | |
39 video.play(); | |
40 } | |
41 | |
42 // These two declarations need to be global for "shouldBe" to see them | |
43 var buf = null; | |
44 var idx = 0; | |
45 var pixel = [0, 0, 0]; | |
46 var correctColor = null; | |
47 var texture; | |
48 | |
49 function runOneIteration(videoElement, useTexSubImage2D, flipY, topColor, bottom
Color, badMinFilter, badClamp, genMips) | |
50 { | |
51 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + | |
52 ' with flipY=' + flipY); | |
53 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
54 // Disable any writes to the alpha channel | |
55 gl.colorMask(1, 1, 1, 0); | |
56 if (!texture) { | |
57 texture = gl.createTexture(); | |
58 } | |
59 // Bind the texture to texture unit 0 | |
60 gl.bindTexture(gl.TEXTURE_2D, texture); | |
61 // Set up pixel store parameters | |
62 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | |
63 // Upload the videoElement into the texture | |
64 debug("size: " + videoElement.videoWidth + "x" + videoElement.videoHeight); | |
65 if (useTexSubImage2D) { | |
66 // Initialize the texture to black first | |
67 debug("use texSubImage2D"); | |
68 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, | |
69 videoElement.videoWidth, videoElement.videoHeight, 0, | |
70 gl.RGBA, gl.UNSIGNED_BYTE, null); | |
71 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, vide
oElement); | |
72 } else { | |
73 debug("use texImage2D"); | |
74 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, vide
oElement); | |
75 } | |
76 | |
77 // Set up texture parameters | |
78 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); | |
79 if (badMinFilter) { | |
80 debug("bad min filter"); | |
81 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_
NEAREST); | |
82 } else { | |
83 debug("good min filter"); | |
84 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); | |
85 } | |
86 if (badClamp) { | |
87 debug("bad clamp"); | |
88 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); | |
89 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); | |
90 } else { | |
91 debug("good clamp"); | |
92 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
93 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
94 } | |
95 if (genMips) { | |
96 debug("generate mips"); | |
97 gl.generateMipmap(gl.TEXTURE_2D); | |
98 glErrorShouldBe(gl, gl.INVALID_OPERATION, "should be INVALID_OPERATION")
; | |
99 } | |
100 | |
101 gl.bindTexture(gl.TEXTURE_2D, null); | |
102 gl.bindTexture(gl.TEXTURE_2D, texture); | |
103 | |
104 // var c = document.createElement("canvas"); | |
105 // c.width = 16; | |
106 // c.height = 16; | |
107 // c.style.border = "1px solid black"; | |
108 // var ctx = c.getContext("2d"); | |
109 // ctx.drawImage(videoElement, 0, 0, 16, 16); | |
110 // document.body.appendChild(c); | |
111 | |
112 // Point the uniform sampler to texture unit 0 | |
113 gl.uniform1i(textureLoc, 0); | |
114 // Draw the triangles | |
115 wtu.drawQuad(gl, [0, 0, 0, 255]); | |
116 // Check a few pixels near the top and bottom and make sure they have | |
117 // the right color. | |
118 debug("Checking lower left corner"); | |
119 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, | |
120 "shouldBe " + bottomColor); | |
121 debug("Checking upper left corner"); | |
122 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, | |
123 "shouldBe " + topColor); | |
124 debug(""); | |
125 } | |
126 | |
127 function runTest(videoElement) | |
128 { | |
129 var red = [255, 0, 0]; | |
130 var green = [0, 255, 0]; | |
131 var black = [0, 0, 0]; | |
132 runOneIteration(videoElement, false, true, black, black, true, true, true); | |
133 runOneIteration(videoElement, false, true, black, black, true, false, false)
; | |
134 runOneIteration(videoElement, false, true, black, black, false, true, false)
; | |
135 runOneIteration(videoElement, false, true, black, black, true, true, false); | |
136 runOneIteration(videoElement, false, true, green, red, false, false, false); | |
137 runOneIteration(videoElement, false, false, red, green, false, false, false)
; | |
138 runOneIteration(videoElement, true, true, green, red, false, false, false); | |
139 runOneIteration(videoElement, true, false, red, green, false, false, false); | |
140 | |
141 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); | |
142 finishTest(); | |
143 } | |
144 </script> | |
145 </head> | |
146 <body onload="init()"> | |
147 <canvas id="example" width="64px" height="48px"></canvas> | |
148 <div id="description"></div> | |
149 <div id="console"></div> | |
150 <video id="vid" style="display:none;"> | |
151 <source src="../resources/npot-video.mp4" type='video/mp4; codecs="avc1.42E01
E"' /> | |
152 <source src="../resources/npot-video.webmvp8.webm" type='video/webm; codecs="v
p8"' /> | |
153 <source src="../resources/npot-video.theora.ogv" type='video/ogg; codecs="the
ora"' /> | |
154 </video> | |
155 </body> | |
156 </html> | |
OLD | NEW |