3 <script src=
"../../../resources/js-test.js"></script>
4 <script src=
"resources/webgl-test.js"></script>
6 function runTest(gl
, width
, height
)
9 debug('Test whether the WebGL internal buffers have been initialized to 0.');
10 var totalBytes
= width
* height
* 4;
11 var buf
= new Uint8Array(totalBytes
);
12 gl
.readPixels(0, 0, width
, height
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
13 if (gl
.getError() != gl
.NO_ERROR
) {
14 testFailed('GL error detected after readPixels().');
17 for (var i
= 0; i
< totalBytes
; ++i
) {
19 testFailed('WebGL internal buffers are dirty.');
23 testPassed('Buffers have been initialized to 0.');
25 debug('Test whether user created buffers have been initialized to 0.');
26 var fbo
= gl
.createFramebuffer();
27 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fbo
);
28 var colorbuffer
= gl
.createRenderbuffer();
29 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, colorbuffer
);
30 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.RGBA4
, width
, height
);
31 if (gl
.getError() != gl
.NO_ERROR
) {
32 testFailed('GL error detected after renderbufferStorage(internalformat = RGBA4).');
35 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, colorbuffer
);
36 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
37 testFailed('Framebuffer incomplete.');
40 gl
.readPixels(0, 0, width
, height
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
41 if (gl
.getError() != gl
.NO_ERROR
) {
42 testFailed('GL error detected after readPixels().');
45 for (var i
= 0; i
< totalBytes
; ++i
) {
47 testFailed('User created buffers are dirty.');
52 testPassed('Buffers have been initialized to 0.');
58 <canvas id=
"testbed" width=
"400px" height=
"400px"></canvas>
59 <div id=
"description"></div>
60 <div id=
"console"></div>
63 description('Verify renderbuffers are initialized to 0 before being read in WebGL');
65 var canvas
= document
.getElementById("testbed");
66 var gl
= canvas
.getContext("webgl");
68 runTest(gl
, canvas
.width
, canvas
.height
);
70 // Testing that canvas resizing will clear the buffers with 0 instead of the current clear values.
71 gl
.clearColor(1, 0, 0, 1);
74 runTest(gl
, canvas
.width
, canvas
.height
);
76 // Testing buffer clearing won't change the clear values.
77 var clearColor
= gl
.getParameter(gl
.COLOR_CLEAR_VALUE
);
78 shouldBe("clearColor", "[1, 0, 0, 1]");
80 testFailed('canvas.getContext() failed');