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 BindAttribLocation Conformance Tests</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 | <div id="description"></div> |
michael@0 | 17 | <div id="console"></div> |
michael@0 | 18 | <canvas style="border: 1px solid black;" id="canvas" width="50" height="50"></canvas> |
michael@0 | 19 | <script id="vshader" type="text/something-not-javascript"> |
michael@0 | 20 | attribute vec4 vPosition; |
michael@0 | 21 | attribute vec4 vColor; |
michael@0 | 22 | varying vec4 color; |
michael@0 | 23 | void main() |
michael@0 | 24 | { |
michael@0 | 25 | gl_Position = vPosition; |
michael@0 | 26 | color = vColor; |
michael@0 | 27 | } |
michael@0 | 28 | </script> |
michael@0 | 29 | <script id="fshader" type="text/something-not-javascript"> |
michael@0 | 30 | precision mediump float; |
michael@0 | 31 | |
michael@0 | 32 | varying vec4 color; |
michael@0 | 33 | void main() |
michael@0 | 34 | { |
michael@0 | 35 | gl_FragColor = color; |
michael@0 | 36 | } |
michael@0 | 37 | </script> |
michael@0 | 38 | <script> |
michael@0 | 39 | description("This test ensures WebGL implementations don't allow names that start with 'gl_' when calling bindAttribLocation."); |
michael@0 | 40 | |
michael@0 | 41 | debug(""); |
michael@0 | 42 | debug("Canvas.getContext"); |
michael@0 | 43 | |
michael@0 | 44 | var gl = create3DContext(document.getElementById("canvas")); |
michael@0 | 45 | shouldBeNonNull("gl"); |
michael@0 | 46 | |
michael@0 | 47 | function fail(x,y, buf, shouldBe) |
michael@0 | 48 | { |
michael@0 | 49 | var i = (y*50+x) * 4; |
michael@0 | 50 | var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe; |
michael@0 | 51 | testFailed(reason); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function pass() |
michael@0 | 55 | { |
michael@0 | 56 | testPassed("drawing is correct"); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function loadShader(shaderType, shaderId) { |
michael@0 | 60 | // Get the shader source. |
michael@0 | 61 | var shaderSource = document.getElementById(shaderId).text; |
michael@0 | 62 | |
michael@0 | 63 | // Create the shader object |
michael@0 | 64 | var shader = gl.createShader(shaderType); |
michael@0 | 65 | if (shader == null) { |
michael@0 | 66 | debug("*** Error: unable to create shader '"+shaderId+"'"); |
michael@0 | 67 | return null; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | // Load the shader source |
michael@0 | 71 | gl.shaderSource(shader, shaderSource); |
michael@0 | 72 | |
michael@0 | 73 | // Compile the shader |
michael@0 | 74 | gl.compileShader(shader); |
michael@0 | 75 | |
michael@0 | 76 | // Check the compile status |
michael@0 | 77 | var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); |
michael@0 | 78 | if (!compiled) { |
michael@0 | 79 | // Something went wrong during compilation; get the error |
michael@0 | 80 | var error = gl.getShaderInfoLog(shader); |
michael@0 | 81 | debug("*** Error compiling shader '"+shader+"':"+error); |
michael@0 | 82 | gl.deleteShader(shader); |
michael@0 | 83 | return null; |
michael@0 | 84 | } |
michael@0 | 85 | return shader; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | debug(""); |
michael@0 | 89 | debug("Checking gl.bindAttribLocation."); |
michael@0 | 90 | |
michael@0 | 91 | var program = gl.createProgram(); |
michael@0 | 92 | gl.bindAttribLocation(program, 0, "gl_foo"); |
michael@0 | 93 | glErrorShouldBe(gl, gl.INVALID_OPERATION, |
michael@0 | 94 | "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'"); |
michael@0 | 95 | gl.bindAttribLocation(program, 0, "gl_TexCoord0"); |
michael@0 | 96 | glErrorShouldBe(gl, gl.INVALID_OPERATION, |
michael@0 | 97 | "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'"); |
michael@0 | 98 | |
michael@0 | 99 | var vs = loadShader(gl.VERTEX_SHADER, "vshader"); |
michael@0 | 100 | var fs = loadShader(gl.FRAGMENT_SHADER, "fshader"); |
michael@0 | 101 | gl.attachShader(program, vs); |
michael@0 | 102 | gl.attachShader(program, fs); |
michael@0 | 103 | |
michael@0 | 104 | var positions = gl.createBuffer(); |
michael@0 | 105 | gl.bindBuffer(gl.ARRAY_BUFFER, positions); |
michael@0 | 106 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW); |
michael@0 | 107 | |
michael@0 | 108 | var colors = gl.createBuffer(); |
michael@0 | 109 | gl.bindBuffer(gl.ARRAY_BUFFER, colors); |
michael@0 | 110 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ |
michael@0 | 111 | 0,1,0,1, |
michael@0 | 112 | 0,1,0,1, |
michael@0 | 113 | 0,1,0,1]), gl.STATIC_DRAW); |
michael@0 | 114 | |
michael@0 | 115 | function setBindLocations(colorLocation, positionLocation) { |
michael@0 | 116 | gl.bindAttribLocation(program, positionLocation, "vPosition"); |
michael@0 | 117 | gl.bindAttribLocation(program, colorLocation, "vColor"); |
michael@0 | 118 | gl.linkProgram(program); |
michael@0 | 119 | gl.useProgram(program); |
michael@0 | 120 | var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0); |
michael@0 | 121 | assertMsg(linked, "program linked successfully"); |
michael@0 | 122 | |
michael@0 | 123 | debug("vPosition:" + gl.getAttribLocation(program, "vPosition")) |
michael@0 | 124 | debug("vColor :" + gl.getAttribLocation(program, "vColor")) |
michael@0 | 125 | assertMsg(gl.getAttribLocation(program, "vPosition") == positionLocation, |
michael@0 | 126 | "location of vPosition should be " + positionLocation); |
michael@0 | 127 | assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation, |
michael@0 | 128 | "location of vColor should be " + colorLocation); |
michael@0 | 129 | |
michael@0 | 130 | var ploc = gl.getAttribLocation(program, "vPosition"); |
michael@0 | 131 | var cloc = gl.getAttribLocation(program, "vColor"); |
michael@0 | 132 | gl.bindBuffer(gl.ARRAY_BUFFER, positions); |
michael@0 | 133 | gl.enableVertexAttribArray(positionLocation); |
michael@0 | 134 | gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0); |
michael@0 | 135 | gl.bindBuffer(gl.ARRAY_BUFFER, colors); |
michael@0 | 136 | gl.enableVertexAttribArray(colorLocation); |
michael@0 | 137 | gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | function checkDraw(colorLocation, positionLocation, r, g, b, a) { |
michael@0 | 141 | gl.clearColor(0, 0, 0, 1); |
michael@0 | 142 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
michael@0 | 143 | gl.drawArrays(gl.TRIANGLES, 0, 3); |
michael@0 | 144 | |
michael@0 | 145 | var width = 50; |
michael@0 | 146 | var height = 50; |
michael@0 | 147 | var buf = new Uint8Array(width * height * 4); |
michael@0 | 148 | gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
michael@0 | 149 | |
michael@0 | 150 | function checkPixel(x, y, r, g, b, a) { |
michael@0 | 151 | var offset = (y * width + x) * 4; |
michael@0 | 152 | if (buf[offset + 0] != r || |
michael@0 | 153 | buf[offset + 1] != g || |
michael@0 | 154 | buf[offset + 2] != b || |
michael@0 | 155 | buf[offset + 3] != a) { |
michael@0 | 156 | fail(x, y, buf, "(" + r + "," + g + "," + b + "," + a + ")"); |
michael@0 | 157 | return false; |
michael@0 | 158 | } |
michael@0 | 159 | return true; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | // Test several locations |
michael@0 | 163 | // First line should be all black |
michael@0 | 164 | var success = true; |
michael@0 | 165 | for (var i = 0; i < 50; ++i) |
michael@0 | 166 | success = success && checkPixel(i, 0, 0, 0, 0, 255); |
michael@0 | 167 | |
michael@0 | 168 | // Line 15 should be red for at least 10 rgba pixels starting 20 pixels in |
michael@0 | 169 | var offset = (15 * 50 + 20) * 4; |
michael@0 | 170 | for (var i = 0; i < 10; ++i) |
michael@0 | 171 | success = success && checkPixel(20 + i, 15, r, g, b, a); |
michael@0 | 172 | |
michael@0 | 173 | // Last line should be all black |
michael@0 | 174 | for (var i = 0; i < 50; ++i) |
michael@0 | 175 | success = success && checkPixel(i, 49, 0, 0, 0, 255); |
michael@0 | 176 | |
michael@0 | 177 | if (success) |
michael@0 | 178 | pass(); |
michael@0 | 179 | |
michael@0 | 180 | gl.disableVertexAttribArray(positionLocation); |
michael@0 | 181 | gl.disableVertexAttribArray(colorLocation); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | setBindLocations(2, 3); |
michael@0 | 185 | checkDraw(2, 3, 0, 255, 0, 255); |
michael@0 | 186 | |
michael@0 | 187 | setBindLocations(0, 3); |
michael@0 | 188 | gl.disableVertexAttribArray(0); |
michael@0 | 189 | gl.vertexAttrib4f(0, 1, 0, 0, 1); |
michael@0 | 190 | checkDraw(0, 3, 255, 0, 0, 255); |
michael@0 | 191 | |
michael@0 | 192 | glErrorShouldBe(gl, gl.NO_ERROR); |
michael@0 | 193 | |
michael@0 | 194 | debug(""); |
michael@0 | 195 | successfullyParsed = true; |
michael@0 | 196 | |
michael@0 | 197 | </script> |
michael@0 | 198 | <script>finishTest();</script> |
michael@0 | 199 | |
michael@0 | 200 | </body> |
michael@0 | 201 | </html> |