Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1 | // |
| 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 Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 6 | // Framebuffer tests: |
| 7 | // Various tests related for Frambuffers. |
| 8 | // |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | |
Jonah Ryan-Davis | beb0eb2 | 2019-06-14 15:10:33 -0400 | [diff] [blame] | 10 | #include "platform/FeaturesD3D.h" |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 11 | #include "test_utils/ANGLETest.h" |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 12 | #include "test_utils/gl_raii.h" |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 13 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 14 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 15 | |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 16 | namespace |
| 17 | { |
| 18 | |
| 19 | void 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 Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 27 | class FramebufferFormatsTest : public ANGLETest |
| 28 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 29 | protected: |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 30 | FramebufferFormatsTest() : mFramebuffer(0), mTexture(0), mRenderbuffer(0), mProgram(0) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 31 | { |
| 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 Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 57 | void testBitCounts(GLuint fbo, |
| 58 | GLint minRedBits, |
| 59 | GLint minGreenBits, |
| 60 | GLint minBlueBits, |
| 61 | GLint minAlphaBits, |
| 62 | GLint minDepthBits, |
| 63 | GLint minStencilBits) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 64 | { |
| 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 Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 73 | void testTextureFormat(GLenum internalFormat, |
| 74 | GLint minRedBits, |
| 75 | GLint minGreenBits, |
| 76 | GLint minBlueBits, |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 77 | GLint minAlphaBits) |
| 78 | { |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 79 | glGenTextures(1, &mTexture); |
| 80 | glBindTexture(GL_TEXTURE_2D, mTexture); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 81 | |
| 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 Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 90 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 91 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 92 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 93 | testBitCounts(mFramebuffer, minRedBits, minGreenBits, minBlueBits, minAlphaBits, 0, 0); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 96 | void testRenderbufferMultisampleFormat(int minESVersion, |
| 97 | GLenum attachmentType, |
| 98 | GLenum internalFormat) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 99 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 100 | int clientVersion = getClientMajorVersion(); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 101 | if (clientVersion < minESVersion) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 102 | { |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 109 | if (clientVersion == 2) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 110 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 111 | if (IsGLExtensionEnabled("ANGLE_framebuffer_multisample")) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 112 | { |
| 113 | int maxSamples; |
| 114 | glGetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSamples); |
| 115 | supports2Samples = maxSamples >= 2; |
| 116 | } |
| 117 | } |
| 118 | else |
| 119 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 120 | assert(clientVersion >= 3); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 121 | int maxSamples; |
| 122 | glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); |
| 123 | supports2Samples = maxSamples >= 2; |
| 124 | } |
| 125 | |
| 126 | if (!supports2Samples) |
| 127 | { |
| 128 | return; |
| 129 | } |
| 130 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 131 | glGenRenderbuffers(1, &mRenderbuffer); |
| 132 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 133 | |
| 134 | EXPECT_GL_NO_ERROR(); |
| 135 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 2, internalFormat, 128, 128); |
| 136 | EXPECT_GL_NO_ERROR(); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 137 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachmentType, GL_RENDERBUFFER, mRenderbuffer); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 138 | EXPECT_GL_NO_ERROR(); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 141 | 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 Madill | 5cbaa3f | 2019-05-07 15:49:22 -0400 | [diff] [blame] | 151 | void testSetUp() override |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 152 | { |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 153 | glGenFramebuffers(1, &mFramebuffer); |
| 154 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Jamie Madill | 5cbaa3f | 2019-05-07 15:49:22 -0400 | [diff] [blame] | 157 | void testTearDown() override |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 158 | { |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 159 | 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 Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 182 | } |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 183 | |
| 184 | GLuint mFramebuffer; |
| 185 | GLuint mTexture; |
| 186 | GLuint mRenderbuffer; |
| 187 | GLuint mProgram; |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 188 | }; |
| 189 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 190 | TEST_P(FramebufferFormatsTest, RGBA4) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 191 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 192 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && |
| 193 | !IsGLExtensionEnabled("GL_EXT_texture_storage")); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 194 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 195 | testTextureFormat(GL_RGBA4, 4, 4, 4, 4); |
| 196 | } |
| 197 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 198 | TEST_P(FramebufferFormatsTest, RGB565) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 199 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 200 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && |
| 201 | !IsGLExtensionEnabled("GL_EXT_texture_storage")); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 202 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 203 | testTextureFormat(GL_RGB565, 5, 6, 5, 0); |
| 204 | } |
| 205 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 206 | TEST_P(FramebufferFormatsTest, RGB8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 207 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 208 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && |
| 209 | (!IsGLExtensionEnabled("GL_OES_rgb8_rgba8") || |
| 210 | !IsGLExtensionEnabled("GL_EXT_texture_storage"))); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 211 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 212 | testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0); |
| 213 | } |
| 214 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 215 | TEST_P(FramebufferFormatsTest, BGRA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 216 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 217 | ANGLE_SKIP_TEST_IF( |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 218 | !IsGLExtensionEnabled("GL_EXT_texture_format_BGRA8888") || |
| 219 | (getClientMajorVersion() < 3 && !IsGLExtensionEnabled("GL_EXT_texture_storage"))); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 220 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 221 | testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8); |
| 222 | } |
| 223 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 224 | TEST_P(FramebufferFormatsTest, RGBA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 225 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 226 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && |
| 227 | (!IsGLExtensionEnabled("GL_OES_rgb8_rgba8") || |
| 228 | !IsGLExtensionEnabled("GL_EXT_texture_storage"))); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 229 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 230 | testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8); |
| 231 | } |
| 232 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 233 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH16) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 234 | { |
| 235 | testRenderbufferMultisampleFormat(2, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16); |
| 236 | } |
| 237 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 238 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 239 | { |
| 240 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24); |
| 241 | } |
| 242 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 243 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 244 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 245 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 246 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 247 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32F); |
| 248 | } |
| 249 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 250 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24_STENCIL8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 251 | { |
| 252 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH24_STENCIL8); |
| 253 | } |
| 254 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 255 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F_STENCIL8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 256 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 257 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 258 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 259 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH32F_STENCIL8); |
| 260 | } |
| 261 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 262 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_STENCIL_INDEX8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 263 | { |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 264 | // TODO(geofflang): Figure out how to support GLSTENCIL_INDEX8 on desktop GL |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 265 | ANGLE_SKIP_TEST_IF(IsDesktopOpenGL()); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 266 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 267 | testRenderbufferMultisampleFormat(2, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8); |
| 268 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 269 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 270 | // Test that binding an incomplete cube map is rejected by ANGLE. |
| 271 | TEST_P(FramebufferFormatsTest, IncompleteCubeMap) |
| 272 | { |
Michael Spang | d8506c7 | 2019-01-29 15:35:09 -0500 | [diff] [blame] | 273 | // http://anglebug.com/3145 |
| 274 | ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan()); |
| 275 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 276 | // 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 Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 308 | ASSERT_GL_NO_ERROR(); |
| 309 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 310 | // Verify drawing with the incomplete framebuffer produces a GL error |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 311 | mProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Red()); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 312 | ASSERT_NE(0u, mProgram); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 313 | drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 314 | ASSERT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 315 | } |
| 316 | |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 317 | // Test that a renderbuffer with zero height but nonzero width is handled without crashes/asserts. |
| 318 | TEST_P(FramebufferFormatsTest, ZeroHeightRenderbuffer) |
| 319 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 320 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3); |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 321 | |
| 322 | testZeroHeightRenderbuffer(); |
| 323 | } |
| 324 | |
Geoff Lang | 9bf86f0 | 2018-07-26 11:46:34 -0400 | [diff] [blame] | 325 | // Test to cover a bug where the read framebuffer affects the completeness of the draw framebuffer. |
| 326 | TEST_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 Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 365 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 366 | // tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 367 | ANGLE_INSTANTIATE_TEST(FramebufferFormatsTest, |
Luc Ferron | fa7503c | 2018-05-08 11:25:06 -0400 | [diff] [blame] | 368 | ES2_VULKAN(), |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame^] | 369 | ES3_VULKAN(), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 370 | ES2_D3D9(), |
| 371 | ES2_D3D11(), |
| 372 | ES3_D3D11(), |
| 373 | ES2_OPENGL(), |
| 374 | ES3_OPENGL(), |
| 375 | ES2_OPENGLES(), |
| 376 | ES3_OPENGLES()); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 377 | |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 378 | class FramebufferTest_ES3 : public ANGLETest |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 379 | {}; |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 380 | |
| 381 | // Covers invalidating an incomplete framebuffer. This should be a no-op, but should not error. |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 382 | TEST_P(FramebufferTest_ES3, InvalidateIncomplete) |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 383 | { |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame^] | 384 | // TODO: anglebug.com/3971 |
| 385 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 386 | |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 387 | GLFramebuffer framebuffer; |
| 388 | GLRenderbuffer renderbuffer; |
| 389 | |
| 390 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 391 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
| 392 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 393 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 394 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 395 | |
| 396 | std::vector<GLenum> attachments; |
| 397 | attachments.push_back(GL_COLOR_ATTACHMENT0); |
| 398 | |
| 399 | glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, attachments.data()); |
| 400 | EXPECT_GL_NO_ERROR(); |
| 401 | } |
| 402 | |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 403 | // Test that the framebuffer state tracking robustly handles a depth-only attachment being set |
| 404 | // as a depth-stencil attachment. It is equivalent to detaching the depth-stencil attachment. |
| 405 | TEST_P(FramebufferTest_ES3, DepthOnlyAsDepthStencil) |
| 406 | { |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 407 | GLFramebuffer framebuffer; |
| 408 | GLRenderbuffer renderbuffer; |
| 409 | |
| 410 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 411 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 412 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 4, 4); |
| 413 | |
| 414 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 415 | renderbuffer); |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 416 | EXPECT_GLENUM_NE(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 417 | } |
| 418 | |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 419 | // Test that the framebuffer correctly returns that it is not complete if invalid texture mip levels |
| 420 | // are bound |
| 421 | TEST_P(FramebufferTest_ES3, TextureAttachmentMipLevels) |
| 422 | { |
| 423 | GLFramebuffer framebuffer; |
| 424 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 425 | |
| 426 | GLTexture texture; |
| 427 | glBindTexture(GL_TEXTURE_2D, texture); |
| 428 | |
| 429 | // Create a complete mip chain in mips 1 to 3 |
| 430 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 431 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 432 | glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 433 | |
| 434 | // Create another complete mip chain in mips 4 to 5 |
| 435 | glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 436 | glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 437 | |
| 438 | // Create a non-complete mip chain in mip 6 |
| 439 | glTexImage2D(GL_TEXTURE_2D, 6, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 440 | |
| 441 | // Incomplete, mipLevel != baseLevel and texture is not mip complete |
| 442 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1); |
| 443 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 444 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 445 | |
| 446 | // Complete, mipLevel == baseLevel |
| 447 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 448 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 449 | |
| 450 | // Complete, mipLevel != baseLevel but texture is now mip complete |
| 451 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 2); |
| 452 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 453 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 3); |
| 454 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 455 | |
| 456 | // Incomplete, attached level below the base level |
| 457 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2); |
| 458 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1); |
| 459 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 460 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 461 | |
| 462 | // Incomplete, attached level is beyond effective max level |
| 463 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 4); |
| 464 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 465 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 466 | |
| 467 | // Complete, mipLevel == baseLevel |
| 468 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 4); |
| 469 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 470 | |
| 471 | // Complete, mipLevel != baseLevel but texture is now mip complete |
| 472 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 5); |
| 473 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 474 | |
| 475 | // Complete, mipLevel == baseLevel |
| 476 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 6); |
| 477 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 6); |
| 478 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 479 | } |
| 480 | |
Martin Radev | d178aa4 | 2017-07-13 14:03:22 +0300 | [diff] [blame] | 481 | // Test that passing an attachment COLOR_ATTACHMENTm where m is equal to MAX_COLOR_ATTACHMENTS |
| 482 | // generates an INVALID_OPERATION. |
| 483 | // OpenGL ES Version 3.0.5 (November 3, 2016), 4.4.2.4 Attaching Texture Images to a Framebuffer, p. |
| 484 | // 208 |
| 485 | TEST_P(FramebufferTest_ES3, ColorAttachmentIndexOutOfBounds) |
| 486 | { |
| 487 | GLFramebuffer framebuffer; |
| 488 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 489 | |
| 490 | GLint maxColorAttachments = 0; |
| 491 | glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); |
| 492 | GLenum attachment = static_cast<GLenum>(maxColorAttachments + GL_COLOR_ATTACHMENT0); |
| 493 | |
| 494 | GLTexture texture; |
| 495 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 496 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, 1, 1); |
| 497 | glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture.get(), 0); |
| 498 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 499 | } |
| 500 | |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 501 | // Check that depth-only attachments report the correct number of samples. |
| 502 | TEST_P(FramebufferTest_ES3, MultisampleDepthOnly) |
| 503 | { |
| 504 | GLRenderbuffer renderbuffer; |
| 505 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
| 506 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 32, 32); |
| 507 | |
| 508 | GLFramebuffer framebuffer; |
| 509 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 510 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer); |
| 511 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 512 | EXPECT_GL_NO_ERROR(); |
| 513 | |
| 514 | GLint samples = 0; |
| 515 | glGetIntegerv(GL_SAMPLES, &samples); |
| 516 | EXPECT_GL_NO_ERROR(); |
| 517 | EXPECT_GE(samples, 2); |
| 518 | } |
| 519 | |
Jeff Gilbert | 8f8edd6 | 2017-10-31 14:26:30 -0700 | [diff] [blame] | 520 | // Check that we only compare width and height of attachments, not depth. |
| 521 | TEST_P(FramebufferTest_ES3, AttachmentWith3DLayers) |
| 522 | { |
| 523 | GLTexture texA; |
| 524 | glBindTexture(GL_TEXTURE_2D, texA); |
| 525 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 526 | |
| 527 | GLTexture texB; |
| 528 | glBindTexture(GL_TEXTURE_3D, texB); |
| 529 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 530 | |
| 531 | GLFramebuffer framebuffer; |
| 532 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 533 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0); |
| 534 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, texB, 0, 0); |
| 535 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 536 | EXPECT_GL_NO_ERROR(); |
| 537 | } |
| 538 | |
Olli Etuaho | dbce1f8 | 2018-09-19 15:32:17 +0300 | [diff] [blame] | 539 | // Test that clearing the stencil buffer when the framebuffer only has a color attachment does not |
| 540 | // crash. |
| 541 | TEST_P(FramebufferTest_ES3, ClearNonexistentStencil) |
| 542 | { |
| 543 | GLRenderbuffer rbo; |
| 544 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 545 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 546 | |
| 547 | GLFramebuffer fbo; |
| 548 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 549 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 550 | |
| 551 | GLint clearValue = 0; |
| 552 | glClearBufferiv(GL_STENCIL, 0, &clearValue); |
| 553 | |
| 554 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 555 | EXPECT_GL_NO_ERROR(); |
| 556 | } |
| 557 | |
| 558 | // Test that clearing the depth buffer when the framebuffer only has a color attachment does not |
| 559 | // crash. |
| 560 | TEST_P(FramebufferTest_ES3, ClearNonexistentDepth) |
| 561 | { |
| 562 | GLRenderbuffer rbo; |
| 563 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 564 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 565 | |
| 566 | GLFramebuffer fbo; |
| 567 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 568 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 569 | |
| 570 | GLfloat clearValue = 0.0f; |
| 571 | glClearBufferfv(GL_DEPTH, 0, &clearValue); |
| 572 | |
| 573 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 574 | EXPECT_GL_NO_ERROR(); |
| 575 | } |
| 576 | |
| 577 | // Test that clearing a nonexistent color attachment does not crash. |
| 578 | TEST_P(FramebufferTest_ES3, ClearNonexistentColor) |
| 579 | { |
| 580 | GLRenderbuffer rbo; |
| 581 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 582 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 583 | |
| 584 | GLFramebuffer fbo; |
| 585 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 586 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 587 | |
| 588 | std::vector<GLfloat> clearValue = {{0.0f, 1.0f, 0.0f, 1.0f}}; |
| 589 | glClearBufferfv(GL_COLOR, 1, clearValue.data()); |
| 590 | |
| 591 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 592 | EXPECT_GL_NO_ERROR(); |
| 593 | } |
| 594 | |
| 595 | // Test that clearing the depth and stencil buffers when the framebuffer only has a color attachment |
| 596 | // does not crash. |
| 597 | TEST_P(FramebufferTest_ES3, ClearNonexistentDepthStencil) |
| 598 | { |
| 599 | GLRenderbuffer rbo; |
| 600 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 601 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 602 | |
| 603 | GLFramebuffer fbo; |
| 604 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 605 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 606 | |
| 607 | glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.0f, 0); |
| 608 | |
| 609 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 610 | EXPECT_GL_NO_ERROR(); |
| 611 | } |
| 612 | |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 613 | // Test that clearing a color attachment that has been deleted doesn't crash. |
| 614 | TEST_P(FramebufferTest_ES3, ClearDeletedAttachment) |
| 615 | { |
| 616 | // An INVALID_FRAMEBUFFER_OPERATION error was seen in this test on Mac, not sure where it might |
| 617 | // be originating from. http://anglebug.com/2834 |
| 618 | ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL()); |
| 619 | |
| 620 | GLFramebuffer fbo; |
| 621 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 622 | |
| 623 | // There used to be a bug where some draw buffer state used to remain set even after the |
| 624 | // attachment was detached via deletion. That's why we create, attach and delete this RBO here. |
| 625 | GLuint rbo = 0u; |
| 626 | glGenRenderbuffers(1, &rbo); |
| 627 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 628 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 629 | glDeleteRenderbuffers(1, &rbo); |
| 630 | |
| 631 | // There needs to be at least one color attachment to prevent early out from the clear calls. |
| 632 | GLRenderbuffer rbo2; |
| 633 | glBindRenderbuffer(GL_RENDERBUFFER, rbo2); |
| 634 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 635 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rbo2); |
| 636 | |
| 637 | ASSERT_GL_NO_ERROR(); |
| 638 | |
| 639 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op, so we |
| 640 | // expect no GL errors below. |
| 641 | std::array<GLfloat, 4> floatClearValue = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 642 | glClearBufferfv(GL_COLOR, 0, floatClearValue.data()); |
| 643 | EXPECT_GL_NO_ERROR(); |
| 644 | std::array<GLuint, 4> uintClearValue = {0u, 0u, 0u, 0u}; |
| 645 | glClearBufferuiv(GL_COLOR, 0, uintClearValue.data()); |
| 646 | EXPECT_GL_NO_ERROR(); |
| 647 | std::array<GLint, 4> intClearValue = {0, 0, 0, 0}; |
| 648 | glClearBufferiv(GL_COLOR, 0, intClearValue.data()); |
| 649 | EXPECT_GL_NO_ERROR(); |
| 650 | } |
| 651 | |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame^] | 652 | // Test that resizing the color attachment is handled correctly. |
| 653 | TEST_P(FramebufferTest_ES3, ResizeColorAttachmentSmallToLarge) |
| 654 | { |
| 655 | GLFramebuffer fbo; |
| 656 | GLTexture smallTexture; |
| 657 | GLTexture largeTexture; |
| 658 | |
| 659 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 660 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 661 | |
| 662 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 663 | |
| 664 | // Bind the small texture |
| 665 | glBindTexture(GL_TEXTURE_2D, smallTexture); |
| 666 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 667 | GL_UNSIGNED_BYTE, nullptr); |
| 668 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 669 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 670 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, smallTexture, 0); |
| 671 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 672 | |
| 673 | // Draw to FBO backed by the small texture |
| 674 | glUseProgram(greenProgram); |
| 675 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 676 | ASSERT_GL_NO_ERROR(); |
| 677 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 678 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 679 | |
| 680 | // Change the attachment to the larger texture that fills the window |
| 681 | glBindTexture(GL_TEXTURE_2D, largeTexture); |
| 682 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 683 | GL_UNSIGNED_BYTE, nullptr); |
| 684 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 685 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 686 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, largeTexture, 0); |
| 687 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 688 | |
| 689 | // Draw to FBO backed by the large texture |
| 690 | glUseProgram(blueProgram); |
| 691 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 692 | ASSERT_GL_NO_ERROR(); |
| 693 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 694 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::blue); |
| 695 | } |
| 696 | |
| 697 | // Test that resizing the color attachment is handled correctly. |
| 698 | TEST_P(FramebufferTest_ES3, ResizeColorAttachmentLargeToSmall) |
| 699 | { |
| 700 | GLFramebuffer fbo; |
| 701 | GLTexture smallTexture; |
| 702 | GLTexture largeTexture; |
| 703 | |
| 704 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 705 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 706 | |
| 707 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 708 | |
| 709 | // Bind the large texture |
| 710 | glBindTexture(GL_TEXTURE_2D, largeTexture); |
| 711 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 712 | GL_UNSIGNED_BYTE, nullptr); |
| 713 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 714 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 715 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, largeTexture, 0); |
| 716 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 717 | |
| 718 | // Draw to FBO backed by the large texture |
| 719 | glUseProgram(blueProgram); |
| 720 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 721 | ASSERT_GL_NO_ERROR(); |
| 722 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 723 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::blue); |
| 724 | |
| 725 | // Change the attachment to the smaller texture |
| 726 | glBindTexture(GL_TEXTURE_2D, smallTexture); |
| 727 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 728 | GL_UNSIGNED_BYTE, nullptr); |
| 729 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 730 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 731 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, smallTexture, 0); |
| 732 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 733 | |
| 734 | // Draw to FBO backed by the small texture |
| 735 | glUseProgram(greenProgram); |
| 736 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 737 | ASSERT_GL_NO_ERROR(); |
| 738 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 739 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 740 | } |
| 741 | |
| 742 | // Test that resizing the texture is handled correctly. |
| 743 | TEST_P(FramebufferTest_ES3, ResizeTextureLargeToSmall) |
| 744 | { |
| 745 | GLFramebuffer fbo; |
| 746 | GLTexture texture; |
| 747 | |
| 748 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 749 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 750 | |
| 751 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 752 | |
| 753 | // Allocate a large texture |
| 754 | glBindTexture(GL_TEXTURE_2D, texture); |
| 755 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 756 | GL_UNSIGNED_BYTE, nullptr); |
| 757 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 758 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 759 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 760 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 761 | |
| 762 | // Draw to FBO backed by the large texture |
| 763 | glUseProgram(blueProgram); |
| 764 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 765 | ASSERT_GL_NO_ERROR(); |
| 766 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 767 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::blue); |
| 768 | |
| 769 | // Shrink the texture |
| 770 | glBindTexture(GL_TEXTURE_2D, texture); |
| 771 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 772 | GL_UNSIGNED_BYTE, nullptr); |
| 773 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 774 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 775 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 776 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 777 | |
| 778 | // Draw to FBO backed by the small texture |
| 779 | glUseProgram(greenProgram); |
| 780 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 781 | ASSERT_GL_NO_ERROR(); |
| 782 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 783 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 784 | } |
| 785 | |
| 786 | // Test that resizing the texture is handled correctly. |
| 787 | TEST_P(FramebufferTest_ES3, ResizeTextureSmallToLarge) |
| 788 | { |
| 789 | GLFramebuffer fbo; |
| 790 | GLTexture texture; |
| 791 | |
| 792 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 793 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 794 | |
| 795 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 796 | |
| 797 | // Allocate a small texture |
| 798 | glBindTexture(GL_TEXTURE_2D, texture); |
| 799 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 800 | GL_UNSIGNED_BYTE, nullptr); |
| 801 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 802 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 803 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 804 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 805 | |
| 806 | // Draw to FBO backed by the large texture |
| 807 | glUseProgram(blueProgram); |
| 808 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 809 | ASSERT_GL_NO_ERROR(); |
| 810 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 811 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::blue); |
| 812 | |
| 813 | // Grow the texture |
| 814 | glBindTexture(GL_TEXTURE_2D, texture); |
| 815 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 816 | GL_UNSIGNED_BYTE, nullptr); |
| 817 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 818 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 819 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 820 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 821 | |
| 822 | // Draw to FBO backed by the small texture |
| 823 | glUseProgram(greenProgram); |
| 824 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 825 | ASSERT_GL_NO_ERROR(); |
| 826 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 827 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green); |
| 828 | } |
| 829 | |
| 830 | ANGLE_INSTANTIATE_TEST(FramebufferTest_ES3, |
| 831 | ES3_D3D11(), |
| 832 | ES3_OPENGL(), |
| 833 | ES3_OPENGLES(), |
| 834 | ES3_VULKAN()); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 835 | |
| 836 | class FramebufferTest_ES31 : public ANGLETest |
| 837 | { |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 838 | protected: |
| 839 | void validateSamplePass(GLuint &query, GLuint &passedCount, GLint width, GLint height) |
| 840 | { |
| 841 | glUniform2i(0, width - 1, height - 1); |
| 842 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 843 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 844 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 845 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 846 | EXPECT_GT(static_cast<GLint>(passedCount), 0); |
| 847 | |
| 848 | glUniform2i(0, width - 1, height); |
| 849 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 850 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 851 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 852 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 853 | EXPECT_EQ(static_cast<GLint>(passedCount), 0); |
| 854 | |
| 855 | glUniform2i(0, width, height - 1); |
| 856 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 857 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 858 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 859 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 860 | EXPECT_EQ(static_cast<GLint>(passedCount), 0); |
| 861 | } |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 862 | }; |
| 863 | |
| 864 | // Test that without attachment, if either the value of FRAMEBUFFER_DEFAULT_WIDTH or |
| 865 | // FRAMEBUFFER_DEFAULT_HEIGHT parameters is zero, the framebuffer is incomplete. |
| 866 | TEST_P(FramebufferTest_ES31, IncompleteMissingAttachmentDefaultParam) |
| 867 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 868 | // anglebug.com/3565 |
| 869 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 870 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 871 | GLFramebuffer mFramebuffer; |
| 872 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 873 | |
| 874 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1); |
| 875 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1); |
| 876 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 877 | |
| 878 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0); |
| 879 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0); |
| 880 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 881 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 882 | |
| 883 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1); |
| 884 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0); |
| 885 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 886 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 887 | |
| 888 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0); |
| 889 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1); |
| 890 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 891 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 892 | |
| 893 | ASSERT_GL_NO_ERROR(); |
| 894 | } |
| 895 | |
| 896 | // Test that the sample count of a mix of texture and renderbuffer should be same. |
| 897 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountMix) |
| 898 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 899 | // anglebug.com/3565 |
| 900 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 901 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 902 | GLFramebuffer mFramebuffer; |
| 903 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 904 | |
| 905 | GLTexture mTexture; |
| 906 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get()); |
| 907 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, true); |
| 908 | |
| 909 | GLRenderbuffer mRenderbuffer; |
| 910 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get()); |
| 911 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_RGBA8, 1, 1); |
| 912 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 913 | mTexture.get(), 0); |
| 914 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, |
| 915 | mRenderbuffer.get()); |
| 916 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 917 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 918 | |
| 919 | ASSERT_GL_NO_ERROR(); |
| 920 | } |
| 921 | |
| 922 | // Test that the sample count of texture attachments should be same. |
| 923 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountTex) |
| 924 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 925 | // anglebug.com/3565 |
| 926 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 927 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 928 | GLFramebuffer mFramebuffer; |
| 929 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 930 | |
| 931 | GLTexture mTextures[2]; |
| 932 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get()); |
| 933 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, true); |
| 934 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get()); |
| 935 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 2, GL_RGBA8, 1, 1, true); |
| 936 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 937 | mTextures[0].get(), 0); |
| 938 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, |
| 939 | mTextures[1].get(), 0); |
| 940 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 941 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 942 | |
| 943 | ASSERT_GL_NO_ERROR(); |
| 944 | } |
| 945 | |
| 946 | // Test that if the attached images are a mix of renderbuffers and textures, the value of |
| 947 | // TEXTURE_FIXED_SAMPLE_LOCATIONS must be TRUE for all attached textures. |
| 948 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsMix) |
| 949 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 950 | // anglebug.com/3565 |
| 951 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 952 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 953 | GLFramebuffer mFramebuffer; |
| 954 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 955 | |
| 956 | GLTexture mTexture; |
| 957 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get()); |
| 958 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false); |
| 959 | |
| 960 | GLRenderbuffer mRenderbuffer; |
| 961 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get()); |
| 962 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 1, GL_RGBA8, 1, 1); |
| 963 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 964 | mTexture.get(), 0); |
| 965 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, |
| 966 | mRenderbuffer.get()); |
| 967 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 968 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 969 | |
| 970 | ASSERT_GL_NO_ERROR(); |
| 971 | } |
| 972 | |
| 973 | // Test that the value of TEXTURE_FIXED_SAMPLE_LOCATIONS is the same for all attached textures. |
| 974 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsTex) |
| 975 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 976 | // anglebug.com/3565 |
| 977 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 978 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 979 | GLFramebuffer mFramebuffer; |
| 980 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 981 | |
| 982 | GLTexture mTextures[2]; |
| 983 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get()); |
| 984 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false); |
| 985 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 986 | mTextures[0].get(), 0); |
| 987 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get()); |
| 988 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGB8, 1, 1, true); |
| 989 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, |
| 990 | mTextures[1].get(), 0); |
| 991 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 992 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 993 | |
| 994 | ASSERT_GL_NO_ERROR(); |
| 995 | } |
| 996 | |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 997 | // If there are no attachments, rendering will be limited to a rectangle having a lower left of |
| 998 | // (0, 0) and an upper right of(width, height), where width and height are the framebuffer |
| 999 | // object's default width and height. |
JiangYizhou | 3db4072 | 2017-08-28 17:59:13 +0800 | [diff] [blame] | 1000 | TEST_P(FramebufferTest_ES31, RenderingLimitToDefaultFBOSizeWithNoAttachments) |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1001 | { |
Yuly Novikov | 98f9f53 | 2017-11-15 19:16:19 -0500 | [diff] [blame] | 1002 | // anglebug.com/2253 |
| 1003 | ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL()); |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1004 | // Occlusion query reports fragments outside the render area are still rendered |
| 1005 | ANGLE_SKIP_TEST_IF(IsAndroid() || (IsWindows() && (IsIntel() || IsAMD()))); |
Yuly Novikov | 98f9f53 | 2017-11-15 19:16:19 -0500 | [diff] [blame] | 1006 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1007 | constexpr char kVS1[] = R"(#version 310 es |
| 1008 | in layout(location = 0) highp vec2 a_position; |
| 1009 | void main() |
| 1010 | { |
| 1011 | gl_Position = vec4(a_position, 0.0, 1.0); |
| 1012 | })"; |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1013 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1014 | constexpr char kFS1[] = R"(#version 310 es |
| 1015 | uniform layout(location = 0) highp ivec2 u_expectedSize; |
| 1016 | out layout(location = 5) mediump vec4 f_color; |
| 1017 | void main() |
| 1018 | { |
| 1019 | if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; |
| 1020 | f_color = vec4(1.0, 0.5, 0.25, 1.0); |
| 1021 | })"; |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1022 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1023 | constexpr char kVS2[] = R"(#version 310 es |
| 1024 | in layout(location = 0) highp vec2 a_position; |
| 1025 | void main() |
| 1026 | { |
| 1027 | gl_Position = vec4(a_position, 0.0, 1.0); |
| 1028 | })"; |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1029 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1030 | constexpr char kFS2[] = R"(#version 310 es |
| 1031 | uniform layout(location = 0) highp ivec2 u_expectedSize; |
| 1032 | out layout(location = 2) mediump vec4 f_color; |
| 1033 | void main() |
| 1034 | { |
| 1035 | if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; |
| 1036 | f_color = vec4(1.0, 0.5, 0.25, 1.0); |
| 1037 | })"; |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1038 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1039 | GLuint program1 = CompileProgram(kVS1, kFS1); |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1040 | ASSERT_NE(program1, 0u); |
| 1041 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1042 | GLuint program2 = CompileProgram(kVS2, kFS2); |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1043 | ASSERT_NE(program2, 0u); |
| 1044 | |
| 1045 | glUseProgram(program1); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1046 | |
| 1047 | GLFramebuffer mFramebuffer; |
| 1048 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer); |
| 1049 | GLuint defaultWidth = 1; |
| 1050 | GLuint defaultHeight = 1; |
| 1051 | |
| 1052 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, defaultWidth); |
| 1053 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, defaultHeight); |
| 1054 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1055 | |
| 1056 | const float data[] = { |
| 1057 | 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, |
| 1058 | }; |
| 1059 | |
| 1060 | GLuint vertexArray = 0; |
| 1061 | GLuint vertexBuffer = 0; |
| 1062 | GLuint query = 0; |
| 1063 | GLuint passedCount = 0; |
| 1064 | |
| 1065 | glGenQueries(1, &query); |
| 1066 | glGenVertexArrays(1, &vertexArray); |
| 1067 | glBindVertexArray(vertexArray); |
| 1068 | |
| 1069 | glGenBuffers(1, &vertexBuffer); |
| 1070 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); |
| 1071 | glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); |
| 1072 | |
| 1073 | glEnableVertexAttribArray(0); |
| 1074 | glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1075 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1076 | |
| 1077 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1078 | |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1079 | glUseProgram(program2); |
| 1080 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1081 | |
| 1082 | glUseProgram(program1); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1083 | // If fbo has attachments, the rendering size should be the same as its attachment. |
| 1084 | GLTexture mTexture; |
| 1085 | GLuint width = 2; |
| 1086 | GLuint height = 2; |
| 1087 | glBindTexture(GL_TEXTURE_2D, mTexture.get()); |
| 1088 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1089 | |
| 1090 | const GLenum bufs[] = {GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT5}; |
| 1091 | |
| 1092 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, GL_TEXTURE_2D, mTexture.get(), |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1093 | 0); |
| 1094 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1095 | glDrawBuffers(6, bufs); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1096 | |
| 1097 | validateSamplePass(query, passedCount, width, height); |
| 1098 | |
| 1099 | // If fbo's attachment has been removed, the rendering size should be the same as framebuffer |
| 1100 | // default size. |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1101 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, 0, 0, 0); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1102 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1103 | |
| 1104 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1105 | |
| 1106 | glDisableVertexAttribArray(0); |
| 1107 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 1108 | glBindVertexArray(0); |
| 1109 | glDeleteBuffers(1, &vertexBuffer); |
| 1110 | glDeleteVertexArrays(1, &vertexArray); |
| 1111 | |
| 1112 | ASSERT_GL_NO_ERROR(); |
| 1113 | } |
| 1114 | |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1115 | ANGLE_INSTANTIATE_TEST(FramebufferTest_ES31, |
| 1116 | ES31_D3D11(), |
| 1117 | ES31_OPENGL(), |
| 1118 | ES31_OPENGLES(), |
| 1119 | ES31_VULKAN()); |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1120 | |
| 1121 | class AddDummyTextureNoRenderTargetTest : public ANGLETest |
| 1122 | { |
| 1123 | public: |
| 1124 | AddDummyTextureNoRenderTargetTest() |
| 1125 | { |
| 1126 | setWindowWidth(512); |
| 1127 | setWindowHeight(512); |
| 1128 | setConfigRedBits(8); |
| 1129 | setConfigGreenBits(8); |
| 1130 | setConfigBlueBits(8); |
| 1131 | setConfigAlphaBits(8); |
| 1132 | } |
| 1133 | |
Jonah Ryan-Davis | eee67c6 | 2019-06-18 13:00:43 -0400 | [diff] [blame] | 1134 | void overrideWorkaroundsD3D(FeaturesD3D *features) override |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1135 | { |
Jonah Ryan-Davis | beb0eb2 | 2019-06-14 15:10:33 -0400 | [diff] [blame] | 1136 | features->overrideFeatures({"add_dummy_texture_no_render_target"}, true); |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1137 | } |
| 1138 | }; |
| 1139 | |
| 1140 | // Test to verify workaround succeeds when no program outputs exist http://anglebug.com/2283 |
| 1141 | TEST_P(AddDummyTextureNoRenderTargetTest, NoProgramOutputWorkaround) |
| 1142 | { |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1143 | constexpr char kVS[] = "void main() {}"; |
| 1144 | constexpr char kFS[] = "void main() {}"; |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1145 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1146 | ANGLE_GL_PROGRAM(drawProgram, kVS, kFS); |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1147 | |
| 1148 | glUseProgram(drawProgram); |
| 1149 | |
| 1150 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 1151 | |
| 1152 | ASSERT_GL_NO_ERROR(); |
| 1153 | } |
| 1154 | |
| 1155 | ANGLE_INSTANTIATE_TEST(AddDummyTextureNoRenderTargetTest, ES2_D3D11()); |