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 depth renderbuffers are initialized to 1.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);
32 debug("Test renderbufferStorageMultisample with webgl1's DEPTH_STENCIL.");
34 const rb
= gl
.createRenderbuffer();
35 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, rb
);
36 wtu
.shouldGenerateGLError(gl
, 0,
37 "gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 0, gl.DEPTH_STENCIL, 1, 1)");
38 wtu
.shouldGenerateGLError(gl
, gl
.INVALID_OPERATION
,
39 "gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 1, gl.DEPTH_STENCIL, 1, 1)");
40 wtu
.shouldGenerateGLError(gl
, gl
.INVALID_OPERATION
,
41 "gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 2, gl.DEPTH_STENCIL, 1, 1)");
42 gl
.deleteRenderbuffer(rb
);
46 var maxSamples
= gl
.getInternalformatParameter(
47 gl
.RENDERBUFFER
, gl
.RGBA8
, gl
.SAMPLES
)[0];
48 for (let i
= 0; i
< 2; ++i
) {
49 // Non-multisampled tests
50 runTest(gl
, {alloc1
: {w
: c
.width
, h
: c
.height
, s
: 0}, alloc2
: null});
51 runTest(gl
, {alloc1
: null, alloc2
: {w
: c
.width
, h
: c
.height
, s
: 0}});
53 runTest(gl
, {alloc1
: {w
: c
.width
, h
: c
.height
, s
: maxSamples
}, alloc2
: null});
54 runTest(gl
, {alloc1
: null, alloc2
: {w
: c
.width
, h
: c
.height
, s
: maxSamples
}});
56 // Tests for initially allocating at the wrong size.
57 // This is caused by a Qualcomm driver bug: http://crbug.com/696126
58 runTest(gl
, {alloc1
: {w
: 5, h
: 5, s
: maxSamples
}, alloc2
: {w
: c
.width
, h
: c
.height
, s
: maxSamples
}});
61 // Testing buffer clearing won't change the clear values.
62 var clearColor
= gl
.getParameter(gl
.COLOR_CLEAR_VALUE
);
63 shouldBe("clearColor", "[0, 1, 0, 1]");
64 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
67 function runTest(gl
, params
) {
69 debug("Test for depth buffer: " + JSON
.stringify(params
));
70 let resolve
= params
.alloc2
? params
.alloc2
: params
.alloc1
;
71 gl
.viewport(0, 0, resolve
.w
, resolve
.h
);
72 wtu
.checkCanvasRect(gl
, 0, 0, resolve
.w
, resolve
.h
,
74 "internal buffers have been initialized to 0");
76 gl
.disable(gl
.DEPTH_TEST
);
78 // fill the back buffer so we know that reading below happens from
81 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
83 // Set up (color+depth) non-multisampled buffer to blit to and read back from.
84 var fbo
= gl
.createFramebuffer();
85 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
86 var buffer
= gl
.createRenderbuffer();
87 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, buffer
);
88 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.RGBA8
, resolve
.w
, resolve
.h
);
89 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, buffer
);
90 var depthBuffer
= gl
.createRenderbuffer();
91 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, depthBuffer
);
92 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.DEPTH_COMPONENT16
, resolve
.w
, resolve
.h
);
93 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.DEPTH_ATTACHMENT
, gl
.RENDERBUFFER
, depthBuffer
);
94 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
95 debug("Skip: framebuffer is allowed to be incomplete.");
98 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
100 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
101 wtu
.checkCanvasRect(gl
, 0, 0, resolve
.w
, resolve
.h
,
103 "user buffer has been cleared to green");
105 // Set up (depth-only) multisampled buffer to test.
106 var fbo_m
= gl
.createFramebuffer();
107 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo_m
);
108 var buffer_m
= gl
.createRenderbuffer();
109 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, buffer_m
);
112 allocStorage(params
.alloc1
.w
, params
.alloc1
.h
, params
.alloc1
.s
);
114 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.DEPTH_ATTACHMENT
, gl
.RENDERBUFFER
, buffer_m
);
117 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
118 debug("Skip: framebuffer is allowed to be incomplete.");
121 // Clear the FBO in order to make sure framebufferRenderbuffer is
122 // committed. (In Firefox, framebufferRenderbuffer is deferred, so this
123 // is needed to trigger the bug.)
124 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
126 allocStorage(params
.alloc2
.w
, params
.alloc2
.h
, params
.alloc2
.s
);
129 function allocStorage(width
, height
, samples
) {
130 gl
.renderbufferStorageMultisample(
131 gl
.RENDERBUFFER
, samples
, gl
.DEPTH_COMPONENT16
, width
, height
);
132 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
133 "should be no error after renderbufferStorageMultisample(DEPTH_COMPONENT16).");
136 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
137 debug("Skip: framebuffer is allowed to be incomplete.");
140 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
142 // Blit from multisampled buffer to non-multisampled buffer.
143 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, fbo_m
);
144 gl
.bindFramebuffer(gl
.DRAW_FRAMEBUFFER
, fbo
);
146 gl
.clear(gl
.DEPTH_BUFFER_BIT
);
147 // Blit depth from fbo_m (should be default value of 1.0) to fbo (should be 0.0).
148 gl
.blitFramebuffer(0, 0, resolve
.w
, resolve
.h
,
149 0, 0, resolve
.w
, resolve
.h
,
150 gl
.DEPTH_BUFFER_BIT
, gl
.NEAREST
);
151 // fbo depth should now be 1.0.
152 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
154 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
155 // Draw a blue quad (at clip z = 0.0, so depth = 0.5) (should pass the depth test: 0.5 < 1.0)
156 gl
.depthFunc(gl
.LESS
);
157 gl
.enable(gl
.DEPTH_TEST
);
158 wtu
.setupColorQuad(gl
);
159 wtu
.setFloatDrawColor(gl
, [0, 0, 1, 1]);
160 wtu
.drawUnitQuad(gl
);
161 wtu
.checkCanvasRect(gl
, 0, 0, resolve
.w
, resolve
.h
,
164 gl
.deleteFramebuffer(fbo_m
);
165 gl
.deleteRenderbuffer(buffer_m
);
166 gl
.deleteFramebuffer(fbo
);
167 gl
.deleteRenderbuffer(buffer
);
169 gl
.canvas
.width
+= 1;
170 gl
.canvas
.height
+= 1;
172 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
176 var successfullyParsed
= true;
178 <script src=
"../../js/js-test-post.js"></script>