OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2010 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 <html> | |
7 <head> | |
8 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
9 <script src="../resources/js-test-pre.js"></script> | |
10 <script src="resources/webgl-test.js"></script> | |
11 <script> | |
12 function runTest(gl, width, height) | |
13 { | |
14 | |
15 debug('Test whether the WebGL internal buffers have been initialized to 0.')
; | |
16 var totalBytes = width * height * 4; | |
17 var buf = new Uint8Array(totalBytes); | |
18 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
19 if (gl.getError() != gl.NO_ERROR) { | |
20 testFailed('GL error detected after readPixels().'); | |
21 return false; | |
22 } | |
23 for (var i = 0; i < totalBytes; ++i) { | |
24 if (buf[i] != 0) { | |
25 testFailed('WebGL internal buffers are dirty.'); | |
26 return false; | |
27 } | |
28 } | |
29 testPassed('Buffers have been initialized to 0.'); | |
30 | |
31 debug('Test whether user created buffers have been initialized to 0.'); | |
32 var fbo = gl.createFramebuffer(); | |
33 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); | |
34 var colorbuffer = gl.createRenderbuffer(); | |
35 gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer); | |
36 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height); | |
37 if (gl.getError() != gl.NO_ERROR) { | |
38 testFailed('GL error detected after renderbufferStorage(internalformat =
RGBA4).'); | |
39 return false; | |
40 } | |
41 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBU
FFER, colorbuffer); | |
42 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { | |
43 testFailed('Framebuffer incomplete.'); | |
44 return false; | |
45 } | |
46 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
47 if (gl.getError() != gl.NO_ERROR) { | |
48 testFailed('GL error detected after readPixels().'); | |
49 return false; | |
50 } | |
51 for (var i = 0; i < totalBytes; ++i) { | |
52 if (buf[i] != 0) { | |
53 testFailed('User created buffers are dirty.'); | |
54 return false; | |
55 } | |
56 } | |
57 | |
58 testPassed('Buffers have been initialized to 0.'); | |
59 return true; | |
60 } | |
61 </script> | |
62 </head> | |
63 <body> | |
64 <canvas id="testbed" width="400px" height="400px"></canvas> | |
65 <div id="description"></div> | |
66 <div id="console"></div> | |
67 <script> | |
68 var successfullyParsed = false; | |
69 | |
70 description('Verify renderbuffers are initialized to 0 before being read in WebG
L'); | |
71 | |
72 var canvas = document.getElementById("testbed"); | |
73 var gl = canvas.getContext("experimental-webgl"); | |
74 if (!gl) { | |
75 testFailed('canvas.getContext() failed'); | |
76 } else { | |
77 runTest(gl, canvas.width, canvas.height); | |
78 | |
79 // Testing that canvas resizing will clear the buffers with 0 instead of the
current clear values. | |
80 gl.clearColor(1, 0, 0, 1); | |
81 canvas.width += 1; | |
82 canvas.height += 1; | |
83 runTest(gl, canvas.width, canvas.height); | |
84 | |
85 // Testing buffer clearing won't change the clear values. | |
86 var clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE); | |
87 shouldBe("clearColor", "[1, 0, 0, 1]"); | |
88 | |
89 successfullyParsed = true; | |
90 } | |
91 </script> | |
92 <script src="../resources/js-test-post.js"></script> | |
93 </body> | |
94 </html> | |
OLD | NEW |