content/canvas/test/webgl-conformance/conformance/glsl/misc/glsl-long-variable-names.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 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <meta charset="utf-8">
     5     <title>glsl long variable name mapping tests</title>
     6     <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     7     <script src="../../../resources/js-test-pre.js"></script>
     8     <script src="../../resources/webgl-test.js"> </script>
     9 </head>
    10 <body>
    11     <canvas id="example" width="50" height="50">
    12     There is supposed to be an example drawing here, but it's not important.
    13     </canvas>
    14     <div id="description"></div>
    15     <div id="console"></div>
    16     <script id="vshader_shared_uniform" type="x-shader/x-vertex">
    17         attribute vec3 vPosition;
    18         uniform mediump float value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;
    19         void main()
    20         {
    21             gl_Position = vec4(vPosition, value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890);
    22         }
    23     </script>
    25     <script id="fshader_shared_uniform" type="x-shader/x-fragment">
    26         precision mediump float;
    27         uniform float value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;
    28         void main()
    29         {
    30             gl_FragColor = vec4(1.0, 0.0, value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890, 1.0);
    31         }
    32     </script>
    34     <script id="vshader_uniform_array" type="x-shader/x-vertex">
    35         attribute vec3 vPosition;
    36         void main()
    37         {
    38             gl_Position = vec4(vPosition, 1.0);
    39         }
    40     </script>
    42     <script id="fshader_uniform_array" type="x-shader/x-fragment">
    43         precision mediump float;
    44         uniform float color01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567[2];
    45         void main()
    46         {
    47             gl_FragColor = vec4(color01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567[0], color01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567[1], 1.0, 1.0);
    48         }
    49     </script>
    51     <script id="vshader_varying" type="x-shader/x-vertex">
    52         attribute vec3 vPosition;
    53         varying float value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;
    54         void main()
    55         {
    56             value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 = 1.0;
    57             gl_Position = vec4(vPosition, 1.0);
    58         }
    59     </script>
    61     <script id="fshader_varying" type="x-shader/x-fragment">
    62         precision mediump float;
    63         varying float value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;
    64         void main()
    65         {
    66             gl_FragColor = vec4(value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890, 0.0, 1.0, 1.0);
    67         }
    68     </script>
    70     <script id="vshader_local" type="x-shader/x-vertex">
    71         attribute vec3 vPosition;
    72         void main()
    73         {
    74             for (int i012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234 = 0; i012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234 < 1; ++i012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234)
    75             {
    76                 gl_Position = vec4(vPosition, 1.0);
    77             }
    78         }
    79     </script>
    81     <script id="fshader_local" type="x-shader/x-fragment">
    82         precision mediump float;
    83         void main()
    84         {
    85             for (int i012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234 = 0; i012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234 < 1; ++i012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234)
    86             {
    87                 gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);
    88             }
    89         }
    90     </script>
    92     <script id="vshader_attrib" type="x-shader/x-vertex">
    93         attribute vec3 vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
    94         void main()
    95         {
    96             gl_Position = vec4(vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456, 1.0);
    97         }
    98     </script>
   100     <script id="fshader_attrib" type="x-shader/x-fragment">
   101         precision mediump float;
   102         void main()
   103         {
   104             gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);
   105         }
   106     </script>
   108     <script>
   109         if (window.initNonKhronosFramework) {
   110             window.initNonKhronosFramework(false);
   111         }
   113         description("Verify that shader long variable names works fine if they are within 256 characters.");
   115         debug("Test same long uniform name in both vertex shader and fragment shader");
   116         var gl = initWebGL("example", "vshader_shared_uniform", "fshader_shared_uniform", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
   117         shouldBeNonNull("gl");
   118         shouldBe("gl.getError()", "gl.NO_ERROR");
   119         var prog = gl.getParameter(gl.CURRENT_PROGRAM);
   120         shouldBeNonNull("prog");
   121         var valueLoc = gl.getUniformLocation(prog, "value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
   122         shouldBeNonNull("valueLoc");
   123         shouldBe("gl.getProgramParameter(prog, gl.ACTIVE_UNIFORMS)", "1");
   124         var activeUniform = gl.getActiveUniform(prog, 0);
   125         shouldBeNonNull("activeUniform");
   126         shouldBe("activeUniform.type", "gl.FLOAT");
   127         shouldBe("activeUniform.size", "1");
   128         shouldBe("activeUniform.name", "'value01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'");
   129         gl.uniform1f(valueLoc, 1.0);
   130         drawAndCheckPixels(gl);
   131         shouldBe("gl.getError()", "gl.NO_ERROR");
   132         debug("");
   134         debug("Test long uniform array name");
   135         var gl = initWebGL("example", "vshader_uniform_array", "fshader_uniform_array", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
   136         shouldBeNonNull("gl");
   137         shouldBe("gl.getError()", "gl.NO_ERROR");
   138         var prog = gl.getParameter(gl.CURRENT_PROGRAM);
   139         shouldBeNonNull("prog");
   140         var redLoc = gl.getUniformLocation(prog, "color01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567[0]");
   141         shouldBeNonNull("redLoc");
   142         var greenLoc = gl.getUniformLocation(prog, "color01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567[1]");
   143         shouldBeNonNull("greenLoc");
   144         shouldBe("gl.getProgramParameter(prog, gl.ACTIVE_UNIFORMS)", "1");
   145         var activeUniform = gl.getActiveUniform(prog, 0);
   146         shouldBeNonNull("activeUniform");
   147         shouldBe("activeUniform.type", "gl.FLOAT");
   148         shouldBe("activeUniform.size", "2");
   149         shouldBe("activeUniform.name", "'color01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567[0]'");
   150         gl.uniform1f(redLoc, 1.0);
   151         gl.uniform1f(greenLoc, 0.0);
   152         drawAndCheckPixels(gl);
   153         shouldBe("gl.getError()", "gl.NO_ERROR");
   154         debug("");
   156         debug("Test long varying name");
   157         var gl = initWebGL("example", "vshader_varying", "fshader_varying", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
   158         shouldBeNonNull("gl");
   159         shouldBe("gl.getError()", "gl.NO_ERROR");
   160         var prog = gl.getParameter(gl.CURRENT_PROGRAM);
   161         shouldBeNonNull("prog");
   162         drawAndCheckPixels(gl);
   163         shouldBe("gl.getError()", "gl.NO_ERROR");
   164         debug("");
   166         debug("Test long local variable name");
   167         var gl = initWebGL("example", "vshader_varying", "fshader_varying", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
   168         shouldBeNonNull("gl");
   169         shouldBe("gl.getError()", "gl.NO_ERROR");
   170         var prog = gl.getParameter(gl.CURRENT_PROGRAM);
   171         shouldBeNonNull("prog");
   172         drawAndCheckPixels(gl);
   173         shouldBe("gl.getError()", "gl.NO_ERROR");
   174         debug("");
   176         debug("Test long attribute name");
   177         var gl = initWebGL("example", "vshader_attrib", "fshader_attrib", [ "vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456"], [ 0, 0, 0, 1 ], 1);
   178         shouldBeNonNull("gl");
   179         shouldBe("gl.getError()", "gl.NO_ERROR");
   180         var prog = gl.getParameter(gl.CURRENT_PROGRAM);
   181         shouldBeNonNull("prog");
   182         shouldBe("gl.getProgramParameter(prog, gl.ACTIVE_ATTRIBUTES)", "1");
   183         var activeAttrib = gl.getActiveAttrib(prog, 0);
   184         shouldBeNonNull("activeAttrib");
   185         shouldBe("activeAttrib.size", "1");
   186         shouldBe("activeAttrib.type", "gl.FLOAT_VEC3");
   187         shouldBe("activeAttrib.name", "'vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456'");
   188         drawAndCheckPixels(gl);
   189         shouldBe("gl.getError()", "gl.NO_ERROR");
   190         debug("");
   193         function fail(x, y, buf, shouldBe)
   194         {
   195             var i = (y*50+x) * 4;
   196             var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
   197             testFailed(reason);
   198         }
   200         function pass()
   201         {
   202             testPassed("drawing is correct");
   203         }
   205         function drawAndCheckPixels(gl)
   206         {
   207             var vertexObject = gl.createBuffer();
   208             gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
   209             gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
   210             gl.enableVertexAttribArray(0);
   211             gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
   213             gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
   214             gl.drawArrays(gl.TRIANGLES, 0, 3);
   216             var buf = new Uint8Array(50 * 50 * 4);
   217             gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf);
   219             // Test several locations
   220             // First line should be all black
   221             for (var i = 0; i < 50; ++i)
   222                 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255) {
   223                     fail(i, 0, buf, "(0,0,0,255)");
   224                     return;
   225                 }
   227             // Line 15 should be magenta for at least 10 pixels starting 20 pixels in
   228             var offset = (15*50+20) * 4;
   229             for (var i = 0; i < 10; ++i)
   230                 if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 255 || buf[offset+i*4+3] != 255) {
   231                     fail(20 + i, 15, buf, "(255,0,255,255)");
   232                     return;
   233                 }
   234             // Last line should be all black
   235             offset = (49*50) * 4;
   236             for (var i = 0; i < 50; ++i)
   237                 if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) {
   238                     fail(i, 49, buf, "(0,0,0,255)");
   239                     return;
   240                 }
   242             pass();
   243         }
   245         successfullyParsed = true;
   246     </script>
   247     <script>finishTest();</script>
   248 </body>
   249 </html>

mercurial