Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / extensions / webgl-draw-buffers-framebuffer-unsupported.html
blob5866a3c38b8a955240d1f7a120c84c6dd91dee68
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 WEBGL_draw_buffers 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");
26 var fb1 = null;
27 var fb2 = null;
29 function checkFramebuffer(expected) {
30 var actual = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
31 if (expected.indexOf(actual) < 0) {
32 var msg = "checkFramebufferStatus expects [";
33 for (var index = 0; index < expected.length; ++index) {
34 msg += wtu.glEnumToString(gl, expected[index]);
35 if (index + 1 < expected.length)
36 msg += ", ";
38 msg += "], was " + wtu.glEnumToString(gl, actual);
39 testFailed(msg);
40 } else {
41 var msg = "checkFramebufferStatus got " + wtu.glEnumToString(gl, actual) +
42 " as expected";
43 testPassed(msg);
47 function testImageAttachedTwoPoints() {
48 debug("");
49 debug("Checking an image is attached to more than one color attachment in a framebuffer.");
51 var tex1 = gl.createTexture();
52 var tex2 = gl.createTexture();
53 gl.bindTexture(gl.TEXTURE_2D, tex1);
54 gl.texImage2D(gl.TEXTURE_2D,
55 0, // level
56 gl.RGBA, // internalFormat
57 1, // width
58 1, // height
59 0, // border
60 gl.RGBA, // format
61 gl.UNSIGNED_BYTE, // type
62 new Uint8Array(4)); // data
63 gl.bindTexture(gl.TEXTURE_2D, tex2);
64 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
65 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Texture creation should succeed.");
67 gl.bindFramebuffer(gl.FRAMEBUFFER, fb1);
68 gl.framebufferTexture2D(gl.FRAMEBUFFER, ext.COLOR_ATTACHMENT0_WEBGL, gl.TEXTURE_2D, tex1, 0);
69 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
70 gl.framebufferTexture2D(gl.FRAMEBUFFER, ext.COLOR_ATTACHMENT1_WEBGL, gl.TEXTURE_2D, tex2, 0);
71 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
72 gl.framebufferTexture2D(gl.FRAMEBUFFER, ext.COLOR_ATTACHMENT2_WEBGL, gl.TEXTURE_2D, tex1, 0);
73 checkFramebuffer([gl.FRAMEBUFFER_UNSUPPORTED]);
75 gl.bindFramebuffer(gl.FRAMEBUFFER, null);
76 gl.bindFramebuffer(gl.FRAMEBUFFER, fb2);
77 var texCube = gl.createTexture();
78 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCube);
79 for (var target = gl.TEXTURE_CUBE_MAP_POSITIVE_X; target < gl.TEXTURE_CUBE_MAP_POSITIVE_X + 6; target++) {
80 gl.texImage2D(target, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
82 gl.framebufferTexture2D(gl.FRAMEBUFFER, ext.COLOR_ATTACHMENT0_WEBGL, gl.TEXTURE_CUBE_MAP_POSITIVE_X, texCube, 0);
83 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
84 gl.framebufferTexture2D(gl.FRAMEBUFFER, ext.COLOR_ATTACHMENT1_WEBGL, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, texCube, 0);
85 checkFramebuffer([gl.FRAMEBUFFER_COMPLETE]);
86 gl.framebufferTexture2D(gl.FRAMEBUFFER, ext.COLOR_ATTACHMENT2_WEBGL, gl.TEXTURE_CUBE_MAP_POSITIVE_X, texCube, 0);
87 checkFramebuffer([gl.FRAMEBUFFER_UNSUPPORTED]);
89 // Clean up
90 gl.deleteTexture(tex1);
91 gl.deleteTexture(tex2);
92 gl.deleteTexture(texCube);
95 description("This tests FRAMEBUFFER_UNSUPPORTED.");
97 shouldBeNonNull("gl = wtu.create3DContext(undefined, undefined, 1)");
98 fb1 = gl.createFramebuffer();
99 fb2 = gl.createFramebuffer();
101 var ext = gl.getExtension("WEBGL_draw_buffers");
102 if (!ext) {
103 testPassed("No WEBGL_draw_buffers support -- this is legal");
104 } else {
105 var bufs = [ext.COLOR_ATTACHMENT0_WEBGL, ext.COLOR_ATTACHMENT1_WEBGL, ext.COLOR_ATTACHMENT2_WEBGL];
106 gl.bindFramebuffer(gl.FRAMEBUFFER, fb1);
107 ext.drawBuffersWEBGL(bufs);
108 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be able to call drawBuffersWEBGL successfully");
109 gl.bindFramebuffer(gl.FRAMEBUFFER, fb2);
110 ext.drawBuffersWEBGL(bufs);
111 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be able to call drawBuffersWEBGL successfully");
113 testPassed("Successfully enabled WEBGL_draw_buffers extension");
114 testImageAttachedTwoPoints();
116 gl.deleteFramebuffer(fb1);
117 gl.deleteFramebuffer(fb2);
120 debug("");
121 var successfullyParsed = true;
122 </script>
123 <script src="../../js/js-test-post.js"></script>
125 </body>
126 </html>