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.
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>
16 <canvas id=
"testbed" width=
"40" height=
"40" style=
"width: 40px; height: 40px;"></canvas>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
21 var wtu
= WebGLTestUtils
;
22 description('Verify multisampled renderbuffers are initialized to 0 before being read in WebGL');
24 var gl
= wtu
.create3DContext("testbed", null, 2);
27 testFailed('canvas.getContext() failed');
29 // Set the clear color to green. It should never show up.
30 gl
.clearColor(0, 1, 0, 1);
33 var maxSamples
= gl
.getInternalformatParameter(
34 gl
.RENDERBUFFER
, gl
.RGBA8
, gl
.SAMPLES
)[0];
35 for (let i
= 0; i
< 2; ++i
) {
36 runTest(gl
, {alloc1
: {w
: c
.width
, h
: c
.height
, s
: maxSamples
}, alloc2
: null});
37 runTest(gl
, {alloc1
: null, alloc2
: {w
: c
.width
, h
: c
.height
, s
: maxSamples
}});
39 // Tests for initially allocating at the wrong size.
40 // This is caused by a Qualcomm driver bug: http://crbug.com/696126
41 runTest(gl
, {alloc1
: {w
: 5, h
: 5, s
: maxSamples
}, alloc2
: {w
: c
.width
, h
: c
.height
, s
: maxSamples
}});
42 runTest(gl
, {alloc1
: {w
: 5, h
: 5, s
: maxSamples
}, alloc2
: {w
: c
.width
, h
: c
.height
, s
: 0}});
43 runTest(gl
, {alloc1
: {w
: 5, h
: 5, s
: 0}, alloc2
: {w
: c
.width
, h
: c
.height
, s
: maxSamples
}});
46 // Testing buffer clearing won't change the clear values.
47 var clearColor
= gl
.getParameter(gl
.COLOR_CLEAR_VALUE
);
48 shouldBe("clearColor", "[0, 1, 0, 1]");
49 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
52 function runTest(gl
, params
) {
53 debug("Test for color buffer: " + JSON
.stringify(params
));
54 let resolve
= params
.alloc2
? params
.alloc2
: params
.alloc1
;
55 wtu
.checkCanvasRect(gl
, 0, 0, resolve
.w
, resolve
.h
,
57 "internal buffers have been initialized to 0");
59 // fill the back buffer so we know that reading below happens from
61 gl
.clear(gl
.COLOR_BUFFER_BIT
);
63 // Set up non-multisampled buffer to blit to and read back from.
64 var fbo
= gl
.createFramebuffer();
65 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
66 var buffer
= gl
.createRenderbuffer();
67 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, buffer
);
68 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.RGBA8
, resolve
.w
, resolve
.h
);
70 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)",
71 "gl.FRAMEBUFFER_COMPLETE");
72 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
73 gl
.clear(gl
.COLOR_BUFFER_BIT
);
74 wtu
.checkCanvasRect(gl
, 0, 0, resolve
.w
, resolve
.h
,
76 "user buffer has been cleared to green");
78 // Set up multisampled buffer to test.
79 var fbo_m
= gl
.createFramebuffer();
80 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo_m
);
81 var buffer_m
= gl
.createRenderbuffer();
82 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, buffer_m
);
85 allocStorage(params
.alloc1
.w
, params
.alloc1
.h
, params
.alloc1
.s
);
87 attachBuffer(buffer_m
);
90 // Clear the FBO in order to make sure framebufferRenderbuffer is
91 // committed. (In Firefox, framebufferRenderbuffer is deferred, so
92 // this is needed to trigger the bug.)
93 gl
.clear(gl
.COLOR_BUFFER_BIT
);
95 allocStorage(params
.alloc2
.w
, params
.alloc2
.h
, params
.alloc2
.s
);
98 function allocStorage(width
, height
, samples
) {
99 gl
.renderbufferStorageMultisample(
100 gl
.RENDERBUFFER
, samples
, gl
.RGBA8
, width
, height
);
101 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
102 "should be no error after renderbufferStorageMultisample(RGBA8).");
105 function attachBuffer(buffer
) {
106 gl
.framebufferRenderbuffer(
107 gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, buffer
);
108 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
109 "should be no error after framebufferRenderbuffer.");
112 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)",
113 "gl.FRAMEBUFFER_COMPLETE");
114 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
116 // Blit from multisampled buffer to non-multisampled buffer.
117 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, fbo_m
);
118 gl
.bindFramebuffer(gl
.DRAW_FRAMEBUFFER
, fbo
);
119 // Blit color from fbo_m (should be black) to fbo (should be green)
120 gl
.blitFramebuffer(0, 0, resolve
.w
, resolve
.h
,
121 0, 0, resolve
.w
, resolve
.h
,
122 gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
123 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
125 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
126 wtu
.checkCanvasRect(gl
, 0, 0, resolve
.w
, resolve
.h
,
128 "user buffer has been initialized to 0");
130 gl
.deleteFramebuffer(fbo_m
);
131 gl
.deleteRenderbuffer(buffer_m
);
132 gl
.deleteFramebuffer(fbo
);
133 gl
.deleteRenderbuffer(buffer
);
135 // this clear should not matter we are about to resize
136 gl
.clear(gl
.COLOR_BUFFER_BIT
);
138 gl
.canvas
.width
+= 1;
139 gl
.canvas
.height
+= 1;
141 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
145 var successfullyParsed
= true;
147 <script src=
"../../js/js-test-post.js"></script>