Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / renderbuffers / multisampled-stencil-renderbuffer-initialization.html
blobcb351454d2c0b5424b9a0117cfbf41a6596950f7
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="testbed" width="40" height="40" style="width: 40px; height: 40px;"></canvas>
17 <div id="description"></div>
18 <div id="console"></div>
19 <script>
20 "use strict";
21 var wtu = WebGLTestUtils;
22 description('Verify multisampled stencil renderbuffers are initialized to 0 before being read in WebGL');
24 var gl = wtu.create3DContext("testbed", null, 2);
26 if (!gl) {
27 testFailed('canvas.getContext() failed');
28 } else {
29 // Set the clear color to green. It should never show up.
30 gl.clearColor(0, 1, 0, 1);
31 gl.disable(gl.DEPTH_TEST);
33 let c = gl.canvas;
34 var maxSamples = gl.getInternalformatParameter(
35 gl.RENDERBUFFER, gl.RGBA8, gl.SAMPLES)[0];
36 for (let i = 0; i < 2; ++i) {
37 // Non-multisampled tests
38 runTest(gl, {alloc1: {w: c.width, h: c.height, s: 0}, alloc2: null});
39 runTest(gl, {alloc1: null, alloc2: {w: c.width, h: c.height, s: 0}});
40 // Multisampled tests
41 runTest(gl, {alloc1: {w: c.width, h: c.height, s: maxSamples}, alloc2: null});
42 runTest(gl, {alloc1: null, alloc2: {w: c.width, h: c.height, s: maxSamples}});
44 // Tests for initially allocating at the wrong size.
45 // This is caused by a Qualcomm driver bug: http://crbug.com/696126
46 runTest(gl, {alloc1: {w: 5, h: 5, s: maxSamples}, alloc2: {w: c.width, h: c.height, s: maxSamples}});
49 // Testing buffer clearing won't change the clear values.
50 var clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE);
51 shouldBe("clearColor", "[0, 1, 0, 1]");
52 wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors');
55 function runTest(gl, params) {
56 debug("Test for stencil buffer: " + JSON.stringify(params));
57 let resolve = params.alloc2 ? params.alloc2 : params.alloc1;
58 gl.viewport(0, 0, resolve.w, resolve.h);
59 wtu.checkCanvasRect(gl, 0, 0, resolve.w, resolve.h,
60 [0, 0, 0, 0],
61 "internal buffers have been initialized to 0");
63 gl.disable(gl.STENCIL_TEST);
65 // fill the back buffer so we know that reading below happens from
66 // the renderbuffer.
67 gl.clearStencil(2);
68 gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
70 // Set up (color+stencil) non-multisampled buffer to blit to and read back from.
71 var fbo = gl.createFramebuffer();
72 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
73 var buffer = gl.createRenderbuffer();
74 gl.bindRenderbuffer(gl.RENDERBUFFER, buffer);
75 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA8, resolve.w, resolve.h);
76 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, buffer);
77 var stencilBuffer = gl.createRenderbuffer();
78 gl.bindRenderbuffer(gl.RENDERBUFFER, stencilBuffer);
79 gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, resolve.w, resolve.h);
80 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, stencilBuffer);
81 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
82 debug("Skip: framebuffer is allowed to be incomplete.");
83 return;
85 wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors');
86 gl.clearStencil(2);
87 gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
88 wtu.checkCanvasRect(gl, 0, 0, resolve.w, resolve.h,
89 [0, 255, 0, 255],
90 "user buffer has been cleared to green");
92 // Set up (stencil-only) multisampled buffer to test.
93 var fbo_m = gl.createFramebuffer();
94 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo_m);
95 var buffer_m = gl.createRenderbuffer();
96 gl.bindRenderbuffer(gl.RENDERBUFFER, buffer_m);
98 if (params.alloc1) {
99 allocStorage(params.alloc1.w, params.alloc1.h, params.alloc1.s);
101 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, buffer_m);
102 if (params.alloc2) {
103 if (params.alloc1) {
104 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
105 debug("Skip: framebuffer is allowed to be incomplete.");
106 return;
108 // Clear the FBO in order to make sure framebufferRenderbuffer is
109 // committed. (In Firefox, framebufferRenderbuffer is deferred, so this
110 // is needed to trigger the bug.)
111 gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
113 allocStorage(params.alloc2.w, params.alloc2.h, params.alloc2.s);
116 function allocStorage(width, height, samples) {
117 gl.renderbufferStorageMultisample(
118 gl.RENDERBUFFER, samples, gl.STENCIL_INDEX8, width, height);
119 wtu.glErrorShouldBe(gl, gl.NO_ERROR,
120 "should be no error after renderbufferStorageMultisample(STENCIL_INDEX8).");
123 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
124 debug("Skip: framebuffer is allowed to be incomplete.");
125 return;
127 wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors');
129 // Blit from multisampled buffer to non-multisampled buffer.
130 gl.bindFramebuffer(gl.READ_FRAMEBUFFER, fbo_m);
131 gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fbo);
132 gl.clearStencil(2);
133 gl.clear(gl.STENCIL_BUFFER_BIT);
134 // Blit stencil from fbo_m (should be default value of 0) to fbo (should be 2).
135 gl.blitFramebuffer(0, 0, resolve.w, resolve.h,
136 0, 0, resolve.w, resolve.h,
137 gl.STENCIL_BUFFER_BIT, gl.NEAREST);
138 // fbo stencil should now be 0.
139 wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors');
141 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
142 // Draw a blue quad (with stencil = 1) (should pass the stencil test: 1 > 0)
143 gl.stencilFunc(gl.GREATER, 1, 0xffffffff);
144 gl.enable(gl.STENCIL_TEST);
145 wtu.setupColorQuad(gl);
146 wtu.setFloatDrawColor(gl, [0, 0, 1, 1]);
147 wtu.drawUnitQuad(gl);
148 wtu.checkCanvasRect(gl, 0, 0, resolve.w, resolve.h,
149 [0, 0, 255, 255]);
151 gl.deleteFramebuffer(fbo_m);
152 gl.deleteRenderbuffer(buffer_m);
153 gl.deleteFramebuffer(fbo);
154 gl.deleteRenderbuffer(buffer);
156 gl.canvas.width += 1;
157 gl.canvas.height += 1;
159 wtu.glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors');
160 debug('');
163 var successfullyParsed = true;
164 </script>
165 <script src="../../js/js-test-post.js"></script>
166 </body>
167 </html>