Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / renderbuffers / multisample-with-full-sample-counts.html
blob2e04385f28e3be03de86bdee1c057c5e9959e157
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../js/js-test-pre.js"></script>
13 <script src="../../js/webgl-test-utils.js"></script>
14 </head>
15 <body>
16 <canvas id="canvas" width="32" height="32" style="width: 32px; height: 32px;"></canvas>
17 <div id="description"></div>
18 <div id="console"></div>
19 <script>
20 "use strict";
21 var wtu = WebGLTestUtils;
22 description(' Test multisample with sample number from 1 to max sample number which also includes the samples that may not be in the supported sample list');
24 var gl = wtu.create3DContext("canvas", null, 2);
25 var size = 32;
26 var program;
28 if (!gl) {
29 testFailed('canvas.getContext() failed');
30 } else {
31 program = wtu.setupColorQuad(gl);
32 gl.viewport(0, 0, size, size);
33 var supportedSampleCountArray = gl.getInternalformatParameter(gl.RENDERBUFFER, gl.RGBA8, gl.SAMPLES);
34 var iterationCount = supportedSampleCountArray[0] + 1;
35 for (var i = 1; i < iterationCount; i++)
37 runTest(gl, i, false);
38 runTest(gl, i, true);
42 function runTest(gl, sampleCount, isInverted) {
43 // Setup multi-sample RBO
44 var msColorRbo = gl.createRenderbuffer();
45 gl.bindRenderbuffer(gl.RENDERBUFFER, msColorRbo);
46 gl.renderbufferStorageMultisample(gl.RENDERBUFFER, sampleCount, gl.RGBA8, size, size);
48 // Setup multi-sample FBO.
49 var msFbo = gl.createFramebuffer();
50 gl.bindFramebuffer(gl.FRAMEBUFFER, msFbo);
51 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, msColorRbo);
53 // Setup resolve color RBO.
54 var resolveColorRbo = gl.createRenderbuffer();
55 gl.bindRenderbuffer(gl.RENDERBUFFER, resolveColorRbo);
56 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA8, size, size);
57 // Setup resolve FBO
58 var resolveFbo = gl.createFramebuffer();
59 gl.bindFramebuffer(gl.FRAMEBUFFER, resolveFbo);
60 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, resolveColorRbo);
62 gl.bindFramebuffer(gl.FRAMEBUFFER, msFbo);
63 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
64 testFailed("Framebuffer incomplete.");
65 return;
67 gl.clearColor(0.0, 0.0, 0.0, 1.0);
68 gl.clear(gl.COLOR_BUFFER_BIT);
70 gl.enable(gl.SAMPLE_COVERAGE);
71 var coverageValue = isInverted ? 0.0 : 1.0;
72 gl.sampleCoverage(coverageValue, isInverted);
74 var quadColor = [1.0, 0.0, 0.0, 1.0];
75 gl.useProgram(program);
76 wtu.drawFloatColorQuad(gl, quadColor);
78 gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, resolveFbo);
79 gl.blitFramebuffer(0, 0, size, size, 0, 0, size, size, gl.COLOR_BUFFER_BIT, gl.NEAREST);
81 gl.bindFramebuffer(gl.FRAMEBUFFER, resolveFbo);
82 wtu.checkCanvasRect(gl, 0, 0, size, size, [255, 0, 0, 255],
83 "User buffer has been rendered to red with sample = "
84 + sampleCount + ", coverageValue = " + coverageValue
85 + " and isInverted = " + isInverted, 3);
87 gl.disable(gl.SAMPLE_COVERAGE);
88 gl.deleteRenderbuffer(msColorRbo);
89 gl.deleteRenderbuffer(resolveColorRbo);
90 gl.deleteFramebuffer(msFbo);
91 gl.deleteFramebuffer(resolveFbo);
94 var successfullyParsed = true;
95 </script>
96 <script src="../../js/js-test-post.js"></script>
97 </body>
98 </html>