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