framebuffer-texture-switch.html (2928B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>WebGL framebuffer texture attachment switching conformance test.</title> 12 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 13 <script src="../../js/js-test-pre.js"></script> 14 <script src="../../js/webgl-test-utils.js"> </script> 15 </head> 16 <body> 17 <canvas id="canvas" width="64" height="64"></canvas> 18 <div id="description"></div> 19 <div id="console"></div> 20 <script> 21 "use strict"; 22 description("Test framebuffer texture attachment switching. The test uses one framebuffer object and switches its color attachment."); 23 var wtu = WebGLTestUtils; 24 var canvas = document.getElementById("canvas"); 25 26 var gl = wtu.create3DContext("canvas"); 27 var program = wtu.setupTexturedQuad(gl); 28 29 var fb = gl.createFramebuffer(); 30 gl.bindFramebuffer(gl.FRAMEBUFFER, fb); 31 32 var tex2 = gl.createTexture(); 33 gl.bindTexture(gl.TEXTURE_2D, tex2); 34 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 35 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 36 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 37 38 var tex1 = gl.createTexture(); 39 gl.bindTexture(gl.TEXTURE_2D, tex1); 40 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 41 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 42 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 43 44 gl.clearColor(1.0, 1.0, 1.0, 1.0); 45 46 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup."); 47 48 var iterate = function(checkFBOs, iterations) { 49 for (var i = 0; i < iterations; ++i) { 50 debug("Clearing tex1 to white"); 51 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex1, 0); 52 if (checkFBOs) 53 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE"); 54 gl.clear(gl.COLOR_BUFFER_BIT); 55 56 debug("Copying tex1 to tex2"); 57 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex2, 0); 58 if (checkFBOs) 59 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE"); 60 gl.drawArrays(gl.TRIANGLES, 0, 6); 61 } 62 // Read what is in tex2 63 wtu.checkCanvas(gl, [255,255,255,255], "tex2 should be white"); 64 }; 65 66 debug(""); 67 debug("Warm-up iteration"); 68 iterate(true, 1); 69 70 debug(""); 71 debug("Iterating the test a few times since at least one bug it has exposed is somewhat flaky."); 72 for (var i = 0; i < 3; ++i) { 73 debug(""); 74 debug("Iteration " + (i + 1)); 75 iterate(false, 2); 76 } 77 78 debug(""); 79 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors at the end of the test."); 80 81 finishTest(); 82 83 var successfullyParsed = true; 84 </script> 85 </body> 86 </html>