summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/canvas/buffer-offscreen-test.html
blob: c0bf2d35fba818e40620060e53b05199f8bfc318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL required buffer clear behaviour test</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>
<style type="text/css">
body {
    height: 3000px;
}
</style>
</head>
<body>
<div id="description"></div>
<canvas width="20" height="20" style="border: 1px solid blue;" id="c"></canvas>
<div id="console"></div>
<script>
description("This test ensures WebGL implementations correctly clear " +
            "the drawing buffer on composite if preserveDrawingBuffer is false.");
debug("");

var wtu = WebGLTestUtils;
var gl1 = wtu.create3DContext("c");
var gl2 = wtu.create3DContext();
shouldBeNonNull("gl1");
shouldBeNonNull("gl2");

shouldBeFalse('gl1.getContextAttributes().preserveDrawingBuffer');
shouldBeFalse('gl2.getContextAttributes().preserveDrawingBuffer');

function init(gl) {
    gl.clearColor(1, 0, 0, 1);
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);

    // enable scissor here, before compositing, to make sure it's correctly
    // ignored and restored
    gl.scissor(0, 10, 10, 10);
    gl.enable(gl.SCISSOR_TEST);
}

init(gl1);
init(gl2);

wtu.waitForComposite(function() {
    function clear(gl) {
        // scissor was set earlier
        gl.clearColor(0, 0, 1, 1);
        gl.clear(gl.COLOR_BUFFER_BIT);
    }
    clear(gl1);
    clear(gl2);

    debug("check on screen canvas");
    wtu.checkCanvasRect(gl1, 0, 10, 10, 10, [0, 0, 255, 255],
        "cleared corner should be blue, stencil should be preserved");
    wtu.checkCanvasRect(gl1, 0, 0, 10, 10, [0, 0, 0, 0],
        "remainder of buffer should be cleared");
    debug("check off screen canvas");
    wtu.checkCanvasRect(gl2, 0, 10, 10, 10, [0, 0, 255, 255],
        "cleared corner should be blue, stencil should be preserved");
    wtu.checkCanvasRect(gl2, 0, 0, 10, 10, [255, 0, 0, 255],
        "remainder of buffer should be un-cleared red");

    finishTest();
});

var successfullyParsed = true;
</script>
</body>
</html>