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>GLSL function nodes Test</title> |
michael@0 | 11 | <link rel="stylesheet" href="../../../resources/js-test-style.css"/> |
michael@0 | 12 | <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/> |
michael@0 | 13 | <script src="../../../resources/js-test-pre.js"></script> |
michael@0 | 14 | <script src="../../resources/webgl-test.js"> </script> |
michael@0 | 15 | <script src="../../resources/webgl-test-utils.js"> </script> |
michael@0 | 16 | |
michael@0 | 17 | <script id="vshaderNoBranch", type="x-shader/x-vertex"> |
michael@0 | 18 | attribute vec3 aPosition; |
michael@0 | 19 | uniform float redIntensity; |
michael@0 | 20 | |
michael@0 | 21 | varying vec4 vColor; |
michael@0 | 22 | |
michael@0 | 23 | float MADBug(float paramValue) { |
michael@0 | 24 | float localVar = 1.0; |
michael@0 | 25 | return 0.25 * ceil(localVar) + paramValue; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | void main(void) { |
michael@0 | 29 | gl_Position = vec4(aPosition, 1.0); |
michael@0 | 30 | vColor = vec4(MADBug(redIntensity), 0., 0., 1.); |
michael@0 | 31 | } |
michael@0 | 32 | </script> |
michael@0 | 33 | |
michael@0 | 34 | <script id="vshaderBranch", type="x-shader/x-vertex"> |
michael@0 | 35 | attribute vec3 aPosition; |
michael@0 | 36 | uniform float redIntensity; |
michael@0 | 37 | |
michael@0 | 38 | varying vec4 vColor; |
michael@0 | 39 | |
michael@0 | 40 | float MADBug(float paramValue) { |
michael@0 | 41 | float localVar = 1.0; |
michael@0 | 42 | return 0.25 * ceil(localVar) + paramValue; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | void main(void) { |
michael@0 | 46 | float condition = 42.; |
michael@0 | 47 | if (condition == 0.) {} |
michael@0 | 48 | gl_Position = vec4(aPosition, 1.0); |
michael@0 | 49 | vColor = vec4(MADBug(redIntensity), 0., 0., 1.); |
michael@0 | 50 | } |
michael@0 | 51 | </script> |
michael@0 | 52 | |
michael@0 | 53 | <script id="fshader", type="x-shader/x-fragment"> |
michael@0 | 54 | #if defined(GL_ES) |
michael@0 | 55 | precision mediump float; |
michael@0 | 56 | #endif |
michael@0 | 57 | varying vec4 vColor; |
michael@0 | 58 | void main() |
michael@0 | 59 | { |
michael@0 | 60 | gl_FragColor = vColor; |
michael@0 | 61 | } |
michael@0 | 62 | </script> |
michael@0 | 63 | </head> |
michael@0 | 64 | <body> |
michael@0 | 65 | <canvas id="canvasNoBranch" width="50" height="50"></canvas> |
michael@0 | 66 | <canvas id="canvasBranch" width="50" height="50"></canvas> |
michael@0 | 67 | <div id="description">This tests against a Mac driver bug related to branches |
michael@0 | 68 | inside of Vertex Shaders.</div> |
michael@0 | 69 | <div id="console"></div> |
michael@0 | 70 | <script> |
michael@0 | 71 | var width = 50; |
michael@0 | 72 | var height = 50; |
michael@0 | 73 | |
michael@0 | 74 | function drawAndRead(canvasID, vshaderID, buffer) |
michael@0 | 75 | { |
michael@0 | 76 | var gl = initWebGL(canvasID, vshaderID, "fshader", ["aPosition"], [0, 0, 0, 1], 1); |
michael@0 | 77 | var vertexObject = gl.createBuffer(); |
michael@0 | 78 | gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
michael@0 | 79 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -1,-1,0, 1,-1,0 ]), gl.STATIC_DRAW); |
michael@0 | 80 | gl.enableVertexAttribArray(0); |
michael@0 | 81 | gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
michael@0 | 82 | |
michael@0 | 83 | var loc = gl.getUniformLocation(gl.program, "redIntensity"); |
michael@0 | 84 | gl.uniform1f(loc, 0.75); |
michael@0 | 85 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
michael@0 | 86 | gl.drawArrays(gl.TRIANGLES, 0, 3); |
michael@0 | 87 | gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buffer); |
michael@0 | 88 | if (gl.getError() != gl.NO_ERROR) |
michael@0 | 89 | return false; |
michael@0 | 90 | return true; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function compareRendering(buffer1, buffer2, tol) |
michael@0 | 94 | { |
michael@0 | 95 | for (var i = 0; i < width * height * 4; ++i) { |
michael@0 | 96 | if (Math.abs(buffer1[i] - buffer2[i]) > tol) |
michael@0 | 97 | return false; |
michael@0 | 98 | } |
michael@0 | 99 | return true; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function init() |
michael@0 | 103 | { |
michael@0 | 104 | if (window.initNonKhronosFramework) { |
michael@0 | 105 | window.initNonKhronosFramework(false); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | description("tests vertex shader with branch"); |
michael@0 | 109 | |
michael@0 | 110 | var bufBranch = new Uint8Array(width * height * 4); |
michael@0 | 111 | var bufNoBranch = new Uint8Array(width * height * 4); |
michael@0 | 112 | |
michael@0 | 113 | if (drawAndRead("canvasBranch", "vshaderBranch", bufBranch) == false || |
michael@0 | 114 | drawAndRead("canvasNoBranch", "vshaderNoBranch", bufNoBranch) == false) { |
michael@0 | 115 | testFailed("Setup failed"); |
michael@0 | 116 | } else { |
michael@0 | 117 | if (compareRendering(bufBranch, bufNoBranch, 4) == false) |
michael@0 | 118 | testFailed("Rendering results are different"); |
michael@0 | 119 | else |
michael@0 | 120 | testPassed("Rendering results are the same"); |
michael@0 | 121 | } |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | init(); |
michael@0 | 125 | successfullyParsed = true; |
michael@0 | 126 | </script> |
michael@0 | 127 | <script>finishTest();</script> |
michael@0 | 128 | </body> |
michael@0 | 129 | </html> |
michael@0 | 130 |