Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / uniforms / gl-uniform-unused-array-elements-get-truncated.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 uniform unused array elements get truncated Conformance Test</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 id="example" width="2" height="2"> </canvas>
41 <script id="vshader" type="x-shader/x-vertex">
42     attribute vec4 a_position;
43     void main()
44     {
45         gl_Position = a_position;
46     }
47 </script>
48 <script id="fshader-max" type="x-shader/x-fragment">
49     precision mediump float;
50     uniform vec4 colora[$(numUniformVectors)];
51     void main()
52     {
53         gl_FragColor = vec4(colora[$(usedUniformVector)]);
54     }
55 </script>
56 <script>
57 "use strict";
58 description();
59 debug("");
60 var wtu = WebGLTestUtils;
61 var gl = wtu.create3DContext("example");
62 var vSrc = wtu.getScript("vshader");
63 var uniforms;
64 // This test is to test drivers the have bugs related to optimizing
65 // an array of uniforms when only 1 of those uniforms is used.
66 debug("");
67 var maxUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
68 var tests = [
69  { desc: "using 5th element",
70    maxUniformVectors: maxUniformVectors,
71    numUniformVectors: maxUniformVectors * 2,
72    usedUniformVector: 5,
73    shader: "fshader-max",
74    color: [0, 1, 0, 1],
75    arrayName: "colora",
76  },
77 ];
78
79 // According to the spec unused array elements must be truncated.
80 var requiredUniformLocationsExist;
81 function testUniformIssues(testIndex) {
82   var test = tests[testIndex];
83   debug("");
84   debug(test.desc);
85   var fSrc = test.source;
86   if (!fSrc) {
87     fSrc = wtu.replaceParams(wtu.getScript(test.shader), test);
88   }
89
90   var consoleElem = document.getElementById("console");
91   wtu.addShaderSource(
92       consoleElem, "vertex shader", vSrc);
93   wtu.addShaderSource(
94       consoleElem, "fragment shader", fSrc);
95
96   var program = wtu.loadProgram(gl, vSrc, fSrc);
97   gl.useProgram(program);
98   uniforms = wtu.getUniformMap(gl, program);
99   shouldBe('uniforms["' + test.arrayName + '[0]"].size', (test.usedUniformVector + 1).toString());
100
101   requiredUniformLocationsExist = true;
102   for (var ii = 0; ii <= test.usedUniformVector + 1; ++ii) {
103     var name = test.arrayName + "[" + ii + "]";
104     var colorLocation = gl.getUniformLocation(program, name);
105     if (ii <= test.usedUniformVector) {
106       if (!colorLocation) {
107         requiredUniformLocationsExist = false
108       }
109     } else {
110       if (colorLocation) {
111         testFailed("uniform array was not truncated as specified in OpenGL ES 2.0.25 section 2.10.4");
112       }
113     }
114   }
115   shouldBeTrue("requiredUniformLocationsExist");
116 }
117
118 var testIndex = 0;
119 function runNextTest() {
120   testUniformIssues(testIndex++);
121   if (testIndex < tests.length) {
122     setTimeout(runNextTest, 0);
123   } else {
124     wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
125     debug("");
126     finishTest();
127   }
128 }
129 runNextTest();
130
131 var successfullyParsed = true;
132
133 </script>
134 </body>
135 </html>