attrib-location-length-limits.html (7996B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>WebGL attrib location length tests</title> 12 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 13 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/> 14 <script src="../../js/js-test-pre.js"></script> 15 <script src="../../js/webgl-test-utils.js"> </script> 16 </head> 17 <body> 18 <canvas id="example" width="50" height="50"> 19 There is supposed to be an example drawing here, but it's not important. 20 </canvas> 21 <div id="description">Verify limits on the lengths of attribute locations per WebGL 2 spec "Maximum Uniform and Attribute Location Lengths"</div> 22 <div id="console"></div> 23 <script id="goodVertexShader" type="x-shader/x-vertex"> 24 // A vertex shader where the needed attrib location is exactly 1024 characters. 25 attribute vec4 vPosition1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345; 26 void main() 27 { 28 gl_Position = vPosition1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345; 29 } 30 </script> 31 <script id="badVertexShader" type="x-shader/x-vertex"> 32 // A vertex shader where the needed attrib location is 1025 characters. 33 attribute vec4 vPosition12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456; 34 35 void main() 36 { 37 gl_Position = vPosition12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456; 38 } 39 </script> 40 <script id="fragmentShader" type="x-shader/x-fragment"> 41 precision mediump float; 42 43 void main() { 44 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); 45 } 46 </script> 47 <script> 48 "use strict"; 49 description("test attrib location length limit"); 50 51 var wtu = WebGLTestUtils; 52 var gl = wtu.create3DContext("example", undefined, 2); 53 54 debug("Test attrib location underneath the length limit"); 55 var program = wtu.loadProgramFromScript(gl, "goodVertexShader", "fragmentShader"); 56 shouldBe('gl.getProgramParameter(program, gl.LINK_STATUS)', 'true'); 57 var attrib1024Name = "vPosition1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"; 58 gl.bindAttribLocation(program, 0, attrib1024Name); 59 wtu.glErrorShouldBe(gl, gl.NONE); 60 var attribLoc = gl.getAttribLocation(program, attrib1024Name); 61 if (attribLoc == -1) { 62 testFailed("attrib location was -1, should not be"); 63 } else { 64 testPassed("attrib location should not be -1"); 65 } 66 wtu.glErrorShouldBe(gl, gl.NONE); 67 68 debug("Test attrib length over the length limit"); 69 var attrib1025Name = attrib1024Name + "6"; 70 71 debug("Shader compilation or link should fail"); 72 shouldBe('wtu.loadProgramFromScriptExpectError(gl, "badVertexShader", "fragmentShader")', 'null'); 73 wtu.glErrorShouldBe(gl, gl.NONE); 74 75 debug("Attempt to bind too-long attrib location should produce error"); 76 program = gl.createProgram(); 77 gl.bindAttribLocation(program, 0, attrib1025Name); 78 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE); 79 80 debug("Attempt to fetch too-long attrib location should produce error"); 81 program = wtu.loadStandardProgram(gl); 82 shouldBe('gl.getAttribLocation(program, attrib1025Name)', '-1'); 83 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE); 84 85 var successfullyParsed = true; 86 </script> 87 <script src="../../js/js-test-post.js"></script> 88 </body> 89 </html>