tex-image-10bpc.html (2309B)
1 <!-- 2 Copyright (c) 2023 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>Ensure 10bpc image is not crushed to 8bpc in texImage2D</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="example" width="24" height="24"></canvas> 18 <div id="description"></div> 19 <div id="console"></div> 20 <script> 21 "use strict"; 22 description(document.title); 23 var wtu = WebGLTestUtils; 24 var gl = wtu.create3DContext("example", undefined, 2); 25 var uniquePixels; 26 27 // This is an 8x1, 10-bit-per-channel PNG (encoded as 16bpc). 28 // The first pixel is black, and each next pixel is one brighter; approximately: 29 // (0/1023,0,0), (1/1023,0,0), (2/1023,0,0), ..., (7/1023,0,0) 30 const imgW = 8, imgH = 1; 31 const imgURL = "../../../resources/red-gradient-8x1-10bit-untagged.png"; 32 33 const img = document.createElement("img"); 34 img.onload = () => { 35 const tex = gl.createTexture(); 36 gl.bindTexture(gl.TEXTURE_2D, tex); 37 const level = 0; 38 const internalformat = gl.RGB10_A2; 39 const border = 0; 40 const format = gl.RGBA; 41 const type = gl.UNSIGNED_INT_2_10_10_10_REV; 42 gl.texImage2D(gl.TEXTURE_2D, level, internalformat, imgW, imgH, border, format, type, img); 43 44 const fbo = gl.createFramebuffer(); 45 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); 46 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); 47 48 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE"); 49 50 const pixels = new Uint32Array(imgW * imgH); 51 gl.readPixels(0, 0, imgW, imgH, format, type, pixels); 52 uniquePixels = new Set(pixels); 53 // If the image was crushed to 8bpc, there will be 2-3 distinct values: 54 // (0/255,0,0), (1/255,0,0), and maybe (2/255,0,0) (depending on truncation vs rounding). 55 // If it wasn't, there should be 7-8. 56 // At time of writing, on Mac M1, Chrome gets 2 if it's crushed, and 7 if it's not. 57 shouldBeGreaterThanOrEqual("uniquePixels.size", "7", "there should be at least 7 distinct color values"); 58 59 finishTest(); 60 }; 61 img.src = imgURL; 62 63 var successfullyParsed = true; 64 </script> 65 </body> 66 </html>