Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / glsl / misc / struct-nesting-of-variable-names.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 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css" />\r
31 <script src="../../../resources/js-test-pre.js"></script>\r
32 <script src="../../resources/webgl-test-utils.js"></script>\r
33 <script src="../../resources/glsl-conformance-test.js"></script>\r
34 <title></title>\r
35 </head>\r
36 <body>\r
37 <div id="description"></div>\r
38 <div id="console"></div>\r
39 <script id="fragmentShader" type="text/something-not-javascript">\r
40 precision mediump float;\r
41 struct S { $(outer_type) u; };\r
42 void main() {\r
43     S S;   // This is legal, 'S' as a typename is defined in another scope.\r
44     {\r
45         struct S { $(inner_type) a; };  // This is legal as well, 'S' is now defined as a variable name in an ancestor scope\r
46         S newvar;\r
47         newvar.a = $(initializer);\r
48         gl_FragColor = $(fragColor);\r
49     }\r
50 }\r
51 </script>\r
52 <script>\r
53 "use strict";\r
54 description("This test verifies that defining a typename in a new scope when the typename is the name of a variable that hides a typename declaration succeeds for all combinations of GLSL types.");\r
55 var tests = [];\r
56 var wtu = WebGLTestUtils;\r
57 var typeInfo = [\r
58     { Type: 'float',    initializer: '1.0',                         fragColor: 'vec4(0.0, newvar.a, 0.0, 1.0)' },\r
59     { Type: 'vec2',     initializer: 'vec2(0.0, 1.0)',              fragColor: 'vec4(newvar.a, 0.0, 1.0)' },\r
60     { Type: 'vec3',     initializer: 'vec3(0.0, 1.0, 0.0)',         fragColor: 'vec4(newvar.a, 1.0)' },\r
61     { Type: 'vec4',     initializer: 'vec4(0.0, 1.0, 0.0, 1.0)',    fragColor: 'newvar.a' },\r
62     { Type: 'int',      initializer: '1',                           fragColor: 'vec4(0.0, newvar.a, 0.0, 1.0)' },\r
63     { Type: 'ivec2',    initializer: 'ivec2(0, 1)',                 fragColor: 'vec4(newvar.a, 0.0, 1.0)' },\r
64     { Type: 'ivec3',    initializer: 'ivec3(0, 1, 0)',              fragColor: 'vec4(newvar.a, 1.0)' },\r
65     { Type: 'ivec4',    initializer: 'ivec4(0, 1, 0, 1)',           fragColor: 'vec4(newvar.a)' },\r
66     { Type: 'bool',     initializer: 'true',                        fragColor: 'vec4(0.0, newvar.a, 0.0, 1.0)' },\r
67     { Type: 'bvec2',    initializer: 'bvec2(false, true)',          fragColor: 'vec4(newvar.a, 0.0, 1.0)' },\r
68     { Type: 'bvec3',    initializer: 'bvec3(false, true, false)',   fragColor: 'vec4(newvar.a, 1.0)' },\r
69     { Type: 'bvec4',    initializer: 'bvec4(false,true,false,true)',fragColor: 'vec4(newvar.a)' },\r
70 ];\r
71 typeInfo.forEach(function (outerType) {\r
72     typeInfo.forEach(function (innerType) {\r
73         var replaceParams = {\r
74             outer_type: outerType.Type,\r
75             inner_type: innerType.Type,\r
76             // use the initializer and fragColor for the inner type. Its definition should override the variable name in the outerscope.\r
77             initializer: innerType.initializer,\r
78             fragColor: innerType.fragColor\r
79         };\r
80         tests.push({\r
81             fShaderSource: wtu.replaceParams(wtu.getScript('fragmentShader'), replaceParams),\r
82             passMsg: 'Outer struct type: ' + outerType.Type + ' inner struct type: ' + innerType.Type,\r
83             fShaderSuccess: true,\r
84             linkSuccess: true,\r
85             render: true\r
86         });\r
87     })\r
88 })\r
89 GLSLConformanceTester.runTests(tests);\r
90 var successfullyParsed = true;\r
91 </script>\r
92 </body>\r
93 </html>