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 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 10 | #include "test_utils/ANGLETest.h" |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 11 | #include "test_utils/gl_raii.h" |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 12 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 13 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 14 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 15 | class FramebufferFormatsTest : public ANGLETest |
| 16 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 17 | protected: |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 18 | FramebufferFormatsTest() : mFramebuffer(0), mTexture(0), mRenderbuffer(0), mProgram(0) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 19 | { |
| 20 | setWindowWidth(128); |
| 21 | setWindowHeight(128); |
| 22 | setConfigRedBits(8); |
| 23 | setConfigGreenBits(8); |
| 24 | setConfigBlueBits(8); |
| 25 | setConfigAlphaBits(8); |
| 26 | } |
| 27 | |
| 28 | void checkBitCount(GLuint fbo, GLenum channel, GLint minBits) |
| 29 | { |
| 30 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 31 | |
| 32 | GLint bits = 0; |
| 33 | glGetIntegerv(channel, &bits); |
| 34 | |
| 35 | if (minBits == 0) |
| 36 | { |
| 37 | EXPECT_EQ(minBits, bits); |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | EXPECT_GE(bits, minBits); |
| 42 | } |
| 43 | } |
| 44 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 45 | void testBitCounts(GLuint fbo, |
| 46 | GLint minRedBits, |
| 47 | GLint minGreenBits, |
| 48 | GLint minBlueBits, |
| 49 | GLint minAlphaBits, |
| 50 | GLint minDepthBits, |
| 51 | GLint minStencilBits) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 52 | { |
| 53 | checkBitCount(fbo, GL_RED_BITS, minRedBits); |
| 54 | checkBitCount(fbo, GL_GREEN_BITS, minGreenBits); |
| 55 | checkBitCount(fbo, GL_BLUE_BITS, minBlueBits); |
| 56 | checkBitCount(fbo, GL_ALPHA_BITS, minAlphaBits); |
| 57 | checkBitCount(fbo, GL_DEPTH_BITS, minDepthBits); |
| 58 | checkBitCount(fbo, GL_STENCIL_BITS, minStencilBits); |
| 59 | } |
| 60 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 61 | void testTextureFormat(GLenum internalFormat, |
| 62 | GLint minRedBits, |
| 63 | GLint minGreenBits, |
| 64 | GLint minBlueBits, |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 65 | GLint minAlphaBits) |
| 66 | { |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 67 | glGenTextures(1, &mTexture); |
| 68 | glBindTexture(GL_TEXTURE_2D, mTexture); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 69 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1); |
| 70 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 71 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 72 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 73 | testBitCounts(mFramebuffer, minRedBits, minGreenBits, minBlueBits, minAlphaBits, 0, 0); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 76 | void testRenderbufferMultisampleFormat(int minESVersion, |
| 77 | GLenum attachmentType, |
| 78 | GLenum internalFormat) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 79 | { |
Geoff Lang | c422207 | 2015-05-25 13:19:48 -0400 | [diff] [blame] | 80 | // TODO(geofflang): Figure out why this is broken on Intel OpenGL |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 81 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | c422207 | 2015-05-25 13:19:48 -0400 | [diff] [blame] | 82 | { |
| 83 | std::cout << "Test skipped on Intel OpenGL." << std::endl; |
| 84 | return; |
| 85 | } |
| 86 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 87 | int clientVersion = getClientMajorVersion(); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 88 | if (clientVersion < minESVersion) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 89 | { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | // Check that multisample is supported with at least two samples (minimum required is 1) |
| 94 | bool supports2Samples = false; |
| 95 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 96 | if (clientVersion == 2) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 97 | { |
| 98 | if (extensionEnabled("ANGLE_framebuffer_multisample")) |
| 99 | { |
| 100 | int maxSamples; |
| 101 | glGetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSamples); |
| 102 | supports2Samples = maxSamples >= 2; |
| 103 | } |
| 104 | } |
| 105 | else |
| 106 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 107 | assert(clientVersion >= 3); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 108 | int maxSamples; |
| 109 | glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); |
| 110 | supports2Samples = maxSamples >= 2; |
| 111 | } |
| 112 | |
| 113 | if (!supports2Samples) |
| 114 | { |
| 115 | return; |
| 116 | } |
| 117 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 118 | glGenRenderbuffers(1, &mRenderbuffer); |
| 119 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 120 | |
| 121 | EXPECT_GL_NO_ERROR(); |
| 122 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 2, internalFormat, 128, 128); |
| 123 | EXPECT_GL_NO_ERROR(); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 124 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachmentType, GL_RENDERBUFFER, mRenderbuffer); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 125 | EXPECT_GL_NO_ERROR(); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 128 | void testZeroHeightRenderbuffer() |
| 129 | { |
| 130 | glGenRenderbuffers(1, &mRenderbuffer); |
| 131 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
| 132 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 0); |
| 133 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, |
| 134 | mRenderbuffer); |
| 135 | EXPECT_GL_NO_ERROR(); |
| 136 | } |
| 137 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 138 | void SetUp() override |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 139 | { |
| 140 | ANGLETest::SetUp(); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 141 | |
| 142 | glGenFramebuffers(1, &mFramebuffer); |
| 143 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 144 | } |
| 145 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 146 | void TearDown() override |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 147 | { |
| 148 | ANGLETest::TearDown(); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 149 | |
| 150 | if (mTexture != 0) |
| 151 | { |
| 152 | glDeleteTextures(1, &mTexture); |
| 153 | mTexture = 0; |
| 154 | } |
| 155 | |
| 156 | if (mRenderbuffer != 0) |
| 157 | { |
| 158 | glDeleteRenderbuffers(1, &mRenderbuffer); |
| 159 | mRenderbuffer = 0; |
| 160 | } |
| 161 | |
| 162 | if (mFramebuffer != 0) |
| 163 | { |
| 164 | glDeleteFramebuffers(1, &mFramebuffer); |
| 165 | mFramebuffer = 0; |
| 166 | } |
| 167 | |
| 168 | if (mProgram != 0) |
| 169 | { |
| 170 | glDeleteProgram(mProgram); |
| 171 | mProgram = 0; |
| 172 | } |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 173 | } |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 174 | |
| 175 | GLuint mFramebuffer; |
| 176 | GLuint mTexture; |
| 177 | GLuint mRenderbuffer; |
| 178 | GLuint mProgram; |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 179 | }; |
| 180 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 181 | TEST_P(FramebufferFormatsTest, RGBA4) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 182 | { |
| 183 | testTextureFormat(GL_RGBA4, 4, 4, 4, 4); |
| 184 | } |
| 185 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 186 | TEST_P(FramebufferFormatsTest, RGB565) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 187 | { |
| 188 | testTextureFormat(GL_RGB565, 5, 6, 5, 0); |
| 189 | } |
| 190 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 191 | TEST_P(FramebufferFormatsTest, RGB8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 192 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 193 | if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_rgb8_rgba8")) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 194 | { |
| 195 | std::cout << "Test skipped due to missing ES3 or GL_OES_rgb8_rgba8." << std::endl; |
| 196 | return; |
| 197 | } |
| 198 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 199 | testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0); |
| 200 | } |
| 201 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 202 | TEST_P(FramebufferFormatsTest, BGRA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 203 | { |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 204 | if (!extensionEnabled("GL_EXT_texture_format_BGRA8888")) |
| 205 | { |
| 206 | std::cout << "Test skipped due to missing GL_EXT_texture_format_BGRA8888." << std::endl; |
| 207 | return; |
| 208 | } |
| 209 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 210 | testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8); |
| 211 | } |
| 212 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 213 | TEST_P(FramebufferFormatsTest, RGBA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 214 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 215 | if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_rgb8_rgba8")) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 216 | { |
| 217 | std::cout << "Test skipped due to missing ES3 or GL_OES_rgb8_rgba8." << std::endl; |
| 218 | return; |
| 219 | } |
| 220 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 221 | testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8); |
| 222 | } |
| 223 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 224 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH16) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 225 | { |
| 226 | testRenderbufferMultisampleFormat(2, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16); |
| 227 | } |
| 228 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 229 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 230 | { |
| 231 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24); |
| 232 | } |
| 233 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 234 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 235 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 236 | if (getClientMajorVersion() < 3) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 237 | { |
| 238 | std::cout << "Test skipped due to missing ES3." << std::endl; |
| 239 | return; |
| 240 | } |
| 241 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 242 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32F); |
| 243 | } |
| 244 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 245 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24_STENCIL8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 246 | { |
| 247 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH24_STENCIL8); |
| 248 | } |
| 249 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 250 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F_STENCIL8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 251 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 252 | if (getClientMajorVersion() < 3) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 253 | { |
| 254 | std::cout << "Test skipped due to missing ES3." << std::endl; |
| 255 | return; |
| 256 | } |
| 257 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 258 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH32F_STENCIL8); |
| 259 | } |
| 260 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 261 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_STENCIL_INDEX8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 262 | { |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 263 | // TODO(geofflang): Figure out how to support GLSTENCIL_INDEX8 on desktop GL |
Geoff Lang | dd323e9 | 2015-06-09 15:16:31 -0400 | [diff] [blame] | 264 | if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 265 | { |
| 266 | std::cout << "Test skipped on Desktop OpenGL." << std::endl; |
| 267 | return; |
| 268 | } |
| 269 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 270 | testRenderbufferMultisampleFormat(2, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8); |
| 271 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 272 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 273 | // Test that binding an incomplete cube map is rejected by ANGLE. |
| 274 | TEST_P(FramebufferFormatsTest, IncompleteCubeMap) |
| 275 | { |
| 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 | |
| 308 | // Verify drawing with the incomplete framebuffer produces a GL error |
| 309 | const std::string &vs = "attribute vec4 position; void main() { gl_Position = position; }"; |
| 310 | const std::string &ps = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }"; |
| 311 | mProgram = CompileProgram(vs, ps); |
| 312 | ASSERT_NE(0u, mProgram); |
| 313 | drawQuad(mProgram, "position", 0.5f); |
| 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 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 320 | if (getClientMajorVersion() < 3) |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 321 | { |
| 322 | std::cout << "Test skipped due to missing ES3" << std::endl; |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | testZeroHeightRenderbuffer(); |
| 327 | } |
| 328 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 329 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 330 | // tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 331 | ANGLE_INSTANTIATE_TEST(FramebufferFormatsTest, |
| 332 | ES2_D3D9(), |
| 333 | ES2_D3D11(), |
| 334 | ES3_D3D11(), |
| 335 | ES2_OPENGL(), |
| 336 | ES3_OPENGL(), |
| 337 | ES2_OPENGLES(), |
| 338 | ES3_OPENGLES()); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 339 | |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 340 | class FramebufferTest_ES3 : public ANGLETest |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 341 | { |
| 342 | protected: |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 343 | FramebufferTest_ES3() : mFramebuffer(0), mRenderbuffer(0) {} |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 344 | |
| 345 | void SetUp() override |
| 346 | { |
| 347 | ANGLETest::SetUp(); |
| 348 | |
| 349 | glGenFramebuffers(1, &mFramebuffer); |
| 350 | glGenRenderbuffers(1, &mRenderbuffer); |
| 351 | } |
| 352 | |
| 353 | void TearDown() override |
| 354 | { |
| 355 | glDeleteFramebuffers(1, &mFramebuffer); |
| 356 | glDeleteRenderbuffers(1, &mRenderbuffer); |
| 357 | ANGLETest::TearDown(); |
| 358 | } |
| 359 | |
| 360 | GLuint mFramebuffer; |
| 361 | GLuint mRenderbuffer; |
| 362 | }; |
| 363 | |
| 364 | // 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] | 365 | TEST_P(FramebufferTest_ES3, InvalidateIncomplete) |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 366 | { |
| 367 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 368 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
| 369 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, mRenderbuffer); |
| 370 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 371 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 372 | |
| 373 | std::vector<GLenum> attachments; |
| 374 | attachments.push_back(GL_COLOR_ATTACHMENT0); |
| 375 | |
| 376 | glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, attachments.data()); |
| 377 | EXPECT_GL_NO_ERROR(); |
| 378 | } |
| 379 | |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 380 | // Test that the framebuffer state tracking robustly handles a depth-only attachment being set |
| 381 | // as a depth-stencil attachment. It is equivalent to detaching the depth-stencil attachment. |
| 382 | TEST_P(FramebufferTest_ES3, DepthOnlyAsDepthStencil) |
| 383 | { |
| 384 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
| 385 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
| 386 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 4, 4); |
| 387 | |
| 388 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 389 | mRenderbuffer); |
| 390 | EXPECT_GLENUM_NE(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 391 | } |
| 392 | |
| 393 | ANGLE_INSTANTIATE_TEST(FramebufferTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 394 | |
| 395 | class FramebufferTest_ES31 : public ANGLETest |
| 396 | { |
| 397 | }; |
| 398 | |
| 399 | // Test that without attachment, if either the value of FRAMEBUFFER_DEFAULT_WIDTH or |
| 400 | // FRAMEBUFFER_DEFAULT_HEIGHT parameters is zero, the framebuffer is incomplete. |
| 401 | TEST_P(FramebufferTest_ES31, IncompleteMissingAttachmentDefaultParam) |
| 402 | { |
| 403 | GLFramebuffer mFramebuffer; |
| 404 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 405 | |
| 406 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1); |
| 407 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1); |
| 408 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 409 | |
| 410 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0); |
| 411 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0); |
| 412 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 413 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 414 | |
| 415 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1); |
| 416 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0); |
| 417 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 418 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 419 | |
| 420 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0); |
| 421 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1); |
| 422 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 423 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 424 | |
| 425 | ASSERT_GL_NO_ERROR(); |
| 426 | } |
| 427 | |
| 428 | // Test that the sample count of a mix of texture and renderbuffer should be same. |
| 429 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountMix) |
| 430 | { |
| 431 | GLFramebuffer mFramebuffer; |
| 432 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 433 | |
| 434 | GLTexture mTexture; |
| 435 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get()); |
| 436 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, true); |
| 437 | |
| 438 | GLRenderbuffer mRenderbuffer; |
| 439 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get()); |
| 440 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_RGBA8, 1, 1); |
| 441 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 442 | mTexture.get(), 0); |
| 443 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, |
| 444 | mRenderbuffer.get()); |
| 445 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 446 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 447 | |
| 448 | ASSERT_GL_NO_ERROR(); |
| 449 | } |
| 450 | |
| 451 | // Test that the sample count of texture attachments should be same. |
| 452 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountTex) |
| 453 | { |
| 454 | GLFramebuffer mFramebuffer; |
| 455 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 456 | |
| 457 | GLTexture mTextures[2]; |
| 458 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get()); |
| 459 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, true); |
| 460 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get()); |
| 461 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 2, GL_RGBA8, 1, 1, true); |
| 462 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 463 | mTextures[0].get(), 0); |
| 464 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, |
| 465 | mTextures[1].get(), 0); |
| 466 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 467 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 468 | |
| 469 | ASSERT_GL_NO_ERROR(); |
| 470 | } |
| 471 | |
| 472 | // Test that if the attached images are a mix of renderbuffers and textures, the value of |
| 473 | // TEXTURE_FIXED_SAMPLE_LOCATIONS must be TRUE for all attached textures. |
| 474 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsMix) |
| 475 | { |
| 476 | GLFramebuffer mFramebuffer; |
| 477 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 478 | |
| 479 | GLTexture mTexture; |
| 480 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get()); |
| 481 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false); |
| 482 | |
| 483 | GLRenderbuffer mRenderbuffer; |
| 484 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get()); |
| 485 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 1, GL_RGBA8, 1, 1); |
| 486 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 487 | mTexture.get(), 0); |
| 488 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, |
| 489 | mRenderbuffer.get()); |
| 490 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 491 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 492 | |
| 493 | ASSERT_GL_NO_ERROR(); |
| 494 | } |
| 495 | |
| 496 | // Test that the value of TEXTURE_FIXED_SAMPLE_LOCATIONS is the same for all attached textures. |
| 497 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsTex) |
| 498 | { |
| 499 | GLFramebuffer mFramebuffer; |
| 500 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 501 | |
| 502 | GLTexture mTextures[2]; |
| 503 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get()); |
| 504 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false); |
| 505 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 506 | mTextures[0].get(), 0); |
| 507 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get()); |
| 508 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGB8, 1, 1, true); |
| 509 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, |
| 510 | mTextures[1].get(), 0); |
| 511 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 512 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 513 | |
| 514 | ASSERT_GL_NO_ERROR(); |
| 515 | } |
| 516 | |
| 517 | ANGLE_INSTANTIATE_TEST(FramebufferTest_ES31, ES31_OPENGL(), ES31_OPENGLES()); |