Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / canvas / drawingbuffer-static-canvas-test.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>WebGL Canvas Conformance Tests</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 <div id="description"></div>
39 <div id="console"></div>
40 <canvas id="canvas" width="50" height="50"> </canvas>
41
42 <script id="vshader" type="x-shader/x-vertex">
43 attribute vec4 vPosition;
44 void main()
45 {
46   gl_Position = vPosition;
47 }
48 </script>
49
50 <script id="fshader" type="x-shader/x-fragment">
51 void main()
52 {
53   gl_FragColor = vec4(1.0,0.0,0.0,1.0);
54 }
55 </script>
56
57 <script>
58 "use strict";
59
60 function drawTriangleTest(gl)
61 {
62   var width = 50;
63   var height = 50;
64   gl.viewport(0, 0, width, height);
65   var vertexObject = gl.createBuffer();
66   gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
67   gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
68   gl.enableVertexAttribArray(0);
69   gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
70
71   gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
72   gl.drawArrays(gl.TRIANGLES, 0, 3);
73
74   // Test several locations
75   wtu.checkCanvasRect(gl, 0, 0, width, 1, [0, 0, 0, 255],
76       'First line should be all black');
77   wtu.checkCanvasRect(gl, 20, 15, 10, 1, [255, 0, 0, 255],
78       'Line 15 should be red for at least 10 red pixels starting 20 pixels in');
79   wtu.checkCanvasRect(gl, 0, height - 1, width, 1, [0, 0, 0, 255],
80       'Last line should be all black');
81 }
82
83 description("This test ensures WebGL implementations correctly implement drawingbufferWidth/Height with compositing.");
84
85 debug("");
86
87 var wtu = WebGLTestUtils;
88 var err;
89 var maxSize;
90 var gl =  wtu.create3DContext("canvas");
91 if (!gl) {
92   testFailed("context does not exist");
93 } else {
94   testPassed("context exists");
95
96   var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]);
97   shouldBeNonNull("program");
98   gl.enable(gl.DEPTH_TEST);
99   gl.clearColor(0, 0, 0, 1);
100   shouldBe('gl.getError()', 'gl.NO_ERROR');
101
102   debug("");
103   debug("Checking drawingBufferWidth/drawingBufferHeight");
104
105   shouldBe('gl.drawingBufferWidth', 'gl.canvas.width');
106   shouldBe('gl.drawingBufferHeight', 'gl.canvas.height');
107
108   // Check that changing the canvas size to something too large falls back to reasonable values.
109   maxSize = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
110   shouldBeTrue('maxSize[0] > 0');
111   shouldBeTrue('maxSize[1] > 0');
112
113   // debug("MAX_VIEWPORT_DIMS = " + maxSize[0] + "x" + maxSize[1]);
114   gl.canvas.width = maxSize[0] * 4;
115   gl.canvas.height = maxSize[1] * 4;
116   shouldBeTrue('gl.drawingBufferWidth > 0');
117   shouldBeTrue('gl.drawingBufferHeight > 0');
118   shouldBeTrue('gl.drawingBufferWidth <= maxSize[0]');
119   shouldBeTrue('gl.drawingBufferHeight <= maxSize[1]');
120   shouldBe('gl.getError()', 'gl.NO_ERROR');
121
122   debug("");
123   debug("Checking scaling up then back down to 50/50, drawing still works.");
124   gl.canvas.width = 50;
125   gl.canvas.height = 50;
126   shouldBeTrue('gl.drawingBufferWidth == 50');
127   shouldBeTrue('gl.drawingBufferHeight == 50');
128   shouldBe('gl.getError()', 'gl.NO_ERROR');
129   drawTriangleTest(gl);
130   shouldBe('gl.getError()', 'gl.NO_ERROR');
131 }
132 debug("")
133 var successfullyParsed = true;
134 </script>
135 <script src="../../resources/js-test-post.js"></script>
136 </body>
137 </html>