blob: 88db8ca5ff9e2712b97ed7faabea98eaa5083101 [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//
Jamie Madill1fbc59f2016-02-24 15:25:51 -05006// Framebuffer tests:
7// Various tests related for Frambuffers.
8//
Jamie Madillfa05f602015-05-07 13:47:11 -04009
Brandon Jones9fc87332017-12-13 15:46:52 -080010#include "platform/WorkaroundsD3D.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -040011#include "test_utils/ANGLETest.h"
JiangYizhou461d9a32017-01-04 16:37:26 +080012#include "test_utils/gl_raii.h"
Geoff Langb6a673a2014-06-05 14:19:16 -040013
Jamie Madillfa05f602015-05-07 13:47:11 -040014using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070015
Geoff Lang857c09d2017-05-16 15:55:04 -040016namespace
17{
18
19void ExpectFramebufferCompleteOrUnsupported(GLenum binding)
20{
21 GLenum status = glCheckFramebufferStatus(binding);
22 EXPECT_TRUE(status == GL_FRAMEBUFFER_COMPLETE || status == GL_FRAMEBUFFER_UNSUPPORTED);
23}
24
25} // anonymous namespace
26
Geoff Langb6a673a2014-06-05 14:19:16 -040027class FramebufferFormatsTest : public ANGLETest
28{
Jamie Madillfa05f602015-05-07 13:47:11 -040029 protected:
Jamie Madill3215b202015-12-15 16:41:39 -050030 FramebufferFormatsTest() : mFramebuffer(0), mTexture(0), mRenderbuffer(0), mProgram(0)
Geoff Langb6a673a2014-06-05 14:19:16 -040031 {
32 setWindowWidth(128);
33 setWindowHeight(128);
34 setConfigRedBits(8);
35 setConfigGreenBits(8);
36 setConfigBlueBits(8);
37 setConfigAlphaBits(8);
38 }
39
40 void checkBitCount(GLuint fbo, GLenum channel, GLint minBits)
41 {
42 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
43
44 GLint bits = 0;
45 glGetIntegerv(channel, &bits);
46
47 if (minBits == 0)
48 {
49 EXPECT_EQ(minBits, bits);
50 }
51 else
52 {
53 EXPECT_GE(bits, minBits);
54 }
55 }
56
Jamie Madill1fbc59f2016-02-24 15:25:51 -050057 void testBitCounts(GLuint fbo,
58 GLint minRedBits,
59 GLint minGreenBits,
60 GLint minBlueBits,
61 GLint minAlphaBits,
62 GLint minDepthBits,
63 GLint minStencilBits)
Geoff Langb6a673a2014-06-05 14:19:16 -040064 {
65 checkBitCount(fbo, GL_RED_BITS, minRedBits);
66 checkBitCount(fbo, GL_GREEN_BITS, minGreenBits);
67 checkBitCount(fbo, GL_BLUE_BITS, minBlueBits);
68 checkBitCount(fbo, GL_ALPHA_BITS, minAlphaBits);
69 checkBitCount(fbo, GL_DEPTH_BITS, minDepthBits);
70 checkBitCount(fbo, GL_STENCIL_BITS, minStencilBits);
71 }
72
Jamie Madill1fbc59f2016-02-24 15:25:51 -050073 void testTextureFormat(GLenum internalFormat,
74 GLint minRedBits,
75 GLint minGreenBits,
76 GLint minBlueBits,
Geoff Langb6a673a2014-06-05 14:19:16 -040077 GLint minAlphaBits)
78 {
Jamie Madill3215b202015-12-15 16:41:39 -050079 glGenTextures(1, &mTexture);
80 glBindTexture(GL_TEXTURE_2D, mTexture);
Geoff Langc4e93662017-05-01 10:45:59 -040081
82 if (getClientMajorVersion() >= 3)
83 {
84 glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
85 }
86 else
87 {
88 glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
89 }
Geoff Langb6a673a2014-06-05 14:19:16 -040090
Jamie Madill3215b202015-12-15 16:41:39 -050091 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0);
Geoff Langb6a673a2014-06-05 14:19:16 -040092
Jamie Madill3215b202015-12-15 16:41:39 -050093 testBitCounts(mFramebuffer, minRedBits, minGreenBits, minBlueBits, minAlphaBits, 0, 0);
Geoff Langb6a673a2014-06-05 14:19:16 -040094 }
95
Jamie Madill1fbc59f2016-02-24 15:25:51 -050096 void testRenderbufferMultisampleFormat(int minESVersion,
97 GLenum attachmentType,
98 GLenum internalFormat)
Corentin Walleze0902642014-11-04 12:32:15 -080099 {
Martin Radev1be913c2016-07-11 17:59:16 +0300100 int clientVersion = getClientMajorVersion();
Jamie Madillfa05f602015-05-07 13:47:11 -0400101 if (clientVersion < minESVersion)
Corentin Walleze0902642014-11-04 12:32:15 -0800102 {
103 return;
104 }
105
106 // Check that multisample is supported with at least two samples (minimum required is 1)
107 bool supports2Samples = false;
108
Jamie Madillfa05f602015-05-07 13:47:11 -0400109 if (clientVersion == 2)
Corentin Walleze0902642014-11-04 12:32:15 -0800110 {
Jamie Madillb8149072019-04-30 16:14:44 -0400111 if (IsGLExtensionEnabled("ANGLE_framebuffer_multisample"))
Corentin Walleze0902642014-11-04 12:32:15 -0800112 {
113 int maxSamples;
114 glGetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSamples);
115 supports2Samples = maxSamples >= 2;
116 }
117 }
118 else
119 {
Jamie Madillfa05f602015-05-07 13:47:11 -0400120 assert(clientVersion >= 3);
Corentin Walleze0902642014-11-04 12:32:15 -0800121 int maxSamples;
122 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
123 supports2Samples = maxSamples >= 2;
124 }
125
126 if (!supports2Samples)
127 {
128 return;
129 }
130
Jamie Madill3215b202015-12-15 16:41:39 -0500131 glGenRenderbuffers(1, &mRenderbuffer);
132 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
Corentin Walleze0902642014-11-04 12:32:15 -0800133
134 EXPECT_GL_NO_ERROR();
135 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 2, internalFormat, 128, 128);
136 EXPECT_GL_NO_ERROR();
Jamie Madill3215b202015-12-15 16:41:39 -0500137 glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachmentType, GL_RENDERBUFFER, mRenderbuffer);
Corentin Walleze0902642014-11-04 12:32:15 -0800138 EXPECT_GL_NO_ERROR();
Corentin Walleze0902642014-11-04 12:32:15 -0800139 }
140
Olli Etuahobc21e182016-02-23 16:04:57 +0200141 void testZeroHeightRenderbuffer()
142 {
143 glGenRenderbuffers(1, &mRenderbuffer);
144 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
145 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 0);
146 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
147 mRenderbuffer);
148 EXPECT_GL_NO_ERROR();
149 }
150
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400151 void testSetUp() override
Geoff Langb6a673a2014-06-05 14:19:16 -0400152 {
Jamie Madill3215b202015-12-15 16:41:39 -0500153 glGenFramebuffers(1, &mFramebuffer);
154 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
Geoff Langb6a673a2014-06-05 14:19:16 -0400155 }
156
Jamie Madill5cbaa3f2019-05-07 15:49:22 -0400157 void testTearDown() override
Geoff Langb6a673a2014-06-05 14:19:16 -0400158 {
Jamie Madill3215b202015-12-15 16:41:39 -0500159 if (mTexture != 0)
160 {
161 glDeleteTextures(1, &mTexture);
162 mTexture = 0;
163 }
164
165 if (mRenderbuffer != 0)
166 {
167 glDeleteRenderbuffers(1, &mRenderbuffer);
168 mRenderbuffer = 0;
169 }
170
171 if (mFramebuffer != 0)
172 {
173 glDeleteFramebuffers(1, &mFramebuffer);
174 mFramebuffer = 0;
175 }
176
177 if (mProgram != 0)
178 {
179 glDeleteProgram(mProgram);
180 mProgram = 0;
181 }
Geoff Langb6a673a2014-06-05 14:19:16 -0400182 }
Jamie Madill3215b202015-12-15 16:41:39 -0500183
184 GLuint mFramebuffer;
185 GLuint mTexture;
186 GLuint mRenderbuffer;
187 GLuint mProgram;
Geoff Langb6a673a2014-06-05 14:19:16 -0400188};
189
Jamie Madillfa05f602015-05-07 13:47:11 -0400190TEST_P(FramebufferFormatsTest, RGBA4)
Geoff Langb6a673a2014-06-05 14:19:16 -0400191{
Jamie Madillb8149072019-04-30 16:14:44 -0400192 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
193 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -0400194
Geoff Langb6a673a2014-06-05 14:19:16 -0400195 testTextureFormat(GL_RGBA4, 4, 4, 4, 4);
196}
197
Jamie Madillfa05f602015-05-07 13:47:11 -0400198TEST_P(FramebufferFormatsTest, RGB565)
Geoff Langb6a673a2014-06-05 14:19:16 -0400199{
Jamie Madillb8149072019-04-30 16:14:44 -0400200 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
201 !IsGLExtensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -0400202
Geoff Langb6a673a2014-06-05 14:19:16 -0400203 testTextureFormat(GL_RGB565, 5, 6, 5, 0);
204}
205
Jamie Madillfa05f602015-05-07 13:47:11 -0400206TEST_P(FramebufferFormatsTest, RGB8)
Geoff Langb6a673a2014-06-05 14:19:16 -0400207{
Jamie Madillb8149072019-04-30 16:14:44 -0400208 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
209 (!IsGLExtensionEnabled("GL_OES_rgb8_rgba8") ||
210 !IsGLExtensionEnabled("GL_EXT_texture_storage")));
Geoff Langf34d1db2015-05-20 14:10:46 -0400211
Geoff Langb6a673a2014-06-05 14:19:16 -0400212 testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0);
213}
214
Jamie Madillfa05f602015-05-07 13:47:11 -0400215TEST_P(FramebufferFormatsTest, BGRA8)
Geoff Langb6a673a2014-06-05 14:19:16 -0400216{
Yunchao He9550c602018-02-13 14:47:05 +0800217 ANGLE_SKIP_TEST_IF(
Jamie Madillb8149072019-04-30 16:14:44 -0400218 !IsGLExtensionEnabled("GL_EXT_texture_format_BGRA8888") ||
219 (getClientMajorVersion() < 3 && !IsGLExtensionEnabled("GL_EXT_texture_storage")));
Geoff Langf34d1db2015-05-20 14:10:46 -0400220
Geoff Langb6a673a2014-06-05 14:19:16 -0400221 testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8);
222}
223
Jamie Madillfa05f602015-05-07 13:47:11 -0400224TEST_P(FramebufferFormatsTest, RGBA8)
Geoff Langb6a673a2014-06-05 14:19:16 -0400225{
Jamie Madillb8149072019-04-30 16:14:44 -0400226 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 &&
227 (!IsGLExtensionEnabled("GL_OES_rgb8_rgba8") ||
228 !IsGLExtensionEnabled("GL_EXT_texture_storage")));
Geoff Langf34d1db2015-05-20 14:10:46 -0400229
Geoff Langb6a673a2014-06-05 14:19:16 -0400230 testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8);
231}
232
Jamie Madillfa05f602015-05-07 13:47:11 -0400233TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH16)
Corentin Walleze0902642014-11-04 12:32:15 -0800234{
235 testRenderbufferMultisampleFormat(2, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16);
236}
237
Jamie Madillfa05f602015-05-07 13:47:11 -0400238TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24)
Corentin Walleze0902642014-11-04 12:32:15 -0800239{
240 testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24);
241}
242
Jamie Madillfa05f602015-05-07 13:47:11 -0400243TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F)
Corentin Walleze0902642014-11-04 12:32:15 -0800244{
Yunchao He9550c602018-02-13 14:47:05 +0800245 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
Geoff Langf34d1db2015-05-20 14:10:46 -0400246
Corentin Walleze0902642014-11-04 12:32:15 -0800247 testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32F);
248}
249
Jamie Madillfa05f602015-05-07 13:47:11 -0400250TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24_STENCIL8)
Corentin Walleze0902642014-11-04 12:32:15 -0800251{
252 testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH24_STENCIL8);
253}
254
Jamie Madillfa05f602015-05-07 13:47:11 -0400255TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F_STENCIL8)
Corentin Walleze0902642014-11-04 12:32:15 -0800256{
Yunchao He9550c602018-02-13 14:47:05 +0800257 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
Geoff Langf34d1db2015-05-20 14:10:46 -0400258
Corentin Walleze0902642014-11-04 12:32:15 -0800259 testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH32F_STENCIL8);
260}
261
Jamie Madillfa05f602015-05-07 13:47:11 -0400262TEST_P(FramebufferFormatsTest, RenderbufferMultisample_STENCIL_INDEX8)
Corentin Walleze0902642014-11-04 12:32:15 -0800263{
Geoff Langf34d1db2015-05-20 14:10:46 -0400264 // TODO(geofflang): Figure out how to support GLSTENCIL_INDEX8 on desktop GL
Yunchao He9550c602018-02-13 14:47:05 +0800265 ANGLE_SKIP_TEST_IF(IsDesktopOpenGL());
Geoff Langf34d1db2015-05-20 14:10:46 -0400266
Corentin Walleze0902642014-11-04 12:32:15 -0800267 testRenderbufferMultisampleFormat(2, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8);
268}
Jamie Madillfa05f602015-05-07 13:47:11 -0400269
Jamie Madill3215b202015-12-15 16:41:39 -0500270// Test that binding an incomplete cube map is rejected by ANGLE.
271TEST_P(FramebufferFormatsTest, IncompleteCubeMap)
272{
Michael Spangd8506c72019-01-29 15:35:09 -0500273 // http://anglebug.com/3145
274 ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan());
275
Jamie Madill3215b202015-12-15 16:41:39 -0500276 // First make a complete CubeMap.
277 glGenTextures(1, &mTexture);
278 glBindTexture(GL_TEXTURE_CUBE_MAP, mTexture);
279 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
280 nullptr);
281 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
282 nullptr);
283 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
284 nullptr);
285 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
286 nullptr);
287 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
288 nullptr);
289 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
290 nullptr);
291 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
292 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
293
294 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X,
295 mTexture, 0);
296
297 // Verify the framebuffer is complete.
298 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
299
300 // Make the CubeMap cube-incomplete.
301 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
302 nullptr);
303
304 // Verify the framebuffer is incomplete.
305 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
306 glCheckFramebufferStatus(GL_FRAMEBUFFER));
307
Jamie Madilld84b6732018-09-06 15:54:35 -0400308 ASSERT_GL_NO_ERROR();
309
Jamie Madill3215b202015-12-15 16:41:39 -0500310 // Verify drawing with the incomplete framebuffer produces a GL error
Olli Etuaho5804dc82018-04-13 14:11:46 +0300311 mProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
Jamie Madill3215b202015-12-15 16:41:39 -0500312 ASSERT_NE(0u, mProgram);
Olli Etuaho5804dc82018-04-13 14:11:46 +0300313 drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f);
Jamie Madill3215b202015-12-15 16:41:39 -0500314 ASSERT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION);
315}
316
Olli Etuahobc21e182016-02-23 16:04:57 +0200317// Test that a renderbuffer with zero height but nonzero width is handled without crashes/asserts.
318TEST_P(FramebufferFormatsTest, ZeroHeightRenderbuffer)
319{
Yunchao He9550c602018-02-13 14:47:05 +0800320 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
Olli Etuahobc21e182016-02-23 16:04:57 +0200321
322 testZeroHeightRenderbuffer();
323}
324
Geoff Lang9bf86f02018-07-26 11:46:34 -0400325// Test to cover a bug where the read framebuffer affects the completeness of the draw framebuffer.
326TEST_P(FramebufferFormatsTest, ReadDrawCompleteness)
327{
328 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
329
330 GLTexture incompleteTexture;
331 glBindTexture(GL_TEXTURE_2D, incompleteTexture);
332
333 GLFramebuffer incompleteFBO;
334 glBindFramebuffer(GL_FRAMEBUFFER, incompleteFBO);
335 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, incompleteTexture,
336 0);
337 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
338 glCheckFramebufferStatus(GL_FRAMEBUFFER));
339
340 GLTexture completeTexture;
341 glBindTexture(GL_TEXTURE_2D, completeTexture);
342 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
343
344 GLFramebuffer completeFBO;
345 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, completeFBO);
346 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
347 completeTexture, 0);
348
349 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
350 glCheckFramebufferStatus(GL_READ_FRAMEBUFFER));
351 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER));
352
353 ASSERT_GL_NO_ERROR();
354
355 // Simple draw program.
356 ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
357
358 drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true);
359 EXPECT_GL_NO_ERROR();
360
361 glBindFramebuffer(GL_READ_FRAMEBUFFER, completeFBO);
362 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
363}
364
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500365// Use this to select which configurations (e.g. which renderer, which GLES major version) these
366// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -0500367ANGLE_INSTANTIATE_TEST(FramebufferFormatsTest,
Luc Ferronfa7503c2018-05-08 11:25:06 -0400368 ES2_VULKAN(),
Geoff Lange0cc2a42016-01-20 10:58:17 -0500369 ES2_D3D9(),
370 ES2_D3D11(),
371 ES3_D3D11(),
372 ES2_OPENGL(),
373 ES3_OPENGL(),
374 ES2_OPENGLES(),
375 ES3_OPENGLES());
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500376
Corentin Wallez57e6d502016-12-09 14:46:39 -0500377class FramebufferTest_ES3 : public ANGLETest
Jamie Madillb980c562018-11-27 11:34:27 -0500378{};
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500379
380// Covers invalidating an incomplete framebuffer. This should be a no-op, but should not error.
Corentin Wallez57e6d502016-12-09 14:46:39 -0500381TEST_P(FramebufferTest_ES3, InvalidateIncomplete)
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500382{
Geoff Lang857c09d2017-05-16 15:55:04 -0400383 GLFramebuffer framebuffer;
384 GLRenderbuffer renderbuffer;
385
386 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
387 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
388 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500389 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
390 glCheckFramebufferStatus(GL_FRAMEBUFFER));
391
392 std::vector<GLenum> attachments;
393 attachments.push_back(GL_COLOR_ATTACHMENT0);
394
395 glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, attachments.data());
396 EXPECT_GL_NO_ERROR();
397}
398
Corentin Wallez57e6d502016-12-09 14:46:39 -0500399// Test that the framebuffer state tracking robustly handles a depth-only attachment being set
400// as a depth-stencil attachment. It is equivalent to detaching the depth-stencil attachment.
401TEST_P(FramebufferTest_ES3, DepthOnlyAsDepthStencil)
402{
Geoff Lang857c09d2017-05-16 15:55:04 -0400403 GLFramebuffer framebuffer;
404 GLRenderbuffer renderbuffer;
405
406 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
407 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
Corentin Wallez57e6d502016-12-09 14:46:39 -0500408 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 4, 4);
409
410 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
Geoff Lang857c09d2017-05-16 15:55:04 -0400411 renderbuffer);
Corentin Wallez57e6d502016-12-09 14:46:39 -0500412 EXPECT_GLENUM_NE(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
413}
414
Geoff Lang857c09d2017-05-16 15:55:04 -0400415// Test that the framebuffer correctly returns that it is not complete if invalid texture mip levels
416// are bound
417TEST_P(FramebufferTest_ES3, TextureAttachmentMipLevels)
418{
419 GLFramebuffer framebuffer;
420 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
421
422 GLTexture texture;
423 glBindTexture(GL_TEXTURE_2D, texture);
424
425 // Create a complete mip chain in mips 1 to 3
426 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
427 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
428 glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
429
430 // Create another complete mip chain in mips 4 to 5
431 glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
432 glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
433
434 // Create a non-complete mip chain in mip 6
435 glTexImage2D(GL_TEXTURE_2D, 6, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
436
437 // Incomplete, mipLevel != baseLevel and texture is not mip complete
438 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
439 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
440 glCheckFramebufferStatus(GL_FRAMEBUFFER));
441
442 // Complete, mipLevel == baseLevel
443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
444 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
445
446 // Complete, mipLevel != baseLevel but texture is now mip complete
447 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 2);
448 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
449 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 3);
450 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
451
452 // Incomplete, attached level below the base level
453 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
454 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
455 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
456 glCheckFramebufferStatus(GL_FRAMEBUFFER));
457
458 // Incomplete, attached level is beyond effective max level
459 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 4);
460 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
461 glCheckFramebufferStatus(GL_FRAMEBUFFER));
462
463 // Complete, mipLevel == baseLevel
464 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 4);
465 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
466
467 // Complete, mipLevel != baseLevel but texture is now mip complete
468 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 5);
469 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
470
471 // Complete, mipLevel == baseLevel
472 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 6);
473 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 6);
474 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
475}
476
Martin Radevd178aa42017-07-13 14:03:22 +0300477// Test that passing an attachment COLOR_ATTACHMENTm where m is equal to MAX_COLOR_ATTACHMENTS
478// generates an INVALID_OPERATION.
479// OpenGL ES Version 3.0.5 (November 3, 2016), 4.4.2.4 Attaching Texture Images to a Framebuffer, p.
480// 208
481TEST_P(FramebufferTest_ES3, ColorAttachmentIndexOutOfBounds)
482{
483 GLFramebuffer framebuffer;
484 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
485
486 GLint maxColorAttachments = 0;
487 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
488 GLenum attachment = static_cast<GLenum>(maxColorAttachments + GL_COLOR_ATTACHMENT0);
489
490 GLTexture texture;
491 glBindTexture(GL_TEXTURE_2D, texture.get());
492 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, 1, 1);
493 glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture.get(), 0);
494 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
495}
496
Jamie Madilla0016b72017-07-14 14:30:46 -0400497// Check that depth-only attachments report the correct number of samples.
498TEST_P(FramebufferTest_ES3, MultisampleDepthOnly)
499{
500 GLRenderbuffer renderbuffer;
501 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
502 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 32, 32);
503
504 GLFramebuffer framebuffer;
505 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
506 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
507 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
508 EXPECT_GL_NO_ERROR();
509
510 GLint samples = 0;
511 glGetIntegerv(GL_SAMPLES, &samples);
512 EXPECT_GL_NO_ERROR();
513 EXPECT_GE(samples, 2);
514}
515
Jeff Gilbert8f8edd62017-10-31 14:26:30 -0700516// Check that we only compare width and height of attachments, not depth.
517TEST_P(FramebufferTest_ES3, AttachmentWith3DLayers)
518{
519 GLTexture texA;
520 glBindTexture(GL_TEXTURE_2D, texA);
521 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
522
523 GLTexture texB;
524 glBindTexture(GL_TEXTURE_3D, texB);
525 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
526
527 GLFramebuffer framebuffer;
528 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
529 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0);
530 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, texB, 0, 0);
531 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
532 EXPECT_GL_NO_ERROR();
533}
534
Olli Etuahodbce1f82018-09-19 15:32:17 +0300535// Test that clearing the stencil buffer when the framebuffer only has a color attachment does not
536// crash.
537TEST_P(FramebufferTest_ES3, ClearNonexistentStencil)
538{
539 GLRenderbuffer rbo;
540 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
541 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
542
543 GLFramebuffer fbo;
544 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
545 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
546
547 GLint clearValue = 0;
548 glClearBufferiv(GL_STENCIL, 0, &clearValue);
549
550 // There's no error specified for clearing nonexistent buffers, it's simply a no-op.
551 EXPECT_GL_NO_ERROR();
552}
553
554// Test that clearing the depth buffer when the framebuffer only has a color attachment does not
555// crash.
556TEST_P(FramebufferTest_ES3, ClearNonexistentDepth)
557{
558 GLRenderbuffer rbo;
559 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
560 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
561
562 GLFramebuffer fbo;
563 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
564 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
565
566 GLfloat clearValue = 0.0f;
567 glClearBufferfv(GL_DEPTH, 0, &clearValue);
568
569 // There's no error specified for clearing nonexistent buffers, it's simply a no-op.
570 EXPECT_GL_NO_ERROR();
571}
572
573// Test that clearing a nonexistent color attachment does not crash.
574TEST_P(FramebufferTest_ES3, ClearNonexistentColor)
575{
576 GLRenderbuffer rbo;
577 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
578 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
579
580 GLFramebuffer fbo;
581 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
582 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
583
584 std::vector<GLfloat> clearValue = {{0.0f, 1.0f, 0.0f, 1.0f}};
585 glClearBufferfv(GL_COLOR, 1, clearValue.data());
586
587 // There's no error specified for clearing nonexistent buffers, it's simply a no-op.
588 EXPECT_GL_NO_ERROR();
589}
590
591// Test that clearing the depth and stencil buffers when the framebuffer only has a color attachment
592// does not crash.
593TEST_P(FramebufferTest_ES3, ClearNonexistentDepthStencil)
594{
595 GLRenderbuffer rbo;
596 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
597 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
598
599 GLFramebuffer fbo;
600 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
601 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
602
603 glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.0f, 0);
604
605 // There's no error specified for clearing nonexistent buffers, it's simply a no-op.
606 EXPECT_GL_NO_ERROR();
607}
608
Olli Etuaho4ebd8f32018-09-20 11:12:46 +0300609// Test that clearing a color attachment that has been deleted doesn't crash.
610TEST_P(FramebufferTest_ES3, ClearDeletedAttachment)
611{
612 // An INVALID_FRAMEBUFFER_OPERATION error was seen in this test on Mac, not sure where it might
613 // be originating from. http://anglebug.com/2834
614 ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL());
615
616 GLFramebuffer fbo;
617 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
618
619 // There used to be a bug where some draw buffer state used to remain set even after the
620 // attachment was detached via deletion. That's why we create, attach and delete this RBO here.
621 GLuint rbo = 0u;
622 glGenRenderbuffers(1, &rbo);
623 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
624 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
625 glDeleteRenderbuffers(1, &rbo);
626
627 // There needs to be at least one color attachment to prevent early out from the clear calls.
628 GLRenderbuffer rbo2;
629 glBindRenderbuffer(GL_RENDERBUFFER, rbo2);
630 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
631 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rbo2);
632
633 ASSERT_GL_NO_ERROR();
634
635 // There's no error specified for clearing nonexistent buffers, it's simply a no-op, so we
636 // expect no GL errors below.
637 std::array<GLfloat, 4> floatClearValue = {0.0f, 0.0f, 0.0f, 0.0f};
638 glClearBufferfv(GL_COLOR, 0, floatClearValue.data());
639 EXPECT_GL_NO_ERROR();
640 std::array<GLuint, 4> uintClearValue = {0u, 0u, 0u, 0u};
641 glClearBufferuiv(GL_COLOR, 0, uintClearValue.data());
642 EXPECT_GL_NO_ERROR();
643 std::array<GLint, 4> intClearValue = {0, 0, 0, 0};
644 glClearBufferiv(GL_COLOR, 0, intClearValue.data());
645 EXPECT_GL_NO_ERROR();
646}
647
Corentin Wallez57e6d502016-12-09 14:46:39 -0500648ANGLE_INSTANTIATE_TEST(FramebufferTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
JiangYizhou461d9a32017-01-04 16:37:26 +0800649
650class FramebufferTest_ES31 : public ANGLETest
651{
JiangYizhou511937d2017-08-03 15:41:29 +0800652 protected:
653 void validateSamplePass(GLuint &query, GLuint &passedCount, GLint width, GLint height)
654 {
655 glUniform2i(0, width - 1, height - 1);
656 glBeginQuery(GL_ANY_SAMPLES_PASSED, query);
657 glDrawArrays(GL_TRIANGLES, 0, 6);
658 glEndQuery(GL_ANY_SAMPLES_PASSED);
659 glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount);
660 EXPECT_GT(static_cast<GLint>(passedCount), 0);
661
662 glUniform2i(0, width - 1, height);
663 glBeginQuery(GL_ANY_SAMPLES_PASSED, query);
664 glDrawArrays(GL_TRIANGLES, 0, 6);
665 glEndQuery(GL_ANY_SAMPLES_PASSED);
666 glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount);
667 EXPECT_EQ(static_cast<GLint>(passedCount), 0);
668
669 glUniform2i(0, width, height - 1);
670 glBeginQuery(GL_ANY_SAMPLES_PASSED, query);
671 glDrawArrays(GL_TRIANGLES, 0, 6);
672 glEndQuery(GL_ANY_SAMPLES_PASSED);
673 glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount);
674 EXPECT_EQ(static_cast<GLint>(passedCount), 0);
675 }
JiangYizhou461d9a32017-01-04 16:37:26 +0800676};
677
678// Test that without attachment, if either the value of FRAMEBUFFER_DEFAULT_WIDTH or
679// FRAMEBUFFER_DEFAULT_HEIGHT parameters is zero, the framebuffer is incomplete.
680TEST_P(FramebufferTest_ES31, IncompleteMissingAttachmentDefaultParam)
681{
682 GLFramebuffer mFramebuffer;
683 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
684
685 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1);
686 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1);
687 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
688
689 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0);
690 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0);
691 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
692 glCheckFramebufferStatus(GL_FRAMEBUFFER));
693
694 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1);
695 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0);
696 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
697 glCheckFramebufferStatus(GL_FRAMEBUFFER));
698
699 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0);
700 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1);
701 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
702 glCheckFramebufferStatus(GL_FRAMEBUFFER));
703
704 ASSERT_GL_NO_ERROR();
705}
706
707// Test that the sample count of a mix of texture and renderbuffer should be same.
708TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountMix)
709{
710 GLFramebuffer mFramebuffer;
711 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
712
713 GLTexture mTexture;
714 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get());
715 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, true);
716
717 GLRenderbuffer mRenderbuffer;
718 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get());
719 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_RGBA8, 1, 1);
720 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE,
721 mTexture.get(), 0);
722 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER,
723 mRenderbuffer.get());
724 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
725 glCheckFramebufferStatus(GL_FRAMEBUFFER));
726
727 ASSERT_GL_NO_ERROR();
728}
729
730// Test that the sample count of texture attachments should be same.
731TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountTex)
732{
733 GLFramebuffer mFramebuffer;
734 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
735
736 GLTexture mTextures[2];
737 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get());
738 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, true);
739 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get());
740 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 2, GL_RGBA8, 1, 1, true);
741 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE,
742 mTextures[0].get(), 0);
743 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE,
744 mTextures[1].get(), 0);
745 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
746 glCheckFramebufferStatus(GL_FRAMEBUFFER));
747
748 ASSERT_GL_NO_ERROR();
749}
750
751// Test that if the attached images are a mix of renderbuffers and textures, the value of
752// TEXTURE_FIXED_SAMPLE_LOCATIONS must be TRUE for all attached textures.
753TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsMix)
754{
755 GLFramebuffer mFramebuffer;
756 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
757
758 GLTexture mTexture;
759 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get());
760 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false);
761
762 GLRenderbuffer mRenderbuffer;
763 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get());
764 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 1, GL_RGBA8, 1, 1);
765 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE,
766 mTexture.get(), 0);
767 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER,
768 mRenderbuffer.get());
769 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
770 glCheckFramebufferStatus(GL_FRAMEBUFFER));
771
772 ASSERT_GL_NO_ERROR();
773}
774
775// Test that the value of TEXTURE_FIXED_SAMPLE_LOCATIONS is the same for all attached textures.
776TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsTex)
777{
778 GLFramebuffer mFramebuffer;
779 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
780
781 GLTexture mTextures[2];
782 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get());
783 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false);
784 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE,
785 mTextures[0].get(), 0);
786 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get());
787 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGB8, 1, 1, true);
788 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE,
789 mTextures[1].get(), 0);
790 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
791 glCheckFramebufferStatus(GL_FRAMEBUFFER));
792
793 ASSERT_GL_NO_ERROR();
794}
795
JiangYizhou511937d2017-08-03 15:41:29 +0800796// If there are no attachments, rendering will be limited to a rectangle having a lower left of
797// (0, 0) and an upper right of(width, height), where width and height are the framebuffer
798// object's default width and height.
JiangYizhou3db40722017-08-28 17:59:13 +0800799TEST_P(FramebufferTest_ES31, RenderingLimitToDefaultFBOSizeWithNoAttachments)
JiangYizhou511937d2017-08-03 15:41:29 +0800800{
Yuly Novikov98f9f532017-11-15 19:16:19 -0500801 // anglebug.com/2253
802 ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL());
803
Jamie Madill35cd7332018-12-02 12:03:33 -0500804 constexpr char kVS1[] = R"(#version 310 es
805in layout(location = 0) highp vec2 a_position;
806void main()
807{
808 gl_Position = vec4(a_position, 0.0, 1.0);
809})";
JiangYizhou511937d2017-08-03 15:41:29 +0800810
Jamie Madill35cd7332018-12-02 12:03:33 -0500811 constexpr char kFS1[] = R"(#version 310 es
812uniform layout(location = 0) highp ivec2 u_expectedSize;
813out layout(location = 5) mediump vec4 f_color;
814void main()
815{
816 if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard;
817 f_color = vec4(1.0, 0.5, 0.25, 1.0);
818})";
JiangYizhou511937d2017-08-03 15:41:29 +0800819
Jamie Madill35cd7332018-12-02 12:03:33 -0500820 constexpr char kVS2[] = R"(#version 310 es
821in layout(location = 0) highp vec2 a_position;
822void main()
823{
824 gl_Position = vec4(a_position, 0.0, 1.0);
825})";
JiangYizhou10d41392017-12-18 18:13:36 +0800826
Jamie Madill35cd7332018-12-02 12:03:33 -0500827 constexpr char kFS2[] = R"(#version 310 es
828uniform layout(location = 0) highp ivec2 u_expectedSize;
829out layout(location = 2) mediump vec4 f_color;
830void main()
831{
832 if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard;
833 f_color = vec4(1.0, 0.5, 0.25, 1.0);
834})";
JiangYizhou10d41392017-12-18 18:13:36 +0800835
Jamie Madill35cd7332018-12-02 12:03:33 -0500836 GLuint program1 = CompileProgram(kVS1, kFS1);
JiangYizhou10d41392017-12-18 18:13:36 +0800837 ASSERT_NE(program1, 0u);
838
Jamie Madill35cd7332018-12-02 12:03:33 -0500839 GLuint program2 = CompileProgram(kVS2, kFS2);
JiangYizhou10d41392017-12-18 18:13:36 +0800840 ASSERT_NE(program2, 0u);
841
842 glUseProgram(program1);
JiangYizhou511937d2017-08-03 15:41:29 +0800843
844 GLFramebuffer mFramebuffer;
845 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer);
846 GLuint defaultWidth = 1;
847 GLuint defaultHeight = 1;
848
849 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, defaultWidth);
850 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, defaultHeight);
851 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
852
853 const float data[] = {
854 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f,
855 };
856
857 GLuint vertexArray = 0;
858 GLuint vertexBuffer = 0;
859 GLuint query = 0;
860 GLuint passedCount = 0;
861
862 glGenQueries(1, &query);
863 glGenVertexArrays(1, &vertexArray);
864 glBindVertexArray(vertexArray);
865
866 glGenBuffers(1, &vertexBuffer);
867 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
868 glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
869
870 glEnableVertexAttribArray(0);
871 glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
JiangYizhou38d92b52017-09-13 13:47:52 +0800872 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
JiangYizhou511937d2017-08-03 15:41:29 +0800873
874 validateSamplePass(query, passedCount, defaultWidth, defaultHeight);
875
JiangYizhou10d41392017-12-18 18:13:36 +0800876 glUseProgram(program2);
877 validateSamplePass(query, passedCount, defaultWidth, defaultHeight);
878
879 glUseProgram(program1);
JiangYizhou511937d2017-08-03 15:41:29 +0800880 // If fbo has attachments, the rendering size should be the same as its attachment.
881 GLTexture mTexture;
882 GLuint width = 2;
883 GLuint height = 2;
884 glBindTexture(GL_TEXTURE_2D, mTexture.get());
885 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width, height);
JiangYizhou38d92b52017-09-13 13:47:52 +0800886
887 const GLenum bufs[] = {GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT5};
888
889 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, GL_TEXTURE_2D, mTexture.get(),
JiangYizhou511937d2017-08-03 15:41:29 +0800890 0);
891 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
JiangYizhou38d92b52017-09-13 13:47:52 +0800892 glDrawBuffers(6, bufs);
JiangYizhou511937d2017-08-03 15:41:29 +0800893
894 validateSamplePass(query, passedCount, width, height);
895
896 // If fbo's attachment has been removed, the rendering size should be the same as framebuffer
897 // default size.
JiangYizhou38d92b52017-09-13 13:47:52 +0800898 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, 0, 0, 0);
JiangYizhou511937d2017-08-03 15:41:29 +0800899 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
900
901 validateSamplePass(query, passedCount, defaultWidth, defaultHeight);
902
903 glDisableVertexAttribArray(0);
904 glBindBuffer(GL_ARRAY_BUFFER, 0);
905 glBindVertexArray(0);
906 glDeleteBuffers(1, &vertexBuffer);
907 glDeleteVertexArrays(1, &vertexArray);
908
909 ASSERT_GL_NO_ERROR();
910}
911
912ANGLE_INSTANTIATE_TEST(FramebufferTest_ES31, ES31_D3D11(), ES31_OPENGL(), ES31_OPENGLES());
Brandon Jones9fc87332017-12-13 15:46:52 -0800913
914class AddDummyTextureNoRenderTargetTest : public ANGLETest
915{
916 public:
917 AddDummyTextureNoRenderTargetTest()
918 {
919 setWindowWidth(512);
920 setWindowHeight(512);
921 setConfigRedBits(8);
922 setConfigGreenBits(8);
923 setConfigBlueBits(8);
924 setConfigAlphaBits(8);
925 }
926
927 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) override
928 {
Jonah Ryan-Davis776694c2019-05-08 10:28:55 -0400929 workarounds->forceFeatureEnabled("add_dummy_texture_no_render_target", true);
Brandon Jones9fc87332017-12-13 15:46:52 -0800930 }
931};
932
933// Test to verify workaround succeeds when no program outputs exist http://anglebug.com/2283
934TEST_P(AddDummyTextureNoRenderTargetTest, NoProgramOutputWorkaround)
935{
Jamie Madill35cd7332018-12-02 12:03:33 -0500936 constexpr char kVS[] = "void main() {}";
937 constexpr char kFS[] = "void main() {}";
Brandon Jones9fc87332017-12-13 15:46:52 -0800938
Jamie Madill35cd7332018-12-02 12:03:33 -0500939 ANGLE_GL_PROGRAM(drawProgram, kVS, kFS);
Brandon Jones9fc87332017-12-13 15:46:52 -0800940
941 glUseProgram(drawProgram);
942
943 glDrawArrays(GL_TRIANGLES, 0, 6);
944
945 ASSERT_GL_NO_ERROR();
946}
947
948ANGLE_INSTANTIATE_TEST(AddDummyTextureNoRenderTargetTest, ES2_D3D11());