Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / glsl / misc / glsl-vertex-branch.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>GLSL function nodes Test</title>
33 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
34 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/>
35 <script src="../../../resources/js-test-pre.js"></script>
36 <script src="../../resources/webgl-test-utils.js"> </script>
37
38 <script id="vshaderNoBranch" type="x-shader/x-vertex">
39 attribute vec3 aPosition;
40 uniform float redIntensity;
41
42 varying vec4 vColor;
43
44 float MADBug(float paramValue) {
45   float localVar = 1.0;
46   return 0.25 * ceil(localVar) + paramValue;
47 }
48
49 void main(void) {
50     gl_Position = vec4(aPosition, 1.0);
51     vColor = vec4(MADBug(redIntensity), 0., 0., 1.);
52 }
53 </script>
54
55 <script id="vshaderBranch" type="x-shader/x-vertex">
56 attribute vec3 aPosition;
57 uniform float redIntensity;
58
59 varying vec4 vColor;
60
61 float MADBug(float paramValue) {
62   float localVar = 1.0;
63   return 0.25 * ceil(localVar) + paramValue;
64 }
65
66 void main(void) {
67     float condition = 42.;
68     if (condition == 0.) {}
69     gl_Position = vec4(aPosition, 1.0);
70     vColor = vec4(MADBug(redIntensity), 0., 0., 1.);
71 }
72 </script>
73
74 <script id="fshader" type="x-shader/x-fragment">
75 precision mediump float;
76
77 varying vec4 vColor;
78 void main()
79 {
80    gl_FragColor = vColor;
81 }
82 </script>
83 </head>
84 <body>
85 <canvas id="canvasNoBranch" width="50" height="50"></canvas>
86 <canvas id="canvasBranch" width="50" height="50"></canvas>
87 <div id="description">This tests against a Mac driver bug related to branches
88  inside of Vertex Shaders.</div>
89 <div id="console"></div>
90 <script>
91 "use strict";
92 var width = 50;
93 var height = 50;
94 var wtu = WebGLTestUtils;
95
96 function drawAndRead(canvasID, vshaderID, buffer)
97 {
98     var gl = wtu.create3DContext(canvasID);
99     var program = wtu.setupProgram(gl, [vshaderID, "fshader"], ["aPosition"]);
100     var vertexObject = gl.createBuffer();
101     gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
102     gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -1,-1,0, 1,-1,0 ]), gl.STATIC_DRAW);
103     gl.enableVertexAttribArray(0);
104     gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
105
106     var loc = gl.getUniformLocation(program, "redIntensity");
107     gl.uniform1f(loc, 0.75);
108     gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
109     gl.drawArrays(gl.TRIANGLES, 0, 3);
110     gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
111     if (gl.getError() != gl.NO_ERROR)
112         return false;
113     return true;
114 }
115
116 function compareRendering(buffer1, buffer2, tol)
117 {
118     for (var i = 0; i < width * height * 4; ++i) {
119         if (Math.abs(buffer1[i] - buffer2[i]) > tol)
120             return false;
121     }
122     return true;
123 }
124
125 function init()
126 {
127     description("tests vertex shader with branch");
128
129     var bufBranch = new Uint8Array(width * height * 4);
130     var bufNoBranch = new Uint8Array(width * height * 4);
131
132     if (drawAndRead("canvasBranch", "vshaderBranch", bufBranch) == false ||
133         drawAndRead("canvasNoBranch", "vshaderNoBranch", bufNoBranch) == false) {
134         testFailed("Setup failed");
135     } else {
136         if (compareRendering(bufBranch, bufNoBranch, 4) == false)
137             testFailed("Rendering results are different");
138         else
139             testPassed("Rendering results are the same");
140     }
141 }
142
143 init();
144 var successfullyParsed = true;
145 </script>
146 <script src="../../../resources/js-test-post.js"></script>
147 </body>
148 </html>
149