summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/rendering/blitframebuffer-resolve-to-back-buffer.html
blob: addbdc4e9d1ac832ffc9fbfdfb80183da2df53da (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!--
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 BlitFramebuffer Resolve to Back Buffer</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="canvasHeader"></div>
<div id="console"></div>

<script>
"use strict";

var wtu = WebGLTestUtils;
description("This test verifies the behavior of blitFramebuffer when resolving directly to the back buffer.");

debug("Regression test for <a href='http://crbug.com/699566'>http://crbug.com/699566</a>");

function runTest(testParams) {
    const sz = 64;

    if (testParams.multisampled === undefined) {
        testParams.multisampled = true;
    }

    debug('');
    debug('Testing with alpha = ' + testParams.attribs.alpha +
          ', antialias = ' + testParams.attribs.antialias +
          ', internalformat = ' + testParams.internalformat +
          ', multisampled = ' + testParams.multisampled);

    var canvas = document.createElement('canvas');
    canvas.width = sz;
    canvas.height = sz;
    document.getElementById('canvasHeader').appendChild(canvas);
    var gl = wtu.create3DContext(canvas, testParams.attribs, 2);

    // Find the supported samples for a multisampled renderbuffer of the appropriate internal format.
    let samples = [0];
    if (testParams.multisampled) {
        samples = gl.getInternalformatParameter(gl.RENDERBUFFER, gl[testParams.internalformat], gl.SAMPLES);
        if (!samples || !samples.length) {
            testFailed("At least one multisampled format is required to be supported");
            return;
        }
    }

    // Create a framebuffer with a multisampled renderbuffer.
    let rb = gl.createRenderbuffer();
    gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
    gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples[0], gl[testParams.internalformat], sz, sz);

    // Create a framebuffer.
    let fb = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
    gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);

    // Check for completeness.
    if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
        testFailed("Rendering to a multisampled renderbuffer of format " + testParams.internalformat + " is required by the spec");
        return;
    }

    // Clear to specified color.
    gl.clearColor.apply(gl, testParams.clearColor);
    gl.clear(gl.COLOR_BUFFER_BIT);

    // Unbind draw framebuffer. Read framebuffer is now user framebuffer;
    // draw framebuffer is default framebuffer.
    gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);

    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors before blit");

    // Blit from user framebuffer to default framebuffer.
    gl.blitFramebuffer(0, 0, sz, sz, 0, 0, sz, sz, gl.COLOR_BUFFER_BIT, gl.NEAREST);

    if (testParams.shouldSucceed) {
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be legal to blit/resolve to default back buffer");
    } else {
        wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "incompatible src/dest blitFramebuffer combination must fail");
    }

    // Unbind user framebuffer completely.
    gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);

    if (testParams.shouldSucceed) {
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no error before readback");
        wtu.checkCanvasRect(gl, 0, 0, 8, 8, testParams.resultColor);
        wtu.glErrorShouldBe(gl, gl.NO_ERROR);
    }
}

var tests = [
    // No-alpha, no-antialias, RGB8 source
    {
        attribs: {
            alpha: false,
            antialias: false,
        },
        internalformat: 'RGB8',
        clearColor: [ 0.0, 1.0, 0.0, 0.5 ],
        resultColor: [ 0, 255, 0, 255 ],
        shouldSucceed: true,
    },
    // No-alpha, no-antialias, RGBA8 source
    {
        attribs: {
            alpha: false,
            antialias: false,
        },
        internalformat: 'RGBA8',
        clearColor: [ 0.0, 1.0, 0.0, 0.5 ],
        resultColor: [ 0, 255, 0, 255 ],
        shouldSucceed: false,
    },
    // No-alpha, no-antialias, RGBA8 source, single-sampled blit
    {
        attribs: {
            alpha: false,
            antialias: false,
        },
        internalformat: 'RGBA8',
        clearColor: [ 0.0, 1.0, 0.0, 0.5 ],
        resultColor: [ 0, 255, 0, 255 ],
        shouldSucceed: true,
        multisampled: false,
    },
    // Alpha, no-antialias, RGB8 source
    {
        attribs: {
            alpha: true,
            antialias: false,
        },
        internalformat: 'RGB8',
        clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
        resultColor: [ 0, 255, 0, 255 ],
        shouldSucceed: false,
    },
    // No-alpha, no-antialias, RGBA8 source
    // premultiplyAlpha:false just to avoid semantically incorrect
    // colors (should only affect rendering, not contents of WebGL
    // back buffer)
    {
        attribs: {
            alpha: false,
            antialias: false,
            premultiplyAlpha: false,
        },
        internalformat: 'RGBA8',
        clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
        resultColor: [ 0, 255, 0, 255 ],
        shouldSucceed: false,
    },
    // Alpha, no-antialias, RGBA8 source
    // premultiplyAlpha:false just to avoid semantically incorrect
    // colors (should only affect rendering, not contents of WebGL
    // back buffer)
    {
        attribs: {
            alpha: true,
            antialias: false,
            premultiplyAlpha: false,
        },
        internalformat: 'RGBA8',
        clearColor: [ 0.0, 1.0, 0.0, 0.0 ],
        resultColor: [ 0, 255, 0, 0 ],
        shouldSucceed: true,
    },

    // All attempts to blit to an antialiased back buffer should fail.

    // No-alpha, antialias, RGB8 source
    {
        attribs: {
            alpha: false,
            antialias: true,
        },
        internalformat: 'RGB8',
        clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
        resultColor: [ 0, 255, 0, 255 ],
        shouldSucceed: false,
    },
    // Alpha, antialias, RGB8 source
    {
        attribs: {
            alpha: true,
            antialias: true,
        },
        internalformat: 'RGB8',
        clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
        resultColor: [ 0, 255, 0, 255 ],
        shouldSucceed: false,
    },
    // No-alpha, antialias, RGBA8 source
    // premultiplyAlpha:false just to avoid semantically incorrect
    // colors (should only affect rendering, not contents of WebGL
    // back buffer)
    {
        attribs: {
            alpha: false,
            antialias: true,
            premultiplyAlpha: false,
        },
        internalformat: 'RGBA8',
        clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
        resultColor: [ 0, 255, 0, 255 ],
        shouldSucceed: false,
    },
    // Alpha, antialias, RGBA8 source
    // premultiplyAlpha:false just to avoid semantically incorrect
    // colors (should only affect rendering, not contents of WebGL
    // back buffer)
    {
        attribs: {
            alpha: true,
            antialias: true,
            premultiplyAlpha: false,
        },
        internalformat: 'RGBA8',
        clearColor: [ 0.0, 1.0, 0.0, 0.0 ],
        resultColor: [ 0, 255, 0, 0 ],
        shouldSucceed: false,
    },
];

for (var ii in tests) {
    runTest(tests[ii]);
}

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>

</body>
</html>