content/canvas/test/webgl-conformance/conformance/glsl/misc/glsl-function-nodes.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

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="vshaderFunction", type="x-shader/x-vertex">
michael@0 18 attribute vec4 aPosition;
michael@0 19 varying vec4 vColor;
michael@0 20
michael@0 21 float sign_emu(float value) {
michael@0 22 if (value == 0.0) return 0.0;
michael@0 23 return value > 0.0 ? 1.0 : -1.0;
michael@0 24 }
michael@0 25
michael@0 26 void main()
michael@0 27 {
michael@0 28 gl_Position = aPosition;
michael@0 29 vec2 texcoord = vec2(aPosition.xy * 0.5 + vec2(0.5, 0.5));
michael@0 30 vec4 color = vec4(
michael@0 31 texcoord,
michael@0 32 texcoord.x * texcoord.y,
michael@0 33 (1.0 - texcoord.x) * texcoord.y * 0.5 + 0.5);
michael@0 34 vColor = vec4(
michael@0 35 sign_emu(color.x * 2.0 - 1.0) * 0.5 + 0.5,
michael@0 36 sign_emu(color.y * 2.0 - 1.0) * 0.5 + 0.5,
michael@0 37 0,
michael@0 38 1);
michael@0 39 }
michael@0 40 </script>
michael@0 41
michael@0 42 <script id="vshaderMacro", type="x-shader/x-vertex">
michael@0 43 attribute vec4 aPosition;
michael@0 44 varying vec4 vColor;
michael@0 45
michael@0 46 #define sign_emu(value) ((value) == 0.0 ? 0.0 : ((value) > 0.0 ? 1.0 : -1.0))
michael@0 47
michael@0 48 void main()
michael@0 49 {
michael@0 50 gl_Position = aPosition;
michael@0 51 vec2 texcoord = vec2(aPosition.xy * 0.5 + vec2(0.5, 0.5));
michael@0 52 vec4 color = vec4(
michael@0 53 texcoord,
michael@0 54 texcoord.x * texcoord.y,
michael@0 55 (1.0 - texcoord.x) * texcoord.y * 0.5 + 0.5);
michael@0 56 vColor = vec4(
michael@0 57 sign_emu(color.x * 2.0 - 1.0) * 0.5 + 0.5,
michael@0 58 sign_emu(color.y * 2.0 - 1.0) * 0.5 + 0.5,
michael@0 59 0,
michael@0 60 1);
michael@0 61 }
michael@0 62 </script>
michael@0 63
michael@0 64 <script id="fshader", type="x-shader/x-fragment">
michael@0 65 #if defined(GL_ES)
michael@0 66 precision mediump float;
michael@0 67 #endif
michael@0 68 varying vec4 vColor;
michael@0 69 void main()
michael@0 70 {
michael@0 71 gl_FragColor = vColor;
michael@0 72 }
michael@0 73 </script>
michael@0 74 </head>
michael@0 75 <body>
michael@0 76 <canvas id="canvasFunction" width="50" height="50"></canvas>
michael@0 77 <canvas id="canvasMacro" width="50" height="50"></canvas>
michael@0 78 <div id="description">This tests against a Mac driver bug related to function calls.</div>
michael@0 79 <div id="console"></div>
michael@0 80 <script>
michael@0 81 var width = 50;
michael@0 82 var height = 50;
michael@0 83
michael@0 84 function drawAndRead(canvasID, vshaderID, buffer)
michael@0 85 {
michael@0 86 var gl = initWebGL(canvasID, vshaderID, "fshader", ["aPosition"], [0, 0, 0, 1], 1);
michael@0 87 var vertexObject = gl.createBuffer();
michael@0 88 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
michael@0 89 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 90 gl.enableVertexAttribArray(0);
michael@0 91 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
michael@0 92
michael@0 93 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
michael@0 94 gl.drawArrays(gl.TRIANGLES, 0, 3);
michael@0 95 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
michael@0 96 if (gl.getError() != gl.NO_ERROR)
michael@0 97 return false;
michael@0 98 return true;
michael@0 99 }
michael@0 100
michael@0 101 function compareRendering(buffer1, buffer2, tol)
michael@0 102 {
michael@0 103 for (var i = 0; i < width * height * 4; ++i) {
michael@0 104 if (Math.abs(buffer1[i] - buffer2[i]) > tol)
michael@0 105 return false;
michael@0 106 }
michael@0 107 return true;
michael@0 108 }
michael@0 109
michael@0 110 function init()
michael@0 111 {
michael@0 112 if (window.initNonKhronosFramework) {
michael@0 113 window.initNonKhronosFramework(false);
michael@0 114 }
michael@0 115
michael@0 116 description("tests function nodes");
michael@0 117
michael@0 118 var bufFunction = new Uint8Array(width * height * 4);
michael@0 119 var bufMacro = new Uint8Array(width * height * 4);
michael@0 120
michael@0 121 if (drawAndRead("canvasFunction", "vshaderFunction", bufFunction) == false ||
michael@0 122 drawAndRead("canvasMacro", "vshaderMacro", bufMacro) == false) {
michael@0 123 testFailed("Setup failed");
michael@0 124 } else {
michael@0 125 if (compareRendering(bufFunction, bufMacro, 4) == false)
michael@0 126 testFailedRender("Rendering results are different", bufMacro,
michael@0 127 bufFunction, width, height);
michael@0 128 else
michael@0 129 testPassed("Rendering results are the same");
michael@0 130 }
michael@0 131 }
michael@0 132
michael@0 133 init();
michael@0 134 successfullyParsed = true;
michael@0 135 </script>
michael@0 136 <script>finishTest();</script>
michael@0 137 </body>
michael@0 138 </html>
michael@0 139

mercurial