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>Test clearBufferfv with alpha:false canvas
</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 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"canvas" width=
"20" height=
"20"> </canvas>
22 description("This tests the operation of clearBufferfv with the back buffer of an alpha:false canvas.");
24 function verifyOnePixel(readFormat
, readType
, arrayType
, expectedColor
) {
25 var buffer
= new arrayType(4);
26 gl
.readPixels(0, 0, 1, 1, readFormat
, readType
, buffer
);
27 if (buffer
[0] == expectedColor
[0] &&
28 buffer
[1] == expectedColor
[1] &&
29 buffer
[2] == expectedColor
[2] &&
30 buffer
[3] == expectedColor
[3]) {
31 testPassed("clearBufferfv set the color buffer to the correct value");
33 testFailed("clearBufferfv failed to work. Expected: " + expectedColor
+ ", got: " + buffer
);
37 function testClearBuffer(func
, format
, arrayType
, readFormat
, readType
, readArrayType
) {
39 debug("Testing " + func
);
41 var srcData
= new arrayType([0, 1, 0, 0]);
42 gl
[func
](gl
.COLOR
, 0, srcData
);
43 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "clearBuffer with no srcOffset should succeed");
44 // Back buffer has no alpha channel
45 verifyOnePixel(readFormat
, readType
, Uint8Array
, [0, 255, 0, 255]);
48 var wtu
= WebGLTestUtils
;
49 var canvas
= document
.getElementById("canvas");
50 var gl
= wtu
.create3DContext(canvas
, { alpha
:false }, 2);
52 testFailed("context does not exist");
54 testPassed("context exists");
58 func
: "clearBufferfv", format
: gl
.RGBA
, arrayType
: Float32Array
,
59 readFormat
: gl
.RGBA
, readType
: gl
.UNSIGNED_BYTE
, readArrayType
: Uint8Array
,
63 for (var tt
= 0; tt
< testCases
.length
; ++tt
) {
64 var test
= testCases
[tt
];
65 if (test
.extension
&& !gl
.getExtension(test
.extension
))
67 testClearBuffer(test
.func
, test
.format
, test
.arrayType
,
68 test
.readFormat
, test
.readType
, test
.readArrayType
);
73 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no error");
74 var successfullyParsed
= true;
77 <script src=
"../../js/js-test-post.js"></script>