OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ** Copyright (c) 2012 The Khronos Group Inc. |
| 3 ** |
| 4 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 5 ** copy of this software and/or associated documentation files (the |
| 6 ** "Materials"), to deal in the Materials without restriction, including |
| 7 ** without limitation the rights to use, copy, modify, merge, publish, |
| 8 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 9 ** permit persons to whom the Materials are furnished to do so, subject to |
| 10 ** the following conditions: |
| 11 ** |
| 12 ** The above copyright notice and this permission notice shall be included |
| 13 ** in all copies or substantial portions of the Materials. |
| 14 ** |
| 15 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 22 */ |
| 23 |
| 24 function generateTest(pixelFormat, pixelType, prologue) { |
| 25 var wtu = WebGLTestUtils; |
| 26 var gl = null; |
| 27 var textureLoc = null; |
| 28 var successfullyParsed = false; |
| 29 |
| 30 if (window.initNonKhronosFramework) { |
| 31 window.initNonKhronosFramework(true); |
| 32 } |
| 33 |
| 34 var init = function() |
| 35 { |
| 36 description('Verify texImage2D and texSubImage2D code paths taking video
elements (' + pixelFormat + '/' + pixelType + ')'); |
| 37 |
| 38 gl = wtu.create3DContext("example"); |
| 39 |
| 40 if (!prologue(gl)) { |
| 41 finishTest(); |
| 42 return; |
| 43 } |
| 44 |
| 45 var program = wtu.setupTexturedQuad(gl); |
| 46 |
| 47 gl.clearColor(0,0,0,1); |
| 48 gl.clearDepth(1); |
| 49 |
| 50 textureLoc = gl.getUniformLocation(program, "tex"); |
| 51 |
| 52 var video = document.getElementById("vid"); |
| 53 video.addEventListener( |
| 54 "playing", function() { runTest(video); }, true); |
| 55 video.loop = true; |
| 56 video.play(); |
| 57 } |
| 58 |
| 59 function runOneIteration(videoElement, useTexSubImage2D, flipY, topColor, bo
ttomColor) |
| 60 { |
| 61 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + |
| 62 ' with flipY=' + flipY); |
| 63 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 64 // Disable any writes to the alpha channel |
| 65 gl.colorMask(1, 1, 1, 0); |
| 66 var texture = gl.createTexture(); |
| 67 // Bind the texture to texture unit 0 |
| 68 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 69 // Set up texture parameters |
| 70 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 71 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 72 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 73 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 74 // Set up pixel store parameters |
| 75 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); |
| 76 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); |
| 77 // Upload the videoElement into the texture |
| 78 if (useTexSubImage2D) { |
| 79 // Initialize the texture to black first |
| 80 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], |
| 81 videoElement.videoWidth, videoElement.videoHeight, 0, |
| 82 gl[pixelFormat], gl[pixelType], null); |
| 83 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelTy
pe], videoElement); |
| 84 } else { |
| 85 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl
[pixelType], videoElement); |
| 86 } |
| 87 |
| 88 var c = document.createElement("canvas"); |
| 89 c.width = 16; |
| 90 c.height = 16; |
| 91 c.style.border = "1px solid black"; |
| 92 var ctx = c.getContext("2d"); |
| 93 ctx.drawImage(videoElement, 0, 0, 16, 16); |
| 94 document.body.appendChild(c); |
| 95 |
| 96 // Point the uniform sampler to texture unit 0 |
| 97 gl.uniform1i(textureLoc, 0); |
| 98 // Draw the triangles |
| 99 wtu.drawQuad(gl, [0, 0, 0, 255]); |
| 100 // Check a few pixels near the top and bottom and make sure they have |
| 101 // the right color. |
| 102 debug("Checking lower left corner"); |
| 103 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, |
| 104 "shouldBe " + bottomColor); |
| 105 debug("Checking upper left corner"); |
| 106 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, |
| 107 "shouldBe " + topColor); |
| 108 } |
| 109 |
| 110 function runTest(videoElement) |
| 111 { |
| 112 var red = [255, 0, 0]; |
| 113 var green = [0, 255, 0]; |
| 114 runOneIteration(videoElement, false, true, red, green); |
| 115 runOneIteration(videoElement, false, false, green, red); |
| 116 runOneIteration(videoElement, true, true, red, green); |
| 117 runOneIteration(videoElement, true, false, green, red); |
| 118 |
| 119 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); |
| 120 finishTest(); |
| 121 } |
| 122 |
| 123 return init; |
| 124 } |
OLD | NEW |