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 <meta charset=
"utf-8">
11 <title>WebGL BindAttribLocation Long Names Conformance Tests
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas style=
"border: 1px solid black;" id=
"canvas" width=
"50" height=
"50"></canvas>
20 <script id=
"vshader" type=
"text/something-not-javascript">
21 attribute vec4 vPosition$(suffix);
22 attribute vec4 vColor$(suffix);
26 gl_Position = vPosition$(suffix);
27 color = vColor$(suffix);
30 <script id=
"fshader" type=
"text/something-not-javascript">
31 precision mediump float;
41 description("This test checks using long names with bindAttribLocation work.");
44 debug("Canvas.getContext");
46 var wtu
= WebGLTestUtils
;
47 var gl
= wtu
.create3DContext("canvas");
48 shouldBeNonNull("gl");
51 debug("Checking gl.bindAttribLocation with long names.");
53 var program
= gl
.createProgram();
56 for (var ii
= 0; ii
< 5; ++ii
) {
57 suffix
= suffix
+ suffix
;
63 var vsrc
= wtu
.replaceParams(wtu
.getScript("vshader"), replacements
);
64 var fsrc
= wtu
.replaceParams(wtu
.getScript("fshader"), replacements
);
66 var vs
= wtu
.loadShader(gl
, vsrc
, gl
.VERTEX_SHADER
);
67 var fs
= wtu
.loadShader(gl
, fsrc
, gl
.FRAGMENT_SHADER
);
70 vPosition
: "vPosition" + suffix
,
71 vColor
: "vColor" + suffix
74 gl
.attachShader(program
, vs
);
75 gl
.attachShader(program
, fs
);
77 var positions
= gl
.createBuffer();
78 gl
.bindBuffer(gl
.ARRAY_BUFFER
, positions
);
90 var colors
= gl
.createBuffer();
91 gl
.bindBuffer(gl
.ARRAY_BUFFER
, colors
);
103 function setBindLocations(colorLocation
, positionLocation
) {
104 gl
.bindAttribLocation(program
, positionLocation
, attribs
.vPosition
);
105 gl
.bindAttribLocation(program
, colorLocation
, attribs
.vColor
);
106 gl
.linkProgram(program
);
107 gl
.useProgram(program
);
108 var linked
= (gl
.getProgramParameter(program
, gl
.LINK_STATUS
) != 0);
109 assertMsg(linked
, "program linked successfully");
111 debug("vPosition:" + gl
.getAttribLocation(program
, attribs
.vPosition
))
112 debug("vColor :" + gl
.getAttribLocation(program
, attribs
.vColor
))
113 assertMsg(gl
.getAttribLocation(program
, attribs
.vPosition
) == positionLocation
,
114 "location of vPosition should be " + positionLocation
);
115 assertMsg(gl
.getAttribLocation(program
, attribs
.vColor
) == colorLocation
,
116 "location of vColor should be " + colorLocation
);
118 var ploc
= gl
.getAttribLocation(program
, attribs
.vPosition
);
119 var cloc
= gl
.getAttribLocation(program
, attribs
.vColor
);
120 gl
.bindBuffer(gl
.ARRAY_BUFFER
, positions
);
121 gl
.enableVertexAttribArray(positionLocation
);
122 gl
.vertexAttribPointer(positionLocation
, 3, gl
.FLOAT
, false, 0, 0);
123 gl
.bindBuffer(gl
.ARRAY_BUFFER
, colors
);
124 gl
.enableVertexAttribArray(colorLocation
);
125 gl
.vertexAttribPointer(colorLocation
, 4, gl
.FLOAT
, false, 0, 0);
128 function checkDraw(colorLocation
, positionLocation
, r
, g
, b
, a
) {
129 wtu
.clearAndDrawUnitQuad(gl
);
130 wtu
.checkCanvas(gl
, [r
, g
, b
, a
], "should be green");
132 gl
.disableVertexAttribArray(positionLocation
);
133 gl
.disableVertexAttribArray(colorLocation
);
136 setBindLocations(2, 3);
137 checkDraw(2, 3, 0, 255, 0, 255);
139 setBindLocations(0, 3);
140 gl
.disableVertexAttribArray(0);
141 gl
.vertexAttrib4f(0, 1, 0, 0, 1);
142 checkDraw(0, 3, 255, 0, 0, 255);
144 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
147 var successfullyParsed
= true;
150 <script src=
"../../js/js-test-post.js"></script>