4 ** Copyright (c) 2013 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.
28 <!-- author: Bill Baxter (wbaxter at google.com) -->
33 <meta charset="utf-8">
34 <title>Modulo Arithmetic Accuracy Bug</title>
35 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
36 <script src="../../../resources/js-test-pre.js"></script>
37 <script src="../../resources/webgl-test-utils.js"></script>
41 <canvas id="repro" style="border: none;" width="256" height="256"></canvas>
42 <div id="description"></div>
43 <div id="console"></div>
45 <script id="shader-vs" type="x-shader/x-vertex">
47 uniform float divisor;
50 gl_Position = vec4(pos, 0.0, 1.0);
52 // mod(x, y) is computed as x-y*floor(x/y). There are no guarantees on
53 // the precision of floating point operations in WebGL shaders, but division
54 // should be accurate to at least 1 part in 10^5.
55 float value = mod(index * 1.00001, divisor);
56 vColor = (value < 1.) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
60 <script id="shader-fs" type="x-shader/x-fragment">
61 precision mediump float;
64 gl_FragColor = vColor;
72 // Reproduces bug seen on Mac OS X with AMD Radeon HD 6490 GPU
73 debug("If things are working correctly, then the square will be green.");
74 debug("If your card thinks mod(9,3) is not 0, then the square will be red.");
76 var wtu = WebGLTestUtils;
77 var canvas = document.getElementById("repro");
78 var gl = wtu.create3DContext(canvas);
80 testFailed("context does not exist");
82 gl.clearColor(0.0, 0.0, 0.0, 1.0);
83 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
84 wtu.setupUnitQuad(gl);
85 var program = wtu.setupProgram(gl, ["shader-vs", "shader-fs"], ["pos"], undefined, true);
86 gl.uniform1f(gl.getUniformLocation(program, "divisor"), 3);
88 wtu.checkCanvasRect(gl, 128, 128, 128, 128, [ 0, 255, 0, 255 ], "should be green", 1);
91 var successfullyParsed = true;
93 <script src="../../../resources/js-test-post.js"></script>