summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/rendering/blitframebuffer-unaffected-by-colormask.html
blob: 3d2d7f54bca5f2010fb82f34e20d8a162fa8e18c (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!--
Copyright (c) 2021 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>BlitFramebuffer Should Be Unaffected by ColorMask</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>
<canvas id="canvas" width="8" height="8"></canvas>
<div id="description"></div>
<div id="console"></div>

<script>
"use strict";

const wtu = WebGLTestUtils;
description("This test verifies that the blitFramebuffer is unaffected by the colorMask state.");

debug('Regression test for <a href="https://crbug.com/1257769">https://crbug.com/1257769</a> and <a href="https://bugs.webkit.org/show_bug.cgi?id=220129">https://bugs.webkit.org/show_bug.cgi?id=220129</a>');

function allocateTexture(gl, size) {
    const tex = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, tex);
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, size, size, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    return tex;
}

function allocateFBO(gl, tex) {
    const fbo = gl.createFramebuffer();
    gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fbo);
    gl.framebufferTexture2D(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
    return fbo;
}

function run() {
    const gl = wtu.create3DContext("canvas", { antialias: false }, 2);

    if (!gl) {
        testFailed("WebGL context does not exist");
        finishTest();
        return;
    }

    const size = 8;

    testPassed("WebGL context exists");

    // Allocate source and destination textures and framebuffer objects.
    const sourceTex = allocateTexture(gl, size);
    const sourceFBO = allocateFBO(gl, sourceTex);

    const destTex = allocateTexture(gl, size);
    const destFBO = allocateFBO(gl, destTex);

    const program = wtu.setupColorQuad(gl);

    gl.bindFramebuffer(gl.FRAMEBUFFER, sourceFBO);

    // Clear the source framebuffer to red.
    gl.clearColor(1, 0, 0, 1);
    gl.colorMask(true, true, true, true);
    gl.clear(gl.COLOR_BUFFER_BIT);

    // Draw a transparent green quad.
    gl.useProgram(program);
    wtu.drawFloatColorQuad(gl, [ 0, 255, 0, 0 ]);

    // Clear the alpha channel.
    gl.colorMask(false, false, false, true);
    gl.clearColor(0, 0, 0, 1);
    gl.clear(gl.COLOR_BUFFER_BIT);

    // At this point, even setting the colorMask to all-true won't
    // work around the bug, since that state is latched inside ANGLE
    // only during draws / clears.

    // Blit source to dest.
    gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, destFBO);
    gl.blitFramebuffer(0, 0, size, size, 0, 0, size, size, gl.COLOR_BUFFER_BIT, gl.NEAREST);
    gl.bindFramebuffer(gl.READ_FRAMEBUFFER, destFBO);

    // Note that the on-screen canvas is always black - we don't blit the result to it.
    wtu.checkCanvas(gl, [ 0, 255, 0, 255 ], "should be green", 1);
    finishTest();
}

var successfullyParsed = true;

requestAnimationFrame(run);

</script>

</body>
</html>