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.
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>
17 <canvas id=
"example" width=
"4" height=
"4"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
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);
36 testFailed("context does not exist");
38 testPassed("context exists");
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");
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]]);
77 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Tests should complete without gl errors");
81 var successfullyParsed
= true;
83 <script src=
"../../js/js-test-post.js"></script>