4 ** Copyright (c) 2012 The Khronos Group Inc.
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 <meta charset="utf-8">
32 <title>WebGL BindAttribLocation Long Names Conformance Tests</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../resources/webgl-test-utils.js"></script>
38 <div id="description"></div>
39 <div id="console"></div>
40 <canvas style="border: 1px solid black;" id="canvas" width="50" height="50"></canvas>
41 <script id="vshader" type="text/something-not-javascript">
42 attribute vec4 vPosition$(suffix);
43 attribute vec4 vColor$(suffix);
47 gl_Position = vPosition$(suffix);
48 color = vColor$(suffix);
51 <script id="fshader" type="text/something-not-javascript">
52 precision mediump float;
62 description("This test checks using long names with bindAttribLocation work.");
65 debug("Canvas.getContext");
67 var wtu = WebGLTestUtils;
68 var gl = wtu.create3DContext("canvas");
69 shouldBeNonNull("gl");
71 function fail(x,y, buf, shouldBe)
74 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
80 testPassed("drawing is correct");
84 debug("Checking gl.bindAttribLocation with long names.");
86 var program = gl.createProgram();
89 for (var ii = 0; ii < 5; ++ii) {
90 suffix = suffix + suffix;
96 var vsrc = wtu.replaceParams(wtu.getScript("vshader"), replacements);
97 var fsrc = wtu.replaceParams(wtu.getScript("fshader"), replacements);
99 var vs = wtu.loadShader(gl, vsrc, gl.VERTEX_SHADER);
100 var fs = wtu.loadShader(gl, fsrc, gl.FRAGMENT_SHADER);
103 vPosition: "vPosition" + suffix,
104 vColor: "vColor" + suffix
107 gl.attachShader(program, vs);
108 gl.attachShader(program, fs);
110 var positions = gl.createBuffer();
111 gl.bindBuffer(gl.ARRAY_BUFFER, positions);
123 var colors = gl.createBuffer();
124 gl.bindBuffer(gl.ARRAY_BUFFER, colors);
136 function setBindLocations(colorLocation, positionLocation) {
137 gl.bindAttribLocation(program, positionLocation, attribs.vPosition);
138 gl.bindAttribLocation(program, colorLocation, attribs.vColor);
139 gl.linkProgram(program);
140 gl.useProgram(program);
141 var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
142 assertMsg(linked, "program linked successfully");
144 debug("vPosition:" + gl.getAttribLocation(program, attribs.vPosition))
145 debug("vColor :" + gl.getAttribLocation(program, attribs.vColor))
146 assertMsg(gl.getAttribLocation(program, attribs.vPosition) == positionLocation,
147 "location of vPosition should be " + positionLocation);
148 assertMsg(gl.getAttribLocation(program, attribs.vColor) == colorLocation,
149 "location of vColor should be " + colorLocation);
151 var ploc = gl.getAttribLocation(program, attribs.vPosition);
152 var cloc = gl.getAttribLocation(program, attribs.vColor);
153 gl.bindBuffer(gl.ARRAY_BUFFER, positions);
154 gl.enableVertexAttribArray(positionLocation);
155 gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
156 gl.bindBuffer(gl.ARRAY_BUFFER, colors);
157 gl.enableVertexAttribArray(colorLocation);
158 gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
161 function checkDraw(colorLocation, positionLocation, r, g, b, a) {
162 wtu.clearAndDrawUnitQuad(gl);
163 wtu.checkCanvas(gl, [r, g, b, a], "should be green");
165 gl.disableVertexAttribArray(positionLocation);
166 gl.disableVertexAttribArray(colorLocation);
169 setBindLocations(2, 3);
170 checkDraw(2, 3, 0, 255, 0, 255);
172 setBindLocations(0, 3);
173 gl.disableVertexAttribArray(0);
174 gl.vertexAttrib4f(0, 1, 0, 0, 1);
175 checkDraw(0, 3, 255, 0, 0, 255);
177 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
180 var successfullyParsed = true;
183 <script src="../../resources/js-test-post.js"></script>