4 ** Copyright (c) 2014 The Khronos Group Inc.
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:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
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.
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>
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;
45 gl_Position = vec4(aPosition, 1);
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;
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.
66 // Multiply by 2.0 to make the color green.
67 gl_FragColor = vec4(0.0, 2.0 * a, 0.0, 1.0);
70 <script type="text/javascript">
73 var wtu = WebGLTestUtils;
76 var gl = wtu.create3DContext("canvas");
78 testFailed("context does not exist");
81 if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision == 0) {
82 testPassed("highp precision not supported");
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);
89 wtu.checkCanvasRect(gl, 0, 0, 256, 256, [0, 255, 0, 255]);
94 var successfullyParsed = true;