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.)

     1 <!--
     2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
     3 Use of this source code is governed by a BSD-style license that can be
     4 found in the LICENSE file.
     5  -->
     6 <!DOCTYPE html>
     7 <html>
     8 <head>
     9 <meta charset="utf-8">
    10 <title>GLSL function nodes Test</title>
    11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
    12 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/>
    13 <script src="../../../resources/js-test-pre.js"></script>
    14 <script src="../../resources/webgl-test.js"> </script>
    15 <script src="../../resources/webgl-test-utils.js"> </script>
    17 <script id="vshaderFunction", type="x-shader/x-vertex">
    18 attribute vec4 aPosition;
    19 varying vec4 vColor;
    21 float sign_emu(float value) {
    22   if (value == 0.0) return 0.0;
    23   return value > 0.0 ? 1.0 : -1.0;
    24 }
    26 void main()
    27 {
    28    gl_Position = aPosition;
    29    vec2 texcoord = vec2(aPosition.xy * 0.5 + vec2(0.5, 0.5));
    30    vec4 color = vec4(
    31        texcoord,
    32        texcoord.x * texcoord.y,
    33        (1.0 - texcoord.x) * texcoord.y * 0.5 + 0.5);
    34    vColor = vec4(
    35     sign_emu(color.x * 2.0 - 1.0) * 0.5 + 0.5,
    36     sign_emu(color.y * 2.0 - 1.0) * 0.5 + 0.5,
    37     0,
    38     1);
    39 }
    40 </script>
    42 <script id="vshaderMacro", type="x-shader/x-vertex">
    43 attribute vec4 aPosition;
    44 varying vec4 vColor;
    46 #define sign_emu(value) ((value) == 0.0 ? 0.0 : ((value) > 0.0 ? 1.0 : -1.0))
    48 void main()
    49 {
    50    gl_Position = aPosition;
    51    vec2 texcoord = vec2(aPosition.xy * 0.5 + vec2(0.5, 0.5));
    52    vec4 color = vec4(
    53        texcoord,
    54        texcoord.x * texcoord.y,
    55        (1.0 - texcoord.x) * texcoord.y * 0.5 + 0.5);
    56    vColor = vec4(
    57     sign_emu(color.x * 2.0 - 1.0) * 0.5 + 0.5,
    58     sign_emu(color.y * 2.0 - 1.0) * 0.5 + 0.5,
    59     0,
    60     1);
    61 }
    62 </script>
    64 <script id="fshader", type="x-shader/x-fragment">
    65 #if defined(GL_ES)
    66 precision mediump float;
    67 #endif
    68 varying vec4 vColor;
    69 void main()
    70 {
    71    gl_FragColor = vColor;
    72 }
    73 </script>
    74 </head>
    75 <body>
    76 <canvas id="canvasFunction" width="50" height="50"></canvas>
    77 <canvas id="canvasMacro" width="50" height="50"></canvas>
    78 <div id="description">This tests against a Mac driver bug related to function calls.</div>
    79 <div id="console"></div>
    80 <script>
    81 var width = 50;
    82 var height = 50;
    84 function drawAndRead(canvasID, vshaderID, buffer)
    85 {
    86     var gl = initWebGL(canvasID, vshaderID, "fshader", ["aPosition"], [0, 0, 0, 1], 1);
    87     var vertexObject = gl.createBuffer();
    88     gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
    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);
    90     gl.enableVertexAttribArray(0);
    91     gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
    93     gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    94     gl.drawArrays(gl.TRIANGLES, 0, 3);
    95     gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
    96     if (gl.getError() != gl.NO_ERROR)
    97         return false;
    98     return true;
    99 }
   101 function compareRendering(buffer1, buffer2, tol)
   102 {
   103     for (var i = 0; i < width * height * 4; ++i) {
   104         if (Math.abs(buffer1[i] - buffer2[i]) > tol)
   105             return false;
   106     }
   107     return true;
   108 }
   110 function init()
   111 {
   112     if (window.initNonKhronosFramework) {
   113         window.initNonKhronosFramework(false);
   114     }
   116     description("tests function nodes");
   118     var bufFunction = new Uint8Array(width * height * 4);
   119     var bufMacro = new Uint8Array(width * height * 4);
   121     if (drawAndRead("canvasFunction", "vshaderFunction", bufFunction) == false ||
   122         drawAndRead("canvasMacro", "vshaderMacro", bufMacro) == false) {
   123         testFailed("Setup failed");
   124     } else {
   125         if (compareRendering(bufFunction, bufMacro, 4) == false)
   126             testFailedRender("Rendering results are different", bufMacro,
   127                              bufFunction, width, height);
   128         else
   129             testPassed("Rendering results are the same");
   130     }
   131 }
   133 init();
   134 successfullyParsed = true;
   135 </script>
   136 <script>finishTest();</script>
   137 </body>
   138 </html>

mercurial