4 ** Copyright (c) 2012 The Khronos Group Inc.
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:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
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.
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>
38 <canvas id="canvas" width="16" height="16" style="width: 40px; height: 40px;"> </canvas>
39 <div id="description"></div>
40 <div id="console"></div>
43 description("Checks the scissor does not change when switching framebuffers.");
45 var wtu = WebGLTestUtils;
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);
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);
68 var gl = wtu.create3DContext("canvas", {antialias: false});
70 testFailed("context does not exist");
72 testPassed("context exists");
74 var fb8x8 = makeFramebuffer(8, 8);
75 var fb32x32 = makeFramebuffer(32, 32);
77 var testScissor = function(scissorX, scissorY, scissorWidth, scissorHeight, msg) {
81 var test = function(fb, size) {
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");
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);
109 gl.bindFramebuffer(gl.FRAMEBUFFER, fb32x32);
110 gl.enable(gl.SCISSOR_TEST);
111 gl.scissor(scissorX, scissorY, scissorWidth, scissorHeight);
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");
122 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
126 var successfullyParsed = true;
128 <script src="../../resources/js-test-post.js"></script>