framebuffer-texture-level1.html (2173B)
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 using texture level 1</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 <div id="description"></div> 18 <div id="console"></div> 19 <canvas id="canvas" width="2" height="2"> </canvas> 20 <script> 21 "use strict"; 22 var wtu = WebGLTestUtils; 23 var gl; 24 25 function testFramebufferTextureWithNonZeroBaseLevel(level) { 26 if (level < 1) { 27 throw "This test is incorrect if level < 1"; 28 } 29 var width = 32; 30 var height = 16; 31 var texture = gl.createTexture(); 32 gl.bindTexture(gl.TEXTURE_2D, texture); 33 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 34 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 35 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 36 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 37 gl.texImage2D(gl.TEXTURE_2D, level, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 38 var fbo = gl.createFramebuffer(); 39 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); 40 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, level); 41 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT"); 42 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_BASE_LEVEL, level); 43 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE"); 44 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Setup framebuffer with texture should succeed."); 45 46 gl.deleteTexture(texture); 47 gl.deleteFramebuffer(fbo); 48 } 49 50 description("Test fbo completeness when using non level 0 texture images"); 51 52 var canvas = document.getElementById("canvas"); 53 shouldBeNonNull("gl = wtu.create3DContext(canvas, undefined, 2)"); 54 55 testFramebufferTextureWithNonZeroBaseLevel(1); 56 57 debug(""); 58 var successfullyParsed = true; 59 60 </script> 61 <script src="../../js/js-test-post.js"></script> 62 63 </body> 64 </html>