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 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");
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
)
36 msg
+= "], was " + wtu
.glEnumToString(gl
, actual
);
39 var msg
= "checkFramebufferStatus got " + wtu
.glEnumToString(gl
, actual
) +
45 function testImageAttachedTwoPoints() {
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
,
55 gl
.RGBA
, // internalFormat
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
,
99 gl
.RGBA
, // internalFormat
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
]);
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();
129 var successfullyParsed
= true;
131 <script src=
"../../js/js-test-post.js"></script>