Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / glsl / bugs / constant-precision-qualifier.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>Bug - the precision qualifier of a constant variable should affect the precision of a consuming operation</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 <canvas id="canvas" width="256" height="256"> </canvas>
39 <div id="description"></div>
40 <div id="console"></div>
41 <script id="vshader" type="x-shader/x-vertex">
42 attribute vec3 aPosition;
43
44 void main() {
45     gl_Position = vec4(aPosition, 1);
46 }
47 </script>
48 <script id="fshader" type="x-shader/x-fragment">
49 // It is assumed that uTest is set to 0. It's here to make the expression not constant.
50 uniform mediump float uTest;
51
52 void main() {
53     // exact representation of 4096.5 requires 13 bits of relative precision.
54     const highp float c = 4096.5;
55     mediump float a = 0.0;
56     // Below, addition should be evaluated at highp, since one of the operands has the highp qualifier.
57     // Thus fract should also be evaluated at highp.
58     // See OpenGL ES Shading Language spec section 4.5.2.
59     // This should make the result 0.5, since highp provides at least 16 bits of relative precision.
60     // (exceptions for operation precision are allowed for a small number of computationally
61     // intensive built-in functions, but it is reasonable to think that fract is not one of those).
62     // However, if fract() is incorrectly evaluated at minimum precision fulfilling mediump criteria,
63     // or at IEEE half float precision, the result is 0.0.
64     a = fract(c + uTest);
65
66     // Multiply by 2.0 to make the color green.
67     gl_FragColor = vec4(0.0, 2.0 * a, 0.0, 1.0);
68 }
69 </script>
70 <script type="text/javascript">
71 "use strict";
72 description();
73 var wtu = WebGLTestUtils;
74
75 function test() {
76   var gl = wtu.create3DContext("canvas");
77   if (!gl) {
78     testFailed("context does not exist");
79     return;
80   }
81   if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision == 0) {
82     testPassed("highp precision not supported");
83   } else {
84     wtu.setupUnitQuad(gl);
85     var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["aPosition"], undefined, true);
86     var uniformLoc = gl.getUniformLocation(program, 'uTest');
87     gl.uniform1f(uniformLoc, 0);
88     wtu.drawUnitQuad(gl);
89     wtu.checkCanvasRect(gl, 0, 0, 256, 256, [0, 255, 0, 255]);
90   }
91 };
92
93 test();
94 var successfullyParsed = true;
95 finishTest();
96 </script>
97 </body>
98 </html>
99