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=
"400" height=
"400" style=
"width: 40px; height: 40px;"></canvas>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
21 var wtu
= WebGLTestUtils
;
22 description('Verify renderbuffers are initialized to 0 before being read in WebGL');
24 var gl
= wtu
.create3DContext("testbed");
26 testFailed('canvas.getContext() failed');
28 // Set the clear color to green. It should never show up.
29 gl
.clearColor(0, 1, 0, 1);
31 runTest(gl
, gl
.canvas
.width
, gl
.canvas
.height
, 0);
32 runTest(gl
, gl
.canvas
.width
, gl
.canvas
.height
, 1);
33 runTest(gl
, gl
.canvas
.width
, gl
.canvas
.height
, 0);
34 runTest(gl
, gl
.canvas
.width
, gl
.canvas
.height
, 1);
36 // Testing buffer clearing won't change the clear values.
37 var clearColor
= gl
.getParameter(gl
.COLOR_CLEAR_VALUE
);
38 shouldBe("clearColor", "[0, 1, 0, 1]");
39 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no errors');
42 function runTest(gl
, width
, height
, order
)
44 wtu
.checkCanvasRect(gl
, 0, 0, width
, height
, [0,0,0,0],
45 "internal buffers have been initialized to 0");
47 // fill the back buffer so we know that reading below happens from
49 gl
.clear(gl
.COLOR_BUFFER_BIT
);
51 var fbo
= gl
.createFramebuffer();
52 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
53 var colorbuffer
= gl
.createRenderbuffer();
54 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, colorbuffer
);
57 allocStorage(width
, height
);
58 attachBuffer(colorbuffer
);
61 attachBuffer(colorbuffer
);
62 allocStorage(width
, height
);
66 function allocStorage(width
, height
) {
67 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.RGBA4
, width
, height
);
68 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, 'should be no error after renderbufferStorage(internalformat = RGBA4).');
71 function attachBuffer(colorbuffer
) {
72 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, colorbuffer
);
75 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
76 testFailed('Framebuffer incomplete.');
80 wtu
.checkCanvasRect(gl
, 0, 0, width
, height
, [0,0,0,0],
81 "user buffers have been initialized to 0");
83 gl
.deleteFramebuffer(fbo
);
84 gl
.deleteRenderbuffer(colorbuffer
);
86 // this clear should not matter we are about to resize
87 gl
.clear(gl
.COLOR_BUFFER_BIT
);
90 gl
.canvas
.height
+= 1;
95 var successfullyParsed
= true;
97 <script src=
"../../js/js-test-post.js"></script>