OLD | NEW |
(Empty) | |
| 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">Verify that shader long variable names works fine if t
hey are within 256 characters.</div> |
| 15 <div id="console"></div> |
| 16 <script id="vshader" type="x-shader/x-vertex"> |
| 17 attribute vec4 vPosition012345678901234567890123456789012345678901234567
89012345678901234567890123456789012345678901234567890123456789012345678901234567
89012345678901234567890123456789012345678901234567890123456789012345678901234567
890123456789012345678901234567890123456; |
| 18 varying float alpha01234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890; |
| 19 void main() |
| 20 { |
| 21 alpha012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
3456789012345678901234567890 = 1.0; |
| 22 gl_Position = vPosition012345678901234567890123456789012345678901234
56789012345678901234567890123456789012345678901234567890123456789012345678901234
56789012345678901234567890123456789012345678901234567890123456789012345678901234
567890123456789012345678901234567890123456; |
| 23 } |
| 24 </script> |
| 25 |
| 26 <script id="fshader" type="x-shader/x-fragment"> |
| 27 precision mediump float; |
| 28 varying float alpha01234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890; |
| 29 uniform float color01234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567[3]; |
| 30 void main() |
| 31 { |
| 32 for (int i0123456789012345678901234567890123456789012345678901234567
89012345678901234567890123456789012345678901234567890123456789012345678901234567
89012345678901234567890123456789012345678901234567890123456789012345678901234567
8901234567890123456789012345678901234 = 0; i012345678901234567890123456789012345
67890123456789012345678901234567890123456789012345678901234567890123456789012345
67890123456789012345678901234567890123456789012345678901234567890123456789012345
67890123456789012345678901234567890123456789012345678901234 < 1; ++i012345678901
23456789012345678901234567890123456789012345678901234567890123456789012345678901
23456789012345678901234567890123456789012345678901234567890123456789012345678901
23456789012345678901234567890123456789012345678901234567890123456789012345678901
234) |
| 33 { |
| 34 gl_FragColor = vec4(color012345678901234567890123456789012345678
90123456789012345678901234567890123456789012345678901234567890123456789012345678
90123456789012345678901234567890123456789012345678901234567890123456789012345678
9012345678901234567890123456789012345678901234567[0], color012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567[1], color012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567[2], alpha01234567890123456789012345678901234567890123456789012345678901234
56789012345678901234567890123456789012345678901234567890123456789012345678901234
56789012345678901234567890123456789012345678901234567890123456789012345678901234
56789012345678901234567890); |
| 35 } |
| 36 } |
| 37 </script> |
| 38 |
| 39 <script> |
| 40 function fail(x,y, buf, shouldBe) |
| 41 { |
| 42 var i = (y*50+x) * 4; |
| 43 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+b
uf[i+2]+","+buf[i+3]+"), should be "+shouldBe; |
| 44 testFailed(reason); |
| 45 } |
| 46 |
| 47 function pass() |
| 48 { |
| 49 testPassed("drawing is correct"); |
| 50 } |
| 51 |
| 52 if (window.initNonKhronosFramework) { |
| 53 window.initNonKhronosFramework(false); |
| 54 } |
| 55 |
| 56 gl = initWebGL("example", "vshader", "fshader", [ "vPosition012345678901
23456789012345678901234567890123456789012345678901234567890123456789012345678901
23456789012345678901234567890123456789012345678901234567890123456789012345678901
234567890123456789012345678901234567890123456789012345678901234567890123456"], [
0, 0, 0, 1 ], 1); |
| 57 |
| 58 var prog = gl.getParameter(gl.CURRENT_PROGRAM); |
| 59 shouldBeNonNull(prog); |
| 60 var redLoc = gl.getUniformLocation(prog, "color0123456789012345678901234
56789012345678901234567890123456789012345678901234567890123456789012345678901234
56789012345678901234567890123456789012345678901234567890123456789012345678901234
567890123456789012345678901234567890123456789012345678901234567[0]"); |
| 61 shouldBeNonNull(redLoc); |
| 62 var greenLoc = gl.getUniformLocation(prog, "color01234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567890123456789012
34567890123456789012345678901234567890123456789012345678901234567[1]"); |
| 63 shouldBeNonNull(greenLoc); |
| 64 var blueLoc = gl.getUniformLocation(prog, "color012345678901234567890123
45678901234567890123456789012345678901234567890123456789012345678901234567890123
45678901234567890123456789012345678901234567890123456789012345678901234567890123
4567890123456789012345678901234567890123456789012345678901234567[2]"); |
| 65 shouldBeNonNull(blueLoc); |
| 66 |
| 67 shouldBe("gl.getProgramParameter(prog, gl.ACTIVE_ATTRIBUTES)", "1"); |
| 68 var activeAttrib = gl.getActiveAttrib(prog, 0); |
| 69 shouldBeNonNull(activeAttrib); |
| 70 shouldBe("activeAttrib.size", "1"); |
| 71 shouldBe("activeAttrib.type", "gl.FLOAT_VEC4"); |
| 72 shouldBe("activeAttrib.name", "'vPosition0123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456'"); |
| 73 |
| 74 shouldBe("gl.getProgramParameter(prog, gl.ACTIVE_UNIFORMS)", "1"); |
| 75 var activeUniform = gl.getActiveUniform(prog, 0); |
| 76 shouldBeNonNull(activeUniform); |
| 77 shouldBe("activeUniform.size", "3"); |
| 78 shouldBe("activeUniform.type", "gl.FLOAT"); |
| 79 shouldBe("activeUniform.name", "'color0123456789012345678901234567890123
45678901234567890123456789012345678901234567890123456789012345678901234567890123
45678901234567890123456789012345678901234567890123456789012345678901234567890123
456789012345678901234567890123456789012345678901234567[0]'"); |
| 80 |
| 81 gl.uniform1f(redLoc, 1.0); |
| 82 gl.uniform1f(greenLoc, 0.0); |
| 83 gl.uniform1f(blueLoc, 1.0); |
| 84 |
| 85 var vertexObject = gl.createBuffer(); |
| 86 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 87 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0,
0.5,-0.5,0 ]), gl.STATIC_DRAW); |
| 88 gl.enableVertexAttribArray(0); |
| 89 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
| 90 |
| 91 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 92 gl.drawArrays(gl.TRIANGLES, 0, 3); |
| 93 |
| 94 var buf = new Uint8Array(50 * 50 * 4); |
| 95 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 96 shouldBe("gl.getError()", "gl.NO_ERROR"); |
| 97 |
| 98 function checkPixels() |
| 99 { |
| 100 // Test several locations |
| 101 // First line should be all black |
| 102 for (var i = 0; i < 50; ++i) |
| 103 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i
*4+3] != 255) { |
| 104 fail(i, 0, buf, "(0,0,0,255)"); |
| 105 return; |
| 106 } |
| 107 |
| 108 // Line 15 should be red for at least 10 red pixels starting 20 pixe
ls in |
| 109 var offset = (15*50+20) * 4; |
| 110 for (var i = 0; i < 10; ++i) |
| 111 if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offs
et+i*4+2] != 255 || buf[offset+i*4+3] != 255) { |
| 112 fail(20 + i, 15, buf, "(255,0,255,255)"); |
| 113 return; |
| 114 } |
| 115 // Last line should be all black |
| 116 offset = (49*50) * 4; |
| 117 for (var i = 0; i < 50; ++i) |
| 118 if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset
+i*4+2] != 0 || buf[offset+i*4+3] != 255) { |
| 119 fail(i, 49, buf, "(0,0,0,255)"); |
| 120 return; |
| 121 } |
| 122 |
| 123 pass(); |
| 124 } |
| 125 checkPixels(); |
| 126 successfullyParsed = true; |
| 127 </script> |
| 128 <script src="../../../resources/js-test-post.js"></script> |
| 129 </body> |
| 130 </html> |
OLD | NEW |