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
content / test / data / gpu / pixel_webgl2_blitframebuffer_result_displayed.html [blame]
<!DOCTYPE HTML>
<html>
<head>
<title>WebGL 2.0 Test: BlitFramebuffer Result Must Be Displayed</title>
<style type="text/css">
.nomargin {
margin: 0px auto;
}
</style>
<script>
function sendResult(status, detail) {
console.log(detail);
if (window.domAutomationController) {
window.domAutomationController.send(status);
} else {
console.log(status);
}
}
var gl;
var fbo;
var width;
var height;
var numFramesBeforeBlit = 15;
var numFramesBeforeEnd = 15;
function main() {
var canvas = document.getElementById("c");
gl = canvas.getContext('webgl2', {alpha: false, antialias: false,
depth: false, stencil: false});
if (!gl) {
sendResult("FAILURE", "WebGL 2.0 context not supported");
return;
}
width = gl.drawingBufferWidth;
height = gl.drawingBufferHeight;
fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
var rb = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA8, width, height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
if (status != gl.FRAMEBUFFER_COMPLETE) {
sendResult("FAILURE", "Framebuffer was incomplete: status = " + status);
return;
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
// Clear background of canvas to red
gl.clearColor(1.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
// Repeatedly clear user framebuffer to green but only do blit the
// last time, to ensure canvas was composited
window.requestAnimationFrame(clearAndMaybeBlit);
}
function clearAndMaybeBlit()
{
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
// Clear user framebuffer to green
gl.clearColor(0.0, 1.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
if (--numFramesBeforeBlit == 0) {
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, fbo);
gl.blitFramebuffer(0, 0, width, height,
0, 0, width, height,
gl.COLOR_BUFFER_BIT, gl.NEAREST);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
// That's the only operation done to the canvas. Wait to signal
// acknowledgment to the harness.
window.requestAnimationFrame(waitForFinish);
} else {
// Do this again
window.requestAnimationFrame(clearAndMaybeBlit);
}
}
function waitForFinish()
{
if (--numFramesBeforeEnd == 0) {
sendResult("SUCCESS", "Test complete");
} else {
window.requestAnimationFrame(waitForFinish);
}
}
</script>
</head>
<body onload="main()">
<canvas id="c" width="200" height="200" class="nomargin" style="position:absolute; top:0px; left:0px"></canvas>
</div>
</body>
</html>