|
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 WebGL'); |
|
22 |
|
23 var gl = wtu.create3DContext("testbed"); |
|
24 if (!gl) { |
|
25 testFailed('canvas.getContext() failed'); |
|
26 } else { |
|
27 // Set the clear color to green. It should never show up. |
|
28 gl.clearColor(0, 1, 0, 1); |
|
29 |
|
30 runTest(gl, gl.canvas.width, gl.canvas.height, 0); |
|
31 runTest(gl, gl.canvas.width, gl.canvas.height, 1); |
|
32 runTest(gl, gl.canvas.width, gl.canvas.height, 0); |
|
33 runTest(gl, gl.canvas.width, gl.canvas.height, 1); |
|
34 |
|
35 // Testing buffer clearing won't change the clear values. |
|
36 var clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE); |
|
37 shouldBe("clearColor", "[0, 1, 0, 1]"); |
|
38 glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors'); |
|
39 } |
|
40 |
|
41 function runTest(gl, width, height, order) |
|
42 { |
|
43 wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0], |
|
44 "internal buffers have been initialized to 0"); |
|
45 |
|
46 // fill the back buffer so we know that reading below happens from |
|
47 // the renderbuffer. |
|
48 gl.clear(gl.COLOR_BUFFER_BIT); |
|
49 |
|
50 var fbo = gl.createFramebuffer(); |
|
51 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); |
|
52 var colorbuffer = gl.createRenderbuffer(); |
|
53 gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer); |
|
54 switch (order) { |
|
55 case 0: |
|
56 allocStorage(width, height); |
|
57 attachBuffer(colorbuffer); |
|
58 break; |
|
59 case 1: |
|
60 attachBuffer(colorbuffer); |
|
61 allocStorage(width, height); |
|
62 break; |
|
63 } |
|
64 |
|
65 function allocStorage(width, height) { |
|
66 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height); |
|
67 glErrorShouldBe(gl, gl.NO_ERROR, 'should be no error after renderbufferStorage(internalformat = RGBA4).'); |
|
68 } |
|
69 |
|
70 function attachBuffer(colorbuffer) { |
|
71 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorbuffer); |
|
72 } |
|
73 |
|
74 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { |
|
75 testFailed('Framebuffer incomplete.'); |
|
76 return; |
|
77 } |
|
78 |
|
79 wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0], |
|
80 "user buffers have been initialized to 0"); |
|
81 |
|
82 gl.deleteFramebuffer(fbo); |
|
83 gl.deleteRenderbuffer(colorbuffer); |
|
84 |
|
85 // this clear should not matter we are about to resize |
|
86 gl.clear(gl.COLOR_BUFFER_BIT); |
|
87 |
|
88 gl.canvas.width += 1; |
|
89 gl.canvas.height += 1; |
|
90 |
|
91 debug(''); |
|
92 } |
|
93 |
|
94 successfullyParsed = true; |
|
95 </script> |
|
96 <script>finishTest();</script> |
|
97 </body> |
|
98 </html> |