Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / glsl / bugs / conditional-discard-optimization.html
1 <!--
2
3 /*
4 ** Copyright (c) 2013 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 <!-- author: Bill Baxter (wbaxter at google.com) -->
29
30 <!DOCTYPE html>
31 <html>
32 <head>
33 <meta charset="utf-8">
34 <title>ANGLE WebGL Shader Conditionals Repro</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>
38 </head>
39
40 <body>
41 <canvas id="repro" style="border: none;" width="256" height="256"></canvas>
42 <div id="description"></div>
43 <div id="console"></div>
44
45 <script id="shader-vs" type="x-shader/x-vertex">
46 attribute vec2 pos;
47 varying mediump float varA;
48 void main(void) {
49   varA = 0.;
50   gl_Position = vec4(pos, 0.0, 1.0);
51 }
52 </script>
53
54 <script id="shader-fs" type="x-shader/x-fragment">
55 precision mediump float;
56 varying float varA;
57 void main(void) {
58   if (varA < -1. || (varA < -1. && varA > 1.)) {
59     discard;
60   }
61   gl_FragColor = vec4(0, 1, 0, 1) + 2. * varA * 2.;
62 }
63 </script>
64
65 <script id="shader-fs-mutable" type="x-shader/x-fragment">
66 precision mediump float;
67 varying float varA;
68 void main(void) {
69   float b = varA;
70   if (varA < (b -= 1.) || (varA < b && varA > (b += 2.))) {
71     discard;
72   }
73   gl_FragColor = vec4(0, 1, 0, 1) + 2. * varA * 2.;
74 }
75 </script>
76
77 <script>
78 "use strict";
79
80 description();
81 debug("");
82 debug("If things are working correctly, then there will be a green square.");
83 debug("Otherwise it will be a black void.");
84 debug("This is a repro for an issue seen on the D3D9 ANGLE implementation of WebGL on Chrome in a shader with a conditional discard, where the conditional is of the form (a || (b && c)).");
85
86 var wtu = WebGLTestUtils;
87 var canvas = document.getElementById("repro");
88 var gl = wtu.create3DContext(canvas);
89 if (!gl) {
90   testFailed("context does not exist");
91 } else {
92   gl.clearColor(0.0, 0.0, 0.0, 1.0);
93   gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
94   wtu.setupUnitQuad(gl);
95   var program = wtu.setupProgram(gl, ["shader-vs", "shader-fs"], ["pos"], undefined, true);
96   wtu.drawUnitQuad(gl);
97   wtu.checkCanvasRect(gl, 128, 128, 128, 128, [ 0, 255, 0, 255 ], "should be green", 1);
98
99   gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
100   var programMutable = wtu.setupProgram(gl, ["shader-vs", "shader-fs-mutable"], ["pos"]);
101   wtu.drawUnitQuad(gl);
102   wtu.checkCanvasRect(gl, 128, 128, 128, 128, [ 0, 255, 0, 255 ], "should be green", 1);
103 }
104
105 var successfullyParsed = true;
106 </script>
107 <script src="../../../resources/js-test-post.js"></script>
108 </body>
109 </html>