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.
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>
17 <canvas id=
"example" width=
"24" height=
"24"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
22 description(document
.title
);
23 var wtu
= WebGLTestUtils
;
24 var gl
= wtu
.create3DContext("example", undefined, 2);
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";
33 const img
= document
.createElement("img");
35 const tex
= gl
.createTexture();
36 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
38 const internalformat
= gl
.RGB10_A2
;
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
);
44 const fbo
= gl
.createFramebuffer();
45 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
46 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, tex
, 0);
48 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
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");
63 var successfullyParsed
= true;