Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / glsl / misc / shaders-with-uniform-structs.html
1 <!--
2
3 /*
4 ** Copyright (c) 2014 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 GLSL Conformance Tests</title>
33 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
34 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/>
35 <script src="../../../resources/js-test-pre.js"></script>
36 <script src="../../resources/webgl-test-utils.js"></script>
37 <script src="../../resources/glsl-conformance-test.js"></script>
38 </head>
39 <body>
40 <div id="description"></div>
41 <div id="console"></div>
42 <script id="vertexShaderStructSequence" type="text/something-not-javascript">
43 // Structures must have the same name, sequence of type names, and 
44 // type definitions, and field names to be considered the same type.
45 // GLSL 1.017 4.2.4
46 precision mediump float;
47 struct info {
48   vec4 pos;
49   vec4 color;
50 };
51
52 uniform info uni;
53 void main()
54 {
55     gl_Position = uni.pos;
56 }
57 </script>
58 <script id="fragmentShaderStructSequence" type="text/something-not-javascript">
59 // Structures must have the same name, sequence of type names, and 
60 // type definitions, and field names to be considered the same type.
61 // GLSL 1.017 4.2.4
62 precision mediump float;
63 struct info {
64   vec4 color;
65   vec4 pos;
66 };
67
68 uniform info uni;
69 void main()
70 {
71     gl_FragColor = uni.color;
72 }
73 </script>
74 <script id="vertexShaderStructName" type="text/something-not-javascript">
75 // Structures must have the same name, sequence of type names, and 
76 // type definitions, and field names to be considered the same type.
77 // GLSL 1.017 4.2.4
78 precision mediump float;
79 struct info {
80   vec4 pos;
81   vec4 color;
82 };
83
84 uniform info uni;
85 void main()
86 {
87     gl_Position = uni.pos;
88 }
89 </script>
90 <script id="fragmentShaderStructNameFailure" type="text/something-not-javascript">
91 // Structures must have the same name, sequence of type names, and 
92 // type definitions, and field names to be considered the same type.
93 // GLSL 1.017 4.2.4
94 precision mediump float;
95 struct info1 {
96   vec4 pos;
97   vec4 color;
98 };
99
100 uniform info1 uni;
101 void main()
102 {
103     gl_FragColor = uni.color;
104 }
105 </script>
106 <script id="fragmentShaderStructNameSuccess" type="text/something-not-javascript">
107 // Structures must have the same name, sequence of type names, and 
108 // type definitions, and field names to be considered the same type.
109 // GLSL 1.017 4.2.4
110 precision mediump float;
111
112 // Add a struct before info to make sure the struct info here is assigned
113 // a different internal unique ID from the struct info in vertex shader.
114 struct extra {
115   vec4 p;
116 };
117
118 struct info {
119   vec4 pos;
120   vec4 color;
121 };
122
123 uniform info uni;
124 void main()
125 {
126     extra my;
127     my.p = uni.color;
128     gl_FragColor = my.p;
129 }
130 </script>
131 <script id="vertexShaderStructFieldName" type="text/something-not-javascript">
132 // Structures must have the same name, sequence of type names, and 
133 // type definitions, and field names to be considered the same type.
134 // GLSL 1.017 4.2.4
135 precision mediump float;
136 struct info {
137   vec4 pos;
138   vec4 color;
139 };
140
141 uniform info uni;
142 void main()
143 {
144     gl_Position = uni.pos;
145 }
146 </script>
147 <script id="fragmentShaderStructFieldName" type="text/something-not-javascript">
148 // Structures must have the same name, sequence of type names, and 
149 // type definitions, and field names to be considered the same type.
150 // GLSL 1.017 4.2.4
151 precision mediump float;
152 struct info {
153   vec4 pos1;
154   vec4 color;
155 };
156
157 uniform info uni;
158 void main()
159 {
160     gl_FragColor = uni.color;
161 }
162 </script>
163 <script id="vertexShaderStructFieldType" type="text/something-not-javascript">
164 // Structures must have the same name, sequence of type names, and 
165 // type definitions, and field names to be considered the same type.
166 // GLSL 1.017 4.2.4
167 precision mediump float;
168 struct info {
169   vec4 pos;
170   vec4 color;
171 };
172
173 uniform info uni;
174 void main()
175 {
176     gl_Position = uni.pos;
177 }
178 </script>
179 <script id="fragmentShaderStructFieldType" type="text/something-not-javascript">
180 // Structures must have the same name, sequence of type names, and 
181 // type definitions, and field names to be considered the same type.
182 // GLSL 1.017 4.2.4
183 precision mediump float;
184 struct info {
185   vec3 pos;
186   vec4 color;
187 };
188
189 uniform info uni;
190 void main()
191 {
192     gl_FragColor = uni.color;
193 }
194 </script>
195 <script id="vertexShaderStructFieldPrecision" type="text/something-not-javascript">
196 // Structures must have the same name, sequence of type names, and 
197 // type definitions, and field names to be considered the same type.
198 // GLSL 1.017 4.2.4
199 struct info {
200   mediump vec4 pos;
201   highp vec4 color;
202 };
203
204 uniform info uni;
205 void main()
206 {
207     gl_Position = uni.pos;
208 }
209 </script>
210 <script id="fragmentShaderStructFieldPrecision" type="text/something-not-javascript">
211 // Structures must have the same name, sequence of type names, and 
212 // type definitions, and field names to be considered the same type.
213 // GLSL 1.017 4.2.4
214 precision mediump float;
215 struct info {
216   vec4 pos;
217   vec4 color;
218 };
219
220 uniform info uni;
221 void main()
222 {
223     gl_FragColor = uni.color;
224 }
225 </script>
226 <script id="vertexShaderUnnamedStruct" type="text/something-not-javascript">
227 // ANGLE regression on Windows, crbug.com/401296
228 uniform struct {
229   float f;
230   vec4 v;
231 } u_struct;
232
233 void main()
234 {
235     gl_Position = u_struct.f * u_struct.v;
236 }
237 </script>
238 <script id="fragmentShaderSimple" type="text/something-not-javascript">
239 void main()
240 {
241     gl_FragColor = vec4(1.0);
242 }
243 </script>
244 <script>
245 "use strict";
246 var wtu = WebGLTestUtils;
247
248 var tests = [];
249 tests.push({
250   vShaderSource: wtu.getScript("vertexShaderStructName"),
251   vShaderSuccess: true,
252   fShaderSource: wtu.getScript("fragmentShaderStructNameSuccess"),
253   fShaderSuccess: true,
254   linkSuccess: true,
255   passMsg: "Structures with the same defination must be considered the same type.",
256 });
257 tests.push({
258   vShaderSource: wtu.getScript("vertexShaderStructName"),
259   vShaderSuccess: true,
260   fShaderSource: wtu.getScript("fragmentShaderStructNameFailure"),
261   fShaderSuccess: true,
262   linkSuccess: false,
263   passMsg: "Structures must have the same name to be considered the same type.",
264 });
265 tests.push({
266   vShaderSource: wtu.getScript("vertexShaderStructSequence"),
267   vShaderSuccess: true,
268   fShaderSource: wtu.getScript("fragmentShaderStructSequence"),
269   fShaderSuccess: true,
270   linkSuccess: false,
271   passMsg: "Structures must have the same sequence of type names to be considered the same type.",
272 });
273 tests.push({
274   vShaderSource: wtu.getScript("vertexShaderStructFieldName"),
275   vShaderSuccess: true,
276   fShaderSource: wtu.getScript("fragmentShaderStructFieldName"),
277   fShaderSuccess: true,
278   linkSuccess: false,
279   passMsg: "Structures must have the same field names to be considered the same type.",
280 });
281 tests.push({
282   vShaderSource: wtu.getScript("vertexShaderStructFieldType"),
283   vShaderSuccess: true,
284   fShaderSource: wtu.getScript("fragmentShaderStructFieldType"),
285   fShaderSuccess: true,
286   linkSuccess: false,
287   passMsg: "Structures must have the same type definitions to be considered the same type.",
288 });
289 tests.push({
290   vShaderSource: wtu.getScript("vertexShaderStructFieldPrecision"),
291   vShaderSuccess: true,
292   fShaderSource: wtu.getScript("fragmentShaderStructFieldPrecision"),
293   fShaderSuccess: true,
294   linkSuccess: false,
295   passMsg: "Structures must have the same type definitions (including precision) to be considered the same type.",
296 });
297 tests.push({
298   vShaderSource: wtu.getScript("vertexShaderUnnamedStruct"),
299   vShaderSuccess: true,
300   fShaderSource: wtu.getScript("fragmentShaderSimple"),
301   fShaderSuccess: true,
302   linkSuccess: true,
303   passMsg: "Shaders with uniforms of unnamed struct type should compile and link successfully.",
304 });
305
306 GLSLConformanceTester.runTests(tests);
307 var successfullyParsed = true;
308 </script>
309 </body>
310 </html>