OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 --> | |
6 <!DOCTYPE html> | |
7 <html> | |
8 <head> | |
9 <meta charset="utf-8"> | |
10 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
11 <script src="../../resources/js-test-pre.js"></script> | |
12 <script src="../resources/webgl-test.js"></script> | |
13 <script src="../resources/webgl-test-utils.js"></script> | |
14 </head> | |
15 <body> | |
16 <canvas id="testbed" width="400" height="400" style="width: 40px; height: 40px;"
></canvas> | |
17 <div id="description"></div> | |
18 <div id="console"></div> | |
19 <script> | |
20 var wtu = WebGLTestUtils; | |
21 description('Verify renderbuffers are initialized to 0 before being read in WebG
L'); | |
22 | |
23 var canvas = document.getElementById("testbed"); | |
24 var gl = create3DContext(canvas); | |
25 if (!gl) { | |
26 testFailed('canvas.getContext() failed'); | |
27 } else { | |
28 // Set the clear color to green. It should never show up. | |
29 gl.clearColor(0, 1, 0, 1); | |
30 | |
31 runTest(gl, canvas.width, canvas.height, 0); | |
32 runTest(gl, canvas.width, canvas.height, 1); | |
33 runTest(gl, canvas.width, canvas.height, 0); | |
34 runTest(gl, canvas.width, canvas.height, 1); | |
35 | |
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 glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors'); | |
40 } | |
41 | |
42 function runTest(gl, width, height, order) | |
43 { | |
44 wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0], | |
45 "internal buffers have been initialized to 0"); | |
46 | |
47 // fill the back buffer so we know that reading below happens from | |
48 // the renderbuffer. | |
49 gl.clear(gl.COLOR_BUFFER_BIT); | |
50 | |
51 var fbo = gl.createFramebuffer(); | |
52 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); | |
53 var colorbuffer = gl.createRenderbuffer(); | |
54 gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer); | |
55 switch (order) { | |
56 case 0: | |
57 allocStorage(width, height); | |
58 attachBuffer(colorbuffer); | |
59 break; | |
60 case 1: | |
61 attachBuffer(colorbuffer); | |
62 allocStorage(width, height); | |
63 break; | |
64 } | |
65 | |
66 function allocStorage(width, height) { | |
67 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height); | |
68 glErrorShouldBe(gl, gl.NO_ERROR, 'should be no error after renderbuffe
rStorage(internalformat = RGBA4).'); | |
69 } | |
70 | |
71 function attachBuffer(colorbuffer) { | |
72 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDER
BUFFER, colorbuffer); | |
73 } | |
74 | |
75 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { | |
76 testFailed('Framebuffer incomplete.'); | |
77 return; | |
78 } | |
79 | |
80 wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0], | |
81 "user buffers have been initialized to 0"); | |
82 | |
83 gl.deleteFramebuffer(fbo); | |
84 gl.deleteRenderbuffer(colorbuffer); | |
85 | |
86 // this clear should not matter we are about to resize | |
87 gl.clear(gl.COLOR_BUFFER_BIT); | |
88 | |
89 canvas.width += 1; | |
90 canvas.height += 1; | |
91 | |
92 debug(''); | |
93 } | |
94 | |
95 successfullyParsed = true; | |
96 </script> | |
97 <script src="../../resources/js-test-post.js"></script> | |
98 </body> | |
99 </html> | |
OLD | NEW |