Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / rendering / framebuffer-unsupported.html
blob1780650ed6580858aede729f2ada676568e4486e
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL FRAMEBUFFER_UNSUPPORTED Test</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <div id="description"></div>
18 <div id="console"></div>
19 <canvas id="canvas" width="2" height="2"> </canvas>
21 <script>
22 "use strict";
23 var wtu = WebGLTestUtils;
24 var gl;
25 var canvas = document.getElementById("canvas");
27 function checkFramebuffer(expected) {
28 var actual = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
29 if (expected.indexOf(actual) < 0) {
30 var msg = "checkFramebufferStatus expects [";
31 for (var index = 0; index < expected.length; ++index) {
32 msg += wtu.glEnumToString(gl, expected[index]);
33 if (index + 1 < expected.length)
34 msg += ", ";
36 msg += "], was " + wtu.glEnumToString(gl, actual);
37 testFailed(msg);
38 } else {
39 var msg = "checkFramebufferStatus got " + wtu.glEnumToString(gl, actual) +
40 " as expected";
41 testPassed(msg);
45 function testImageAttachedTwoPoints() {
46 debug("");
47 debug("Checking an image is attached to more than one color attachment in a framebuffer.");
49 var tex1 = gl.createTexture();
50 var tex2 = gl.createTexture();
51 var fb = gl.createFramebuffer();
52 gl.bindTexture(gl.TEXTURE_2D, tex1);
53 gl.texImage2D(gl.TEXTURE_2D,
54 0, // level
55 gl.RGBA, // internalFormat
56 1, // width
57 1, // height
58 0, // border
59 gl.RGBA, // format
60 gl.UNSIGNED_BYTE, // type
61 new Uint8Array(4)); // data
62 gl.bindTexture(gl.TEXTURE_2D, tex2);
63 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
64 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Texture creation should succeed.");
66 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
67 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex1, 0);
68 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
69 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, tex2, 0);
70 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
71 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT2, gl.TEXTURE_2D, tex1, 0);
72 checkFramebuffer([gl.FRAMEBUFFER_UNSUPPORTED]);
74 gl.bindFramebuffer(gl.FRAMEBUFFER, null);
75 gl.deleteFramebuffer(fb);
76 fb = gl.createFramebuffer();
77 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
78 var texCube = gl.createTexture();
79 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCube);
80 for (var target = gl.TEXTURE_CUBE_MAP_POSITIVE_X; target < gl.TEXTURE_CUBE_MAP_POSITIVE_X + 6; target++) {
81 gl.texImage2D(target, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
83 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X, texCube, 0);
84 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
85 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, texCube, 0);
86 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
87 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT2, gl.TEXTURE_CUBE_MAP_POSITIVE_X, texCube, 0);
88 checkFramebuffer([gl.FRAMEBUFFER_UNSUPPORTED]);
91 gl.bindFramebuffer(gl.FRAMEBUFFER, null);
92 gl.deleteFramebuffer(fb);
93 fb = gl.createFramebuffer();
94 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
95 var tex3d = gl.createTexture();
96 gl.bindTexture(gl.TEXTURE_3D, tex3d);
97 gl.texImage3D(gl.TEXTURE_3D,
98 0, // level
99 gl.RGBA, // internalFormat
100 2, // width
101 2, // height
102 2, // depth
103 0, // border
104 gl.RGBA, // format
105 gl.UNSIGNED_BYTE, // type
106 new Uint8Array(4 * 2 * 2 * 2)); // data
107 gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, tex3d, 0, 0);
108 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
109 gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, tex3d, 0, 1);
110 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
111 gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT2, tex3d, 0, 0);
112 checkFramebuffer([gl.FRAMEBUFFER_UNSUPPORTED]);
114 // Clean up
115 gl.deleteTexture(tex1);
116 gl.deleteTexture(tex2);
117 gl.deleteTexture(texCube);
118 gl.deleteTexture(tex3d);
119 gl.deleteFramebuffer(fb);
122 description("This tests FRAMEBUFFER_UNSUPPORTED.");
124 shouldBeNonNull("gl = wtu.create3DContext(undefined, undefined, 2)");
126 testImageAttachedTwoPoints();
128 debug("");
129 var successfullyParsed = true;
130 </script>
131 <script src="../../js/js-test-post.js"></script>
133 </body>
134 </html>