blob: dcf817d3d9dd8dffb7e2336bd664ffe89e0175d9 [file] [log] [blame]
<!--
/*
** Copyright (c) 2017 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test clearBufferfv with alpha:false canvas</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="20" height="20"> </canvas>
<script>
"use strict";
description("This tests the operation of clearBufferfv with the back buffer of an alpha:false canvas.");
function verifyOnePixel(readFormat, readType, arrayType, expectedColor) {
var buffer = new arrayType(4);
gl.readPixels(0, 0, 1, 1, readFormat, readType, buffer);
if (buffer[0] == expectedColor[0] &&
buffer[1] == expectedColor[1] &&
buffer[2] == expectedColor[2] &&
buffer[3] == expectedColor[3]) {
testPassed("clearBufferfv set the color buffer to the correct value");
} else {
testFailed("clearBufferfv failed to work. Expected: " + expectedColor + ", got: " + buffer);
}
}
function testClearBuffer(func, format, arrayType, readFormat, readType, readArrayType) {
debug("");
debug("Testing " + func);
var srcData = new arrayType([0, 1, 0, 0]);
gl[func](gl.COLOR, 0, srcData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "clearBuffer with no srcOffset should succeed");
// Back buffer has no alpha channel
verifyOnePixel(readFormat, readType, Uint8Array, [0, 255, 0, 255]);
}
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, { alpha:false }, 2);
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
var testCases = [
{
func: "clearBufferfv", format: gl.RGBA, arrayType: Float32Array,
readFormat: gl.RGBA, readType: gl.UNSIGNED_BYTE, readArrayType: Uint8Array,
},
];
for (var tt = 0; tt < testCases.length; ++tt) {
var test = testCases[tt];
if (test.extension && !gl.getExtension(test.extension))
continue;
testClearBuffer(test.func, test.format, test.arrayType,
test.readFormat, test.readType, test.readArrayType);
}
}
debug("");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no error");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>