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.
10 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
11 <script src=
"../../js/js-test-pre.js"></script>
12 <script src=
"../../js/webgl-test-utils.js"></script>
13 <title>bindAttribLocation with nonexistent attribute name
</title>
16 <div id=
"description"></div>
17 <div id=
"console"></div>
18 <canvas id=
"canvas" width=
"8" height=
"8"></canvas>
19 <script id=
"vertexShader" type=
"text/something-not-javascript">
20 precision highp float;
23 gl_Position = vec4(attr);
28 description("This test verifies that calling bindAttribLocation with a non-existent attribute location is fine.");
30 // OpenGL ES 2.0.25 section 2.10 page 34.
32 var wtu
= WebGLTestUtils
;
33 var canvas
= document
.getElementById("canvas");
34 var gl
= wtu
.create3DContext(canvas
);
35 var fragmentShader
= wtu
.loadShader(gl
, wtu
.simpleColorFragmentShader
, gl
.FRAGMENT_SHADER
);
36 var vertexShader
= wtu
.loadShaderFromScript(gl
, 'vertexShader', gl
.VERTEX_SHADER
);
37 assertMsg(vertexShader
!= null, "Vertex shader compiled successfully.");
39 var checkAttribLocation = function(program
, expectedLocation
) {
40 var location
= gl
.getAttribLocation(program
, 'attr');
41 if (location
!= expectedLocation
) {
42 testFailed('Unexpected location for attr: ' + location
);
44 testPassed('Location of attr is: ' + location
);
48 var testProgramNonExistentAttributeBound = function() {
49 var program
= gl
.createProgram();
50 gl
.bindAttribLocation(program
, 0, 'attr');
51 gl
.bindAttribLocation(program
, 1, 'bogus_attr');
52 gl
.attachShader(program
, vertexShader
);
53 gl
.attachShader(program
, fragmentShader
);
54 gl
.linkProgram(program
);
55 var linkStatus
= gl
.getProgramParameter(program
, gl
.LINK_STATUS
);
56 expectTrue(linkStatus
, "Link should succeed even if a non-existent attribute is bound.");
58 checkAttribLocation(program
, 0);
61 var testProgramNonExistentAttributeOverlap = function() {
62 var program
= gl
.createProgram();
63 gl
.bindAttribLocation(program
, 1, 'attr');
64 gl
.bindAttribLocation(program
, 1, 'bogus_attr');
65 gl
.attachShader(program
, vertexShader
);
66 gl
.attachShader(program
, fragmentShader
);
67 gl
.linkProgram(program
);
68 var linkStatus
= gl
.getProgramParameter(program
, gl
.LINK_STATUS
);
69 expectTrue(linkStatus
, "Link should succeed even if a non-existent attribute is bound to the same location as an attribute that's present in the shader text.");
71 checkAttribLocation(program
, 1);
75 testProgramNonExistentAttributeBound();
76 testProgramNonExistentAttributeOverlap();
78 var successfullyParsed
= true;
80 <script src=
"../../js/js-test-post.js"></script>