blob: b4d124c4ee1879eb61ef063a113698eee77084d7 [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 {
Geoff Langc4222072015-05-25 13:19:48 -0400100 // TODO(geofflang): Figure out why this is broken on Intel OpenGL
Jamie Madill518b9fa2016-03-02 11:26:02 -0500101 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Langc4222072015-05-25 13:19:48 -0400102 {
103 std::cout << "Test skipped on Intel OpenGL." << std::endl;
104 return;
105 }
106
Martin Radev1be913c2016-07-11 17:59:16 +0300107 int clientVersion = getClientMajorVersion();
Jamie Madillfa05f602015-05-07 13:47:11 -0400108 if (clientVersion < minESVersion)
Corentin Walleze0902642014-11-04 12:32:15 -0800109 {
110 return;
111 }
112
113 // Check that multisample is supported with at least two samples (minimum required is 1)
114 bool supports2Samples = false;
115
Jamie Madillfa05f602015-05-07 13:47:11 -0400116 if (clientVersion == 2)
Corentin Walleze0902642014-11-04 12:32:15 -0800117 {
118 if (extensionEnabled("ANGLE_framebuffer_multisample"))
119 {
120 int maxSamples;
121 glGetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSamples);
122 supports2Samples = maxSamples >= 2;
123 }
124 }
125 else
126 {
Jamie Madillfa05f602015-05-07 13:47:11 -0400127 assert(clientVersion >= 3);
Corentin Walleze0902642014-11-04 12:32:15 -0800128 int maxSamples;
129 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
130 supports2Samples = maxSamples >= 2;
131 }
132
133 if (!supports2Samples)
134 {
135 return;
136 }
137
Jamie Madill3215b202015-12-15 16:41:39 -0500138 glGenRenderbuffers(1, &mRenderbuffer);
139 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
Corentin Walleze0902642014-11-04 12:32:15 -0800140
141 EXPECT_GL_NO_ERROR();
142 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 2, internalFormat, 128, 128);
143 EXPECT_GL_NO_ERROR();
Jamie Madill3215b202015-12-15 16:41:39 -0500144 glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachmentType, GL_RENDERBUFFER, mRenderbuffer);
Corentin Walleze0902642014-11-04 12:32:15 -0800145 EXPECT_GL_NO_ERROR();
Corentin Walleze0902642014-11-04 12:32:15 -0800146 }
147
Olli Etuahobc21e182016-02-23 16:04:57 +0200148 void testZeroHeightRenderbuffer()
149 {
150 glGenRenderbuffers(1, &mRenderbuffer);
151 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
152 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 0);
153 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
154 mRenderbuffer);
155 EXPECT_GL_NO_ERROR();
156 }
157
Jamie Madill3215b202015-12-15 16:41:39 -0500158 void SetUp() override
Geoff Langb6a673a2014-06-05 14:19:16 -0400159 {
160 ANGLETest::SetUp();
Jamie Madill3215b202015-12-15 16:41:39 -0500161
162 glGenFramebuffers(1, &mFramebuffer);
163 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
Geoff Langb6a673a2014-06-05 14:19:16 -0400164 }
165
Jamie Madill3215b202015-12-15 16:41:39 -0500166 void TearDown() override
Geoff Langb6a673a2014-06-05 14:19:16 -0400167 {
168 ANGLETest::TearDown();
Jamie Madill3215b202015-12-15 16:41:39 -0500169
170 if (mTexture != 0)
171 {
172 glDeleteTextures(1, &mTexture);
173 mTexture = 0;
174 }
175
176 if (mRenderbuffer != 0)
177 {
178 glDeleteRenderbuffers(1, &mRenderbuffer);
179 mRenderbuffer = 0;
180 }
181
182 if (mFramebuffer != 0)
183 {
184 glDeleteFramebuffers(1, &mFramebuffer);
185 mFramebuffer = 0;
186 }
187
188 if (mProgram != 0)
189 {
190 glDeleteProgram(mProgram);
191 mProgram = 0;
192 }
Geoff Langb6a673a2014-06-05 14:19:16 -0400193 }
Jamie Madill3215b202015-12-15 16:41:39 -0500194
195 GLuint mFramebuffer;
196 GLuint mTexture;
197 GLuint mRenderbuffer;
198 GLuint mProgram;
Geoff Langb6a673a2014-06-05 14:19:16 -0400199};
200
Jamie Madillfa05f602015-05-07 13:47:11 -0400201TEST_P(FramebufferFormatsTest, RGBA4)
Geoff Langb6a673a2014-06-05 14:19:16 -0400202{
Geoff Langc4e93662017-05-01 10:45:59 -0400203 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))
204 {
205 std::cout << "Test skipped due to missing ES3 or GL_EXT_texture_storage." << std::endl;
206 return;
207 }
208
Geoff Langb6a673a2014-06-05 14:19:16 -0400209 testTextureFormat(GL_RGBA4, 4, 4, 4, 4);
210}
211
Jamie Madillfa05f602015-05-07 13:47:11 -0400212TEST_P(FramebufferFormatsTest, RGB565)
Geoff Langb6a673a2014-06-05 14:19:16 -0400213{
Geoff Langc4e93662017-05-01 10:45:59 -0400214 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))
215 {
216 std::cout << "Test skipped due to missing ES3 or GL_EXT_texture_storage." << std::endl;
217 return;
218 }
219
Geoff Langb6a673a2014-06-05 14:19:16 -0400220 testTextureFormat(GL_RGB565, 5, 6, 5, 0);
221}
222
Jamie Madillfa05f602015-05-07 13:47:11 -0400223TEST_P(FramebufferFormatsTest, RGB8)
Geoff Langb6a673a2014-06-05 14:19:16 -0400224{
Geoff Langc4e93662017-05-01 10:45:59 -0400225 if (getClientMajorVersion() < 3 &&
226 (!extensionEnabled("GL_OES_rgb8_rgba8") || !extensionEnabled("GL_EXT_texture_storage")))
Geoff Langf34d1db2015-05-20 14:10:46 -0400227 {
Geoff Langc4e93662017-05-01 10:45:59 -0400228 std::cout
229 << "Test skipped due to missing ES3 or GL_OES_rgb8_rgba8 and GL_EXT_texture_storage."
230 << std::endl;
Geoff Langf34d1db2015-05-20 14:10:46 -0400231 return;
232 }
233
Geoff Langb6a673a2014-06-05 14:19:16 -0400234 testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0);
235}
236
Jamie Madillfa05f602015-05-07 13:47:11 -0400237TEST_P(FramebufferFormatsTest, BGRA8)
Geoff Langb6a673a2014-06-05 14:19:16 -0400238{
Geoff Langc4e93662017-05-01 10:45:59 -0400239 if (!extensionEnabled("GL_EXT_texture_format_BGRA8888") ||
240 (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage")))
Geoff Langf34d1db2015-05-20 14:10:46 -0400241 {
Geoff Langc4e93662017-05-01 10:45:59 -0400242 std::cout << "Test skipped due to missing GL_EXT_texture_format_BGRA8888 or "
243 "GL_EXT_texture_storage."
244 << std::endl;
Geoff Langf34d1db2015-05-20 14:10:46 -0400245 return;
246 }
247
Geoff Langb6a673a2014-06-05 14:19:16 -0400248 testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8);
249}
250
Jamie Madillfa05f602015-05-07 13:47:11 -0400251TEST_P(FramebufferFormatsTest, RGBA8)
Geoff Langb6a673a2014-06-05 14:19:16 -0400252{
Geoff Langc4e93662017-05-01 10:45:59 -0400253 if (getClientMajorVersion() < 3 &&
254 (!extensionEnabled("GL_OES_rgb8_rgba8") || !extensionEnabled("GL_EXT_texture_storage")))
Geoff Langf34d1db2015-05-20 14:10:46 -0400255 {
Geoff Langc4e93662017-05-01 10:45:59 -0400256 std::cout
257 << "Test skipped due to missing ES3 or GL_OES_rgb8_rgba8 and GL_EXT_texture_storage."
258 << std::endl;
Geoff Langf34d1db2015-05-20 14:10:46 -0400259 return;
260 }
261
Geoff Langb6a673a2014-06-05 14:19:16 -0400262 testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8);
263}
264
Jamie Madillfa05f602015-05-07 13:47:11 -0400265TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH16)
Corentin Walleze0902642014-11-04 12:32:15 -0800266{
267 testRenderbufferMultisampleFormat(2, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16);
268}
269
Jamie Madillfa05f602015-05-07 13:47:11 -0400270TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24)
Corentin Walleze0902642014-11-04 12:32:15 -0800271{
272 testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24);
273}
274
Jamie Madillfa05f602015-05-07 13:47:11 -0400275TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F)
Corentin Walleze0902642014-11-04 12:32:15 -0800276{
Martin Radev1be913c2016-07-11 17:59:16 +0300277 if (getClientMajorVersion() < 3)
Geoff Langf34d1db2015-05-20 14:10:46 -0400278 {
279 std::cout << "Test skipped due to missing ES3." << std::endl;
280 return;
281 }
282
Corentin Walleze0902642014-11-04 12:32:15 -0800283 testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32F);
284}
285
Jamie Madillfa05f602015-05-07 13:47:11 -0400286TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24_STENCIL8)
Corentin Walleze0902642014-11-04 12:32:15 -0800287{
288 testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH24_STENCIL8);
289}
290
Jamie Madillfa05f602015-05-07 13:47:11 -0400291TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F_STENCIL8)
Corentin Walleze0902642014-11-04 12:32:15 -0800292{
Martin Radev1be913c2016-07-11 17:59:16 +0300293 if (getClientMajorVersion() < 3)
Geoff Langf34d1db2015-05-20 14:10:46 -0400294 {
295 std::cout << "Test skipped due to missing ES3." << std::endl;
296 return;
297 }
298
Corentin Walleze0902642014-11-04 12:32:15 -0800299 testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH32F_STENCIL8);
300}
301
Jamie Madillfa05f602015-05-07 13:47:11 -0400302TEST_P(FramebufferFormatsTest, RenderbufferMultisample_STENCIL_INDEX8)
Corentin Walleze0902642014-11-04 12:32:15 -0800303{
Geoff Langf34d1db2015-05-20 14:10:46 -0400304 // TODO(geofflang): Figure out how to support GLSTENCIL_INDEX8 on desktop GL
Geoff Langdd323e92015-06-09 15:16:31 -0400305 if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Langf34d1db2015-05-20 14:10:46 -0400306 {
307 std::cout << "Test skipped on Desktop OpenGL." << std::endl;
308 return;
309 }
310
Corentin Walleze0902642014-11-04 12:32:15 -0800311 testRenderbufferMultisampleFormat(2, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8);
312}
Jamie Madillfa05f602015-05-07 13:47:11 -0400313
Jamie Madill3215b202015-12-15 16:41:39 -0500314// Test that binding an incomplete cube map is rejected by ANGLE.
315TEST_P(FramebufferFormatsTest, IncompleteCubeMap)
316{
317 // First make a complete CubeMap.
318 glGenTextures(1, &mTexture);
319 glBindTexture(GL_TEXTURE_CUBE_MAP, mTexture);
320 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
321 nullptr);
322 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
323 nullptr);
324 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
325 nullptr);
326 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
327 nullptr);
328 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
329 nullptr);
330 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
331 nullptr);
332 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
333 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
334
335 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X,
336 mTexture, 0);
337
338 // Verify the framebuffer is complete.
339 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
340
341 // Make the CubeMap cube-incomplete.
342 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
343 nullptr);
344
345 // Verify the framebuffer is incomplete.
346 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
347 glCheckFramebufferStatus(GL_FRAMEBUFFER));
348
349 // Verify drawing with the incomplete framebuffer produces a GL error
350 const std::string &vs = "attribute vec4 position; void main() { gl_Position = position; }";
351 const std::string &ps = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }";
352 mProgram = CompileProgram(vs, ps);
353 ASSERT_NE(0u, mProgram);
354 drawQuad(mProgram, "position", 0.5f);
355 ASSERT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION);
356}
357
Olli Etuahobc21e182016-02-23 16:04:57 +0200358// Test that a renderbuffer with zero height but nonzero width is handled without crashes/asserts.
359TEST_P(FramebufferFormatsTest, ZeroHeightRenderbuffer)
360{
Martin Radev1be913c2016-07-11 17:59:16 +0300361 if (getClientMajorVersion() < 3)
Olli Etuahobc21e182016-02-23 16:04:57 +0200362 {
363 std::cout << "Test skipped due to missing ES3" << std::endl;
364 return;
365 }
366
367 testZeroHeightRenderbuffer();
368}
369
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500370// Use this to select which configurations (e.g. which renderer, which GLES major version) these
371// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -0500372ANGLE_INSTANTIATE_TEST(FramebufferFormatsTest,
373 ES2_D3D9(),
374 ES2_D3D11(),
375 ES3_D3D11(),
376 ES2_OPENGL(),
377 ES3_OPENGL(),
378 ES2_OPENGLES(),
379 ES3_OPENGLES());
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500380
Corentin Wallez57e6d502016-12-09 14:46:39 -0500381class FramebufferTest_ES3 : public ANGLETest
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500382{
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500383};
384
385// Covers invalidating an incomplete framebuffer. This should be a no-op, but should not error.
Corentin Wallez57e6d502016-12-09 14:46:39 -0500386TEST_P(FramebufferTest_ES3, InvalidateIncomplete)
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500387{
Geoff Lang857c09d2017-05-16 15:55:04 -0400388 GLFramebuffer framebuffer;
389 GLRenderbuffer renderbuffer;
390
391 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
392 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
393 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
Jamie Madill1fbc59f2016-02-24 15:25:51 -0500394 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
395 glCheckFramebufferStatus(GL_FRAMEBUFFER));
396
397 std::vector<GLenum> attachments;
398 attachments.push_back(GL_COLOR_ATTACHMENT0);
399
400 glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, attachments.data());
401 EXPECT_GL_NO_ERROR();
402}
403
Corentin Wallez57e6d502016-12-09 14:46:39 -0500404// Test that the framebuffer state tracking robustly handles a depth-only attachment being set
405// as a depth-stencil attachment. It is equivalent to detaching the depth-stencil attachment.
406TEST_P(FramebufferTest_ES3, DepthOnlyAsDepthStencil)
407{
Geoff Lang857c09d2017-05-16 15:55:04 -0400408 GLFramebuffer framebuffer;
409 GLRenderbuffer renderbuffer;
410
411 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
412 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
Corentin Wallez57e6d502016-12-09 14:46:39 -0500413 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 4, 4);
414
415 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
Geoff Lang857c09d2017-05-16 15:55:04 -0400416 renderbuffer);
Corentin Wallez57e6d502016-12-09 14:46:39 -0500417 EXPECT_GLENUM_NE(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
418}
419
Geoff Lang857c09d2017-05-16 15:55:04 -0400420// Test that the framebuffer correctly returns that it is not complete if invalid texture mip levels
421// are bound
422TEST_P(FramebufferTest_ES3, TextureAttachmentMipLevels)
423{
424 GLFramebuffer framebuffer;
425 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
426
427 GLTexture texture;
428 glBindTexture(GL_TEXTURE_2D, texture);
429
430 // Create a complete mip chain in mips 1 to 3
431 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
432 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
433 glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
434
435 // Create another complete mip chain in mips 4 to 5
436 glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
437 glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
438
439 // Create a non-complete mip chain in mip 6
440 glTexImage2D(GL_TEXTURE_2D, 6, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
441
442 // Incomplete, mipLevel != baseLevel and texture is not mip complete
443 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
444 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
445 glCheckFramebufferStatus(GL_FRAMEBUFFER));
446
447 // Complete, mipLevel == baseLevel
448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
449 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
450
451 // Complete, mipLevel != baseLevel but texture is now mip complete
452 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 2);
453 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
454 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 3);
455 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
456
457 // Incomplete, attached level below the base level
458 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
459 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
460 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
461 glCheckFramebufferStatus(GL_FRAMEBUFFER));
462
463 // Incomplete, attached level is beyond effective max level
464 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 4);
465 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
466 glCheckFramebufferStatus(GL_FRAMEBUFFER));
467
468 // Complete, mipLevel == baseLevel
469 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 4);
470 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
471
472 // Complete, mipLevel != baseLevel but texture is now mip complete
473 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 5);
474 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
475
476 // Complete, mipLevel == baseLevel
477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 6);
478 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 6);
479 ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER);
480}
481
Martin Radevd178aa42017-07-13 14:03:22 +0300482// Test that passing an attachment COLOR_ATTACHMENTm where m is equal to MAX_COLOR_ATTACHMENTS
483// generates an INVALID_OPERATION.
484// OpenGL ES Version 3.0.5 (November 3, 2016), 4.4.2.4 Attaching Texture Images to a Framebuffer, p.
485// 208
486TEST_P(FramebufferTest_ES3, ColorAttachmentIndexOutOfBounds)
487{
488 GLFramebuffer framebuffer;
489 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
490
491 GLint maxColorAttachments = 0;
492 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
493 GLenum attachment = static_cast<GLenum>(maxColorAttachments + GL_COLOR_ATTACHMENT0);
494
495 GLTexture texture;
496 glBindTexture(GL_TEXTURE_2D, texture.get());
497 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, 1, 1);
498 glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture.get(), 0);
499 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
500}
501
Jamie Madilla0016b72017-07-14 14:30:46 -0400502// Check that depth-only attachments report the correct number of samples.
503TEST_P(FramebufferTest_ES3, MultisampleDepthOnly)
504{
505 GLRenderbuffer renderbuffer;
506 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
507 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 32, 32);
508
509 GLFramebuffer framebuffer;
510 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
511 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
512 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
513 EXPECT_GL_NO_ERROR();
514
515 GLint samples = 0;
516 glGetIntegerv(GL_SAMPLES, &samples);
517 EXPECT_GL_NO_ERROR();
518 EXPECT_GE(samples, 2);
519}
520
Jeff Gilbert8f8edd62017-10-31 14:26:30 -0700521// Check that we only compare width and height of attachments, not depth.
522TEST_P(FramebufferTest_ES3, AttachmentWith3DLayers)
523{
524 GLTexture texA;
525 glBindTexture(GL_TEXTURE_2D, texA);
526 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
527
528 GLTexture texB;
529 glBindTexture(GL_TEXTURE_3D, texB);
530 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
531
532 GLFramebuffer framebuffer;
533 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
534 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0);
535 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, texB, 0, 0);
536 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
537 EXPECT_GL_NO_ERROR();
538}
539
Corentin Wallez57e6d502016-12-09 14:46:39 -0500540ANGLE_INSTANTIATE_TEST(FramebufferTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
JiangYizhou461d9a32017-01-04 16:37:26 +0800541
542class FramebufferTest_ES31 : public ANGLETest
543{
JiangYizhou511937d2017-08-03 15:41:29 +0800544 protected:
545 void validateSamplePass(GLuint &query, GLuint &passedCount, GLint width, GLint height)
546 {
547 glUniform2i(0, width - 1, height - 1);
548 glBeginQuery(GL_ANY_SAMPLES_PASSED, query);
549 glDrawArrays(GL_TRIANGLES, 0, 6);
550 glEndQuery(GL_ANY_SAMPLES_PASSED);
551 glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount);
552 EXPECT_GT(static_cast<GLint>(passedCount), 0);
553
554 glUniform2i(0, width - 1, height);
555 glBeginQuery(GL_ANY_SAMPLES_PASSED, query);
556 glDrawArrays(GL_TRIANGLES, 0, 6);
557 glEndQuery(GL_ANY_SAMPLES_PASSED);
558 glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount);
559 EXPECT_EQ(static_cast<GLint>(passedCount), 0);
560
561 glUniform2i(0, width, height - 1);
562 glBeginQuery(GL_ANY_SAMPLES_PASSED, query);
563 glDrawArrays(GL_TRIANGLES, 0, 6);
564 glEndQuery(GL_ANY_SAMPLES_PASSED);
565 glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount);
566 EXPECT_EQ(static_cast<GLint>(passedCount), 0);
567 }
JiangYizhou461d9a32017-01-04 16:37:26 +0800568};
569
570// Test that without attachment, if either the value of FRAMEBUFFER_DEFAULT_WIDTH or
571// FRAMEBUFFER_DEFAULT_HEIGHT parameters is zero, the framebuffer is incomplete.
572TEST_P(FramebufferTest_ES31, IncompleteMissingAttachmentDefaultParam)
573{
574 GLFramebuffer mFramebuffer;
575 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
576
577 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1);
578 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1);
579 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
580
581 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0);
582 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0);
583 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
584 glCheckFramebufferStatus(GL_FRAMEBUFFER));
585
586 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1);
587 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0);
588 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
589 glCheckFramebufferStatus(GL_FRAMEBUFFER));
590
591 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0);
592 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1);
593 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
594 glCheckFramebufferStatus(GL_FRAMEBUFFER));
595
596 ASSERT_GL_NO_ERROR();
597}
598
599// Test that the sample count of a mix of texture and renderbuffer should be same.
600TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountMix)
601{
602 GLFramebuffer mFramebuffer;
603 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
604
605 GLTexture mTexture;
606 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get());
607 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, true);
608
609 GLRenderbuffer mRenderbuffer;
610 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get());
611 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_RGBA8, 1, 1);
612 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE,
613 mTexture.get(), 0);
614 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER,
615 mRenderbuffer.get());
616 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
617 glCheckFramebufferStatus(GL_FRAMEBUFFER));
618
619 ASSERT_GL_NO_ERROR();
620}
621
622// Test that the sample count of texture attachments should be same.
623TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountTex)
624{
625 GLFramebuffer mFramebuffer;
626 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
627
628 GLTexture mTextures[2];
629 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get());
630 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, true);
631 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get());
632 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 2, GL_RGBA8, 1, 1, true);
633 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE,
634 mTextures[0].get(), 0);
635 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE,
636 mTextures[1].get(), 0);
637 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
638 glCheckFramebufferStatus(GL_FRAMEBUFFER));
639
640 ASSERT_GL_NO_ERROR();
641}
642
643// Test that if the attached images are a mix of renderbuffers and textures, the value of
644// TEXTURE_FIXED_SAMPLE_LOCATIONS must be TRUE for all attached textures.
645TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsMix)
646{
647 GLFramebuffer mFramebuffer;
648 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
649
650 GLTexture mTexture;
651 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get());
652 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false);
653
654 GLRenderbuffer mRenderbuffer;
655 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get());
656 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 1, GL_RGBA8, 1, 1);
657 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE,
658 mTexture.get(), 0);
659 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER,
660 mRenderbuffer.get());
661 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
662 glCheckFramebufferStatus(GL_FRAMEBUFFER));
663
664 ASSERT_GL_NO_ERROR();
665}
666
667// Test that the value of TEXTURE_FIXED_SAMPLE_LOCATIONS is the same for all attached textures.
668TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsTex)
669{
670 GLFramebuffer mFramebuffer;
671 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get());
672
673 GLTexture mTextures[2];
674 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get());
675 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false);
676 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE,
677 mTextures[0].get(), 0);
678 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get());
679 glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGB8, 1, 1, true);
680 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE,
681 mTextures[1].get(), 0);
682 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
683 glCheckFramebufferStatus(GL_FRAMEBUFFER));
684
685 ASSERT_GL_NO_ERROR();
686}
687
JiangYizhou511937d2017-08-03 15:41:29 +0800688// If there are no attachments, rendering will be limited to a rectangle having a lower left of
689// (0, 0) and an upper right of(width, height), where width and height are the framebuffer
690// object's default width and height.
JiangYizhou3db40722017-08-28 17:59:13 +0800691TEST_P(FramebufferTest_ES31, RenderingLimitToDefaultFBOSizeWithNoAttachments)
JiangYizhou511937d2017-08-03 15:41:29 +0800692{
Yuly Novikov98f9f532017-11-15 19:16:19 -0500693 // anglebug.com/2253
694 ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL());
695
JiangYizhou511937d2017-08-03 15:41:29 +0800696 const std::string &vertexShader =
697 "#version 310 es\n"
698 "in layout(location = 0) highp vec2 a_position;\n\n"
699 "void main()\n"
700 "{\n"
Jeff Gilbert8f8edd62017-10-31 14:26:30 -0700701 " gl_Position = vec4(a_position, 0.0, 1.0);\n"
JiangYizhou511937d2017-08-03 15:41:29 +0800702 "}\n";
703 const std::string &fragShader =
704 "#version 310 es\n"
705 "uniform layout(location = 0) highp ivec2 u_expectedSize;\n"
JiangYizhou38d92b52017-09-13 13:47:52 +0800706 "out layout(location = 5) mediump vec4 f_color;\n\n"
JiangYizhou511937d2017-08-03 15:41:29 +0800707 "void main()\n"
708 "{\n"
Jeff Gilbert8f8edd62017-10-31 14:26:30 -0700709 " if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard;\n"
710 " f_color = vec4(1.0, 0.5, 0.25, 1.0);\n"
JiangYizhou511937d2017-08-03 15:41:29 +0800711 "}\n";
712
713 GLuint program = CompileProgram(vertexShader, fragShader);
714 ASSERT_NE(program, 0u);
715
716 glUseProgram(program);
717
718 GLFramebuffer mFramebuffer;
719 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer);
720 GLuint defaultWidth = 1;
721 GLuint defaultHeight = 1;
722
723 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, defaultWidth);
724 glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, defaultHeight);
725 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
726
727 const float data[] = {
728 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f,
729 };
730
731 GLuint vertexArray = 0;
732 GLuint vertexBuffer = 0;
733 GLuint query = 0;
734 GLuint passedCount = 0;
735
736 glGenQueries(1, &query);
737 glGenVertexArrays(1, &vertexArray);
738 glBindVertexArray(vertexArray);
739
740 glGenBuffers(1, &vertexBuffer);
741 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
742 glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
743
744 glEnableVertexAttribArray(0);
745 glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
JiangYizhou38d92b52017-09-13 13:47:52 +0800746 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
JiangYizhou511937d2017-08-03 15:41:29 +0800747
748 validateSamplePass(query, passedCount, defaultWidth, defaultHeight);
749
750 // If fbo has attachments, the rendering size should be the same as its attachment.
751 GLTexture mTexture;
752 GLuint width = 2;
753 GLuint height = 2;
754 glBindTexture(GL_TEXTURE_2D, mTexture.get());
755 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width, height);
JiangYizhou38d92b52017-09-13 13:47:52 +0800756
757 const GLenum bufs[] = {GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT5};
758
759 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, GL_TEXTURE_2D, mTexture.get(),
JiangYizhou511937d2017-08-03 15:41:29 +0800760 0);
761 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
JiangYizhou38d92b52017-09-13 13:47:52 +0800762 glDrawBuffers(6, bufs);
JiangYizhou511937d2017-08-03 15:41:29 +0800763
764 validateSamplePass(query, passedCount, width, height);
765
766 // If fbo's attachment has been removed, the rendering size should be the same as framebuffer
767 // default size.
JiangYizhou38d92b52017-09-13 13:47:52 +0800768 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, 0, 0, 0);
JiangYizhou511937d2017-08-03 15:41:29 +0800769 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
770
771 validateSamplePass(query, passedCount, defaultWidth, defaultHeight);
772
773 glDisableVertexAttribArray(0);
774 glBindBuffer(GL_ARRAY_BUFFER, 0);
775 glBindVertexArray(0);
776 glDeleteBuffers(1, &vertexBuffer);
777 glDeleteVertexArrays(1, &vertexArray);
778
779 ASSERT_GL_NO_ERROR();
780}
781
782ANGLE_INSTANTIATE_TEST(FramebufferTest_ES31, ES31_D3D11(), ES31_OPENGL(), ES31_OPENGLES());
Brandon Jones9fc87332017-12-13 15:46:52 -0800783
784class AddDummyTextureNoRenderTargetTest : public ANGLETest
785{
786 public:
787 AddDummyTextureNoRenderTargetTest()
788 {
789 setWindowWidth(512);
790 setWindowHeight(512);
791 setConfigRedBits(8);
792 setConfigGreenBits(8);
793 setConfigBlueBits(8);
794 setConfigAlphaBits(8);
795 }
796
797 void overrideWorkaroundsD3D(WorkaroundsD3D *workarounds) override
798 {
799 workarounds->addDummyTextureNoRenderTarget = true;
800 }
801};
802
803// Test to verify workaround succeeds when no program outputs exist http://anglebug.com/2283
804TEST_P(AddDummyTextureNoRenderTargetTest, NoProgramOutputWorkaround)
805{
806 const std::string &vShader = "void main() {}";
807 const std::string &fShader = "void main() {}";
808
809 ANGLE_GL_PROGRAM(drawProgram, vShader, fShader);
810
811 glUseProgram(drawProgram);
812
813 glDrawArrays(GL_TRIANGLES, 0, 6);
814
815 ASSERT_GL_NO_ERROR();
816}
817
818ANGLE_INSTANTIATE_TEST(AddDummyTextureNoRenderTargetTest, ES2_D3D11());