1 // This block needs to be outside the onload handler in order for this
2 // test to run reliably in WebKit's test harness (at least the
3 // Chromium port). https://bugs.webkit.org/show_bug.cgi?id=87448
4 if (window
.initNonKhronosFramework
) {
5 window
.initNonKhronosFramework(true);
8 function generateTest(pixelFormat
, pixelType
, prologue
) {
9 var wtu
= WebGLTestUtils
;
11 var textureLoc
= null;
12 var successfullyParsed
= false;
16 description('Verify texImage2D and texSubImage2D code paths taking video elements (' + pixelFormat
+ '/' + pixelType
+ ')');
18 gl
= wtu
.create3DContext("example");
25 var program
= wtu
.setupTexturedQuad(gl
);
27 gl
.clearColor(0,0,0,1);
30 textureLoc
= gl
.getUniformLocation(program
, "tex");
32 var video
= document
.getElementById("vid");
33 video
.addEventListener(
34 "playing", function() { runTest(video
); }, true);
39 function runOneIteration(videoElement
, useTexSubImage2D
, flipY
, topColor
, bottomColor
)
41 debug('Testing ' + (useTexSubImage2D
? 'texSubImage2D' : 'texImage2D') +
42 ' with flipY=' + flipY
);
43 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
44 // Disable any writes to the alpha channel
45 gl
.colorMask(1, 1, 1, 0);
46 var texture
= gl
.createTexture();
47 // Bind the texture to texture unit 0
48 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
49 // Set up texture parameters
50 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
51 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
52 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
53 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
54 // Set up pixel store parameters
55 gl
.pixelStorei(gl
.UNPACK_FLIP_Y_WEBGL
, flipY
);
56 gl
.pixelStorei(gl
.UNPACK_PREMULTIPLY_ALPHA_WEBGL
, false);
57 // Upload the videoElement into the texture
58 if (useTexSubImage2D
) {
59 // Initialize the texture to black first
60 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
[pixelFormat
],
61 videoElement
.videoWidth
, videoElement
.videoHeight
, 0,
62 gl
[pixelFormat
], gl
[pixelType
], null);
63 gl
.texSubImage2D(gl
.TEXTURE_2D
, 0, 0, 0, gl
[pixelFormat
], gl
[pixelType
], videoElement
);
65 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
[pixelFormat
], gl
[pixelFormat
], gl
[pixelType
], videoElement
);
68 var c
= document
.createElement("canvas");
71 c
.style
.border
= "1px solid black";
72 var ctx
= c
.getContext("2d");
73 ctx
.drawImage(videoElement
, 0, 0, 16, 16);
74 document
.body
.appendChild(c
);
76 // Point the uniform sampler to texture unit 0
77 gl
.uniform1i(textureLoc
, 0);
79 wtu
.drawQuad(gl
, [0, 0, 0, 255]);
80 // Check a few pixels near the top and bottom and make sure they have
82 debug("Checking lower left corner");
83 wtu
.checkCanvasRect(gl
, 4, 4, 2, 2, bottomColor
,
84 "shouldBe " + bottomColor
);
85 debug("Checking upper left corner");
86 wtu
.checkCanvasRect(gl
, 4, gl
.canvas
.height
- 8, 2, 2, topColor
,
87 "shouldBe " + topColor
);
90 function runTest(videoElement
)
92 var red
= [255, 0, 0];
93 var green
= [0, 255, 0];
94 runOneIteration(videoElement
, false, true, red
, green
);
95 runOneIteration(videoElement
, false, false, green
, red
);
96 runOneIteration(videoElement
, true, true, red
, green
);
97 runOneIteration(videoElement
, true, false, green
, red
);
99 glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");