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