6 <title>Verifies that GL framebuffer bindings do not change when canvas is resized</title>
7 <link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
8 <script src="../../js/resources/js-test-pre.js"></script>
9 <script src="resources/webgl-test.js"></script>
10 <script src="resources/webgl-test-utils.js"></script>
13 <canvas id="example" width="4px" height="4px"></canvas>
14 <div id="description"></div>
15 <div id="console"></div>
17 description("Verifies that GL framebuffer bindings do not change when canvas is resized");
19 if (window.initNonKhronosFramework) {
20 window.initNonKhronosFramework(true);
24 var wtu = WebGLTestUtils;
25 var canvas = document.getElementById("example");
26 var gl = wtu.create3DContext(canvas);
27 var green = [0, 255, 0, 255];
28 var blue = [0, 0, 255, 255];
30 shouldBeTrue("fboSize < canvas.width");
31 var fbo = gl.createFramebuffer();
32 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
33 var fboTex = gl.createTexture();
34 gl.activeTexture(gl.TEXTURE1);
35 gl.bindTexture(gl.TEXTURE_2D, fboTex);
36 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fboTex, 0);
37 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, fboSize, fboSize, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
38 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
39 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
40 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
41 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
42 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
44 function checkFBO(color, msg) {
45 wtu.checkCanvasRect(gl, 0, 0, fboSize, fboSize, color, msg);
46 wtu.checkCanvasRect(gl, fboSize, fboSize, fboSize, fboSize, [0, 0, 0, 0], "area outside fbo should be transparent black");
49 // The FBO is 2x2 and it's bound so clearing should clear a 2x2 area
50 // and calling read pixels should read the clear color in that 2x2 area
51 // and 0,0,0,0 outside that area.
53 // If the FBO is no longer bound because of a WebGL implementation error
54 // then likely the clear will clear the backbuffer and reading outside
55 // the 2x2 area will not be 0,0,0,0
58 gl.clearColor(0, 0, 1, 1);
59 gl.clear(gl.COLOR_BUFFER_BIT);
60 checkFBO(blue, "should be blue");
61 gl.clearColor(0, 1, 0, 1);
62 gl.clear(gl.COLOR_BUFFER_BIT);
63 checkFBO(green, "should be green");
66 debug("test before resizing canvas");
68 debug("test after resizing canvas");
71 debug("test after resizing canvas and waiting for compositing");
73 wtu.waitFrames(5, function() {
76 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
79 successfullyParsed = true;