context-no-alpha-fbo-with-alpha.html (2490B)
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 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 12 <script src="../../js/js-test-pre.js"></script> 13 <script src="../../js/webgl-test-utils.js"></script> 14 15 <script> 16 "use strict"; 17 18 var wtu = WebGLTestUtils; 19 20 // This declaration needs to be global for "shouldBe" to see it 21 var gl; 22 23 function init() 24 { 25 description('Verify that a WebGL context with alpha:false still works correctly after handling textures with an alpha channel.'); 26 27 runTest(); 28 } 29 30 function getWebGL(contextAttribs) 31 { 32 return wtu.create3DContext("c", contextAttribs); 33 } 34 35 function runTest() 36 { 37 var buf = new Uint8Array(1 * 1 * 4); 38 shouldBeNonNull("gl = getWebGL({ alpha: false, antialias: false })"); 39 40 // Clear to black. Alpha channel of clearColor() is ignored. 41 gl.clearColor(0.0, 0.0, 0.0, 0.7); 42 gl.clear(gl.COLOR_BUFFER_BIT); 43 wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 255], 44 "Alpha channel of clearColor should be ignored"); 45 46 wtu.waitForComposite(function() { 47 // Make a new framebuffer and attach a texture with an alpha channel. 48 var fbo = gl.createFramebuffer(); 49 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); 50 var texture = gl.createTexture(); 51 gl.bindTexture(gl.TEXTURE_2D, texture); 52 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 53 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); 54 55 // Clear texture. Note that alpha channel is not 1.0. 56 gl.clearColor(1.0, 0.0, 0.0, 0.5); 57 gl.clear(gl.COLOR_BUFFER_BIT); 58 wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255, 0, 0, 128], 59 "Alpha channel of clearColor should be obeyed for FBO with alpha channel", 60 1); 61 62 // Bind back buffer and check that its alpha channel is still 1.0. 63 gl.bindFramebuffer(gl.FRAMEBUFFER, null); 64 wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 255], 65 "Alpha channel of back buffer should still be 255"); 66 finishTest(); 67 }); 68 } 69 70 </script> 71 </head> 72 <body onload="init()"> 73 <div id="description"></div> 74 <div id="console"></div> 75 <canvas width="20" height="20" style="border: 1px solid blue;" id="c"></canvas> 76 </body> 77 </html>