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=
"canvas" width=
"8" height=
"8"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
24 var wtu
= WebGLTestUtils
;
25 description("This test verifies the functionality of blitFramebuffer with multisampled sRGB color buffer.");
27 var gl
= wtu
.create3DContext("canvas", undefined, 2);
29 var tex_blit
= gl
.createTexture();
30 var fb0
= gl
.createFramebuffer();
31 var rb0
= gl
.createRenderbuffer();
32 var fbo_blit
= gl
.createFramebuffer();
37 testFailed("WebGL context does not exist");
39 testPassed("WebGL context exists");
43 var filters
= [gl
.LINEAR
, gl
.NEAREST
];
44 for (var ii
= 0; ii
< filters
.length
; ++ii
) {
45 blitframebuffer_multisampled_readbuffer(gl
.SRGB8_ALPHA8
, gl
.SRGB8_ALPHA8
, filters
[ii
]);
50 program
= wtu
.setupColorQuad(gl
);
51 gl
.viewport(0, 0, size
, size
);
54 function blitframebuffer_helper(readbufferFormat
, drawbufferFormat
, filter
) {
55 // Create draw framebuffer and feed 0 to draw buffer
56 gl
.bindTexture(gl
.TEXTURE_2D
, tex_blit
);
57 gl
.texImage2D(gl
.TEXTURE_2D
, 0, drawbufferFormat
, size
, size
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
58 gl
.bindFramebuffer(gl
.DRAW_FRAMEBUFFER
, fbo_blit
);
59 gl
.framebufferTexture2D(gl
.DRAW_FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, tex_blit
, 0);
60 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "setup draw framebuffer should succeed");
62 gl
.blitFramebuffer(0, 0, size
, size
, 0, 0, size
, size
, gl
.COLOR_BUFFER_BIT
, filter
);
63 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "blitframebuffer should succeed");
66 function blitframebuffer_multisampled_readbuffer(readbufferFormat
, drawbufferFormat
, filter
) {
68 debug("Test blitFramebuffer when the read buffer is a multisampled srgb image. The filter is: " + wtu
.glEnumToString(gl
, filter
));
69 debug("read buffer format is: " + wtu
.glEnumToString(gl
, readbufferFormat
) + ", draw buffer format is: " + wtu
.glEnumToString(gl
, drawbufferFormat
));
71 // Draw to a multi-sampled srgb image, and blit to a srgb image.
72 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, rb0
);
73 gl
.renderbufferStorageMultisample(gl
.RENDERBUFFER
, 4, readbufferFormat
, size
, size
);
74 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fb0
);
75 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, rb0
);
76 if (gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) != gl
.FRAMEBUFFER_COMPLETE
) {
77 testFailed("Framebuffer incomplete.");
80 var color
= [252, 122, 15, 255];
81 var expectedColor
= wtu
.linearToSRGB(color
);
82 for (var i
= 0; i
< 4; ++i
) {
83 color
[i
] = color
[i
] / 255;
85 // Draw a rectangle. Fill it with solid color.
86 // Note that the draw buffer is a multisampled srgb image. So during drawing, the color will be converted into srgb color space.
87 gl
.useProgram(program
);
88 wtu
.drawFloatColorQuad(gl
, color
);
89 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, fb0
);
90 blitframebuffer_helper(readbufferFormat
, drawbufferFormat
, filter
);
91 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Blit from a multi-sampled srgb image to a srgb image should succeed");
94 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, fbo_blit
);
95 wtu
.checkCanvasRect(gl
, 0, 0, size
, size
, expectedColor
);
98 gl
.bindTexture(gl
.TEXTURE_2D
, null);
99 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, null);
100 gl
.bindFramebuffer(gl
.READ_FRAMEBUFFER
, null);
101 gl
.bindFramebuffer(gl
.DRAW_FRAMEBUFFER
, null);
102 gl
.deleteRenderbuffer(rb0
);
103 gl
.deleteTexture(tex_blit
);
104 gl
.deleteFramebuffer(fb0
);
105 gl
.deleteFramebuffer(fbo_blit
);
107 var successfullyParsed
= true;
109 <script src=
"../../js/js-test-post.js"></script>