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 ActiveTexture BindTexture 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="2" height="2" style="width: 40px; height: 40px;"></canvas> |
michael@0 | 18 | <canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></canvas> |
michael@0 | 19 | <div id="description"></div> |
michael@0 | 20 | <div id="console"></div> |
michael@0 | 21 | <script id="vshader" type="x-shader/x-vertex"> |
michael@0 | 22 | uniform mat4 world; |
michael@0 | 23 | attribute vec3 vPosition; |
michael@0 | 24 | attribute vec2 texCoord0; |
michael@0 | 25 | varying vec2 texCoord; |
michael@0 | 26 | void main() |
michael@0 | 27 | { |
michael@0 | 28 | gl_Position = world * vec4(vPosition, 1); |
michael@0 | 29 | texCoord = texCoord0; |
michael@0 | 30 | } |
michael@0 | 31 | </script> |
michael@0 | 32 | <script> |
michael@0 | 33 | var gl; |
michael@0 | 34 | |
michael@0 | 35 | function init() |
michael@0 | 36 | { |
michael@0 | 37 | if (window.initNonKhronosFramework) { |
michael@0 | 38 | window.initNonKhronosFramework(false); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | description( |
michael@0 | 42 | "Tests that glActiveTexture and glBindTexture work as expected" + |
michael@0 | 43 | "Specifically texture targets are per active texture unit."); |
michael@0 | 44 | |
michael@0 | 45 | var canvas2d = document.getElementById("canvas2d"); |
michael@0 | 46 | var ctx2d = canvas2d.getContext("2d"); |
michael@0 | 47 | |
michael@0 | 48 | var wtu = WebGLTestUtils; |
michael@0 | 49 | gl = wtu.create3DContext("example"); |
michael@0 | 50 | var program = wtu.setupProgram( |
michael@0 | 51 | gl, |
michael@0 | 52 | ["vshader", wtu.setupSimpleTextureFragmentShader(gl)], |
michael@0 | 53 | ['vPosition', 'texCoord0']); |
michael@0 | 54 | wtu.setupUnitQuad(gl); |
michael@0 | 55 | gl.disable(gl.DEPTH_TEST); |
michael@0 | 56 | gl.disable(gl.BLEND); |
michael@0 | 57 | glErrorShouldBe(gl, gl.NO_ERROR); |
michael@0 | 58 | |
michael@0 | 59 | var colors = [ |
michael@0 | 60 | [0,192,128,255], |
michael@0 | 61 | [128,64,255,255], |
michael@0 | 62 | [192,255,64,255], |
michael@0 | 63 | [200,0,255,255]]; |
michael@0 | 64 | |
michael@0 | 65 | // Make 4 textures by using 4 active texture units if available. |
michael@0 | 66 | var texunits = Math.min(colors.length, gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS)) |
michael@0 | 67 | var textures = []; |
michael@0 | 68 | for (var ii = 0; ii < texunits; ++ii) { |
michael@0 | 69 | var tex = gl.createTexture(); |
michael@0 | 70 | gl.activeTexture(gl.TEXTURE0 + ii); |
michael@0 | 71 | gl.bindTexture(gl.TEXTURE_2D, tex); |
michael@0 | 72 | textures[ii] = tex; |
michael@0 | 73 | } |
michael@0 | 74 | glErrorShouldBe(gl, gl.NO_ERROR); |
michael@0 | 75 | |
michael@0 | 76 | // now use each texture unit to write into the textures, |
michael@0 | 77 | for (var ii = 0; ii < texunits; ++ii) { |
michael@0 | 78 | var c = colors[ii]; |
michael@0 | 79 | ctx2d.fillStyle = |
michael@0 | 80 | "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")"; |
michael@0 | 81 | ctx2d.fillRect(0, 0, 1, 1); |
michael@0 | 82 | gl.activeTexture(gl.TEXTURE0 + ii); |
michael@0 | 83 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); |
michael@0 | 84 | } |
michael@0 | 85 | glErrorShouldBe(gl, gl.NO_ERROR); |
michael@0 | 86 | |
michael@0 | 87 | var textureLoc = gl.getUniformLocation(program, "tex"); |
michael@0 | 88 | var worldLoc = gl.getUniformLocation(program, "world"); |
michael@0 | 89 | glErrorShouldBe(gl, gl.NO_ERROR); |
michael@0 | 90 | |
michael@0 | 91 | gl.clearColor(1,0,0,1); |
michael@0 | 92 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
michael@0 | 93 | |
michael@0 | 94 | for (var ii = 0; ii < texunits; ++ii) { |
michael@0 | 95 | var x = ii % 2; |
michael@0 | 96 | var y = Math.floor(ii / 2); |
michael@0 | 97 | gl.uniform1i(textureLoc, ii); |
michael@0 | 98 | gl.uniformMatrix4fv( |
michael@0 | 99 | worldLoc, false, |
michael@0 | 100 | [0.5, 0, 0, 0, |
michael@0 | 101 | 0, 0.5, 0, 0, |
michael@0 | 102 | 0, 0, 1, 0, |
michael@0 | 103 | -0.5 + x, -0.5 + y, 0, 1]); |
michael@0 | 104 | gl.drawArrays(gl.TRIANGLES, 0, 6); |
michael@0 | 105 | } |
michael@0 | 106 | glErrorShouldBe(gl, gl.NO_ERROR); |
michael@0 | 107 | |
michael@0 | 108 | for (var ii = 0; ii < texunits; ++ii) { |
michael@0 | 109 | var c = colors[ii]; |
michael@0 | 110 | var x = ii % 2; |
michael@0 | 111 | var y = Math.floor(ii / 2); |
michael@0 | 112 | var buf = new Uint8Array(4); |
michael@0 | 113 | gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
michael@0 | 114 | var msg = 'expected:' + |
michael@0 | 115 | c[0] + ', ' + c[1] + ', ' + c[2] + ', ' + c[3] + ' found: ' + |
michael@0 | 116 | buf[0] + ', ' + |
michael@0 | 117 | buf[1] + ', ' + |
michael@0 | 118 | buf[2] + ', ' + |
michael@0 | 119 | buf[3]; |
michael@0 | 120 | if (buf[0] != c[0] || |
michael@0 | 121 | buf[1] != c[1] || |
michael@0 | 122 | buf[2] != c[2] || |
michael@0 | 123 | buf[3] != c[3]) |
michael@0 | 124 | testFailed(msg); |
michael@0 | 125 | else |
michael@0 | 126 | testPassed(msg); |
michael@0 | 127 | } |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | init(); |
michael@0 | 131 | successfullyParsed = true; |
michael@0 | 132 | </script> |
michael@0 | 133 | |
michael@0 | 134 | <script>finishTest();</script> |
michael@0 | 135 | |
michael@0 | 136 | </body> |
michael@0 | 137 | </html> |
michael@0 | 138 |