clearbufferfv-with-alpha-false.html (2498B)
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>Test clearBufferfv with alpha:false canvas</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="20" height="20"> </canvas> 20 <script> 21 "use strict"; 22 description("This tests the operation of clearBufferfv with the back buffer of an alpha:false canvas."); 23 24 function verifyOnePixel(readFormat, readType, arrayType, expectedColor) { 25 var buffer = new arrayType(4); 26 gl.readPixels(0, 0, 1, 1, readFormat, readType, buffer); 27 if (buffer[0] == expectedColor[0] && 28 buffer[1] == expectedColor[1] && 29 buffer[2] == expectedColor[2] && 30 buffer[3] == expectedColor[3]) { 31 testPassed("clearBufferfv set the color buffer to the correct value"); 32 } else { 33 testFailed("clearBufferfv failed to work. Expected: " + expectedColor + ", got: " + buffer); 34 } 35 } 36 37 function testClearBuffer(func, format, arrayType, readFormat, readType, readArrayType) { 38 debug(""); 39 debug("Testing " + func); 40 41 var srcData = new arrayType([0, 1, 0, 0]); 42 gl[func](gl.COLOR, 0, srcData); 43 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "clearBuffer with no srcOffset should succeed"); 44 // Back buffer has no alpha channel 45 verifyOnePixel(readFormat, readType, Uint8Array, [0, 255, 0, 255]); 46 } 47 48 var wtu = WebGLTestUtils; 49 var canvas = document.getElementById("canvas"); 50 var gl = wtu.create3DContext(canvas, { alpha:false }, 2); 51 if (!gl) { 52 testFailed("context does not exist"); 53 } else { 54 testPassed("context exists"); 55 56 var testCases = [ 57 { 58 func: "clearBufferfv", format: gl.RGBA, arrayType: Float32Array, 59 readFormat: gl.RGBA, readType: gl.UNSIGNED_BYTE, readArrayType: Uint8Array, 60 }, 61 ]; 62 63 for (var tt = 0; tt < testCases.length; ++tt) { 64 var test = testCases[tt]; 65 if (test.extension && !gl.getExtension(test.extension)) 66 continue; 67 testClearBuffer(test.func, test.format, test.arrayType, 68 test.readFormat, test.readType, test.readArrayType); 69 } 70 } 71 72 debug(""); 73 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no error"); 74 var successfullyParsed = true; 75 76 </script> 77 <script src="../../js/js-test-post.js"></script> 78 79 </body> 80 </html>