Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / programs / gl-bind-attrib-location-test.html
1 <!--
2
3 /*
4 ** Copyright (c) 2012 The Khronos Group Inc.
5 **
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:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
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.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset="utf-8">
32 <title>WebGL BindAttribLocation 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>
36 </head>
37 <body>
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;
43 attribute vec4 vColor;
44 varying vec4 color;
45 void main()
46 {
47   gl_Position = vPosition;
48   color = vColor;
49 }
50 </script>
51 <script id="fshader" type="text/something-not-javascript">
52 precision mediump float;
53
54 varying vec4 color;
55 void main()
56 {
57   gl_FragColor = color;
58 }
59 </script>
60 <script>
61 "use strict";
62 description("This test ensures WebGL implementations don't allow names that start with 'gl_' when calling bindAttribLocation.");
63
64 debug("");
65 debug("Canvas.getContext");
66
67 var wtu = WebGLTestUtils;
68 var gl = wtu.create3DContext("canvas");
69 shouldBeNonNull("gl");
70
71 debug("");
72 debug("Checking gl.bindAttribLocation.");
73
74 var program = gl.createProgram();
75 gl.bindAttribLocation(program, 0, "gl_foo");
76 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
77     "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'");
78 gl.bindAttribLocation(program, 0, "gl_TexCoord0");
79 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
80     "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_'");
81
82 var vs = wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER);
83 var fs = wtu.loadShaderFromScript(gl, 'fshader', gl.FRAGMENT_SHADER);
84 gl.attachShader(program, vs);
85 gl.attachShader(program, fs);
86
87 var positions = gl.createBuffer();
88 gl.bindBuffer(gl.ARRAY_BUFFER, positions);
89 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
90
91 var colors = gl.createBuffer();
92 gl.bindBuffer(gl.ARRAY_BUFFER, colors);
93 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
94     0,1,0,1,
95     0,1,0,1,
96     0,1,0,1]), gl.STATIC_DRAW);
97
98 function setBindLocations(colorLocation, positionLocation) {
99   gl.bindAttribLocation(program, positionLocation, "vPosition");
100   gl.bindAttribLocation(program, colorLocation, "vColor");
101   gl.linkProgram(program);
102   gl.useProgram(program);
103   var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
104   assertMsg(linked, "program linked successfully");
105
106   debug("vPosition:" + gl.getAttribLocation(program, "vPosition"))
107   debug("vColor   :" + gl.getAttribLocation(program, "vColor"))
108   assertMsg(gl.getAttribLocation(program, "vPosition") == positionLocation,
109             "location of vPosition should be " + positionLocation);
110   assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation,
111             "location of vColor should be " + colorLocation);
112
113   var ploc = gl.getAttribLocation(program, "vPosition");
114   var cloc = gl.getAttribLocation(program, "vColor");
115   gl.bindBuffer(gl.ARRAY_BUFFER, positions);
116   gl.enableVertexAttribArray(positionLocation);
117   gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
118   gl.bindBuffer(gl.ARRAY_BUFFER, colors);
119   gl.enableVertexAttribArray(colorLocation);
120   gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
121 }
122
123 function checkDraw(colorLocation, positionLocation, r, g, b, a) {
124   gl.clearColor(0, 0, 0, 1);
125   gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
126   gl.drawArrays(gl.TRIANGLES, 0, 3);
127
128   var width = 50;
129   var height = 50;
130
131   // Test several locations
132   wtu.checkCanvasRect(gl, 0, 0, width, 1, [0, 0, 0, 255],
133       "First line should be all black");
134   wtu.checkCanvasRect(gl, 20, 15, 10, 1, [r, g, b, a],
135       "Line 15 should be red for at least 10 rgba pixels starting 20 pixels in");
136   wtu.checkCanvasRect(gl, 0, height - 1, width, 0, [0, 0, 0, 255],
137       "Last line should be all black");
138
139   gl.disableVertexAttribArray(positionLocation);
140   gl.disableVertexAttribArray(colorLocation);
141 }
142
143 setBindLocations(2, 3);
144 checkDraw(2, 3, 0, 255, 0, 255);
145
146 setBindLocations(0, 3);
147 gl.disableVertexAttribArray(0);
148 gl.vertexAttrib4f(0, 1, 0, 0, 1);
149 checkDraw(0, 3, 255, 0, 0, 255);
150
151 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
152
153 debug("");
154 var successfullyParsed = true;
155
156 </script>
157 <script src="../../resources/js-test-post.js"></script>
158
159 </body>
160 </html>