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 TexParameter 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 | </head> |
michael@0 | 15 | <body> |
michael@0 | 16 | <canvas id="example" width="24" height="24"></canvas> |
michael@0 | 17 | <canvas id="canvas2d" width="2" height="2"></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 | uniform mat4 world; |
michael@0 | 22 | attribute vec3 vPosition; |
michael@0 | 23 | attribute vec2 texCoord0; |
michael@0 | 24 | varying vec2 texCoord; |
michael@0 | 25 | void main() |
michael@0 | 26 | { |
michael@0 | 27 | gl_Position = world * vec4(vPosition, 1); |
michael@0 | 28 | texCoord = texCoord0; |
michael@0 | 29 | } |
michael@0 | 30 | </script> |
michael@0 | 31 | |
michael@0 | 32 | <script id="fshader" type="x-shader/x-fragment"> |
michael@0 | 33 | precision mediump float; |
michael@0 | 34 | |
michael@0 | 35 | uniform sampler2D tex; |
michael@0 | 36 | varying vec2 texCoord; |
michael@0 | 37 | void main() |
michael@0 | 38 | { |
michael@0 | 39 | gl_FragColor = texture2D(tex, texCoord); |
michael@0 | 40 | } |
michael@0 | 41 | </script> |
michael@0 | 42 | |
michael@0 | 43 | <script> |
michael@0 | 44 | function init() |
michael@0 | 45 | { |
michael@0 | 46 | if (window.initNonKhronosFramework) { |
michael@0 | 47 | window.initNonKhronosFramework(false); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | description("Tests TexParameter works as expected"); |
michael@0 | 51 | debug(""); |
michael@0 | 52 | |
michael@0 | 53 | var canvas2d = document.getElementById("canvas2d"); |
michael@0 | 54 | var ctx2d = canvas2d.getContext("2d"); |
michael@0 | 55 | |
michael@0 | 56 | gl = initWebGL("example", "vshader", "fshader", [ "vPosition", "texCoord0"], |
michael@0 | 57 | [ 0, 0, 0, 1 ], 1); |
michael@0 | 58 | |
michael@0 | 59 | gl.disable(gl.DEPTH_TEST); |
michael@0 | 60 | gl.disable(gl.BLEND); |
michael@0 | 61 | |
michael@0 | 62 | var vertexObject = gl.createBuffer(); |
michael@0 | 63 | gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
michael@0 | 64 | gl.bufferData( |
michael@0 | 65 | gl.ARRAY_BUFFER, |
michael@0 | 66 | new Float32Array([-1, 1,0, 1,1,0, -1,-1,0, |
michael@0 | 67 | -1,-1,0, 1,1,0, 1,-1,0]), |
michael@0 | 68 | gl.STATIC_DRAW); |
michael@0 | 69 | gl.enableVertexAttribArray(0); |
michael@0 | 70 | gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
michael@0 | 71 | |
michael@0 | 72 | var vertexObject = gl.createBuffer(); |
michael@0 | 73 | gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
michael@0 | 74 | gl.bufferData( |
michael@0 | 75 | gl.ARRAY_BUFFER, |
michael@0 | 76 | new Float32Array([ -2.5,-2.5, 3.5,-2.5, -2.5,3.5, |
michael@0 | 77 | -2.5,3.5, 3.5,-2.5, 3.5,3.5]), |
michael@0 | 78 | gl.STATIC_DRAW); |
michael@0 | 79 | gl.enableVertexAttribArray(1); |
michael@0 | 80 | gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); |
michael@0 | 81 | |
michael@0 | 82 | var colors = [ |
michael@0 | 83 | [0,255,128,255], |
michael@0 | 84 | [128,64,255,255], |
michael@0 | 85 | [192,255,64,255], |
michael@0 | 86 | [200,0,255,255]]; |
michael@0 | 87 | var texParam = [ |
michael@0 | 88 | gl.REPEAT, |
michael@0 | 89 | gl.CLAMP_TO_EDGE, |
michael@0 | 90 | gl.MIRRORED_REPEAT, |
michael@0 | 91 | gl.REPEAT]; |
michael@0 | 92 | |
michael@0 | 93 | // Make textures setting the texture parameters differently each time.. |
michael@0 | 94 | // This verifies both that the render correct AND that texture parameters |
michael@0 | 95 | // are associated with the textures, not with the texture-units. |
michael@0 | 96 | var textures = []; |
michael@0 | 97 | for (var ii = 0; ii < colors.length; ++ii) { |
michael@0 | 98 | var c = colors[ii]; |
michael@0 | 99 | ctx2d.fillStyle = |
michael@0 | 100 | "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")"; |
michael@0 | 101 | ctx2d.fillRect(0, 0, 1, 1); |
michael@0 | 102 | var tex = gl.createTexture(); |
michael@0 | 103 | gl.bindTexture(gl.TEXTURE_2D, tex); |
michael@0 | 104 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); |
michael@0 | 105 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
michael@0 | 106 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
michael@0 | 107 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, texParam[ii]); |
michael@0 | 108 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, texParam[ii]); |
michael@0 | 109 | textures[ii] = tex; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | var textureLoc = gl.getUniformLocation(gl.program, "tex"); |
michael@0 | 113 | var worldLoc = gl.getUniformLocation(gl.program, "world"); |
michael@0 | 114 | |
michael@0 | 115 | gl.clearColor(1,1,1,1); |
michael@0 | 116 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
michael@0 | 117 | |
michael@0 | 118 | for (var ii = 0; ii < colors.length; ++ii) { |
michael@0 | 119 | var x = ii % 2; |
michael@0 | 120 | var y = Math.floor(ii / 2); |
michael@0 | 121 | gl.bindTexture(gl.TEXTURE_2D, textures[ii]); |
michael@0 | 122 | gl.uniformMatrix4fv( |
michael@0 | 123 | worldLoc, false, |
michael@0 | 124 | [0.5, 0, 0, 0, |
michael@0 | 125 | 0, 0.5, 0, 0, |
michael@0 | 126 | 0, 0, 1, 0, |
michael@0 | 127 | -0.5 + x, -0.5 + y, 0, 1]); |
michael@0 | 128 | gl.drawArrays(gl.TRIANGLES, 0, 6); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | var buf = new Uint8Array(24 * 24 * 4); |
michael@0 | 132 | gl.readPixels(0, 0, 24, 24, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
michael@0 | 133 | var passed = true; |
michael@0 | 134 | for (var ii = 0; ii < colors.length; ++ii) { |
michael@0 | 135 | var x = ii % 2; |
michael@0 | 136 | var y = Math.floor(ii / 2); |
michael@0 | 137 | var c = colors[ii]; |
michael@0 | 138 | for (var yy = 0; yy < 12; ++yy) { |
michael@0 | 139 | for (var xx = 0; xx < 12; ++xx) { |
michael@0 | 140 | var ec = [0,0,0,0]; |
michael@0 | 141 | switch (texParam[ii]) { |
michael@0 | 142 | case gl.REPEAT: |
michael@0 | 143 | if (xx % 2 == 1 && yy % 2 == 0) { |
michael@0 | 144 | ec = c; |
michael@0 | 145 | } |
michael@0 | 146 | break; |
michael@0 | 147 | case gl.CLAMP_TO_EDGE: |
michael@0 | 148 | if (xx < 6 && yy >= 6) { |
michael@0 | 149 | ec = c; |
michael@0 | 150 | } |
michael@0 | 151 | break; |
michael@0 | 152 | case gl.MIRRORED_REPEAT: |
michael@0 | 153 | if (xx % 4 < 2 && yy % 4 >= 2) { |
michael@0 | 154 | ec = c; |
michael@0 | 155 | } |
michael@0 | 156 | break; |
michael@0 | 157 | } |
michael@0 | 158 | var off = ((y * 12 + yy) * 24 + x * 12 + xx) * 4; |
michael@0 | 159 | if (buf[off + 0] != ec[0] || |
michael@0 | 160 | buf[off + 1] != ec[1] || |
michael@0 | 161 | buf[off + 2] != ec[2] || |
michael@0 | 162 | buf[off + 3] != ec[3]) { |
michael@0 | 163 | var msg = 'at (' + (x * 12 + xx) + ', ' + (y * 12 + yy) + |
michael@0 | 164 | ') expected: ' + |
michael@0 | 165 | ec[0] + ', ' + ec[1] + ', ' + ec[2] + ', ' + ec[3] + ' found: ' + |
michael@0 | 166 | buf[off + 0] + ', ' + |
michael@0 | 167 | buf[off + 1] + ', ' + |
michael@0 | 168 | buf[off + 2] + ', ' + |
michael@0 | 169 | buf[off + 3]; |
michael@0 | 170 | testFailed(msg); |
michael@0 | 171 | passed = false; |
michael@0 | 172 | } |
michael@0 | 173 | } |
michael@0 | 174 | } |
michael@0 | 175 | } |
michael@0 | 176 | if (passed) { |
michael@0 | 177 | testPassed("rendered as expected"); |
michael@0 | 178 | } |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | init(); |
michael@0 | 182 | successfullyParsed = true; |
michael@0 | 183 | </script> |
michael@0 | 184 | <script>finishTest();</script> |
michael@0 | 185 | |
michael@0 | 186 | </body> |
michael@0 | 187 | </html> |
michael@0 | 188 |