Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / glsl / bugs / uniforms-should-not-lose-values.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>Driver Bug - Uniforms should no lose values</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="512" height="256"> </canvas>
39 <div id="description"></div>
40 <div id="console"></div>
41 <script id="vshader" type="x-shader/x-vertex">
42 uniform float k,u;
43 uniform mat4 l;
44 attribute vec3 a;
45 void main(){
46   gl_Position=l*vec4(a,1.+u+k);
47 }
48 </script>
49 <script id="fshader" type="x-shader/x-fragment">
50 precision mediump float;
51 uniform float w,x,y,z;
52 void main() {
53  gl_FragColor=vec4(1.-y,y,w+x+z,1);
54 }
55 </script>
56 <script>
57 "use strict";
58 // Certain drivers fail this test. Specifically Mac NVidia GT 330 on OSX 10.8.2
59 description();
60 debug("");
61 var wtu = WebGLTestUtils;
62 function test() {
63   var gl = wtu.create3DContext("canvas");
64   if (!gl) {
65     testFailed("context does not exist");
66     return;
67   }
68
69   wtu.setupUnitQuad(gl);
70   var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a"], undefined, true);
71
72   var setUniformf = function(name, val) {
73     var loc = gl.getUniformLocation(program, name);
74     var func = 'uniform' + val.length + 'fv';
75     gl[func](loc, val);
76   };
77
78   var setUniformMat = function(name, val) {
79     var loc = gl.getUniformLocation(program, name);
80     var func = 'uniformMatrix' + Math.sqrt(val.length) + 'fv';
81     gl[func](loc, false, val);
82   };
83
84   setUniformMat('l', [1, 0 ,0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
85   gl.viewport(0, 0, 256, 256);
86   setUniformf('y', [0]);
87   wtu.drawUnitQuad(gl);
88   gl.viewport(256, 0, 256, 256);
89   setUniformf('y', [1]);
90   wtu.drawUnitQuad(gl);
91   wtu.checkCanvasRect(gl, 0, 0, 256, 256, [255, 0, 0, 255]);
92   wtu.checkCanvasRect(gl, 256, 0, 256, 256, [0, 255, 0, 255]);
93
94   wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
95 }
96 test();
97 var successfullyParsed = true;
98 </script>
99 <script src="../../../resources/js-test-post.js"></script>
100 </body>
101 </html>
102