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

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

mercurial