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 | |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 10 | #include "platform/WorkaroundsD3D.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 | { |
Geoff Lang | c422207 | 2015-05-25 13:19:48 -0400 | [diff] [blame] | 100 | // TODO(geofflang): Figure out why this is broken on Intel OpenGL |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 101 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | c422207 | 2015-05-25 13:19:48 -0400 | [diff] [blame] | 102 | { |
| 103 | std::cout << "Test skipped on Intel OpenGL." << std::endl; |
| 104 | return; |
| 105 | } |
| 106 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 107 | int clientVersion = getClientMajorVersion(); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 108 | if (clientVersion < minESVersion) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 109 | { |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 116 | if (clientVersion == 2) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 117 | { |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 127 | assert(clientVersion >= 3); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 128 | int maxSamples; |
| 129 | glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); |
| 130 | supports2Samples = maxSamples >= 2; |
| 131 | } |
| 132 | |
| 133 | if (!supports2Samples) |
| 134 | { |
| 135 | return; |
| 136 | } |
| 137 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 138 | glGenRenderbuffers(1, &mRenderbuffer); |
| 139 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 140 | |
| 141 | EXPECT_GL_NO_ERROR(); |
| 142 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 2, internalFormat, 128, 128); |
| 143 | EXPECT_GL_NO_ERROR(); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 144 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachmentType, GL_RENDERBUFFER, mRenderbuffer); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 145 | EXPECT_GL_NO_ERROR(); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 148 | 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 Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 158 | void SetUp() override |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 159 | { |
| 160 | ANGLETest::SetUp(); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 161 | |
| 162 | glGenFramebuffers(1, &mFramebuffer); |
| 163 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 166 | void TearDown() override |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 167 | { |
| 168 | ANGLETest::TearDown(); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 169 | |
| 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 Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 193 | } |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 194 | |
| 195 | GLuint mFramebuffer; |
| 196 | GLuint mTexture; |
| 197 | GLuint mRenderbuffer; |
| 198 | GLuint mProgram; |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 199 | }; |
| 200 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 201 | TEST_P(FramebufferFormatsTest, RGBA4) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 202 | { |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 203 | 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 Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 209 | testTextureFormat(GL_RGBA4, 4, 4, 4, 4); |
| 210 | } |
| 211 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 212 | TEST_P(FramebufferFormatsTest, RGB565) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 213 | { |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 214 | 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 Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 220 | testTextureFormat(GL_RGB565, 5, 6, 5, 0); |
| 221 | } |
| 222 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 223 | TEST_P(FramebufferFormatsTest, RGB8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 224 | { |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 225 | if (getClientMajorVersion() < 3 && |
| 226 | (!extensionEnabled("GL_OES_rgb8_rgba8") || !extensionEnabled("GL_EXT_texture_storage"))) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 227 | { |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 228 | std::cout |
| 229 | << "Test skipped due to missing ES3 or GL_OES_rgb8_rgba8 and GL_EXT_texture_storage." |
| 230 | << std::endl; |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 231 | return; |
| 232 | } |
| 233 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 234 | testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0); |
| 235 | } |
| 236 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 237 | TEST_P(FramebufferFormatsTest, BGRA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 238 | { |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 239 | if (!extensionEnabled("GL_EXT_texture_format_BGRA8888") || |
| 240 | (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"))) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 241 | { |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 242 | std::cout << "Test skipped due to missing GL_EXT_texture_format_BGRA8888 or " |
| 243 | "GL_EXT_texture_storage." |
| 244 | << std::endl; |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 245 | return; |
| 246 | } |
| 247 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 248 | testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8); |
| 249 | } |
| 250 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 251 | TEST_P(FramebufferFormatsTest, RGBA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 252 | { |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 253 | if (getClientMajorVersion() < 3 && |
| 254 | (!extensionEnabled("GL_OES_rgb8_rgba8") || !extensionEnabled("GL_EXT_texture_storage"))) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 255 | { |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 256 | std::cout |
| 257 | << "Test skipped due to missing ES3 or GL_OES_rgb8_rgba8 and GL_EXT_texture_storage." |
| 258 | << std::endl; |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 259 | return; |
| 260 | } |
| 261 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 262 | testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8); |
| 263 | } |
| 264 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 265 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH16) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 266 | { |
| 267 | testRenderbufferMultisampleFormat(2, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16); |
| 268 | } |
| 269 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 270 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 271 | { |
| 272 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24); |
| 273 | } |
| 274 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 275 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 276 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 277 | if (getClientMajorVersion() < 3) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 278 | { |
| 279 | std::cout << "Test skipped due to missing ES3." << std::endl; |
| 280 | return; |
| 281 | } |
| 282 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 283 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32F); |
| 284 | } |
| 285 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 286 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24_STENCIL8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 287 | { |
| 288 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH24_STENCIL8); |
| 289 | } |
| 290 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 291 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F_STENCIL8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 292 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 293 | if (getClientMajorVersion() < 3) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 294 | { |
| 295 | std::cout << "Test skipped due to missing ES3." << std::endl; |
| 296 | return; |
| 297 | } |
| 298 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 299 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH32F_STENCIL8); |
| 300 | } |
| 301 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 302 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_STENCIL_INDEX8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 303 | { |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 304 | // TODO(geofflang): Figure out how to support GLSTENCIL_INDEX8 on desktop GL |
Geoff Lang | dd323e9 | 2015-06-09 15:16:31 -0400 | [diff] [blame] | 305 | if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 306 | { |
| 307 | std::cout << "Test skipped on Desktop OpenGL." << std::endl; |
| 308 | return; |
| 309 | } |
| 310 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 311 | testRenderbufferMultisampleFormat(2, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8); |
| 312 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 313 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 314 | // Test that binding an incomplete cube map is rejected by ANGLE. |
| 315 | TEST_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 Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 358 | // Test that a renderbuffer with zero height but nonzero width is handled without crashes/asserts. |
| 359 | TEST_P(FramebufferFormatsTest, ZeroHeightRenderbuffer) |
| 360 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 361 | if (getClientMajorVersion() < 3) |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 362 | { |
| 363 | std::cout << "Test skipped due to missing ES3" << std::endl; |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | testZeroHeightRenderbuffer(); |
| 368 | } |
| 369 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 370 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 371 | // tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 372 | ANGLE_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 Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 380 | |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 381 | class FramebufferTest_ES3 : public ANGLETest |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 382 | { |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | // 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] | 386 | TEST_P(FramebufferTest_ES3, InvalidateIncomplete) |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 387 | { |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 388 | 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 Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 394 | 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 Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 404 | // 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. |
| 406 | TEST_P(FramebufferTest_ES3, DepthOnlyAsDepthStencil) |
| 407 | { |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 408 | GLFramebuffer framebuffer; |
| 409 | GLRenderbuffer renderbuffer; |
| 410 | |
| 411 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 412 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 413 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 4, 4); |
| 414 | |
| 415 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 416 | renderbuffer); |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 417 | EXPECT_GLENUM_NE(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 418 | } |
| 419 | |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 420 | // Test that the framebuffer correctly returns that it is not complete if invalid texture mip levels |
| 421 | // are bound |
| 422 | TEST_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 Radev | d178aa4 | 2017-07-13 14:03:22 +0300 | [diff] [blame] | 482 | // 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 |
| 486 | TEST_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 Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 502 | // Check that depth-only attachments report the correct number of samples. |
| 503 | TEST_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 Gilbert | 8f8edd6 | 2017-10-31 14:26:30 -0700 | [diff] [blame] | 521 | // Check that we only compare width and height of attachments, not depth. |
| 522 | TEST_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 Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 540 | ANGLE_INSTANTIATE_TEST(FramebufferTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 541 | |
| 542 | class FramebufferTest_ES31 : public ANGLETest |
| 543 | { |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 544 | 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 | } |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 568 | }; |
| 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. |
| 572 | TEST_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. |
| 600 | TEST_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. |
| 623 | TEST_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. |
| 645 | TEST_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. |
| 668 | TEST_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 | |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 688 | // 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. |
JiangYizhou | 3db4072 | 2017-08-28 17:59:13 +0800 | [diff] [blame] | 691 | TEST_P(FramebufferTest_ES31, RenderingLimitToDefaultFBOSizeWithNoAttachments) |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 692 | { |
Yuly Novikov | 98f9f53 | 2017-11-15 19:16:19 -0500 | [diff] [blame] | 693 | // anglebug.com/2253 |
| 694 | ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL()); |
| 695 | |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 696 | 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 Gilbert | 8f8edd6 | 2017-10-31 14:26:30 -0700 | [diff] [blame] | 701 | " gl_Position = vec4(a_position, 0.0, 1.0);\n" |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 702 | "}\n"; |
| 703 | const std::string &fragShader = |
| 704 | "#version 310 es\n" |
| 705 | "uniform layout(location = 0) highp ivec2 u_expectedSize;\n" |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 706 | "out layout(location = 5) mediump vec4 f_color;\n\n" |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 707 | "void main()\n" |
| 708 | "{\n" |
Jeff Gilbert | 8f8edd6 | 2017-10-31 14:26:30 -0700 | [diff] [blame] | 709 | " if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard;\n" |
| 710 | " f_color = vec4(1.0, 0.5, 0.25, 1.0);\n" |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 711 | "}\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); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 746 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 747 | |
| 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); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 756 | |
| 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(), |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 760 | 0); |
| 761 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 762 | glDrawBuffers(6, bufs); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 763 | |
| 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. |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 768 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, 0, 0, 0); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 769 | 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 | |
| 782 | ANGLE_INSTANTIATE_TEST(FramebufferTest_ES31, ES31_D3D11(), ES31_OPENGL(), ES31_OPENGLES()); |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 783 | |
| 784 | class 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 |
| 804 | TEST_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 | |
| 818 | ANGLE_INSTANTIATE_TEST(AddDummyTextureNoRenderTargetTest, ES2_D3D11()); |