Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / reading / read-pixels-from-rgb8-into-pbo-bug.html
blobb4f91f1d3c0a89a7afc0b82034402f92b0e17c81
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 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL 2 Conformance Test: readPixels from RGB8 Buffer Into Pixel Pack Buffer.</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="4" height="4"></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
20 <script>
21 "use strict";
23 debug("");
24 description("Verifies readPixels from RGB8 buffer into PIXEL_PACK buffer works");
26 debug("On MacOSX with AMD GPUs, the alpha channel is readback as 0 instead of 255");
28 var wtu = WebGLTestUtils;
29 var pixel = [0, 0, 0, 0];
30 var expectedColor = [255, 102, 0, 255];
32 var canvas = document.getElementById("example");
33 var gl = wtu.create3DContext(canvas, undefined, 2);
35 if (!gl) {
36 testFailed("context does not exist");
37 } else {
38 testPassed("context exists");
40 var width = 4;
41 var height = 4;
43 var renderbuffer = gl.createRenderbuffer();
44 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
45 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGB8, width, height);
47 var fbo = gl.createFramebuffer();
48 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
49 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, renderbuffer);
51 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
52 testFailed("framebuffer with RGB8 color buffer is incomplete");
53 } else {
54 gl.clearColor(1.0, 0.0, 0.0, 1.0);
55 gl.clear(gl.COLOR_BUFFER_BIT);
57 var pbo = gl.createBuffer();
58 gl.bindBuffer(gl.PIXEL_PACK_BUFFER, pbo);
59 gl.bufferData(gl.PIXEL_PACK_BUFFER, width * height * 4, gl.STATIC_COPY);
61 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, 0);
63 var data = new Uint8Array(width * height * 4);
64 gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data);
66 for (var ii = 0; ii < width * height; ++ii) {
67 if (data[ii * 4] != 255 ||
68 data[ii * 4 + 1] != 0 ||
69 data[ii * 4 + 2] != 0 ||
70 data[ii * 4 + 3] != 255) {
71 testFailed("Expected in pixel " + ii + ": [255,0,0,255], got: " +
72 [data[ii * 4], data[ii * 4 + 1], data[ii * 4 + 2], data[ii * 4 + 3]]);
73 break;
77 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Tests should complete without gl errors");
80 debug("");
81 var successfullyParsed = true;
82 </script>
83 <script src="../../js/js-test-post.js"></script>
84 </body>
85 </html>