6 Copyright (c) 2019 The Khronos Group Inc.
7 Use of this source code is governed by an MIT-style license that can be
8 found in the LICENSE.txt file.
10 <title>WebGL attrib location length tests
</title>
11 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
12 <link rel=
"stylesheet" href=
"../../../resources/glsl-feature-tests.css"/>
13 <script src=
"../../../js/js-test-pre.js"></script>
14 <script src=
"../../../js/webgl-test-utils.js"> </script>
17 <canvas id=
"example" width=
"50" height=
"50">
18 There is supposed to be an example drawing here, but it's not important.
20 <div id=
"description">Verify limits on the lengths of attribute locations per WebGL spec,
"Maximum Uniform and Attribute Location Lengths".
</div>
21 <div id=
"console"></div>
22 <script id=
"goodVertexShader" type=
"x-shader/x-vertex">
23 // A vertex shader where the needed attrib location is exactly
256 characters.
24 attribute vec4 vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
28 gl_Position = vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456;
31 <script id=
"badVertexShader" type=
"x-shader/x-vertex">
32 // A vertex shader where the needed attrib location is
257 characters.
33 attribute vec4 vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567;
37 gl_Position = vPosition01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567;
40 <script id=
"fragmentShader" type=
"x-shader/x-fragment">
41 precision mediump float;
44 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
49 description("test attrib location length limit");
51 var wtu
= WebGLTestUtils
;
52 var gl
= wtu
.create3DContext("example");
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 attrib256Name
= "vPosition0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";
58 gl
.bindAttribLocation(program
, 0, attrib256Name
);
59 wtu
.glErrorShouldBe(gl
, gl
.NONE
);
60 var attribLoc
= gl
.getAttribLocation(program
, attrib256Name
);
61 if (attribLoc
== -1) {
62 testFailed("attrib location was -1, should not be");
64 testPassed("attrib location should not be -1");
66 wtu
.glErrorShouldBe(gl
, gl
.NONE
);
68 debug("Test attrib location over the length limit");
69 var attrib257Name
= attrib256Name
+ "7";
71 debug("Shader compilation or link should fail");
72 shouldBe('wtu.loadProgramFromScriptExpectError(gl, "badVertexShader", "fragmentShader")', 'null');
73 wtu
.glErrorShouldBe(gl
, gl
.NONE
);
75 debug("Attempt to bind too-long attrib location should produce error");
76 program
= gl
.createProgram();
77 gl
.bindAttribLocation(program
, 0, attrib257Name
);
78 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
);
80 debug("Attempt to fetch too-long attrib location should produce error");
81 program
= wtu
.loadStandardProgram(gl
);
82 shouldBe('gl.getAttribLocation(program, attrib257Name)', '-1');
83 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
);
85 var successfullyParsed
= true;
87 <script src=
"../../../js/js-test-post.js"></script>