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 depth renderbuffers are initialized to 1.0 before being read in WebGL');
24 var gl
= wtu
.create3DContext("testbed");
27 testFailed('canvas.getContext() failed');
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
);
32 gl
.disable(gl
.STENCIL_TEST
);
35 for (let i
= 0; i
< 2; ++i
) {
36 runTest(gl
, {alloc1
: {w
: c
.width
, h
: c
.height
}, alloc2
: null});
37 runTest(gl
, {alloc1
: null, alloc2
: {w
: c
.width
, h
: c
.height
}});
38 // Tests for initially allocating at the wrong size.
39 runTest(gl
, {alloc1
: {w
: 5, h
: 5}, alloc2
: {w
: c
.width
, h
: c
.height
}});
42 // Testing buffer clearing won't change the clear values.
43 var clearColor
= gl
.getParameter(gl
.COLOR_CLEAR_VALUE
);
44 shouldBe("clearColor", "[0, 1, 0, 1]");
45 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
48 function runTest(gl
, params
) {
49 debug("Test for depth buffer: " + JSON
.stringify(params
));
50 let final
= params
.alloc2
? params
.alloc2
: params
.alloc1
;
51 gl
.viewport(0, 0, final
.w
, final
.h
);
52 wtu
.checkCanvasRect(gl
, 0, 0, final
.w
, final
.h
,
54 "internal buffers have been initialized to 0");
56 gl
.disable(gl
.DEPTH_TEST
);
58 // fill the back buffer so we know that reading below happens from
61 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
63 // Set up (color+depth) test buffer.
64 var fbo
= gl
.createFramebuffer();
65 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
66 var buffer
= gl
.createRenderbuffer();
67 var depthBuffer
= gl
.createRenderbuffer();
70 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, buffer
);
71 allocStorage(gl
.RGBA4
, params
.alloc1
.w
, params
.alloc1
.h
);
72 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, depthBuffer
);
73 allocStorage(gl
.DEPTH_COMPONENT16
, params
.alloc1
.w
, params
.alloc1
.h
);
75 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, buffer
);
76 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, buffer
);
77 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, depthBuffer
);
78 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.DEPTH_ATTACHMENT
, gl
.RENDERBUFFER
, depthBuffer
);
81 // Clear the FBO in order to make sure framebufferRenderbuffer is
83 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
84 debug("Skip: framebuffer is allowed to be incomplete.");
87 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
89 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, buffer
);
90 allocStorage(gl
.RGBA4
, params
.alloc2
.w
, params
.alloc2
.h
);
91 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, depthBuffer
);
92 allocStorage(gl
.DEPTH_COMPONENT16
, params
.alloc2
.w
, params
.alloc2
.h
);
95 function allocStorage(format
, width
, height
) {
96 gl
.renderbufferStorage(gl
.RENDERBUFFER
, format
, width
, height
);
97 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
98 "should be no error after renderbufferStorage.");
101 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
102 debug("Skip: framebuffer is allowed to be incomplete.");
105 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
107 // fbo depth should now be the default value of 1.0.
109 // Draw a blue quad (at clip z = 0.0, so depth = 0.5) (should pass the depth test: 0.5 < 1.0)
110 gl
.depthFunc(gl
.LESS
);
111 gl
.enable(gl
.DEPTH_TEST
);
112 wtu
.setupColorQuad(gl
);
113 wtu
.setFloatDrawColor(gl
, [0, 0, 1, 1]);
114 wtu
.drawUnitQuad(gl
);
115 wtu
.checkCanvasRect(gl
, 0, 0, final
.w
, final
.h
,
118 gl
.deleteFramebuffer(fbo
);
119 gl
.deleteRenderbuffer(buffer
);
121 gl
.canvas
.width
+= 1;
122 gl
.canvas
.height
+= 1;
124 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
128 var successfullyParsed
= true;
130 <script src=
"../../js/js-test-post.js"></script>