blob: 79b84918f800928627c10943be30b26f12a4f40f [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Corentin Wallezd3970de2015-05-14 11:07:48 -04007#include "test_utils/ANGLETest.h"
Jamie Madill78a9c732016-07-15 11:22:43 -04008#include "test_utils/gl_raii.h"
9
Jamie Madillfa05f602015-05-07 13:47:11 -040010using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070011
Geoff Lange8a1f782013-10-18 16:14:30 -040012class BlitFramebufferANGLETest : public ANGLETest
13{
Jamie Madillfa05f602015-05-07 13:47:11 -040014 protected:
15 BlitFramebufferANGLETest()
Geoff Lange8a1f782013-10-18 16:14:30 -040016 {
17 setWindowWidth(256);
18 setWindowHeight(256);
Geoff Langefc551f2013-10-31 10:20:28 -040019 setConfigRedBits(8);
20 setConfigGreenBits(8);
21 setConfigBlueBits(8);
22 setConfigAlphaBits(8);
23 setConfigDepthBits(24);
Geoff Lang784cc8f2015-02-05 09:00:54 -050024 setConfigStencilBits(8);
Geoff Lange8a1f782013-10-18 16:14:30 -040025
26 mCheckerProgram = 0;
27 mBlueProgram = 0;
Luc Ferron5c8113d2018-07-10 15:03:01 -040028 mRedProgram = 0;
Geoff Lange8a1f782013-10-18 16:14:30 -040029
30 mOriginalFBO = 0;
31
32 mUserFBO = 0;
33 mUserColorBuffer = 0;
34 mUserDepthStencilBuffer = 0;
35
36 mSmallFBO = 0;
37 mSmallColorBuffer = 0;
38 mSmallDepthStencilBuffer = 0;
39
40 mColorOnlyFBO = 0;
41 mColorOnlyColorBuffer = 0;
42
43 mDiffFormatFBO = 0;
44 mDiffFormatColorBuffer = 0;
45
46 mDiffSizeFBO = 0;
47 mDiffSizeColorBuffer = 0;
48
49 mMRTFBO = 0;
50 mMRTColorBuffer0 = 0;
51 mMRTColorBuffer1 = 0;
Jamie Madillc93d6f32014-04-15 16:12:41 -040052
53 mRGBAColorbuffer = 0;
54 mRGBAFBO = 0;
Kenneth Russell69382852017-07-21 16:38:44 -040055 mRGBAMultisampledRenderbuffer = 0;
56 mRGBAMultisampledFBO = 0;
Jamie Madillc93d6f32014-04-15 16:12:41 -040057
Kenneth Russell69382852017-07-21 16:38:44 -040058 mBGRAColorbuffer = 0;
59 mBGRAFBO = 0;
Jamie Madillc93d6f32014-04-15 16:12:41 -040060 mBGRAMultisampledRenderbuffer = 0;
61 mBGRAMultisampledFBO = 0;
Geoff Lange8a1f782013-10-18 16:14:30 -040062 }
63
64 virtual void SetUp()
65 {
66 ANGLETest::SetUp();
67
Olli Etuaho5804dc82018-04-13 14:11:46 +030068 mCheckerProgram =
69 CompileProgram(essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Checkered());
70 mBlueProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
Luc Ferron5c8113d2018-07-10 15:03:01 -040071 mRedProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
72 if (mCheckerProgram == 0 || mBlueProgram == 0 || mRedProgram == 0)
Geoff Lange8a1f782013-10-18 16:14:30 -040073 {
74 FAIL() << "shader compilation failed.";
75 }
76
77 EXPECT_GL_NO_ERROR();
78
79 GLint originalFBO;
80 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &originalFBO);
81 if (originalFBO >= 0)
82 {
83 mOriginalFBO = (GLuint)originalFBO;
84 }
85
Geoff Langc4e93662017-05-01 10:45:59 -040086 GLenum format = GL_BGRA_EXT;
87
Geoff Lange8a1f782013-10-18 16:14:30 -040088 glGenFramebuffers(1, &mUserFBO);
89 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
90 glGenTextures(1, &mUserColorBuffer);
91 glGenRenderbuffers(1, &mUserDepthStencilBuffer);
92 glBindTexture(GL_TEXTURE_2D, mUserColorBuffer);
Geoff Lange8a1f782013-10-18 16:14:30 -040093 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mUserColorBuffer, 0);
Geoff Langc4e93662017-05-01 10:45:59 -040094 glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth(), getWindowHeight(), 0, format,
95 GL_UNSIGNED_BYTE, nullptr);
Geoff Lange8a1f782013-10-18 16:14:30 -040096 glBindRenderbuffer(GL_RENDERBUFFER, mUserDepthStencilBuffer);
97 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth(), getWindowHeight());
98 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer);
99 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer);
100
Corentin Wallez322653b2015-06-17 18:33:56 +0200101 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Geoff Lange8a1f782013-10-18 16:14:30 -0400102 ASSERT_GL_NO_ERROR();
103
104 glGenFramebuffers(1, &mSmallFBO);
105 glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO);
106 glGenTextures(1, &mSmallColorBuffer);
107 glGenRenderbuffers(1, &mSmallDepthStencilBuffer);
108 glBindTexture(GL_TEXTURE_2D, mSmallColorBuffer);
Geoff Langc4e93662017-05-01 10:45:59 -0400109 glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth() / 2, getWindowHeight() / 2, 0,
110 format, GL_UNSIGNED_BYTE, nullptr);
Geoff Lange8a1f782013-10-18 16:14:30 -0400111 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mSmallColorBuffer, 0);
112 glBindRenderbuffer(GL_RENDERBUFFER, mSmallDepthStencilBuffer);
113 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth() / 2, getWindowHeight() / 2);
114 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer);
115 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer);
116
Corentin Wallez322653b2015-06-17 18:33:56 +0200117 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Geoff Lange8a1f782013-10-18 16:14:30 -0400118 ASSERT_GL_NO_ERROR();
119
120 glGenFramebuffers(1, &mColorOnlyFBO);
121 glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO);
122 glGenTextures(1, &mColorOnlyColorBuffer);
123 glBindTexture(GL_TEXTURE_2D, mColorOnlyColorBuffer);
Geoff Langc4e93662017-05-01 10:45:59 -0400124 glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth(), getWindowHeight(), 0, format,
125 GL_UNSIGNED_BYTE, nullptr);
Geoff Lange8a1f782013-10-18 16:14:30 -0400126 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorOnlyColorBuffer, 0);
127
Corentin Wallez322653b2015-06-17 18:33:56 +0200128 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Geoff Lange8a1f782013-10-18 16:14:30 -0400129 ASSERT_GL_NO_ERROR();
130
131 glGenFramebuffers(1, &mDiffFormatFBO);
132 glBindFramebuffer(GL_FRAMEBUFFER, mDiffFormatFBO);
133 glGenTextures(1, &mDiffFormatColorBuffer);
134 glBindTexture(GL_TEXTURE_2D, mDiffFormatColorBuffer);
Geoff Langc4e93662017-05-01 10:45:59 -0400135 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
136 GL_UNSIGNED_SHORT_5_6_5, nullptr);
Geoff Lange8a1f782013-10-18 16:14:30 -0400137 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffFormatColorBuffer, 0);
138
Corentin Wallez322653b2015-06-17 18:33:56 +0200139 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Geoff Lange8a1f782013-10-18 16:14:30 -0400140 ASSERT_GL_NO_ERROR();
141
142 glGenFramebuffers(1, &mDiffSizeFBO);
143 glBindFramebuffer(GL_FRAMEBUFFER, mDiffSizeFBO);
144 glGenTextures(1, &mDiffSizeColorBuffer);
145 glBindTexture(GL_TEXTURE_2D, mDiffSizeColorBuffer);
Geoff Langc4e93662017-05-01 10:45:59 -0400146 glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth() * 2, getWindowHeight() * 2, 0,
147 format, GL_UNSIGNED_BYTE, nullptr);
Geoff Lange8a1f782013-10-18 16:14:30 -0400148 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffSizeColorBuffer, 0);
149
Corentin Wallez322653b2015-06-17 18:33:56 +0200150 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Geoff Lange8a1f782013-10-18 16:14:30 -0400151 ASSERT_GL_NO_ERROR();
152
153 if (extensionEnabled("GL_EXT_draw_buffers"))
154 {
155 glGenFramebuffers(1, &mMRTFBO);
156 glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO);
157 glGenTextures(1, &mMRTColorBuffer0);
158 glGenTextures(1, &mMRTColorBuffer1);
159 glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer0);
Geoff Langc4e93662017-05-01 10:45:59 -0400160 glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth(), getWindowHeight(), 0, format,
161 GL_UNSIGNED_BYTE, nullptr);
Geoff Lange8a1f782013-10-18 16:14:30 -0400162 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mMRTColorBuffer0, 0);
163 glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer1);
Geoff Langc4e93662017-05-01 10:45:59 -0400164 glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth(), getWindowHeight(), 0, format,
165 GL_UNSIGNED_BYTE, nullptr);
Geoff Lange8a1f782013-10-18 16:14:30 -0400166 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0);
167
Corentin Wallez322653b2015-06-17 18:33:56 +0200168 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Geoff Lange8a1f782013-10-18 16:14:30 -0400169 ASSERT_GL_NO_ERROR();
170 }
171
Kenneth Russell69382852017-07-21 16:38:44 -0400172 if (extensionEnabled("GL_ANGLE_framebuffer_multisample") &&
173 extensionEnabled("GL_OES_rgb8_rgba8"))
Jamie Madillc93d6f32014-04-15 16:12:41 -0400174 {
Kenneth Russell69382852017-07-21 16:38:44 -0400175 // RGBA single-sampled framebuffer
Jamie Madillc93d6f32014-04-15 16:12:41 -0400176 glGenTextures(1, &mRGBAColorbuffer);
177 glBindTexture(GL_TEXTURE_2D, mRGBAColorbuffer);
Geoff Langc4e93662017-05-01 10:45:59 -0400178 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
179 GL_UNSIGNED_BYTE, nullptr);
Jamie Madillc93d6f32014-04-15 16:12:41 -0400180
181 glGenFramebuffers(1, &mRGBAFBO);
182 glBindFramebuffer(GL_FRAMEBUFFER, mRGBAFBO);
183 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mRGBAColorbuffer, 0);
184
185 ASSERT_GL_NO_ERROR();
Corentin Wallez322653b2015-06-17 18:33:56 +0200186 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madillc93d6f32014-04-15 16:12:41 -0400187
Kenneth Russell69382852017-07-21 16:38:44 -0400188 // RGBA multisampled framebuffer
189 glGenRenderbuffers(1, &mRGBAMultisampledRenderbuffer);
190 glBindRenderbuffer(GL_RENDERBUFFER, mRGBAMultisampledRenderbuffer);
191 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_RGBA8, getWindowWidth(),
192 getWindowHeight());
Jamie Madillc93d6f32014-04-15 16:12:41 -0400193
Kenneth Russell69382852017-07-21 16:38:44 -0400194 glGenFramebuffers(1, &mRGBAMultisampledFBO);
195 glBindFramebuffer(GL_FRAMEBUFFER, mRGBAMultisampledFBO);
196 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
197 mRGBAMultisampledRenderbuffer);
Jamie Madillc93d6f32014-04-15 16:12:41 -0400198
199 ASSERT_GL_NO_ERROR();
Corentin Wallez322653b2015-06-17 18:33:56 +0200200 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Kenneth Russell69382852017-07-21 16:38:44 -0400201
202 if (extensionEnabled("GL_EXT_texture_format_BGRA8888"))
203 {
204 // BGRA single-sampled framebuffer
205 glGenTextures(1, &mBGRAColorbuffer);
206 glBindTexture(GL_TEXTURE_2D, mBGRAColorbuffer);
207 glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, getWindowWidth(), getWindowHeight(), 0,
208 GL_BGRA_EXT, GL_UNSIGNED_BYTE, nullptr);
209
210 glGenFramebuffers(1, &mBGRAFBO);
211 glBindFramebuffer(GL_FRAMEBUFFER, mBGRAFBO);
212 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
213 mBGRAColorbuffer, 0);
214
215 ASSERT_GL_NO_ERROR();
216 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
217
218 // BGRA multisampled framebuffer
219 glGenRenderbuffers(1, &mBGRAMultisampledRenderbuffer);
220 glBindRenderbuffer(GL_RENDERBUFFER, mBGRAMultisampledRenderbuffer);
221 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_BGRA8_EXT,
222 getWindowWidth(), getWindowHeight());
223
224 glGenFramebuffers(1, &mBGRAMultisampledFBO);
225 glBindFramebuffer(GL_FRAMEBUFFER, mBGRAMultisampledFBO);
226 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
227 mBGRAMultisampledRenderbuffer);
228
229 ASSERT_GL_NO_ERROR();
230 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
231 }
Jamie Madillc93d6f32014-04-15 16:12:41 -0400232 }
233
Geoff Lange8a1f782013-10-18 16:14:30 -0400234 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
235 }
236
237 virtual void TearDown()
238 {
239 glDeleteProgram(mCheckerProgram);
240 glDeleteProgram(mBlueProgram);
Luc Ferron5c8113d2018-07-10 15:03:01 -0400241 glDeleteProgram(mRedProgram);
Geoff Lange8a1f782013-10-18 16:14:30 -0400242
243 glDeleteFramebuffers(1, &mUserFBO);
244 glDeleteTextures(1, &mUserColorBuffer);
245 glDeleteRenderbuffers(1, &mUserDepthStencilBuffer);
246
247 glDeleteFramebuffers(1, &mSmallFBO);
248 glDeleteTextures(1, &mSmallColorBuffer);
249 glDeleteRenderbuffers(1, &mSmallDepthStencilBuffer);
250
251 glDeleteFramebuffers(1, &mColorOnlyFBO);
252 glDeleteTextures(1, &mSmallDepthStencilBuffer);
253
254 glDeleteFramebuffers(1, &mDiffFormatFBO);
255 glDeleteTextures(1, &mDiffFormatColorBuffer);
256
257 glDeleteFramebuffers(1, &mDiffSizeFBO);
258 glDeleteTextures(1, &mDiffSizeColorBuffer);
259
260 if (extensionEnabled("GL_EXT_draw_buffers"))
261 {
262 glDeleteFramebuffers(1, &mMRTFBO);
263 glDeleteTextures(1, &mMRTColorBuffer0);
264 glDeleteTextures(1, &mMRTColorBuffer1);
265 }
266
Jamie Madillc93d6f32014-04-15 16:12:41 -0400267 if (mRGBAColorbuffer != 0)
268 {
269 glDeleteTextures(1, &mRGBAColorbuffer);
270 }
271
272 if (mRGBAFBO != 0)
273 {
Kenneth Russell69382852017-07-21 16:38:44 -0400274 glDeleteFramebuffers(1, &mRGBAFBO);
275 }
276
277 if (mRGBAMultisampledRenderbuffer != 0)
278 {
279 glDeleteRenderbuffers(1, &mRGBAMultisampledRenderbuffer);
280 }
281
282 if (mRGBAMultisampledFBO != 0)
283 {
284 glDeleteFramebuffers(1, &mRGBAMultisampledFBO);
285 }
286
287 if (mBGRAColorbuffer != 0)
288 {
289 glDeleteTextures(1, &mBGRAColorbuffer);
290 }
291
292 if (mBGRAFBO != 0)
293 {
294 glDeleteFramebuffers(1, &mBGRAFBO);
Jamie Madillc93d6f32014-04-15 16:12:41 -0400295 }
296
297 if (mBGRAMultisampledRenderbuffer != 0)
298 {
299 glDeleteRenderbuffers(1, &mBGRAMultisampledRenderbuffer);
300 }
301
302 if (mBGRAMultisampledFBO != 0)
303 {
304 glDeleteFramebuffers(1, &mBGRAMultisampledFBO);
305 }
306
Geoff Lange8a1f782013-10-18 16:14:30 -0400307 ANGLETest::TearDown();
308 }
309
Kenneth Russell69382852017-07-21 16:38:44 -0400310 void multisampleTestHelper(GLuint readFramebuffer, GLuint drawFramebuffer)
311 {
312 glClearColor(0.0, 1.0, 0.0, 1.0);
313 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, readFramebuffer);
314 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
315 EXPECT_GL_NO_ERROR();
316
317 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFramebuffer);
318 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFramebuffer);
319 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
320 getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
321 EXPECT_GL_NO_ERROR();
322
323 glBindFramebuffer(GL_READ_FRAMEBUFFER, drawFramebuffer);
324 EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
325 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
326 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
327 EXPECT_PIXEL_EQ(getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
328 }
329
330 bool checkExtension(const std::string &extension)
331 {
332 if (!extensionEnabled(extension))
333 {
334 std::cout << "Test skipped because " << extension << " not supported." << std::endl;
335 return false;
336 }
337
338 return true;
339 }
340
Geoff Lange8a1f782013-10-18 16:14:30 -0400341 GLuint mCheckerProgram;
342 GLuint mBlueProgram;
Luc Ferron5c8113d2018-07-10 15:03:01 -0400343 GLuint mRedProgram;
Geoff Lange8a1f782013-10-18 16:14:30 -0400344
345 GLuint mOriginalFBO;
346
347 GLuint mUserFBO;
348 GLuint mUserColorBuffer;
349 GLuint mUserDepthStencilBuffer;
350
351 GLuint mSmallFBO;
352 GLuint mSmallColorBuffer;
353 GLuint mSmallDepthStencilBuffer;
354
355 GLuint mColorOnlyFBO;
356 GLuint mColorOnlyColorBuffer;
357
358 GLuint mDiffFormatFBO;
359 GLuint mDiffFormatColorBuffer;
360
361 GLuint mDiffSizeFBO;
362 GLuint mDiffSizeColorBuffer;
363
364 GLuint mMRTFBO;
365 GLuint mMRTColorBuffer0;
366 GLuint mMRTColorBuffer1;
Jamie Madillc93d6f32014-04-15 16:12:41 -0400367
368 GLuint mRGBAColorbuffer;
369 GLuint mRGBAFBO;
Kenneth Russell69382852017-07-21 16:38:44 -0400370 GLuint mRGBAMultisampledRenderbuffer;
371 GLuint mRGBAMultisampledFBO;
Jamie Madillc93d6f32014-04-15 16:12:41 -0400372
Kenneth Russell69382852017-07-21 16:38:44 -0400373 GLuint mBGRAColorbuffer;
374 GLuint mBGRAFBO;
Jamie Madillc93d6f32014-04-15 16:12:41 -0400375 GLuint mBGRAMultisampledRenderbuffer;
376 GLuint mBGRAMultisampledFBO;
Geoff Lange8a1f782013-10-18 16:14:30 -0400377};
378
379// Draw to user-created framebuffer, blit whole-buffer color to original framebuffer.
Jamie Madillfa05f602015-05-07 13:47:11 -0400380TEST_P(BlitFramebufferANGLETest, BlitColorToDefault)
Geoff Lange8a1f782013-10-18 16:14:30 -0400381{
Luc Ferronaf883622018-06-08 15:57:31 -0400382 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
383
Geoff Lange8a1f782013-10-18 16:14:30 -0400384 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
385
386 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
387
Olli Etuaho5804dc82018-04-13 14:11:46 +0300388 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400389
390 EXPECT_GL_NO_ERROR();
391
392 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
393 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
394
395 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
396 GL_COLOR_BUFFER_BIT, GL_NEAREST);
397
398 EXPECT_GL_NO_ERROR();
399
400 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
401
402 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
403 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
404 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
405 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
406}
407
408// Draw to system framebuffer, blit whole-buffer color to user-created framebuffer.
Jamie Madillfa05f602015-05-07 13:47:11 -0400409TEST_P(BlitFramebufferANGLETest, ReverseColorBlit)
Geoff Lange8a1f782013-10-18 16:14:30 -0400410{
Luc Ferronaf883622018-06-08 15:57:31 -0400411 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
412
Geoff Lange8a1f782013-10-18 16:14:30 -0400413 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
414
415 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
416
Olli Etuaho5804dc82018-04-13 14:11:46 +0300417 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400418
419 EXPECT_GL_NO_ERROR();
420
421 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO);
422 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO);
423
424 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
425 GL_COLOR_BUFFER_BIT, GL_NEAREST);
426
427 EXPECT_GL_NO_ERROR();
428
429 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
430
431 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
432 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
433 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
434 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
435}
436
437// blit from user-created FBO to system framebuffer, with the scissor test enabled.
Jamie Madillfa05f602015-05-07 13:47:11 -0400438TEST_P(BlitFramebufferANGLETest, ScissoredBlit)
Geoff Lange8a1f782013-10-18 16:14:30 -0400439{
Luc Ferronaf883622018-06-08 15:57:31 -0400440 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
441
Geoff Lange8a1f782013-10-18 16:14:30 -0400442 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
443
444 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
445
Olli Etuaho5804dc82018-04-13 14:11:46 +0300446 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400447
448 EXPECT_GL_NO_ERROR();
449
450 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
451 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
452
453 glClearColor(1.0, 1.0, 1.0, 1.0);
454 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
455
456 glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight());
457 glEnable(GL_SCISSOR_TEST);
458
459 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
460 GL_COLOR_BUFFER_BIT, GL_NEAREST);
461
462 EXPECT_GL_NO_ERROR();
463
464 glDisable(GL_SCISSOR_TEST);
465
466 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
467
468 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255);
469 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
470 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
471 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255);
472}
473
474// blit from system FBO to user-created framebuffer, with the scissor test enabled.
Jamie Madillfa05f602015-05-07 13:47:11 -0400475TEST_P(BlitFramebufferANGLETest, ReverseScissoredBlit)
Geoff Lange8a1f782013-10-18 16:14:30 -0400476{
Luc Ferronaf883622018-06-08 15:57:31 -0400477 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
478
Geoff Lange8a1f782013-10-18 16:14:30 -0400479 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
480
481 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
482
Olli Etuaho5804dc82018-04-13 14:11:46 +0300483 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400484
485 EXPECT_GL_NO_ERROR();
486
487 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO);
488 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO);
489
490 glClearColor(1.0, 1.0, 1.0, 1.0);
491 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
492
493 glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight());
494 glEnable(GL_SCISSOR_TEST);
495
496 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
497 GL_COLOR_BUFFER_BIT, GL_NEAREST);
498
499 EXPECT_GL_NO_ERROR();
500
501 glDisable(GL_SCISSOR_TEST);
502
503 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
504
505 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255);
506 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
507 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
508 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255);
509}
510
511// blit from user-created FBO to system framebuffer, using region larger than buffer.
Jamie Madillfa05f602015-05-07 13:47:11 -0400512TEST_P(BlitFramebufferANGLETest, OversizedBlit)
Geoff Lange8a1f782013-10-18 16:14:30 -0400513{
Luc Ferronaf883622018-06-08 15:57:31 -0400514 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
515
Geoff Lange8a1f782013-10-18 16:14:30 -0400516 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
517
518 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
519
Olli Etuaho5804dc82018-04-13 14:11:46 +0300520 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400521
522 EXPECT_GL_NO_ERROR();
523
524 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
525 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
526
527 glClearColor(1.0, 1.0, 1.0, 1.0);
528 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
529
530 glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2,
531 GL_COLOR_BUFFER_BIT, GL_NEAREST);
532
533 EXPECT_GL_NO_ERROR();
534
535 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
536
537 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
538 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
539 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
540 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
541}
542
543// blit from system FBO to user-created framebuffer, using region larger than buffer.
Jamie Madillfa05f602015-05-07 13:47:11 -0400544TEST_P(BlitFramebufferANGLETest, ReverseOversizedBlit)
Geoff Lange8a1f782013-10-18 16:14:30 -0400545{
Luc Ferronaf883622018-06-08 15:57:31 -0400546 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
547
Geoff Lange8a1f782013-10-18 16:14:30 -0400548 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
549
550 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
551
Olli Etuaho5804dc82018-04-13 14:11:46 +0300552 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400553
554 EXPECT_GL_NO_ERROR();
555
556 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO);
557 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO);
558
559 glClearColor(1.0, 1.0, 1.0, 1.0);
560 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
561
562 glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2,
563 GL_COLOR_BUFFER_BIT, GL_NEAREST);
564 EXPECT_GL_NO_ERROR();
565
566 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
567
568 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
569 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
570 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
571 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
572}
573
574// blit from user-created FBO to system framebuffer, with depth buffer.
Luc Ferron5c8113d2018-07-10 15:03:01 -0400575TEST_P(BlitFramebufferANGLETest, BlitWithDepthUserToDefault)
Geoff Lange8a1f782013-10-18 16:14:30 -0400576{
Luc Ferronaf883622018-06-08 15:57:31 -0400577 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
578
Geoff Lange8a1f782013-10-18 16:14:30 -0400579 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
580
581 glDepthMask(GL_TRUE);
582 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
583
584 glEnable(GL_DEPTH_TEST);
585
Geoff Lange8a1f782013-10-18 16:14:30 -0400586 EXPECT_GL_NO_ERROR();
587
Luc Ferron5c8113d2018-07-10 15:03:01 -0400588 // Clear the first half of the screen
589 glEnable(GL_SCISSOR_TEST);
590 glScissor(0, 0, getWindowWidth(), getWindowHeight() / 2);
591
592 glClearDepthf(0.1f);
593 glClearColor(1.0, 0.0, 0.0, 1.0);
594 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
595
596 // Scissor the second half of the screen
597 glScissor(0, getWindowHeight() / 2, getWindowWidth(), getWindowHeight() / 2);
598
599 glClearDepthf(0.9f);
600 glClearColor(0.0, 1.0, 0.0, 1.0);
601 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
602
603 glDisable(GL_SCISSOR_TEST);
604
Geoff Lange8a1f782013-10-18 16:14:30 -0400605 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
606 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
607
Geoff Lange8a1f782013-10-18 16:14:30 -0400608 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
609 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
610 EXPECT_GL_NO_ERROR();
611
612 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
613
Luc Ferron5c8113d2018-07-10 15:03:01 -0400614 // if blit is happening correctly, this quad will draw only on the bottom half since it will be
615 // behind on the first half and in front on the second half.
616 drawQuad(mBlueProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400617
618 glDisable(GL_DEPTH_TEST);
619
Luc Ferron5c8113d2018-07-10 15:03:01 -0400620 EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
621 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
622 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255);
623 EXPECT_PIXEL_EQ(getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255);
Geoff Lange8a1f782013-10-18 16:14:30 -0400624}
625
626// blit from system FBO to user-created framebuffer, with depth buffer.
Luc Ferron5c8113d2018-07-10 15:03:01 -0400627TEST_P(BlitFramebufferANGLETest, BlitWithDepthDefaultToUser)
Geoff Lange8a1f782013-10-18 16:14:30 -0400628{
Luc Ferronaf883622018-06-08 15:57:31 -0400629 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
630
Geoff Lange8a1f782013-10-18 16:14:30 -0400631 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
632
Luc Ferron5c8113d2018-07-10 15:03:01 -0400633 glDepthMask(GL_TRUE);
Geoff Lange8a1f782013-10-18 16:14:30 -0400634 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
635
636 glEnable(GL_DEPTH_TEST);
637
Geoff Lange8a1f782013-10-18 16:14:30 -0400638 EXPECT_GL_NO_ERROR();
639
Luc Ferron5c8113d2018-07-10 15:03:01 -0400640 // Clear the first half of the screen
641 glEnable(GL_SCISSOR_TEST);
642 glScissor(0, 0, getWindowWidth(), getWindowHeight() / 2);
643
644 glClearDepthf(0.1f);
645 glClearColor(1.0, 0.0, 0.0, 1.0);
646 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
647
648 // Scissor the second half of the screen
649 glScissor(0, getWindowHeight() / 2, getWindowWidth(), getWindowHeight() / 2);
650
651 glClearDepthf(0.9f);
652 glClearColor(0.0, 1.0, 0.0, 1.0);
653 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
654
655 glDisable(GL_SCISSOR_TEST);
656
Geoff Lange8a1f782013-10-18 16:14:30 -0400657 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO);
658 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO);
659
Geoff Lange8a1f782013-10-18 16:14:30 -0400660 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
661 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
662 EXPECT_GL_NO_ERROR();
663
664 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
665
Luc Ferron5c8113d2018-07-10 15:03:01 -0400666 // if blit is happening correctly, this quad will draw only on the bottom half since it will be
667 // behind on the first half and in front on the second half.
668 drawQuad(mBlueProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400669
670 glDisable(GL_DEPTH_TEST);
671
Luc Ferron5c8113d2018-07-10 15:03:01 -0400672 EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
673 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
674 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255);
675 EXPECT_PIXEL_EQ(getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255);
Geoff Lange8a1f782013-10-18 16:14:30 -0400676}
677
678// blit from one region of the system fbo to another-- this should fail.
Jamie Madillfa05f602015-05-07 13:47:11 -0400679TEST_P(BlitFramebufferANGLETest, BlitSameBufferOriginal)
Geoff Lange8a1f782013-10-18 16:14:30 -0400680{
Luc Ferronaf883622018-06-08 15:57:31 -0400681 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
682
Geoff Lange8a1f782013-10-18 16:14:30 -0400683 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
684
685 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
686
Olli Etuaho5804dc82018-04-13 14:11:46 +0300687 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400688
689 EXPECT_GL_NO_ERROR();
690
691 glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(),
692 GL_COLOR_BUFFER_BIT, GL_NEAREST);
693 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
694}
695
696// blit from one region of the system fbo to another.
Jamie Madillfa05f602015-05-07 13:47:11 -0400697TEST_P(BlitFramebufferANGLETest, BlitSameBufferUser)
Geoff Lange8a1f782013-10-18 16:14:30 -0400698{
Luc Ferronaf883622018-06-08 15:57:31 -0400699 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
700
Geoff Lange8a1f782013-10-18 16:14:30 -0400701 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
702
703 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
704
Olli Etuaho5804dc82018-04-13 14:11:46 +0300705 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400706
707 EXPECT_GL_NO_ERROR();
708
709 glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(),
710 GL_COLOR_BUFFER_BIT, GL_NEAREST);
711 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
712}
713
Jamie Madillfa05f602015-05-07 13:47:11 -0400714TEST_P(BlitFramebufferANGLETest, BlitPartialColor)
Geoff Lange8a1f782013-10-18 16:14:30 -0400715{
Luc Ferronaf883622018-06-08 15:57:31 -0400716 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
717
Geoff Lange8a1f782013-10-18 16:14:30 -0400718 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
719
720 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
721
Olli Etuaho5804dc82018-04-13 14:11:46 +0300722 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400723
724 EXPECT_GL_NO_ERROR();
725
726 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
727 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
728
729 glClearColor(1.0, 1.0, 1.0, 1.0);
730 glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
731
732 glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight(),
733 GL_COLOR_BUFFER_BIT, GL_NEAREST);
734
735 EXPECT_GL_NO_ERROR();
736
737 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
738
739 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255);
740 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255);
741 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255);
742 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
743}
744
Jamie Madillfa05f602015-05-07 13:47:11 -0400745TEST_P(BlitFramebufferANGLETest, BlitDifferentSizes)
Geoff Lange8a1f782013-10-18 16:14:30 -0400746{
Luc Ferronaf883622018-06-08 15:57:31 -0400747 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
748
Geoff Lange8a1f782013-10-18 16:14:30 -0400749 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
750
751 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
752
Olli Etuaho5804dc82018-04-13 14:11:46 +0300753 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400754
755 EXPECT_GL_NO_ERROR();
756
757 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mSmallFBO);
758 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
759
760 glClearColor(1.0, 1.0, 1.0, 1.0);
761 glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
762
763 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
764 GL_COLOR_BUFFER_BIT, GL_NEAREST);
765
766 EXPECT_GL_NO_ERROR();
767
768 glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO);
769
770 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
771
772 EXPECT_GL_NO_ERROR();
773}
774
Jamie Madillfa05f602015-05-07 13:47:11 -0400775TEST_P(BlitFramebufferANGLETest, BlitWithMissingAttachments)
Geoff Lange8a1f782013-10-18 16:14:30 -0400776{
Luc Ferronaf883622018-06-08 15:57:31 -0400777 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
778
Geoff Lange8a1f782013-10-18 16:14:30 -0400779 glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO);
780
781 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho5804dc82018-04-13 14:11:46 +0300782 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400783
784 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
785 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO);
786
787 glClearColor(1.0, 1.0, 1.0, 1.0);
788 glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
789
He Yunchao66a41a22016-12-15 16:45:05 +0800790 // generate INVALID_OPERATION if the read FBO has no depth attachment
791 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
792 getWindowHeight(), GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
793 GL_NEAREST);
Geoff Lange8a1f782013-10-18 16:14:30 -0400794
He Yunchao66a41a22016-12-15 16:45:05 +0800795 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lange8a1f782013-10-18 16:14:30 -0400796
He Yunchao66a41a22016-12-15 16:45:05 +0800797 // generate INVALID_OPERATION if the read FBO has no stencil attachment
798 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
799 getWindowHeight(), GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
800 GL_NEAREST);
Geoff Lange8a1f782013-10-18 16:14:30 -0400801
He Yunchao66a41a22016-12-15 16:45:05 +0800802 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lange8a1f782013-10-18 16:14:30 -0400803
He Yunchao66a41a22016-12-15 16:45:05 +0800804 // generate INVALID_OPERATION if we read from a missing color attachment
805 glReadBuffer(GL_COLOR_ATTACHMENT1);
806 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
807 getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
Geoff Lange8a1f782013-10-18 16:14:30 -0400808
He Yunchao66a41a22016-12-15 16:45:05 +0800809 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lange8a1f782013-10-18 16:14:30 -0400810}
811
Jamie Madillfa05f602015-05-07 13:47:11 -0400812TEST_P(BlitFramebufferANGLETest, BlitStencil)
Geoff Lange8a1f782013-10-18 16:14:30 -0400813{
Luc Ferronaf883622018-06-08 15:57:31 -0400814 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
815
Jamie Madill8e1936c2014-12-03 15:20:12 -0500816 // TODO(jmadill): Figure out if we can fix this on D3D9.
Yunchao He9550c602018-02-13 14:47:05 +0800817 // https://code.google.com/p/angleproject/issues/detail?id=2205
818 ANGLE_SKIP_TEST_IF(IsIntel() && IsD3D9());
Jamie Madill8e1936c2014-12-03 15:20:12 -0500819
Luc Ferronbe30c4f2018-06-21 09:43:08 -0400820 // TODO(lucferron): Diagnose and fix http://anglebug.com/2693
821 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux() && IsVulkan());
822
Geoff Lange8a1f782013-10-18 16:14:30 -0400823 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
824
Luc Ferron5c8113d2018-07-10 15:03:01 -0400825 glClearColor(0.0, 1.0, 0.0, 1.0);
826 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
827 glClearStencil(0x0);
828
829 // Scissor half the screen so we fill the stencil only halfway
830 glScissor(0, 0, getWindowWidth(), getWindowHeight() / 2);
831 glEnable(GL_SCISSOR_TEST);
832
Geoff Lange8a1f782013-10-18 16:14:30 -0400833 // fill the stencil buffer with 0x1
834 glStencilFunc(GL_ALWAYS, 0x1, 0xFF);
835 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
Yunchao He9550c602018-02-13 14:47:05 +0800836 glEnable(GL_STENCIL_TEST);
Luc Ferron5c8113d2018-07-10 15:03:01 -0400837 drawQuad(mRedProgram, essl1_shaders::PositionAttrib(), 0.3f);
838
839 glDisable(GL_SCISSOR_TEST);
Geoff Lange8a1f782013-10-18 16:14:30 -0400840
841 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
842 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
843
Luc Ferron5c8113d2018-07-10 15:03:01 -0400844 // These clears are not useful in theory because we're copying over them, but its
845 // helpful in debugging if we see white in any result.
Geoff Lange8a1f782013-10-18 16:14:30 -0400846 glClearColor(1.0, 1.0, 1.0, 1.0);
847 glClearStencil(0x0);
848 glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
849
850 // depth blit request should be silently ignored, because the read FBO has no depth attachment
851 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
852 GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
853
854 EXPECT_GL_NO_ERROR();
855
856 glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
857
858 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
Luc Ferron5c8113d2018-07-10 15:03:01 -0400859 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
860 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
Geoff Lange8a1f782013-10-18 16:14:30 -0400861 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
862
863 glStencilFunc(GL_EQUAL, 0x1, 0xFF); // only pass if stencil buffer at pixel reads 0x1
Luc Ferron5c8113d2018-07-10 15:03:01 -0400864
Olli Etuaho5804dc82018-04-13 14:11:46 +0300865 drawQuad(mBlueProgram, essl1_shaders::PositionAttrib(),
866 0.8f); // blue quad will draw if stencil buffer was copied
Luc Ferron5c8113d2018-07-10 15:03:01 -0400867
Geoff Lange8a1f782013-10-18 16:14:30 -0400868 glDisable(GL_STENCIL_TEST);
869
870 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255);
871 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255);
Luc Ferron5c8113d2018-07-10 15:03:01 -0400872 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
873 EXPECT_PIXEL_EQ(getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
Geoff Lange8a1f782013-10-18 16:14:30 -0400874}
875
876// make sure that attempting to blit a partial depth buffer issues an error
Jamie Madillfa05f602015-05-07 13:47:11 -0400877TEST_P(BlitFramebufferANGLETest, BlitPartialDepthStencil)
Geoff Lange8a1f782013-10-18 16:14:30 -0400878{
Luc Ferron82eda932018-07-09 15:10:22 -0400879 // TODO(lucferron): Fix this test and the implementation.
880 // http://anglebug.com/2673
881 ANGLE_SKIP_TEST_IF(IsVulkan());
882
Luc Ferronaf883622018-06-08 15:57:31 -0400883 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
884
Geoff Lange8a1f782013-10-18 16:14:30 -0400885 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
886
887 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
888
Olli Etuaho5804dc82018-04-13 14:11:46 +0300889 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lange8a1f782013-10-18 16:14:30 -0400890
891 EXPECT_GL_NO_ERROR();
892
893 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
894 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
895
896 glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0,
897 getWindowWidth() / 2, getWindowHeight() / 2, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
898 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
899}
900
901// Test blit with MRT framebuffers
Jamie Madillfa05f602015-05-07 13:47:11 -0400902TEST_P(BlitFramebufferANGLETest, BlitMRT)
Geoff Lange8a1f782013-10-18 16:14:30 -0400903{
Luc Ferronaf883622018-06-08 15:57:31 -0400904 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
905
Geoff Lange8a1f782013-10-18 16:14:30 -0400906 if (!extensionEnabled("GL_EXT_draw_buffers"))
907 {
908 return;
909 }
910
911 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT };
912
913 glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO);
914 glDrawBuffersEXT(2, drawBuffers);
915
916 glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO);
917
918 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho5804dc82018-04-13 14:11:46 +0300919
920 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f);
921
Geoff Lange8a1f782013-10-18 16:14:30 -0400922 EXPECT_GL_NO_ERROR();
923
924 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO);
925 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mMRTFBO);
926
927 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
928 GL_COLOR_BUFFER_BIT, GL_NEAREST);
929
930 EXPECT_GL_NO_ERROR();
931
932 glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO);
933
934 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
935 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
936 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
937 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
938
939 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0);
940 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0);
941
942 EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255);
943 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255);
944 EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255);
945 EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255);
946
947 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0);
948 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0);
949}
950
Kenneth Russell69382852017-07-21 16:38:44 -0400951// Test multisampled framebuffer blits if supported
952TEST_P(BlitFramebufferANGLETest, MultisampledRGBAToRGBA)
953{
Luc Ferronaf883622018-06-08 15:57:31 -0400954 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
955
Kenneth Russell69382852017-07-21 16:38:44 -0400956 if (!checkExtension("GL_ANGLE_framebuffer_multisample"))
957 return;
958
959 if (!checkExtension("GL_OES_rgb8_rgba8"))
960 return;
961
962 multisampleTestHelper(mRGBAMultisampledFBO, mRGBAFBO);
963}
964
965TEST_P(BlitFramebufferANGLETest, MultisampledRGBAToBGRA)
966{
Luc Ferronaf883622018-06-08 15:57:31 -0400967 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
968
Kenneth Russell69382852017-07-21 16:38:44 -0400969 if (!checkExtension("GL_ANGLE_framebuffer_multisample"))
970 return;
971
972 if (!checkExtension("GL_OES_rgb8_rgba8"))
973 return;
974
975 if (!checkExtension("GL_EXT_texture_format_BGRA8888"))
976 return;
977
978 multisampleTestHelper(mRGBAMultisampledFBO, mBGRAFBO);
979}
980
981TEST_P(BlitFramebufferANGLETest, MultisampledBGRAToRGBA)
982{
Luc Ferronaf883622018-06-08 15:57:31 -0400983 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
984
Kenneth Russell69382852017-07-21 16:38:44 -0400985 if (!checkExtension("GL_ANGLE_framebuffer_multisample"))
986 return;
987
988 if (!checkExtension("GL_OES_rgb8_rgba8"))
989 return;
990
991 if (!checkExtension("GL_EXT_texture_format_BGRA8888"))
992 return;
993
994 multisampleTestHelper(mBGRAMultisampledFBO, mRGBAFBO);
995}
996
997TEST_P(BlitFramebufferANGLETest, MultisampledBGRAToBGRA)
998{
Luc Ferronaf883622018-06-08 15:57:31 -0400999 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
1000
Kenneth Russell69382852017-07-21 16:38:44 -04001001 if (!checkExtension("GL_ANGLE_framebuffer_multisample"))
1002 return;
1003
1004 if (!checkExtension("GL_OES_rgb8_rgba8"))
1005 return;
1006
1007 if (!checkExtension("GL_EXT_texture_format_BGRA8888"))
1008 return;
1009
1010 multisampleTestHelper(mBGRAMultisampledFBO, mBGRAFBO);
1011}
1012
Geoff Lange8a1f782013-10-18 16:14:30 -04001013// Make sure that attempts to stretch in a blit call issue an error
Jamie Madillfa05f602015-05-07 13:47:11 -04001014TEST_P(BlitFramebufferANGLETest, ErrorStretching)
Geoff Lange8a1f782013-10-18 16:14:30 -04001015{
Luc Ferronaf883622018-06-08 15:57:31 -04001016 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
1017
Geoff Lange8a1f782013-10-18 16:14:30 -04001018 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
1019
1020 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1021
Olli Etuaho5804dc82018-04-13 14:11:46 +03001022 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lange8a1f782013-10-18 16:14:30 -04001023
1024 EXPECT_GL_NO_ERROR();
1025
1026 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
1027 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
1028
1029 glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0,
1030 getWindowWidth(), getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
1031 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1032}
1033
1034// Make sure that attempts to flip in a blit call issue an error
Jamie Madillfa05f602015-05-07 13:47:11 -04001035TEST_P(BlitFramebufferANGLETest, ErrorFlipping)
Geoff Lange8a1f782013-10-18 16:14:30 -04001036{
Luc Ferronaf883622018-06-08 15:57:31 -04001037 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
1038
Geoff Lange8a1f782013-10-18 16:14:30 -04001039 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
1040
1041 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1042
Olli Etuaho5804dc82018-04-13 14:11:46 +03001043 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lange8a1f782013-10-18 16:14:30 -04001044
1045 EXPECT_GL_NO_ERROR();
1046
1047 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
1048 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
1049
1050 glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight() / 2,
1051 0, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1052 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1053}
1054
Jamie Madillfa05f602015-05-07 13:47:11 -04001055TEST_P(BlitFramebufferANGLETest, Errors)
Geoff Lange8a1f782013-10-18 16:14:30 -04001056{
Luc Ferronaf883622018-06-08 15:57:31 -04001057 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
1058
Geoff Lange8a1f782013-10-18 16:14:30 -04001059 glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
1060
1061 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1062
Olli Etuaho5804dc82018-04-13 14:11:46 +03001063 drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f);
Geoff Lange8a1f782013-10-18 16:14:30 -04001064
1065 EXPECT_GL_NO_ERROR();
1066
1067 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO);
1068 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO);
1069
1070 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
1071 GL_COLOR_BUFFER_BIT, GL_LINEAR);
1072 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1073
1074 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
1075 GL_COLOR_BUFFER_BIT | 234, GL_NEAREST);
1076 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1077
1078 glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mDiffFormatFBO);
1079
1080 glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(),
1081 GL_COLOR_BUFFER_BIT, GL_NEAREST);
1082 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lange8a1f782013-10-18 16:14:30 -04001083}
Jamie Madillfa05f602015-05-07 13:47:11 -04001084
Geoff Lange0cc2a42016-01-20 10:58:17 -05001085// TODO(geofflang): Fix the dependence on glBlitFramebufferANGLE without checks and assuming the
1086// default framebuffer is BGRA to enable the GL and GLES backends. (http://anglebug.com/1289)
1087
Jamie Madill78a9c732016-07-15 11:22:43 -04001088class BlitFramebufferTest : public ANGLETest
1089{
1090 protected:
1091 BlitFramebufferTest()
1092 {
1093 setWindowWidth(256);
1094 setWindowHeight(256);
1095 setConfigRedBits(8);
1096 setConfigGreenBits(8);
1097 setConfigBlueBits(8);
1098 setConfigAlphaBits(8);
1099 setConfigDepthBits(24);
1100 setConfigStencilBits(8);
1101 }
Olli Etuahode279592018-04-26 12:25:13 +03001102
1103 void initColorFBO(GLFramebuffer *fbo,
1104 GLRenderbuffer *rbo,
1105 GLenum rboFormat,
1106 GLsizei width,
1107 GLsizei height)
1108 {
1109 glBindRenderbuffer(GL_RENDERBUFFER, *rbo);
1110 glRenderbufferStorage(GL_RENDERBUFFER, rboFormat, width, height);
1111
1112 glBindFramebuffer(GL_FRAMEBUFFER, *fbo);
1113 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, *rbo);
1114 }
1115
1116 void initColorFBOWithCheckerPattern(GLFramebuffer *fbo,
1117 GLRenderbuffer *rbo,
1118 GLenum rboFormat,
1119 GLsizei width,
1120 GLsizei height)
1121 {
1122 initColorFBO(fbo, rbo, rboFormat, width, height);
1123
1124 ANGLE_GL_PROGRAM(checkerProgram, essl1_shaders::vs::Passthrough(),
1125 essl1_shaders::fs::Checkered());
1126 glViewport(0, 0, width, height);
1127 glBindFramebuffer(GL_FRAMEBUFFER, *fbo);
1128 drawQuad(checkerProgram.get(), essl1_shaders::PositionAttrib(), 0.5f);
1129 }
Jamie Madill78a9c732016-07-15 11:22:43 -04001130};
1131
Jamie Madill196ca362016-07-12 10:54:04 -04001132// Tests resolving a multisample depth buffer.
1133TEST_P(BlitFramebufferTest, MultisampleDepth)
1134{
Luc Ferronaf883622018-06-08 15:57:31 -04001135 ANGLE_SKIP_TEST_IF(!extensionEnabled("EXT_framebuffer_blit"));
1136
Geoff Langf1bcd012018-04-27 14:21:55 -04001137 // TODO(oetuaho@nvidia.com): http://crbug.com/837717
1138 ANGLE_SKIP_TEST_IF(IsOpenGL() && IsOSX());
1139
Jamie Madill196ca362016-07-12 10:54:04 -04001140 GLRenderbuffer renderbuf;
1141 glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get());
1142 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 256, 256);
1143
Jamie Madill196ca362016-07-12 10:54:04 -04001144 const std::string &fragment =
1145 "#version 300 es\n"
1146 "out mediump vec4 red;\n"
1147 "void main() {\n"
1148 " red = vec4(1.0, 0.0, 0.0, 1.0);\n"
1149 " gl_FragDepth = 0.5;\n"
1150 "}";
1151
Olli Etuaho5804dc82018-04-13 14:11:46 +03001152 ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), fragment);
Jamie Madill196ca362016-07-12 10:54:04 -04001153
1154 GLFramebuffer framebuffer;
1155 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1156 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
1157 renderbuf.get());
1158
1159 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1160
1161 glClearDepthf(0.5f);
1162 glClear(GL_DEPTH_BUFFER_BIT);
1163
1164 GLRenderbuffer destRenderbuf;
1165 glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get());
1166 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 256, 256);
1167
1168 GLFramebuffer resolved;
1169 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get());
1170 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
1171 destRenderbuf.get());
1172
1173 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get());
1174 glBlitFramebuffer(0, 0, 256, 256, 0, 0, 256, 256, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
1175
1176 glBindFramebuffer(GL_FRAMEBUFFER, resolved.get());
1177
1178 GLTexture colorbuf;
1179 glBindTexture(GL_TEXTURE_2D, colorbuf.get());
1180 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256);
1181 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuf.get(), 0);
1182
1183 ASSERT_GL_NO_ERROR();
1184
1185 // Clear to green
1186 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1187 glClear(GL_COLOR_BUFFER_BIT);
1188 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1189
1190 // Draw with 0.5f test and the test should pass.
1191 glEnable(GL_DEPTH_TEST);
1192 glDepthFunc(GL_EQUAL);
Olli Etuaho5804dc82018-04-13 14:11:46 +03001193 drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f);
Jamie Madill196ca362016-07-12 10:54:04 -04001194 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1195
1196 ASSERT_GL_NO_ERROR();
1197}
1198
Jamie Madill78a9c732016-07-15 11:22:43 -04001199// Test resolving a multisampled stencil buffer.
1200TEST_P(BlitFramebufferTest, MultisampleStencil)
1201{
Luc Ferronaf883622018-06-08 15:57:31 -04001202 ANGLE_SKIP_TEST_IF(!extensionEnabled("EXT_framebuffer_blit"));
1203
Olli Etuahode279592018-04-26 12:25:13 +03001204 // Incorrect rendering results seen on AMD Windows OpenGL. http://anglebug.com/2486
1205 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL() && IsWindows());
1206
Jamie Madill78a9c732016-07-15 11:22:43 -04001207 GLRenderbuffer renderbuf;
1208 glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get());
1209 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_STENCIL_INDEX8, 256, 256);
1210
Olli Etuaho5804dc82018-04-13 14:11:46 +03001211 ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), essl3_shaders::fs::Red());
Jamie Madill78a9c732016-07-15 11:22:43 -04001212
1213 GLFramebuffer framebuffer;
1214 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1215 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1216 renderbuf.get());
1217
1218 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1219
1220 // fill the stencil buffer with 0x1
1221 glStencilFunc(GL_ALWAYS, 0x1, 0xFF);
1222 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
1223 glEnable(GL_STENCIL_TEST);
Olli Etuaho5804dc82018-04-13 14:11:46 +03001224 drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f);
Jamie Madill78a9c732016-07-15 11:22:43 -04001225
1226 GLTexture destColorbuf;
1227 glBindTexture(GL_TEXTURE_2D, destColorbuf.get());
1228 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256);
1229
1230 GLRenderbuffer destRenderbuf;
1231 glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get());
1232 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 256, 256);
1233
1234 GLFramebuffer resolved;
1235 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get());
1236 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
1237 destColorbuf.get(), 0);
1238 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1239 destRenderbuf.get());
1240
1241 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get());
1242 glBlitFramebuffer(0, 0, 256, 256, 0, 0, 256, 256, GL_STENCIL_BUFFER_BIT, GL_NEAREST);
1243
1244 glBindFramebuffer(GL_FRAMEBUFFER, resolved.get());
1245
1246 ASSERT_GL_NO_ERROR();
1247
1248 // Clear to green
1249 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
1250 glClear(GL_COLOR_BUFFER_BIT);
1251 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1252
1253 // Draw red if the stencil is 0x1, which should be true after the blit/resolve.
1254 glStencilFunc(GL_EQUAL, 0x1, 0xFF);
Olli Etuaho5804dc82018-04-13 14:11:46 +03001255 drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f);
Jamie Madill78a9c732016-07-15 11:22:43 -04001256 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1257
1258 ASSERT_GL_NO_ERROR();
1259}
1260
Olli Etuahode279592018-04-26 12:25:13 +03001261// Blit an SRGB framebuffer and scale it.
1262TEST_P(BlitFramebufferTest, BlitSRGBToRGBAndScale)
1263{
Luc Ferronaf883622018-06-08 15:57:31 -04001264 ANGLE_SKIP_TEST_IF(!extensionEnabled("EXT_framebuffer_blit"));
1265
Olli Etuahode279592018-04-26 12:25:13 +03001266 constexpr const GLsizei kWidth = 256;
1267 constexpr const GLsizei kHeight = 256;
1268
1269 GLRenderbuffer sourceRBO, targetRBO;
1270 GLFramebuffer sourceFBO, targetFBO;
1271 initColorFBOWithCheckerPattern(&sourceFBO, &sourceRBO, GL_SRGB8_ALPHA8, kWidth * 2,
1272 kHeight * 2);
1273 initColorFBO(&targetFBO, &targetRBO, GL_RGBA8, kWidth, kHeight);
1274
1275 EXPECT_GL_NO_ERROR();
1276
1277 glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO);
1278 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO);
1279
1280 glViewport(0, 0, kWidth, kHeight);
1281
1282 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1283 glClear(GL_COLOR_BUFFER_BIT);
1284
1285 // Scale down without flipping.
1286 glBlitFramebuffer(0, 0, kWidth * 2, kHeight * 2, 0, 0, kWidth, kHeight, GL_COLOR_BUFFER_BIT,
1287 GL_NEAREST);
1288
1289 EXPECT_GL_NO_ERROR();
1290
1291 glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
1292
1293 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::red);
1294 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::green);
1295 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::red);
1296 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::green);
1297
1298 glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO);
1299 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO);
1300
1301 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1302 glClear(GL_COLOR_BUFFER_BIT);
1303
1304 // Scale down and flip in the X direction.
1305 glBlitFramebuffer(0, 0, kWidth * 2, kHeight * 2, kWidth, 0, 0, kHeight, GL_COLOR_BUFFER_BIT,
1306 GL_NEAREST);
1307
1308 EXPECT_GL_NO_ERROR();
1309
1310 glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
1311
1312 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::green);
1313 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::red);
1314 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::green);
1315 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::red);
1316}
1317
1318// Blit a subregion of an SRGB framebuffer to an RGB framebuffer.
1319TEST_P(BlitFramebufferTest, PartialBlitSRGBToRGB)
1320{
Luc Ferronaf883622018-06-08 15:57:31 -04001321 ANGLE_SKIP_TEST_IF(!extensionEnabled("EXT_framebuffer_blit"));
1322
Olli Etuahode279592018-04-26 12:25:13 +03001323 constexpr const GLsizei kWidth = 256;
1324 constexpr const GLsizei kHeight = 256;
1325
1326 GLRenderbuffer sourceRBO, targetRBO;
1327 GLFramebuffer sourceFBO, targetFBO;
1328 initColorFBOWithCheckerPattern(&sourceFBO, &sourceRBO, GL_SRGB8_ALPHA8, kWidth * 2,
1329 kHeight * 2);
1330 initColorFBO(&targetFBO, &targetRBO, GL_RGBA8, kWidth, kHeight);
1331
1332 EXPECT_GL_NO_ERROR();
1333
1334 glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO);
1335 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO);
1336
1337 glViewport(0, 0, kWidth, kHeight);
1338
1339 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1340 glClear(GL_COLOR_BUFFER_BIT);
1341
1342 // Blit a part of the source FBO without flipping.
1343 glBlitFramebuffer(kWidth, kHeight, kWidth * 2, kHeight * 2, 0, 0, kWidth, kHeight,
1344 GL_COLOR_BUFFER_BIT, GL_NEAREST);
1345
1346 EXPECT_GL_NO_ERROR();
1347
1348 glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
1349
1350 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::red);
1351 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::red);
1352 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::red);
1353 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::red);
1354
1355 glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO);
1356 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO);
1357
1358 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1359 glClear(GL_COLOR_BUFFER_BIT);
1360
1361 // Blit a part of the source FBO and flip in the X direction.
1362 glBlitFramebuffer(kWidth * 2, 0, kWidth, kHeight, kWidth, 0, 0, kHeight, GL_COLOR_BUFFER_BIT,
1363 GL_NEAREST);
1364
1365 EXPECT_GL_NO_ERROR();
1366
1367 glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
1368
1369 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::green);
1370 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::green);
1371 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::green);
1372 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::green);
1373}
1374
1375// Blit an SRGB framebuffer with an oversized source area (parts outside the source area should be
1376// clipped out).
1377TEST_P(BlitFramebufferTest, BlitSRGBToRGBOversizedSourceArea)
1378{
Luc Ferronaf883622018-06-08 15:57:31 -04001379 ANGLE_SKIP_TEST_IF(!extensionEnabled("EXT_framebuffer_blit"));
1380
Olli Etuahode279592018-04-26 12:25:13 +03001381 constexpr const GLsizei kWidth = 256;
1382 constexpr const GLsizei kHeight = 256;
1383
1384 GLRenderbuffer sourceRBO, targetRBO;
1385 GLFramebuffer sourceFBO, targetFBO;
1386 initColorFBOWithCheckerPattern(&sourceFBO, &sourceRBO, GL_SRGB8_ALPHA8, kWidth, kHeight);
1387 initColorFBO(&targetFBO, &targetRBO, GL_RGBA8, kWidth, kHeight);
1388
1389 EXPECT_GL_NO_ERROR();
1390
1391 glViewport(0, 0, kWidth, kHeight);
1392
1393 glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO);
1394 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO);
1395
1396 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1397 glClear(GL_COLOR_BUFFER_BIT);
1398
1399 // Blit so that the source area gets placed at the center of the target FBO.
1400 // The width of the source area is 1/4 of the width of the target FBO.
1401 glBlitFramebuffer(-3 * kWidth / 2, -3 * kHeight / 2, 5 * kWidth / 2, 5 * kHeight / 2, 0, 0,
1402 kWidth, kHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1403
1404 EXPECT_GL_NO_ERROR();
1405
1406 glBindFramebuffer(GL_FRAMEBUFFER, targetFBO);
1407
1408 // Source FBO colors can be found in the middle of the target FBO.
1409 EXPECT_PIXEL_COLOR_EQ(7 * kWidth / 16, 7 * kHeight / 16, GLColor::red);
1410 EXPECT_PIXEL_COLOR_EQ(9 * kWidth / 16, 7 * kHeight / 16, GLColor::green);
1411 EXPECT_PIXEL_COLOR_EQ(9 * kWidth / 16, 9 * kHeight / 16, GLColor::red);
1412 EXPECT_PIXEL_COLOR_EQ(7 * kWidth / 16, 9 * kHeight / 16, GLColor::green);
1413
1414 // Clear color should remain around the edges of the target FBO (WebGL 2.0 spec explicitly
1415 // requires this and ANGLE is expected to follow that).
1416 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::black);
1417 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::black);
1418 EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::black);
1419 EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::black);
1420}
1421
Olli Etuaho9aef81c2018-04-30 14:56:15 +03001422// Test blitFramebuffer size overflow checks. WebGL 2.0 spec section 5.41. We do validation for
1423// overflows also in non-WebGL mode to avoid triggering driver bugs.
1424TEST_P(BlitFramebufferTest, BlitFramebufferSizeOverflow)
1425{
Luc Ferronaf883622018-06-08 15:57:31 -04001426 ANGLE_SKIP_TEST_IF(!extensionEnabled("EXT_framebuffer_blit"));
1427
Olli Etuaho9aef81c2018-04-30 14:56:15 +03001428 GLTexture textures[2];
1429 glBindTexture(GL_TEXTURE_2D, textures[0]);
1430 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
1431 glBindTexture(GL_TEXTURE_2D, textures[1]);
1432 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
1433
1434 GLFramebuffer framebuffers[2];
1435 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
1436 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
1437
1438 ASSERT_GL_NO_ERROR();
1439
1440 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
1441 0);
1442 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
1443 0);
1444 ASSERT_GL_NO_ERROR();
1445
1446 // srcX
1447 glBlitFramebuffer(-1, 0, std::numeric_limits<GLint>::max(), 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT,
1448 GL_NEAREST);
1449 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1450 glBlitFramebuffer(std::numeric_limits<GLint>::max(), 0, -1, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT,
1451 GL_NEAREST);
1452 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1453
1454 // srcY
1455 glBlitFramebuffer(0, -1, 4, std::numeric_limits<GLint>::max(), 0, 0, 4, 4, GL_COLOR_BUFFER_BIT,
1456 GL_NEAREST);
1457 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1458 glBlitFramebuffer(0, std::numeric_limits<GLint>::max(), 4, -1, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT,
1459 GL_NEAREST);
1460 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1461
1462 // dstX
1463 glBlitFramebuffer(0, 0, 4, 4, -1, 0, std::numeric_limits<GLint>::max(), 4, GL_COLOR_BUFFER_BIT,
1464 GL_NEAREST);
1465 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1466 glBlitFramebuffer(0, 0, 4, 4, std::numeric_limits<GLint>::max(), 0, -1, 4, GL_COLOR_BUFFER_BIT,
1467 GL_NEAREST);
1468 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1469
1470 // dstY
1471 glBlitFramebuffer(0, 0, 4, 4, 0, -1, 4, std::numeric_limits<GLint>::max(), GL_COLOR_BUFFER_BIT,
1472 GL_NEAREST);
1473 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1474 glBlitFramebuffer(0, 0, 4, 4, 0, std::numeric_limits<GLint>::max(), 4, -1, GL_COLOR_BUFFER_BIT,
1475 GL_NEAREST);
1476 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1477}
1478
Jamie Madillfa05f602015-05-07 13:47:11 -04001479// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Austin Kinross2a63b3f2016-02-08 12:29:08 -08001480ANGLE_INSTANTIATE_TEST(BlitFramebufferANGLETest,
1481 ES2_D3D9(),
1482 ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE),
Kenneth Russell69382852017-07-21 16:38:44 -04001483 ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE),
1484 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04001485 ES3_OPENGL(),
1486 ES2_VULKAN());
Jamie Madill78a9c732016-07-15 11:22:43 -04001487
Olli Etuahode279592018-04-26 12:25:13 +03001488// We're specifically testing GL 4.4 and GL 4.3 since on versions earlier than 4.4 FramebufferGL
1489// takes a different path for blitting SRGB textures.
1490ANGLE_INSTANTIATE_TEST(BlitFramebufferTest, ES3_D3D11(), ES3_OPENGL(4, 4), ES3_OPENGL(4, 3));