Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | <!-- |
michael@0 | 2 | Copyright (c) 2011 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 | <!DOCTYPE html> |
michael@0 | 7 | <html> |
michael@0 | 8 | <head> |
michael@0 | 9 | <meta charset="utf-8"> |
michael@0 | 10 | <title>WebGL Non-Power of 2 texture conformance test.</title> |
michael@0 | 11 | <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
michael@0 | 12 | <script src="../../resources/js-test-pre.js"></script> |
michael@0 | 13 | <script src="../resources/webgl-test.js"> </script> |
michael@0 | 14 | <script src="../resources/webgl-test-utils.js"> </script> |
michael@0 | 15 | </head> |
michael@0 | 16 | <body> |
michael@0 | 17 | <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas> |
michael@0 | 18 | <div id="description"></div> |
michael@0 | 19 | <div id="console"></div> |
michael@0 | 20 | <script id="vshader" type="x-shader/x-vertex"> |
michael@0 | 21 | attribute vec4 vPosition; |
michael@0 | 22 | attribute vec2 texCoord0; |
michael@0 | 23 | varying vec2 texCoord; |
michael@0 | 24 | void main() |
michael@0 | 25 | { |
michael@0 | 26 | gl_Position = vPosition; |
michael@0 | 27 | texCoord = texCoord0; |
michael@0 | 28 | } |
michael@0 | 29 | </script> |
michael@0 | 30 | |
michael@0 | 31 | <script id="fshader" type="x-shader/x-fragment"> |
michael@0 | 32 | precision mediump float; |
michael@0 | 33 | uniform samplerCube tex; |
michael@0 | 34 | varying vec2 texCoord; |
michael@0 | 35 | void main() |
michael@0 | 36 | { |
michael@0 | 37 | gl_FragColor = textureCube(tex, normalize(vec3(texCoord, 1))); |
michael@0 | 38 | } |
michael@0 | 39 | </script> |
michael@0 | 40 | <script> |
michael@0 | 41 | description(document.title); |
michael@0 | 42 | var wtu = WebGLTestUtils; |
michael@0 | 43 | var gl = wtu.create3DContext("example"); |
michael@0 | 44 | var program = wtu.setupTexturedQuad(gl); |
michael@0 | 45 | |
michael@0 | 46 | glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
michael@0 | 47 | |
michael@0 | 48 | var tex = gl.createTexture(); |
michael@0 | 49 | |
michael@0 | 50 | // Check that an NPOT texture not on level 0 generates INVALID_VALUE |
michael@0 | 51 | wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1); |
michael@0 | 52 | glErrorShouldBe(gl, gl.INVALID_VALUE, |
michael@0 | 53 | "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE"); |
michael@0 | 54 | |
michael@0 | 55 | // Check that an NPOT texture on level 0 succeeds |
michael@0 | 56 | wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255]); |
michael@0 | 57 | glErrorShouldBe(gl, gl.NO_ERROR, |
michael@0 | 58 | "gl.texImage2D with NPOT texture at level 0 should succeed"); |
michael@0 | 59 | |
michael@0 | 60 | // Check that generateMipmap fails on NPOT |
michael@0 | 61 | gl.generateMipmap(gl.TEXTURE_2D); |
michael@0 | 62 | glErrorShouldBe(gl, gl.INVALID_OPERATION, |
michael@0 | 63 | "gl.generateMipmap with NPOT texture should return INVALID_OPERATION"); |
michael@0 | 64 | |
michael@0 | 65 | var loc = gl.getUniformLocation(program, "tex"); |
michael@0 | 66 | gl.uniform1i(loc, 0); |
michael@0 | 67 | |
michael@0 | 68 | // Check that nothing is drawn if filtering is not correct for NPOT |
michael@0 | 69 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
michael@0 | 70 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
michael@0 | 71 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); |
michael@0 | 72 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); |
michael@0 | 73 | |
michael@0 | 74 | wtu.drawQuad(gl); |
michael@0 | 75 | wtu.checkCanvas( |
michael@0 | 76 | gl, [0, 0, 0, 255], |
michael@0 | 77 | "NPOT texture with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255"); |
michael@0 | 78 | glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
michael@0 | 79 | |
michael@0 | 80 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
michael@0 | 81 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
michael@0 | 82 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR); |
michael@0 | 83 | |
michael@0 | 84 | wtu.drawQuad(gl); |
michael@0 | 85 | wtu.checkCanvas( |
michael@0 | 86 | gl, [0, 0, 0, 255], |
michael@0 | 87 | "NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255"); |
michael@0 | 88 | glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
michael@0 | 89 | |
michael@0 | 90 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
michael@0 | 91 | |
michael@0 | 92 | wtu.drawQuad(gl); |
michael@0 | 93 | wtu.checkCanvas( |
michael@0 | 94 | gl, [0, 192, 128, 255], |
michael@0 | 95 | "NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw."); |
michael@0 | 96 | |
michael@0 | 97 | gl.copyTexImage2D(gl.TEXTURE_2D, 1, gl.RGBA, 0, 0, 5, 3, 0); |
michael@0 | 98 | glErrorShouldBe(gl, gl.INVALID_VALUE, |
michael@0 | 99 | "copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE."); |
michael@0 | 100 | |
michael@0 | 101 | // Check that generateMipmap for an POT texture succeeds |
michael@0 | 102 | wtu.fillTexture(gl, tex, 4, 4, [0, 192, 128, 255]); |
michael@0 | 103 | gl.generateMipmap(gl.TEXTURE_2D); |
michael@0 | 104 | glErrorShouldBe(gl, gl.NO_ERROR, |
michael@0 | 105 | "gl.texImage2D and gl.generateMipmap with POT texture at level 0 should succeed"); |
michael@0 | 106 | |
michael@0 | 107 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); |
michael@0 | 108 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
michael@0 | 109 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); |
michael@0 | 110 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); |
michael@0 | 111 | |
michael@0 | 112 | wtu.drawQuad(gl); |
michael@0 | 113 | wtu.checkCanvas( |
michael@0 | 114 | gl, [0, 192, 128, 255], |
michael@0 | 115 | "POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw."); |
michael@0 | 116 | glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
michael@0 | 117 | |
michael@0 | 118 | debug(""); |
michael@0 | 119 | debug("check using cubemap"); |
michael@0 | 120 | var program = wtu.setupProgram( |
michael@0 | 121 | gl, ['vshader', 'fshader'], ['vPosition', 'texCoord0'], [0, 1]); |
michael@0 | 122 | var tex = gl.createTexture(); |
michael@0 | 123 | |
michael@0 | 124 | // Check that an NPOT texture not on level 0 generates INVALID_VALUE |
michael@0 | 125 | fillCubeTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1); |
michael@0 | 126 | glErrorShouldBe(gl, gl.INVALID_VALUE, |
michael@0 | 127 | "gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE"); |
michael@0 | 128 | |
michael@0 | 129 | // Check that an NPOT texture on level 0 succeeds |
michael@0 | 130 | fillCubeTexture(gl, tex, 5, 5, [0, 192, 128, 255]); |
michael@0 | 131 | glErrorShouldBe(gl, gl.NO_ERROR, |
michael@0 | 132 | "gl.texImage2D with NPOT texture at level 0 should succeed"); |
michael@0 | 133 | |
michael@0 | 134 | // Check that generateMipmap fails on NPOT |
michael@0 | 135 | gl.generateMipmap(gl.TEXTURE_CUBE_MAP); |
michael@0 | 136 | glErrorShouldBe(gl, gl.INVALID_OPERATION, |
michael@0 | 137 | "gl.generateMipmap with NPOT texture should return INVALID_OPERATION"); |
michael@0 | 138 | |
michael@0 | 139 | var loc = gl.getUniformLocation(program, "tex"); |
michael@0 | 140 | gl.uniform1i(loc, 0); |
michael@0 | 141 | |
michael@0 | 142 | // Check that nothing is drawn if filtering is not correct for NPOT |
michael@0 | 143 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
michael@0 | 144 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
michael@0 | 145 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.REPEAT); |
michael@0 | 146 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.REPEAT); |
michael@0 | 147 | |
michael@0 | 148 | wtu.drawQuad(gl); |
michael@0 | 149 | wtu.checkCanvas( |
michael@0 | 150 | gl, [0, 0, 0, 255], |
michael@0 | 151 | "NPOT cubemap with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255"); |
michael@0 | 152 | glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
michael@0 | 153 | |
michael@0 | 154 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
michael@0 | 155 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
michael@0 | 156 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR); |
michael@0 | 157 | |
michael@0 | 158 | wtu.drawQuad(gl); |
michael@0 | 159 | wtu.checkCanvas( |
michael@0 | 160 | gl, [0, 0, 0, 255], |
michael@0 | 161 | "NPOT cubemap with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255"); |
michael@0 | 162 | glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); |
michael@0 | 163 | |
michael@0 | 164 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
michael@0 | 165 | |
michael@0 | 166 | wtu.drawQuad(gl); |
michael@0 | 167 | wtu.checkCanvas( |
michael@0 | 168 | gl, [0, 192, 128, 255], |
michael@0 | 169 | "NPOT cubemap with TEXTURE_MIN_FILTER set to LINEAR should draw."); |
michael@0 | 170 | |
michael@0 | 171 | // Check that an POT texture on level 0 succeeds |
michael@0 | 172 | fillCubeTexture(gl, tex, 4, 4, [0, 192, 128, 255]); |
michael@0 | 173 | glErrorShouldBe(gl, gl.NO_ERROR, |
michael@0 | 174 | "gl.texImage2D with POT texture at level 0 should succeed"); |
michael@0 | 175 | |
michael@0 | 176 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); |
michael@0 | 177 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
michael@0 | 178 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.REPEAT); |
michael@0 | 179 | gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.REPEAT); |
michael@0 | 180 | |
michael@0 | 181 | wtu.drawQuad(gl); |
michael@0 | 182 | wtu.checkCanvas( |
michael@0 | 183 | gl, [0, 0, 0, 255], |
michael@0 | 184 | "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR but no mips draw with 0,0,0,255"); |
michael@0 | 185 | |
michael@0 | 186 | // Check that generateMipmap succeeds on POT |
michael@0 | 187 | gl.generateMipmap(gl.TEXTURE_CUBE_MAP); |
michael@0 | 188 | glErrorShouldBe(gl, gl.NO_ERROR, |
michael@0 | 189 | "gl.generateMipmap with POT texture should return succeed"); |
michael@0 | 190 | |
michael@0 | 191 | wtu.drawQuad(gl); |
michael@0 | 192 | wtu.checkCanvas( |
michael@0 | 193 | gl, [0, 192, 128, 255], |
michael@0 | 194 | "POT cubemap with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw."); |
michael@0 | 195 | |
michael@0 | 196 | successfullyParsed = true; |
michael@0 | 197 | |
michael@0 | 198 | function fillCubeTexture(gl, tex, width, height, color, opt_level) { |
michael@0 | 199 | opt_level = opt_level || 0; |
michael@0 | 200 | var canvas = document.createElement('canvas'); |
michael@0 | 201 | canvas.width = width; |
michael@0 | 202 | canvas.height = height; |
michael@0 | 203 | var ctx2d = canvas.getContext('2d'); |
michael@0 | 204 | ctx2d.fillStyle = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ")"; |
michael@0 | 205 | ctx2d.fillRect(0, 0, width, height); |
michael@0 | 206 | gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex); |
michael@0 | 207 | var targets = [ |
michael@0 | 208 | gl.TEXTURE_CUBE_MAP_POSITIVE_X, |
michael@0 | 209 | gl.TEXTURE_CUBE_MAP_NEGATIVE_X, |
michael@0 | 210 | gl.TEXTURE_CUBE_MAP_POSITIVE_Y, |
michael@0 | 211 | gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, |
michael@0 | 212 | gl.TEXTURE_CUBE_MAP_POSITIVE_Z, |
michael@0 | 213 | gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]; |
michael@0 | 214 | for (var tt = 0; tt < targets.length; ++tt) { |
michael@0 | 215 | gl.texImage2D( |
michael@0 | 216 | targets[tt], opt_level, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas); |
michael@0 | 217 | } |
michael@0 | 218 | }; |
michael@0 | 219 | |
michael@0 | 220 | </script> |
michael@0 | 221 | <script>finishTest();</script> |
michael@0 | 222 | |
michael@0 | 223 | </body> |
michael@0 | 224 | </html> |
michael@0 | 225 |