OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 <!DOCTYPE html> |
| 28 <html> |
| 29 <head> |
| 30 <meta charset="utf-8"> |
| 31 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 32 <script src="../../resources/js-test-pre.js"></script> |
| 33 <script src="../resources/webgl-test.js"></script> |
| 34 <script src="../resources/webgl-test-utils.js"></script> |
| 35 <script> |
| 36 var wtu = WebGLTestUtils; |
| 37 var gl = null; |
| 38 var textureLoc = null; |
| 39 var successfullyParsed = false; |
| 40 |
| 41 if (window.initNonKhronosFramework) { |
| 42 window.initNonKhronosFramework(true); |
| 43 } |
| 44 |
| 45 function init() |
| 46 { |
| 47 description('Verify npot video'); |
| 48 |
| 49 var canvas = document.getElementById("example"); |
| 50 gl = wtu.create3DContext(canvas); |
| 51 var program = wtu.setupTexturedQuad(gl); |
| 52 |
| 53 gl.clearColor(0,0,0,1); |
| 54 gl.clearDepth(1); |
| 55 |
| 56 textureLoc = gl.getUniformLocation(program, "tex"); |
| 57 |
| 58 var video = document.getElementById("vid"); |
| 59 video.addEventListener( |
| 60 "playing", function() { runTest(video); }, true); |
| 61 video.loop = true; |
| 62 video.play(); |
| 63 } |
| 64 |
| 65 // These two declarations need to be global for "shouldBe" to see them |
| 66 var buf = null; |
| 67 var idx = 0; |
| 68 var pixel = [0, 0, 0]; |
| 69 var correctColor = null; |
| 70 var texture; |
| 71 |
| 72 function runOneIteration(videoElement, useTexSubImage2D, flipY, topColor, bottom
Color, badMinFilter, badClamp, genMips) |
| 73 { |
| 74 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + |
| 75 ' with flipY=' + flipY); |
| 76 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 77 // Disable any writes to the alpha channel |
| 78 gl.colorMask(1, 1, 1, 0); |
| 79 if (!texture) { |
| 80 texture = gl.createTexture(); |
| 81 } |
| 82 // Bind the texture to texture unit 0 |
| 83 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 84 // Set up pixel store parameters |
| 85 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); |
| 86 // Upload the videoElement into the texture |
| 87 debug("size: " + videoElement.videoWidth + "x" + videoElement.videoHeight); |
| 88 if (useTexSubImage2D) { |
| 89 // Initialize the texture to black first |
| 90 debug("use texSubImage2D"); |
| 91 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, |
| 92 videoElement.videoWidth, videoElement.videoHeight, 0, |
| 93 gl.RGBA, gl.UNSIGNED_BYTE, null); |
| 94 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, vide
oElement); |
| 95 } else { |
| 96 debug("use texImage2D"); |
| 97 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, vide
oElement); |
| 98 } |
| 99 |
| 100 // Set up texture parameters |
| 101 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
| 102 if (badMinFilter) { |
| 103 debug("bad min filter"); |
| 104 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_
NEAREST); |
| 105 } else { |
| 106 debug("good min filter"); |
| 107 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
| 108 } |
| 109 if (badClamp) { |
| 110 debug("bad clamp"); |
| 111 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); |
| 112 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); |
| 113 } else { |
| 114 debug("good clamp"); |
| 115 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 116 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 117 } |
| 118 if (genMips) { |
| 119 debug("generate mips"); |
| 120 gl.generateMipmap(gl.TEXTURE_2D); |
| 121 glErrorShouldBe(gl, gl.INVALID_OPERATION, "should be INVALID_OPERATION")
; |
| 122 } |
| 123 |
| 124 gl.bindTexture(gl.TEXTURE_2D, null); |
| 125 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 126 |
| 127 // var c = document.createElement("canvas"); |
| 128 // c.width = 16; |
| 129 // c.height = 16; |
| 130 // c.style.border = "1px solid black"; |
| 131 // var ctx = c.getContext("2d"); |
| 132 // ctx.drawImage(videoElement, 0, 0, 16, 16); |
| 133 // document.body.appendChild(c); |
| 134 |
| 135 // Point the uniform sampler to texture unit 0 |
| 136 gl.uniform1i(textureLoc, 0); |
| 137 // Draw the triangles |
| 138 wtu.drawQuad(gl, [0, 0, 0, 255]); |
| 139 // Check a few pixels near the top and bottom and make sure they have |
| 140 // the right color. |
| 141 debug("Checking lower left corner"); |
| 142 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, |
| 143 "shouldBe " + bottomColor); |
| 144 debug("Checking upper left corner"); |
| 145 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, |
| 146 "shouldBe " + topColor); |
| 147 debug(""); |
| 148 } |
| 149 |
| 150 function runTest(videoElement) |
| 151 { |
| 152 var red = [255, 0, 0]; |
| 153 var green = [0, 255, 0]; |
| 154 var black = [0, 0, 0]; |
| 155 runOneIteration(videoElement, false, true, black, black, true, true, true); |
| 156 runOneIteration(videoElement, false, true, black, black, true, false, false)
; |
| 157 runOneIteration(videoElement, false, true, black, black, false, true, false)
; |
| 158 runOneIteration(videoElement, false, true, black, black, true, true, false); |
| 159 runOneIteration(videoElement, false, true, green, red, false, false, false); |
| 160 runOneIteration(videoElement, false, false, red, green, false, false, false)
; |
| 161 runOneIteration(videoElement, true, true, green, red, false, false, false); |
| 162 runOneIteration(videoElement, true, false, red, green, false, false, false); |
| 163 |
| 164 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); |
| 165 finishTest(); |
| 166 } |
| 167 </script> |
| 168 </head> |
| 169 <body onload="init()"> |
| 170 <canvas id="example" width="64px" height="48px"></canvas> |
| 171 <div id="description"></div> |
| 172 <div id="console"></div> |
| 173 <video id="vid" style="display:none;"> |
| 174 <source src="../resources/npot-video.mp4" type='video/mp4; codecs="avc1.42E01
E"' /> |
| 175 <source src="../resources/npot-video.webmvp8.webm" type='video/webm; codecs="v
p8"' /> |
| 176 <source src="../resources/npot-video.theora.ogv" type='video/ogg; codecs="the
ora"' /> |
| 177 </video> |
| 178 </body> |
| 179 </html> |
OLD | NEW |