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 BlitFramebuffer Tests
</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 <canvas id=
"example" width=
"8" height=
"8"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
23 var wtu
= WebGLTestUtils
;
24 description("This test verifies blitFramebuffer won't cause a crash when the computed sizes might overflow.");
29 var gl
= wtu
.create3DContext("example", undefined, 2);
31 testFailed("WebGL context does not exist");
33 testPassed("WebGL context exists");
37 function blit_region_test() {
40 debug("Begin to run blitFramebuffer. The computed width/height of src and/or dst region might overflow during blitting.");
41 var tex0
= gl
.createTexture();
42 gl
.bindTexture(gl
.TEXTURE_2D
, tex0
);
43 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA8
, width
, height
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
44 var fb0
= gl
.createFramebuffer();
45 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, fb0
);
46 gl
.framebufferTexture2D(gl
.READ_FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, tex0
, 0);
48 var tex1
= gl
.createTexture();
49 gl
.bindTexture(gl
.TEXTURE_2D
, tex1
);
50 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA8
, width
, height
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
51 var fb1
= gl
.createFramebuffer();
52 gl
.bindFramebuffer(gl
.DRAW_FRAMEBUFFER
, fb1
);
53 gl
.framebufferTexture2D(gl
.DRAW_FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, tex1
, 0);
54 if ((gl
.checkFramebufferStatus(gl
.READ_FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) ||
55 (gl
.checkFramebufferStatus(gl
.DRAW_FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
)) {
56 testFailed("Framebuffer incomplete.");
61 gl
.blitFramebuffer(0, 0, max
, max
, 0, 0, width
, height
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
62 gl
.blitFramebuffer(0, 0, width
, height
, 0, 0, max
, max
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
63 gl
.blitFramebuffer(0, 0, max
, max
, 0, 0, max
, max
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
64 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Using max 32-bit integer as blitFramebuffer parameter should succeed.");
66 gl
.blitFramebuffer(-1, -1, max
- 1, max
- 1, 0, 0, width
, height
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
67 gl
.blitFramebuffer(0, 0, width
, height
, -1, -1, max
- 1, max
- 1, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
68 gl
.blitFramebuffer(-1, -1, max
- 1, max
- 1, -1, -1, max
- 1, max
- 1, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
69 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Using blitFramebuffer parameters where calculated width/height matches max 32-bit integer should succeed.");
71 gl
.blitFramebuffer(-1, -1, max
, max
, 0, 0, width
, height
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
72 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
, "Using source width/height greater than max 32-bit integer should fail.");
73 gl
.blitFramebuffer(max
, max
, -1, -1, 0, 0, width
, height
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
74 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
, "Using source width/height greater than max 32-bit integer should fail.");
75 gl
.blitFramebuffer(0, 0, width
, height
, -1, -1, max
, max
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
76 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
, "Using destination width/height greater than max 32-bit integer should fail.");
77 gl
.blitFramebuffer(0, 0, width
, height
, max
, max
, -1, -1, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
78 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
, "Using destination width/height greater than max 32-bit integer should fail.");
79 gl
.blitFramebuffer(-1, -1, max
, max
, -1, -1, max
, max
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
80 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
, "Using both source and destination width/height greater than max 32-bit integer should fail.");
81 gl
.blitFramebuffer(-max
- 1, -max
- 1, max
, max
, -max
- 1, -max
- 1, max
, max
, gl
.COLOR_BUFFER_BIT
, gl
.NEAREST
);
82 wtu
.glErrorShouldBe(gl
, gl
.INVALID_VALUE
, "Using minimum and maximum integers for all boundaries should fail.");
84 gl
.bindTexture(gl
.TEXTURE_2D
, null)
85 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, null);
86 gl
.bindFramebuffer(gl
.DRAW_FRAMEBUFFER
, null);
87 gl
.deleteTexture(tex0
);
88 gl
.deleteTexture(tex1
);
89 gl
.deleteFramebuffer(fb0
);
90 gl
.deleteFramebuffer(fb1
);
93 var successfullyParsed
= true;
95 <script src=
"../../js/js-test-post.js"></script>