Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="utf-8"> |
michael@0 | 5 | <title>WebGL attrib location length tests</title> |
michael@0 | 6 | <link rel="stylesheet" href="../../../resources/js-test-style.css"/> |
michael@0 | 7 | <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/> |
michael@0 | 8 | <script src="../../../resources/js-test-pre.js"></script> |
michael@0 | 9 | <script src="../../resources/webgl-test.js"> </script> |
michael@0 | 10 | <script src="../../resources/webgl-test-utils.js"> </script> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <canvas id="example" width="50" height="50"> |
michael@0 | 14 | There is supposed to be an example drawing here, but it's not important. |
michael@0 | 15 | </canvas> |
michael@0 | 16 | <div id="description">Verify limits on the lengths of attribute locations per WebGL spec, "Maximum Uniform and Attribute Location Lengths".</div> |
michael@0 | 17 | <div id="console"></div> |
michael@0 | 18 | <script id="goodVertexShader" type="x-shader/x-vertex"> |
michael@0 | 19 | // A vertex shader where the needed attrib location is exactly 256 characters. |
michael@0 | 20 | attribute vec4 vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456; |
michael@0 | 21 | |
michael@0 | 22 | void main() |
michael@0 | 23 | { |
michael@0 | 24 | gl_Position = vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456; |
michael@0 | 25 | } |
michael@0 | 26 | </script> |
michael@0 | 27 | <script id="badVertexShader" type="x-shader/x-vertex"> |
michael@0 | 28 | // A vertex shader where the needed attrib location is 257 characters. |
michael@0 | 29 | attribute vec4 vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567; |
michael@0 | 30 | |
michael@0 | 31 | void main() |
michael@0 | 32 | { |
michael@0 | 33 | gl_Position = vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567; |
michael@0 | 34 | } |
michael@0 | 35 | </script> |
michael@0 | 36 | <script id="fragmentShader" type="x-shader/x-fragment"> |
michael@0 | 37 | precision mediump float; |
michael@0 | 38 | |
michael@0 | 39 | void main() { |
michael@0 | 40 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
michael@0 | 41 | } |
michael@0 | 42 | </script> |
michael@0 | 43 | <script> |
michael@0 | 44 | if (window.initNonKhronosFramework) { |
michael@0 | 45 | window.initNonKhronosFramework(false); |
michael@0 | 46 | } |
michael@0 | 47 | description("test attrib location length limit"); |
michael@0 | 48 | |
michael@0 | 49 | var wtu = WebGLTestUtils; |
michael@0 | 50 | var gl = wtu.create3DContext("example"); |
michael@0 | 51 | |
michael@0 | 52 | debug("Test attrib location underneath the length limit"); |
michael@0 | 53 | var program = wtu.loadProgramFromScript(gl, "goodVertexShader", "fragmentShader"); |
michael@0 | 54 | shouldBe('gl.getProgramParameter(program, gl.LINK_STATUS)', 'true'); |
michael@0 | 55 | var attribLoc = gl.getAttribLocation(program, "vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456"); |
michael@0 | 56 | if (attribLoc == -1) { |
michael@0 | 57 | testFailed("attrib location was -1, should not be"); |
michael@0 | 58 | } else { |
michael@0 | 59 | testPassed("attrib location should not be -1"); |
michael@0 | 60 | } |
michael@0 | 61 | wtu.glErrorShouldBe(gl, gl.NONE); |
michael@0 | 62 | |
michael@0 | 63 | debug("Test attrib location over the length limit"); |
michael@0 | 64 | debug("Shader compilation or link should fail"); |
michael@0 | 65 | shouldBe('wtu.loadProgramFromScriptExpectError(gl, "badVertexShader", "fragmentShader")', 'null'); |
michael@0 | 66 | wtu.glErrorShouldBe(gl, gl.NONE); |
michael@0 | 67 | |
michael@0 | 68 | debug("Attempt to bind too-long attrib location should produce error"); |
michael@0 | 69 | program = gl.createProgram(); |
michael@0 | 70 | gl.bindAttribLocation(program, 0, "vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"); |
michael@0 | 71 | wtu.glErrorShouldBe(gl, gl.INVALID_VALUE); |
michael@0 | 72 | |
michael@0 | 73 | debug("Attempt to fetch too-long attrib location should produce error"); |
michael@0 | 74 | program = wtu.loadStandardProgram(gl); |
michael@0 | 75 | shouldBe('gl.getAttribLocation(program, "vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567")', '-1'); |
michael@0 | 76 | wtu.glErrorShouldBe(gl, gl.INVALID_VALUE); |
michael@0 | 77 | |
michael@0 | 78 | successfullyParsed = true; |
michael@0 | 79 | </script> |
michael@0 | 80 | <script>finishTest();</script> |
michael@0 | 81 | </body> |
michael@0 | 82 | </html> |