summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/rendering/framebuffer-switch.html
blob: df2a9ef55ec5463358176de6dde1c84c7930cca9 (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
<!--
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 framebuffer switching conformance 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>
</head>
<body>
<canvas id="canvas" width="64" height="64"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Test framebuffer switching. The test switches between two framebuffers, copying rendering results from one to the other.");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");

var gl = wtu.create3DContext("canvas");
var program = wtu.setupTexturedQuad(gl);

var tex1 = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex1);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
var fb1 = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb1);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex1, 0);

var tex2 = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex2);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
var fb2 = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb2);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex2, 0);

gl.bindTexture(gl.TEXTURE_2D, tex1);
gl.clearColor(1.0, 1.0, 1.0, 1.0);

wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");

var iterate = function(checkFBOs, iterations) {
    for (var i = 0; i < iterations; ++i) {
        debug("Clearing framebuffer 1 to white");
        gl.bindFramebuffer(gl.FRAMEBUFFER, fb1);
        if (checkFBOs)
            shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
        gl.clear(gl.COLOR_BUFFER_BIT);

        debug("Copying framebuffer 1 to framebuffer 2");
        gl.bindFramebuffer(gl.FRAMEBUFFER, fb2);
        if (checkFBOs)
            shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
        gl.drawArrays(gl.TRIANGLES, 0, 6);
    }
    // Read what is in fb2
    wtu.checkCanvas(gl, [255,255,255,255], "Framebuffer 2 should be white");
};

debug("");
debug("Warm-up iteration");
iterate(true, 1);

debug("");
debug("Iterating the test a few times since at least one bug it has exposed is somewhat flaky.");
for (var i = 0; i < 3; ++i) {
    debug("");
    debug("Iteration " + (i + 1));
    iterate(false, 2);
}

debug("");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors at the end of the test.");

finishTest();

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