Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / rendering / gl-scissor-fbo-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 Scissor FBO Test</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="16" height="16" style="width: 40px; height: 40px;"> </canvas>
39 <div id="description"></div>
40 <div id="console"></div>
41 <script>
42 "use strict";
43 description("Checks the scissor does not change when switching framebuffers.");
44
45 var wtu = WebGLTestUtils;
46
47 function makeFramebuffer(width, height) {
48   var tex = gl.createTexture();
49   gl.bindTexture(gl.TEXTURE_2D, tex);
50   gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
51   gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
52   gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
53   gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
54   gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
55   var fb = gl.createFramebuffer();
56   gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
57   gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
58   shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
59   gl.bindFramebuffer(gl.FRAMEBUFFER, null);
60   return fb;
61 }
62
63 function checkCanvasRect(x, y, width, height, color, msg) {
64   debug("checking: " + x + ", " + y + ", " + width + ", " + height);
65   wtu.checkCanvasRect(gl, x, y, width, height, color, msg);
66 }
67
68 var gl = wtu.create3DContext("canvas", {antialias: false});
69 if (!gl) {
70   testFailed("context does not exist");
71 } else {
72   testPassed("context exists");
73
74   var fb8x8 = makeFramebuffer(8, 8);
75   var fb32x32 = makeFramebuffer(32, 32);
76
77   var testScissor = function(scissorX, scissorY, scissorWidth, scissorHeight, msg) {
78     debug("");
79     debug(msg);
80
81     var test = function(fb, size) {
82       debug("");
83       debug("checking size: " + size);
84       gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
85       gl.clearColor(0, 1, 0, 1);
86       gl.clear(gl.COLOR_BUFFER_BIT);
87       var scissorRight = Math.min(scissorX + scissorWidth, size);
88       var scissorTop = Math.min(scissorY + scissorHeight, size);
89       var scWidth = scissorRight - scissorX;
90       var scHeight = scissorTop - scissorY;
91       var rightWidth = Math.min(size - scissorRight, 0);
92       var topHeight = Math.max(size - scissorTop, 0);
93       checkCanvasRect(scissorX, scissorY, scWidth, scHeight, [0, 255, 0, 255], "should be green");
94       checkCanvasRect(0, 0, size, scissorY, [255, 0, 0, 255], "should be red");
95       checkCanvasRect(0, scissorTop, size, topHeight, [255, 0, 0, 255], "should be red");
96       checkCanvasRect(0, 0, scissorX, size, [255, 0, 0, 255], "should be red");
97       checkCanvasRect(scissorRight, 0, scissorX, rightWidth, [255, 0, 0, 255], "should be red");
98     };
99
100     gl.disable(gl.SCISSOR_TEST);
101     gl.clearColor(1, 0, 0, 1);
102     gl.bindFramebuffer(gl.FRAMEBUFFER, null);
103     gl.clear(gl.COLOR_BUFFER_BIT);
104     gl.bindFramebuffer(gl.FRAMEBUFFER, fb8x8);
105     gl.clear(gl.COLOR_BUFFER_BIT);
106     gl.bindFramebuffer(gl.FRAMEBUFFER, fb32x32);
107     gl.clear(gl.COLOR_BUFFER_BIT);
108
109     gl.bindFramebuffer(gl.FRAMEBUFFER, fb32x32);
110     gl.enable(gl.SCISSOR_TEST);
111     gl.scissor(scissorX, scissorY, scissorWidth, scissorHeight);
112     test(null, 16);
113     test(fb8x8, 8);
114     test(fb32x32, 32);
115     test(null, 16);
116   };
117
118   testScissor(2, 4, 12, 10, "test scissor in middle");
119   testScissor(0, 0, 12, 10, "test scissor at 0,0");
120   testScissor(0, 0, 16, 16, "test scissor with size that matches drawingbuffer");
121
122   wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
123 }
124
125 debug("");
126 var successfullyParsed = true;
127 </script>
128 <script src="../../resources/js-test-post.js"></script>
129
130 </body>
131 </html>