Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / attribs / gl-bindAttribLocation-aliasing.html
1 <!--\r
2 /*\r
3 ** Copyright (c) 2014 The Khronos Group Inc.\r
4 **\r
5 ** Permission is hereby granted, free of charge, to any person obtaining a\r
6 ** copy of this software and/or associated documentation files (the\r
7 ** "Materials"), to deal in the Materials without restriction, including\r
8 ** without limitation the rights to use, copy, modify, merge, publish,\r
9 ** distribute, sublicense, and/or sell copies of the Materials, and to\r
10 ** permit persons to whom the Materials are furnished to do so, subject to\r
11 ** the following conditions:\r
12 **\r
13 ** The above copyright notice and this permission notice shall be included\r
14 ** in all copies or substantial portions of the Materials.\r
15 **\r
16 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
19 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\r
20 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
21 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
22 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.\r
23 */\r
24 -->\r
25 <!DOCTYPE html>\r
26 <html>\r
27 <head>\r
28 <meta charset="utf-8">\r
29 <link rel="stylesheet" href="../../resources/js-test-style.css"/>\r
30 <script src="../../resources/js-test-pre.js"></script>\r
31 <script src="../resources/webgl-test-utils.js"></script>\r
32 <title>bindAttribLocation with aliasing</title>\r
33 </head>\r
34 <body>\r
35 <div id="description"></div>\r
36 <div id="console"></div>\r
37 <canvas id="canvas" width="8" height="8" style="width: 8px; height: 8px;"></canvas>\r
38 <script id="vertexShader" type="text/something-not-javascript">\r
39 precision mediump float;\r
40 attribute $(type_1) a_1;\r
41 attribute $(type_2) a_2;\r
42 void main() {\r
43     gl_Position = $(gl_Position_1) + $(gl_Position_2);\r
44 }\r
45 </script>\r
46 <script>\r
47 "use strict";\r
48 description("This test verifies combinations of valid, active attribute types cannot be bound to the same location with bindAttribLocation.");\r
49 var wtu = WebGLTestUtils;\r
50 var canvas = document.getElementById("canvas");\r
51 var gl = wtu.create3DContext(canvas, {antialias: false});\r
52 var glFragmentShader = wtu.setupSimpleColorFragmentShader(gl);\r
53 var typeInfo = [\r
54     { type: 'float',    asVec4: 'vec4(0.0, $(var), 0.0, 1.0)' },\r
55     { type: 'vec2',     asVec4: 'vec4($(var), 0.0, 1.0)' },\r
56     { type: 'vec3',     asVec4: 'vec4($(var), 1.0)' },\r
57     { type: 'vec4',     asVec4: '$(var)' },\r
58 ];\r
59 var maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);\r
60 // Test all type combinations of a_1 and a_2.\r
61 typeInfo.forEach(function(typeInfo1) {\r
62     typeInfo.forEach(function(typeInfo2) {\r
63         debug('attribute_1: ' + typeInfo1.type + ' attribute_2: ' + typeInfo2.type);\r
64         var replaceParams = {\r
65             type_1: typeInfo1.type,\r
66             type_2: typeInfo2.type,\r
67             gl_Position_1: wtu.replaceParams(typeInfo1.asVec4, {var: 'a_1'}),\r
68             gl_Position_2: wtu.replaceParams(typeInfo2.asVec4, {var: 'a_2'})\r
69         };\r
70         var strVertexShader = wtu.replaceParams(wtu.getScript('vertexShader'), replaceParams);\r
71         var glVertexShader = wtu.loadShader(gl, strVertexShader, gl.VERTEX_SHADER);\r
72         assertMsg(glVertexShader != null, "Vertex shader compiled successfully.");\r
73         // Bind both a_1 and a_2 to the same position and verify the link fails.  \r
74         // Do so for all valid positions available.\r
75         for (var l = 0; l < maxAttributes; l++) {\r
76             var glProgram = gl.createProgram();\r
77             gl.bindAttribLocation(glProgram, l, 'a_1');\r
78             gl.bindAttribLocation(glProgram, l, 'a_2');\r
79             gl.attachShader(glProgram, glVertexShader);\r
80             gl.attachShader(glProgram, glFragmentShader);\r
81             gl.linkProgram(glProgram);\r
82             assertMsg(!gl.getProgramParameter(glProgram, gl.LINK_STATUS), "Link should fail when both types are aliased to location " + l);\r
83         }\r
84     });\r
85 });\r
86 var successfullyParsed = true;\r
87 </script>\r
88 <script src="../../resources/js-test-post.js"></script>\r
89 </body>\r
90 </html>