Backed out changeset 713114c0331a (bug 1938707) by developer request CLOSED TREE
[gecko.git] / dom / canvas / test / webgl-mochitest / test_depth_readpixels.html
blobd0ed8e60b0fe2b53403d520f7331487066ce7aa2
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>WebGL test: Check for error on ReadPixels from a depth-only FB.</title>
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
7 <script src="webgl-util.js"></script>
8 <script src="driver-info.js"></script>
9 </head>
10 <body>
11 <canvas id="c"></canvas>
12 <script>
13 "use strict";
15 (function() {
16 var gl = c.getContext('webgl');
17 if (!gl) {
18 todo(gl, 'Get GL working here first.');
19 return;
22 var rb = gl.createRenderbuffer();
23 gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
24 gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 4, 4);
26 var fb = gl.createFramebuffer();
27 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
28 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT,
29 gl.RENDERBUFFER, rb);
31 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
32 todo(false, 'Depth-only FB incomplete. This is valid.');
33 return;
36 ok(!gl.getError(), 'Should have no errors after constructing FB.');
38 var pixels = new Uint8Array([1, 2, 3, 4]);
39 gl.readPixels(0, 0, // x,y
40 1, 1, // w,h
41 gl.RGBA, gl.UNSIGNED_BYTE, pixels);
43 ok(gl.getError() == gl.INVALID_OPERATION,
44 '1x1 color read from a depth FB should generated INVALID_OP.');
45 console.log('Data after 1x1 color-from-depth readpixels:');
46 console.log(pixels);
48 gl.readPixels(0, 0, // x,y
49 0, 0, // w,h
50 gl.RGBA, gl.UNSIGNED_BYTE, pixels);
52 ok(gl.getError() == gl.INVALID_OPERATION,
53 '0x0 color read from a depth FB should generated INVALID_OP.');
54 })();
56 ok(true, 'Test complete.');
58 </script>
59 </body>
60 </html>