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.
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>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
19 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
23 var wtu
= WebGLTestUtils
;
25 var canvas
= document
.getElementById("canvas");
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
)
38 msg
+= "], was " + wtu
.glEnumToString(gl
, actual
);
41 var msg
= "checkFramebufferStatus got " + wtu
.glEnumToString(gl
, actual
) +
47 function testImageAttachedTwoPoints() {
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
,
56 gl
.RGBA
, // internalFormat
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
]);
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");
103 testPassed("No WEBGL_draw_buffers support -- this is legal");
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
);
121 var successfullyParsed
= true;
123 <script src=
"../../js/js-test-post.js"></script>