5 <title>WebGL attrib location length tests
</title>
6 <script src=
"../../../resources/js-test.js"></script>
7 <script src=
"resources/webgl-test.js"> </script>
8 <script src=
"resources/webgl-test-utils.js"> </script>
11 <canvas id=
"example" width=
"50" height=
"50">
12 There is supposed to be an example drawing here, but it's not important.
14 <div id=
"description">Verify limits on the lengths of attrib locations.
</div>
15 <div id=
"console"></div>
16 <script id=
"goodVertexShader1" type=
"x-shader/x-vertex">
17 // A vertex shader where the needed attrib location is long, but not over the limit.
18 attribute vec4 vPosition01234567890123456789012345678901234567890123456789012345678901234567890;
22 gl_Position = vPosition01234567890123456789012345678901234567890123456789012345678901234567890;
25 <script id=
"goodVertexShader2" type=
"x-shader/x-vertex">
26 // A vertex shader where the needed attrib location is exactly
256 characters.
27 attribute vec4 vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
31 gl_Position = vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
34 <script id=
"badVertexShader" type=
"x-shader/x-vertex">
35 // A vertex shader where the needed attrib location is
257 characters.
36 attribute vec4 vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567;
40 gl_Position = vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567;
43 <script id=
"fragmentShader" type=
"x-shader/x-fragment">
44 precision mediump float;
47 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
51 if (window
.initNonKhronosFramework
) {
52 window
.initNonKhronosFramework(false);
55 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
57 var wtu
= WebGLTestUtils
;
58 var gl
= wtu
.create3DContext(document
.getElementById("example"));
60 debug("Test attrib location underneath the length limit");
61 var program
= wtu
.loadProgramFromScript(gl
, "goodVertexShader1", "fragmentShader");
62 shouldBe('gl.getProgramParameter(program, gl.LINK_STATUS)', 'true');
63 var attribLoc
= gl
.getAttribLocation(program
, "vPosition01234567890123456789012345678901234567890123456789012345678901234567890");
64 if (attribLoc
== -1) {
65 testFailed("attrib location was -1, should not be");
67 testPassed("attrib location should not be -1");
69 wtu
.glErrorShouldBe(gl
, gl
.NONE
);
71 debug("Test attrib location exactly at the length limit");
72 var program
= wtu
.loadProgramFromScript(gl
, "goodVertexShader2", "fragmentShader");
73 shouldBe('gl.getProgramParameter(program, gl.LINK_STATUS)', 'true');
74 var attribLoc
= gl
.getAttribLocation(program
, "vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456");
75 if (attribLoc
== -1) {
76 testFailed("attrib location was -1, should not be");
78 testPassed("attrib location should not be -1");
80 wtu
.glErrorShouldBe(gl
, gl
.NONE
);
82 debug("Test attrib location over the length limit");
83 debug("Shader compilation should fail");
84 shouldBe('wtu.loadShaderFromScript(gl, "badVertexShader", gl.VERTEX_SHADER, function (err) {})', 'null');
85 wtu
.glErrorShouldBe(gl
, gl
.NONE
);
87 debug("Attempt to bind too-long attrib location should produce error");
88 var program
= gl
.createProgram();
89 gl
.bindAttribLocation(program
, 0, "vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567");
90 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
);
92 debug("Attempt to fetch too-long attrib location should produce error");
93 shouldBe('gl.getAttribLocation(program, "vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567")', '-1');
94 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
);