readPixels.html (1305B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <!-- 6 Copyright (c) 2019 The Khronos Group Inc. 7 Use of this source code is governed by an MIT-style license that can be 8 found in the LICENSE.txt file. 9 --> 10 <link rel="stylesheet" type="text/css" href="../unit.css" /> 11 <script type="application/javascript" src="../unit.js"></script> 12 <script type="application/javascript" src="../util.js"></script> 13 <script type="application/javascript"> 14 15 Tests.startUnit = function () { 16 var canvas = document.getElementById('gl'); 17 var gl = wrapGLContext(getGLContext(canvas)); 18 return [gl]; 19 } 20 21 Tests.testReadPixels = function(gl) { 22 var id = new Uint8Array(16 * 16 * 4); 23 assertOk(function(){gl.readPixels(0,0,1,1,gl.RGBA, gl.UNSIGNED_BYTE, id);}); 24 assertOk(function(){gl.readPixels(0,0,16,16,gl.RGBA, gl.UNSIGNED_BYTE, id);}); 25 assertOk(function(){gl.readPixels(15,15,1,1,gl.RGBA, gl.UNSIGNED_BYTE, id);}); 26 } 27 Tests.testReadPixelsRGBA = function(gl) { 28 gl.clearColor(1, 0, 1, 0); 29 gl.clear(gl.COLOR_BUFFER_BIT); 30 var id = new Uint8Array(4); 31 gl.readPixels(1,2,1,1,gl.RGBA, gl.UNSIGNED_BYTE, id); 32 assertArrayEquals([255, 0, 255, 0], id); 33 } 34 35 Tests.endUnit = function(gl) { 36 } 37 38 </script> 39 <style>canvas{ position:absolute; }</style> 40 </head><body> 41 <canvas id="gl" width="16" height="16"></canvas> 42 </body></html>