Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 6 | // Framebuffer tests: |
| 7 | // Various tests related for Frambuffers. |
| 8 | // |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | |
Jonah Ryan-Davis | beb0eb2 | 2019-06-14 15:10:33 -0400 | [diff] [blame] | 10 | #include "platform/FeaturesD3D.h" |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 11 | #include "test_utils/ANGLETest.h" |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 12 | #include "test_utils/gl_raii.h" |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 13 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 14 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 15 | |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 16 | namespace |
| 17 | { |
| 18 | |
| 19 | void ExpectFramebufferCompleteOrUnsupported(GLenum binding) |
| 20 | { |
| 21 | GLenum status = glCheckFramebufferStatus(binding); |
| 22 | EXPECT_TRUE(status == GL_FRAMEBUFFER_COMPLETE || status == GL_FRAMEBUFFER_UNSUPPORTED); |
| 23 | } |
| 24 | |
| 25 | } // anonymous namespace |
| 26 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 27 | class FramebufferFormatsTest : public ANGLETest |
| 28 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 29 | protected: |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 30 | FramebufferFormatsTest() : mFramebuffer(0), mTexture(0), mRenderbuffer(0), mProgram(0) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 31 | { |
| 32 | setWindowWidth(128); |
| 33 | setWindowHeight(128); |
| 34 | setConfigRedBits(8); |
| 35 | setConfigGreenBits(8); |
| 36 | setConfigBlueBits(8); |
| 37 | setConfigAlphaBits(8); |
| 38 | } |
| 39 | |
| 40 | void checkBitCount(GLuint fbo, GLenum channel, GLint minBits) |
| 41 | { |
| 42 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 43 | |
| 44 | GLint bits = 0; |
| 45 | glGetIntegerv(channel, &bits); |
| 46 | |
| 47 | if (minBits == 0) |
| 48 | { |
| 49 | EXPECT_EQ(minBits, bits); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | EXPECT_GE(bits, minBits); |
| 54 | } |
| 55 | } |
| 56 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 57 | void testBitCounts(GLuint fbo, |
| 58 | GLint minRedBits, |
| 59 | GLint minGreenBits, |
| 60 | GLint minBlueBits, |
| 61 | GLint minAlphaBits, |
| 62 | GLint minDepthBits, |
| 63 | GLint minStencilBits) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 64 | { |
| 65 | checkBitCount(fbo, GL_RED_BITS, minRedBits); |
| 66 | checkBitCount(fbo, GL_GREEN_BITS, minGreenBits); |
| 67 | checkBitCount(fbo, GL_BLUE_BITS, minBlueBits); |
| 68 | checkBitCount(fbo, GL_ALPHA_BITS, minAlphaBits); |
| 69 | checkBitCount(fbo, GL_DEPTH_BITS, minDepthBits); |
| 70 | checkBitCount(fbo, GL_STENCIL_BITS, minStencilBits); |
| 71 | } |
| 72 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 73 | void testTextureFormat(GLenum internalFormat, |
| 74 | GLint minRedBits, |
| 75 | GLint minGreenBits, |
| 76 | GLint minBlueBits, |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 77 | GLint minAlphaBits) |
| 78 | { |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 79 | glGenTextures(1, &mTexture); |
| 80 | glBindTexture(GL_TEXTURE_2D, mTexture); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 81 | |
| 82 | if (getClientMajorVersion() >= 3) |
| 83 | { |
| 84 | glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, 1, 1); |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1); |
| 89 | } |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 90 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 91 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 92 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 93 | testBitCounts(mFramebuffer, minRedBits, minGreenBits, minBlueBits, minAlphaBits, 0, 0); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 96 | void testRenderbufferMultisampleFormat(int minESVersion, |
| 97 | GLenum attachmentType, |
| 98 | GLenum internalFormat) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 99 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 100 | int clientVersion = getClientMajorVersion(); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 101 | if (clientVersion < minESVersion) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 102 | { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | // Check that multisample is supported with at least two samples (minimum required is 1) |
| 107 | bool supports2Samples = false; |
| 108 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 109 | if (clientVersion == 2) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 110 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 111 | if (IsGLExtensionEnabled("ANGLE_framebuffer_multisample")) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 112 | { |
| 113 | int maxSamples; |
| 114 | glGetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSamples); |
| 115 | supports2Samples = maxSamples >= 2; |
| 116 | } |
| 117 | } |
| 118 | else |
| 119 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 120 | assert(clientVersion >= 3); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 121 | int maxSamples; |
| 122 | glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); |
| 123 | supports2Samples = maxSamples >= 2; |
| 124 | } |
| 125 | |
| 126 | if (!supports2Samples) |
| 127 | { |
| 128 | return; |
| 129 | } |
| 130 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 131 | glGenRenderbuffers(1, &mRenderbuffer); |
| 132 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 133 | |
| 134 | EXPECT_GL_NO_ERROR(); |
| 135 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 2, internalFormat, 128, 128); |
| 136 | EXPECT_GL_NO_ERROR(); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 137 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachmentType, GL_RENDERBUFFER, mRenderbuffer); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 138 | EXPECT_GL_NO_ERROR(); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 141 | void testZeroHeightRenderbuffer() |
| 142 | { |
| 143 | glGenRenderbuffers(1, &mRenderbuffer); |
| 144 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
| 145 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 0); |
| 146 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, |
| 147 | mRenderbuffer); |
| 148 | EXPECT_GL_NO_ERROR(); |
| 149 | } |
| 150 | |
Jamie Madill | 5cbaa3f | 2019-05-07 15:49:22 -0400 | [diff] [blame] | 151 | void testSetUp() override |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 152 | { |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 153 | glGenFramebuffers(1, &mFramebuffer); |
| 154 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Jamie Madill | 5cbaa3f | 2019-05-07 15:49:22 -0400 | [diff] [blame] | 157 | void testTearDown() override |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 158 | { |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 159 | if (mTexture != 0) |
| 160 | { |
| 161 | glDeleteTextures(1, &mTexture); |
| 162 | mTexture = 0; |
| 163 | } |
| 164 | |
| 165 | if (mRenderbuffer != 0) |
| 166 | { |
| 167 | glDeleteRenderbuffers(1, &mRenderbuffer); |
| 168 | mRenderbuffer = 0; |
| 169 | } |
| 170 | |
| 171 | if (mFramebuffer != 0) |
| 172 | { |
| 173 | glDeleteFramebuffers(1, &mFramebuffer); |
| 174 | mFramebuffer = 0; |
| 175 | } |
| 176 | |
| 177 | if (mProgram != 0) |
| 178 | { |
| 179 | glDeleteProgram(mProgram); |
| 180 | mProgram = 0; |
| 181 | } |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 182 | } |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 183 | |
| 184 | GLuint mFramebuffer; |
| 185 | GLuint mTexture; |
| 186 | GLuint mRenderbuffer; |
| 187 | GLuint mProgram; |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 188 | }; |
| 189 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 190 | TEST_P(FramebufferFormatsTest, RGBA4) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 191 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 192 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && |
| 193 | !IsGLExtensionEnabled("GL_EXT_texture_storage")); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 194 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 195 | testTextureFormat(GL_RGBA4, 4, 4, 4, 4); |
| 196 | } |
| 197 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 198 | TEST_P(FramebufferFormatsTest, RGB565) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 199 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 200 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && |
| 201 | !IsGLExtensionEnabled("GL_EXT_texture_storage")); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 202 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 203 | testTextureFormat(GL_RGB565, 5, 6, 5, 0); |
| 204 | } |
| 205 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 206 | TEST_P(FramebufferFormatsTest, RGB8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 207 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 208 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && |
| 209 | (!IsGLExtensionEnabled("GL_OES_rgb8_rgba8") || |
| 210 | !IsGLExtensionEnabled("GL_EXT_texture_storage"))); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 211 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 212 | testTextureFormat(GL_RGB8_OES, 8, 8, 8, 0); |
| 213 | } |
| 214 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 215 | TEST_P(FramebufferFormatsTest, BGRA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 216 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 217 | ANGLE_SKIP_TEST_IF( |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 218 | !IsGLExtensionEnabled("GL_EXT_texture_format_BGRA8888") || |
| 219 | (getClientMajorVersion() < 3 && !IsGLExtensionEnabled("GL_EXT_texture_storage"))); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 220 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 221 | testTextureFormat(GL_BGRA8_EXT, 8, 8, 8, 8); |
| 222 | } |
| 223 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 224 | TEST_P(FramebufferFormatsTest, RGBA8) |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 225 | { |
Jamie Madill | b814907 | 2019-04-30 16:14:44 -0400 | [diff] [blame] | 226 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && |
| 227 | (!IsGLExtensionEnabled("GL_OES_rgb8_rgba8") || |
| 228 | !IsGLExtensionEnabled("GL_EXT_texture_storage"))); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 229 | |
Geoff Lang | b6a673a | 2014-06-05 14:19:16 -0400 | [diff] [blame] | 230 | testTextureFormat(GL_RGBA8_OES, 8, 8, 8, 8); |
| 231 | } |
| 232 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 233 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH16) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 234 | { |
| 235 | testRenderbufferMultisampleFormat(2, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16); |
| 236 | } |
| 237 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 238 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 239 | { |
| 240 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24); |
| 241 | } |
| 242 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 243 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 244 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 245 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 246 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 247 | testRenderbufferMultisampleFormat(3, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32F); |
| 248 | } |
| 249 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 250 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH24_STENCIL8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 251 | { |
| 252 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH24_STENCIL8); |
| 253 | } |
| 254 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 255 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_DEPTH32F_STENCIL8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 256 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 257 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 258 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 259 | testRenderbufferMultisampleFormat(3, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH32F_STENCIL8); |
| 260 | } |
| 261 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 262 | TEST_P(FramebufferFormatsTest, RenderbufferMultisample_STENCIL_INDEX8) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 263 | { |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 264 | // TODO(geofflang): Figure out how to support GLSTENCIL_INDEX8 on desktop GL |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 265 | ANGLE_SKIP_TEST_IF(IsDesktopOpenGL()); |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 266 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 267 | testRenderbufferMultisampleFormat(2, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8); |
| 268 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 269 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 270 | // Test that binding an incomplete cube map is rejected by ANGLE. |
| 271 | TEST_P(FramebufferFormatsTest, IncompleteCubeMap) |
| 272 | { |
Michael Spang | d8506c7 | 2019-01-29 15:35:09 -0500 | [diff] [blame] | 273 | // http://anglebug.com/3145 |
| 274 | ANGLE_SKIP_TEST_IF(IsFuchsia() && IsIntel() && IsVulkan()); |
| 275 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 276 | // First make a complete CubeMap. |
| 277 | glGenTextures(1, &mTexture); |
| 278 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTexture); |
| 279 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 280 | nullptr); |
| 281 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 282 | nullptr); |
| 283 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 284 | nullptr); |
| 285 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 286 | nullptr); |
| 287 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 288 | nullptr); |
| 289 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 290 | nullptr); |
| 291 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 292 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 293 | |
| 294 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
| 295 | mTexture, 0); |
| 296 | |
| 297 | // Verify the framebuffer is complete. |
| 298 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 299 | |
| 300 | // Make the CubeMap cube-incomplete. |
| 301 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 302 | nullptr); |
| 303 | |
| 304 | // Verify the framebuffer is incomplete. |
| 305 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 306 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 307 | |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 308 | ASSERT_GL_NO_ERROR(); |
| 309 | |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 310 | // Verify drawing with the incomplete framebuffer produces a GL error |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 311 | mProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Red()); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 312 | ASSERT_NE(0u, mProgram); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 313 | drawQuad(mProgram, essl1_shaders::PositionAttrib(), 0.5f); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 314 | ASSERT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 315 | } |
| 316 | |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 317 | // Test that a renderbuffer with zero height but nonzero width is handled without crashes/asserts. |
| 318 | TEST_P(FramebufferFormatsTest, ZeroHeightRenderbuffer) |
| 319 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 320 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3); |
Olli Etuaho | bc21e18 | 2016-02-23 16:04:57 +0200 | [diff] [blame] | 321 | |
| 322 | testZeroHeightRenderbuffer(); |
| 323 | } |
| 324 | |
Geoff Lang | 9bf86f0 | 2018-07-26 11:46:34 -0400 | [diff] [blame] | 325 | // Test to cover a bug where the read framebuffer affects the completeness of the draw framebuffer. |
| 326 | TEST_P(FramebufferFormatsTest, ReadDrawCompleteness) |
| 327 | { |
| 328 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3); |
| 329 | |
| 330 | GLTexture incompleteTexture; |
| 331 | glBindTexture(GL_TEXTURE_2D, incompleteTexture); |
| 332 | |
| 333 | GLFramebuffer incompleteFBO; |
| 334 | glBindFramebuffer(GL_FRAMEBUFFER, incompleteFBO); |
| 335 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, incompleteTexture, |
| 336 | 0); |
| 337 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 338 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 339 | |
| 340 | GLTexture completeTexture; |
| 341 | glBindTexture(GL_TEXTURE_2D, completeTexture); |
| 342 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight()); |
| 343 | |
| 344 | GLFramebuffer completeFBO; |
| 345 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, completeFBO); |
| 346 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 347 | completeTexture, 0); |
| 348 | |
| 349 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 350 | glCheckFramebufferStatus(GL_READ_FRAMEBUFFER)); |
| 351 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)); |
| 352 | |
| 353 | ASSERT_GL_NO_ERROR(); |
| 354 | |
| 355 | // Simple draw program. |
| 356 | ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red()); |
| 357 | |
| 358 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 359 | EXPECT_GL_NO_ERROR(); |
| 360 | |
| 361 | glBindFramebuffer(GL_READ_FRAMEBUFFER, completeFBO); |
| 362 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 363 | } |
| 364 | |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 365 | class FramebufferTest_ES3 : public ANGLETest |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 366 | {}; |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 367 | |
| 368 | // 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] | 369 | TEST_P(FramebufferTest_ES3, InvalidateIncomplete) |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 370 | { |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 371 | // TODO: anglebug.com/3971 |
| 372 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 373 | |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 374 | GLFramebuffer framebuffer; |
| 375 | GLRenderbuffer renderbuffer; |
| 376 | |
| 377 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 378 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
| 379 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 380 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 381 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 382 | |
| 383 | std::vector<GLenum> attachments; |
| 384 | attachments.push_back(GL_COLOR_ATTACHMENT0); |
| 385 | |
| 386 | glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, attachments.data()); |
| 387 | EXPECT_GL_NO_ERROR(); |
| 388 | } |
| 389 | |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 390 | // Test that the framebuffer state tracking robustly handles a depth-only attachment being set |
| 391 | // as a depth-stencil attachment. It is equivalent to detaching the depth-stencil attachment. |
| 392 | TEST_P(FramebufferTest_ES3, DepthOnlyAsDepthStencil) |
| 393 | { |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 394 | GLFramebuffer framebuffer; |
| 395 | GLRenderbuffer renderbuffer; |
| 396 | |
| 397 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 398 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 399 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 4, 4); |
| 400 | |
| 401 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 402 | renderbuffer); |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 403 | EXPECT_GLENUM_NE(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 404 | } |
| 405 | |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 406 | // Test that the framebuffer correctly returns that it is not complete if invalid texture mip levels |
| 407 | // are bound |
| 408 | TEST_P(FramebufferTest_ES3, TextureAttachmentMipLevels) |
| 409 | { |
| 410 | GLFramebuffer framebuffer; |
| 411 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 412 | |
| 413 | GLTexture texture; |
| 414 | glBindTexture(GL_TEXTURE_2D, texture); |
| 415 | |
| 416 | // Create a complete mip chain in mips 1 to 3 |
| 417 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 418 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 419 | glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 420 | |
| 421 | // Create another complete mip chain in mips 4 to 5 |
| 422 | glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 423 | glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 424 | |
| 425 | // Create a non-complete mip chain in mip 6 |
| 426 | glTexImage2D(GL_TEXTURE_2D, 6, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 427 | |
| 428 | // Incomplete, mipLevel != baseLevel and texture is not mip complete |
| 429 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1); |
| 430 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 431 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 432 | |
| 433 | // Complete, mipLevel == baseLevel |
| 434 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 435 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 436 | |
| 437 | // Complete, mipLevel != baseLevel but texture is now mip complete |
| 438 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 2); |
| 439 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 440 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 3); |
| 441 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 442 | |
| 443 | // Incomplete, attached level below the base level |
| 444 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2); |
| 445 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1); |
| 446 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 447 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 448 | |
| 449 | // Incomplete, attached level is beyond effective max level |
| 450 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 4); |
| 451 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 452 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 453 | |
| 454 | // Complete, mipLevel == baseLevel |
| 455 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 4); |
| 456 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 457 | |
| 458 | // Complete, mipLevel != baseLevel but texture is now mip complete |
| 459 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 5); |
| 460 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 461 | |
| 462 | // Complete, mipLevel == baseLevel |
| 463 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 6); |
| 464 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 6); |
| 465 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 466 | } |
| 467 | |
Martin Radev | d178aa4 | 2017-07-13 14:03:22 +0300 | [diff] [blame] | 468 | // Test that passing an attachment COLOR_ATTACHMENTm where m is equal to MAX_COLOR_ATTACHMENTS |
| 469 | // generates an INVALID_OPERATION. |
| 470 | // OpenGL ES Version 3.0.5 (November 3, 2016), 4.4.2.4 Attaching Texture Images to a Framebuffer, p. |
| 471 | // 208 |
| 472 | TEST_P(FramebufferTest_ES3, ColorAttachmentIndexOutOfBounds) |
| 473 | { |
| 474 | GLFramebuffer framebuffer; |
| 475 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 476 | |
| 477 | GLint maxColorAttachments = 0; |
| 478 | glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); |
| 479 | GLenum attachment = static_cast<GLenum>(maxColorAttachments + GL_COLOR_ATTACHMENT0); |
| 480 | |
| 481 | GLTexture texture; |
| 482 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 483 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, 1, 1); |
| 484 | glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture.get(), 0); |
| 485 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 486 | } |
| 487 | |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 488 | // Check that depth-only attachments report the correct number of samples. |
| 489 | TEST_P(FramebufferTest_ES3, MultisampleDepthOnly) |
| 490 | { |
| 491 | GLRenderbuffer renderbuffer; |
| 492 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
| 493 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 32, 32); |
| 494 | |
| 495 | GLFramebuffer framebuffer; |
| 496 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 497 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer); |
| 498 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 499 | EXPECT_GL_NO_ERROR(); |
| 500 | |
| 501 | GLint samples = 0; |
| 502 | glGetIntegerv(GL_SAMPLES, &samples); |
| 503 | EXPECT_GL_NO_ERROR(); |
| 504 | EXPECT_GE(samples, 2); |
| 505 | } |
| 506 | |
Jeff Gilbert | 8f8edd6 | 2017-10-31 14:26:30 -0700 | [diff] [blame] | 507 | // Check that we only compare width and height of attachments, not depth. |
| 508 | TEST_P(FramebufferTest_ES3, AttachmentWith3DLayers) |
| 509 | { |
| 510 | GLTexture texA; |
| 511 | glBindTexture(GL_TEXTURE_2D, texA); |
| 512 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 513 | |
| 514 | GLTexture texB; |
| 515 | glBindTexture(GL_TEXTURE_3D, texB); |
| 516 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 517 | |
| 518 | GLFramebuffer framebuffer; |
| 519 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 520 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0); |
| 521 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, texB, 0, 0); |
| 522 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 523 | EXPECT_GL_NO_ERROR(); |
| 524 | } |
| 525 | |
Olli Etuaho | dbce1f8 | 2018-09-19 15:32:17 +0300 | [diff] [blame] | 526 | // Test that clearing the stencil buffer when the framebuffer only has a color attachment does not |
| 527 | // crash. |
| 528 | TEST_P(FramebufferTest_ES3, ClearNonexistentStencil) |
| 529 | { |
| 530 | GLRenderbuffer rbo; |
| 531 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 532 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 533 | |
| 534 | GLFramebuffer fbo; |
| 535 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 536 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 537 | |
| 538 | GLint clearValue = 0; |
| 539 | glClearBufferiv(GL_STENCIL, 0, &clearValue); |
| 540 | |
| 541 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 542 | EXPECT_GL_NO_ERROR(); |
| 543 | } |
| 544 | |
| 545 | // Test that clearing the depth buffer when the framebuffer only has a color attachment does not |
| 546 | // crash. |
| 547 | TEST_P(FramebufferTest_ES3, ClearNonexistentDepth) |
| 548 | { |
| 549 | GLRenderbuffer rbo; |
| 550 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 551 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 552 | |
| 553 | GLFramebuffer fbo; |
| 554 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 555 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 556 | |
| 557 | GLfloat clearValue = 0.0f; |
| 558 | glClearBufferfv(GL_DEPTH, 0, &clearValue); |
| 559 | |
| 560 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 561 | EXPECT_GL_NO_ERROR(); |
| 562 | } |
| 563 | |
| 564 | // Test that clearing a nonexistent color attachment does not crash. |
| 565 | TEST_P(FramebufferTest_ES3, ClearNonexistentColor) |
| 566 | { |
| 567 | GLRenderbuffer rbo; |
| 568 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 569 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 570 | |
| 571 | GLFramebuffer fbo; |
| 572 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 573 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 574 | |
| 575 | std::vector<GLfloat> clearValue = {{0.0f, 1.0f, 0.0f, 1.0f}}; |
| 576 | glClearBufferfv(GL_COLOR, 1, clearValue.data()); |
| 577 | |
| 578 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 579 | EXPECT_GL_NO_ERROR(); |
| 580 | } |
| 581 | |
| 582 | // Test that clearing the depth and stencil buffers when the framebuffer only has a color attachment |
| 583 | // does not crash. |
| 584 | TEST_P(FramebufferTest_ES3, ClearNonexistentDepthStencil) |
| 585 | { |
| 586 | GLRenderbuffer rbo; |
| 587 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 588 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 589 | |
| 590 | GLFramebuffer fbo; |
| 591 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 592 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 593 | |
| 594 | glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.0f, 0); |
| 595 | |
| 596 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 597 | EXPECT_GL_NO_ERROR(); |
| 598 | } |
| 599 | |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 600 | // Test that clearing a color attachment that has been deleted doesn't crash. |
| 601 | TEST_P(FramebufferTest_ES3, ClearDeletedAttachment) |
| 602 | { |
| 603 | // An INVALID_FRAMEBUFFER_OPERATION error was seen in this test on Mac, not sure where it might |
| 604 | // be originating from. http://anglebug.com/2834 |
| 605 | ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL()); |
| 606 | |
| 607 | GLFramebuffer fbo; |
| 608 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 609 | |
| 610 | // There used to be a bug where some draw buffer state used to remain set even after the |
| 611 | // attachment was detached via deletion. That's why we create, attach and delete this RBO here. |
| 612 | GLuint rbo = 0u; |
| 613 | glGenRenderbuffers(1, &rbo); |
| 614 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 615 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 616 | glDeleteRenderbuffers(1, &rbo); |
| 617 | |
| 618 | // There needs to be at least one color attachment to prevent early out from the clear calls. |
| 619 | GLRenderbuffer rbo2; |
| 620 | glBindRenderbuffer(GL_RENDERBUFFER, rbo2); |
| 621 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 622 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rbo2); |
| 623 | |
| 624 | ASSERT_GL_NO_ERROR(); |
| 625 | |
| 626 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op, so we |
| 627 | // expect no GL errors below. |
| 628 | std::array<GLfloat, 4> floatClearValue = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 629 | glClearBufferfv(GL_COLOR, 0, floatClearValue.data()); |
| 630 | EXPECT_GL_NO_ERROR(); |
| 631 | std::array<GLuint, 4> uintClearValue = {0u, 0u, 0u, 0u}; |
| 632 | glClearBufferuiv(GL_COLOR, 0, uintClearValue.data()); |
| 633 | EXPECT_GL_NO_ERROR(); |
| 634 | std::array<GLint, 4> intClearValue = {0, 0, 0, 0}; |
| 635 | glClearBufferiv(GL_COLOR, 0, intClearValue.data()); |
| 636 | EXPECT_GL_NO_ERROR(); |
| 637 | } |
| 638 | |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 639 | // Test that resizing the color attachment is handled correctly. |
| 640 | TEST_P(FramebufferTest_ES3, ResizeColorAttachmentSmallToLarge) |
| 641 | { |
| 642 | GLFramebuffer fbo; |
| 643 | GLTexture smallTexture; |
| 644 | GLTexture largeTexture; |
| 645 | |
| 646 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 647 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 648 | |
| 649 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 650 | |
| 651 | // Bind the small texture |
| 652 | glBindTexture(GL_TEXTURE_2D, smallTexture); |
| 653 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 654 | GL_UNSIGNED_BYTE, nullptr); |
| 655 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 656 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 657 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, smallTexture, 0); |
| 658 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 659 | |
| 660 | // Draw to FBO backed by the small texture |
| 661 | glUseProgram(greenProgram); |
| 662 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 663 | ASSERT_GL_NO_ERROR(); |
| 664 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 665 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 666 | |
| 667 | // Change the attachment to the larger texture that fills the window |
| 668 | glBindTexture(GL_TEXTURE_2D, largeTexture); |
| 669 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 670 | GL_UNSIGNED_BYTE, nullptr); |
| 671 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 672 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 673 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, largeTexture, 0); |
| 674 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 675 | |
| 676 | // Draw to FBO backed by the large texture |
| 677 | glUseProgram(blueProgram); |
| 678 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 679 | ASSERT_GL_NO_ERROR(); |
| 680 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 681 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::blue); |
| 682 | } |
| 683 | |
| 684 | // Test that resizing the color attachment is handled correctly. |
| 685 | TEST_P(FramebufferTest_ES3, ResizeColorAttachmentLargeToSmall) |
| 686 | { |
| 687 | GLFramebuffer fbo; |
| 688 | GLTexture smallTexture; |
| 689 | GLTexture largeTexture; |
| 690 | |
| 691 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 692 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 693 | |
| 694 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 695 | |
| 696 | // Bind the large texture |
| 697 | glBindTexture(GL_TEXTURE_2D, largeTexture); |
| 698 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 699 | GL_UNSIGNED_BYTE, nullptr); |
| 700 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 701 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 702 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, largeTexture, 0); |
| 703 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 704 | |
| 705 | // Draw to FBO backed by the large texture |
| 706 | glUseProgram(blueProgram); |
| 707 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 708 | ASSERT_GL_NO_ERROR(); |
| 709 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 710 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::blue); |
| 711 | |
| 712 | // Change the attachment to the smaller texture |
| 713 | glBindTexture(GL_TEXTURE_2D, smallTexture); |
| 714 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 715 | GL_UNSIGNED_BYTE, nullptr); |
| 716 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 717 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 718 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, smallTexture, 0); |
| 719 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 720 | |
| 721 | // Draw to FBO backed by the small texture |
| 722 | glUseProgram(greenProgram); |
| 723 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 724 | ASSERT_GL_NO_ERROR(); |
| 725 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 726 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 727 | } |
| 728 | |
| 729 | // Test that resizing the texture is handled correctly. |
| 730 | TEST_P(FramebufferTest_ES3, ResizeTextureLargeToSmall) |
| 731 | { |
| 732 | GLFramebuffer fbo; |
| 733 | GLTexture texture; |
| 734 | |
| 735 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 736 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 737 | |
| 738 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 739 | |
| 740 | // Allocate a large texture |
| 741 | glBindTexture(GL_TEXTURE_2D, texture); |
| 742 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 743 | GL_UNSIGNED_BYTE, nullptr); |
| 744 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 745 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 746 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 747 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 748 | |
| 749 | // Draw to FBO backed by the large texture |
| 750 | glUseProgram(blueProgram); |
| 751 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 752 | ASSERT_GL_NO_ERROR(); |
| 753 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 754 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::blue); |
| 755 | |
| 756 | // Shrink the texture |
| 757 | glBindTexture(GL_TEXTURE_2D, texture); |
| 758 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 759 | GL_UNSIGNED_BYTE, nullptr); |
| 760 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 761 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 762 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 763 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 764 | |
| 765 | // Draw to FBO backed by the small texture |
| 766 | glUseProgram(greenProgram); |
| 767 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 768 | ASSERT_GL_NO_ERROR(); |
| 769 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 770 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 771 | } |
| 772 | |
| 773 | // Test that resizing the texture is handled correctly. |
| 774 | TEST_P(FramebufferTest_ES3, ResizeTextureSmallToLarge) |
| 775 | { |
| 776 | GLFramebuffer fbo; |
| 777 | GLTexture texture; |
| 778 | |
| 779 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 780 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 781 | |
| 782 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 783 | |
| 784 | // Allocate a small texture |
| 785 | glBindTexture(GL_TEXTURE_2D, texture); |
| 786 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 787 | GL_UNSIGNED_BYTE, nullptr); |
| 788 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 789 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 790 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 791 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 792 | |
| 793 | // Draw to FBO backed by the large texture |
| 794 | glUseProgram(blueProgram); |
| 795 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 796 | ASSERT_GL_NO_ERROR(); |
| 797 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 798 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::blue); |
| 799 | |
| 800 | // Grow the texture |
| 801 | glBindTexture(GL_TEXTURE_2D, texture); |
| 802 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 803 | GL_UNSIGNED_BYTE, nullptr); |
| 804 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 805 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 806 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 807 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 808 | |
| 809 | // Draw to FBO backed by the small texture |
| 810 | glUseProgram(greenProgram); |
| 811 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 812 | ASSERT_GL_NO_ERROR(); |
| 813 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 814 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green); |
| 815 | } |
| 816 | |
Shahbaz Youssefi | e28883d | 2020-01-25 23:25:43 -0500 | [diff] [blame] | 817 | // Test that fewer outputs than framebuffer attachments doesn't crash. This causes a Vulkan |
| 818 | // validation warning, but should not be fatal. |
| 819 | TEST_P(FramebufferTest_ES3, FewerShaderOutputsThanAttachments) |
| 820 | { |
| 821 | constexpr char kFS[] = R"(#version 300 es |
| 822 | precision highp float; |
| 823 | |
| 824 | layout(location = 0) out vec4 color0; |
| 825 | layout(location = 1) out vec4 color1; |
| 826 | layout(location = 2) out vec4 color2; |
| 827 | |
| 828 | void main() |
| 829 | { |
| 830 | color0 = vec4(1.0, 0.0, 0.0, 1.0); |
| 831 | color1 = vec4(0.0, 1.0, 0.0, 1.0); |
| 832 | color2 = vec4(0.0, 0.0, 1.0, 1.0); |
| 833 | } |
| 834 | )"; |
| 835 | |
| 836 | ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); |
| 837 | |
| 838 | constexpr GLint kDrawBufferCount = 4; |
| 839 | |
| 840 | GLint maxDrawBuffers; |
| 841 | glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); |
| 842 | ASSERT_GE(maxDrawBuffers, kDrawBufferCount); |
| 843 | |
| 844 | GLTexture textures[kDrawBufferCount]; |
| 845 | |
| 846 | for (GLint texIndex = 0; texIndex < kDrawBufferCount; ++texIndex) |
| 847 | { |
| 848 | glBindTexture(GL_TEXTURE_2D, textures[texIndex]); |
| 849 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 850 | GL_UNSIGNED_BYTE, nullptr); |
| 851 | } |
| 852 | |
| 853 | GLenum allBufs[kDrawBufferCount] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, |
| 854 | GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3}; |
| 855 | |
| 856 | GLFramebuffer fbo; |
| 857 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); |
| 858 | |
| 859 | // Enable all draw buffers. |
| 860 | for (GLint texIndex = 0; texIndex < kDrawBufferCount; ++texIndex) |
| 861 | { |
| 862 | glBindTexture(GL_TEXTURE_2D, textures[texIndex]); |
| 863 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + texIndex, GL_TEXTURE_2D, |
| 864 | textures[texIndex], 0); |
| 865 | } |
| 866 | glDrawBuffers(kDrawBufferCount, allBufs); |
| 867 | |
| 868 | // Draw with simple program. |
| 869 | drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 870 | ASSERT_GL_NO_ERROR(); |
| 871 | } |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 872 | |
| 873 | class FramebufferTest_ES31 : public ANGLETest |
| 874 | { |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 875 | protected: |
| 876 | void validateSamplePass(GLuint &query, GLuint &passedCount, GLint width, GLint height) |
| 877 | { |
| 878 | glUniform2i(0, width - 1, height - 1); |
| 879 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 880 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 881 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 882 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 883 | EXPECT_GT(static_cast<GLint>(passedCount), 0); |
| 884 | |
| 885 | glUniform2i(0, width - 1, height); |
| 886 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 887 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 888 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 889 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 890 | EXPECT_EQ(static_cast<GLint>(passedCount), 0); |
| 891 | |
| 892 | glUniform2i(0, width, height - 1); |
| 893 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 894 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 895 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 896 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 897 | EXPECT_EQ(static_cast<GLint>(passedCount), 0); |
| 898 | } |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 899 | }; |
| 900 | |
| 901 | // Test that without attachment, if either the value of FRAMEBUFFER_DEFAULT_WIDTH or |
| 902 | // FRAMEBUFFER_DEFAULT_HEIGHT parameters is zero, the framebuffer is incomplete. |
| 903 | TEST_P(FramebufferTest_ES31, IncompleteMissingAttachmentDefaultParam) |
| 904 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 905 | // anglebug.com/3565 |
| 906 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 907 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 908 | GLFramebuffer mFramebuffer; |
| 909 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 910 | |
| 911 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1); |
| 912 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1); |
| 913 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 914 | |
| 915 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0); |
| 916 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0); |
| 917 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 918 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 919 | |
| 920 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1); |
| 921 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0); |
| 922 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 923 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 924 | |
| 925 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0); |
| 926 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1); |
| 927 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 928 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 929 | |
| 930 | ASSERT_GL_NO_ERROR(); |
| 931 | } |
| 932 | |
| 933 | // Test that the sample count of a mix of texture and renderbuffer should be same. |
| 934 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountMix) |
| 935 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 936 | // anglebug.com/3565 |
| 937 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 938 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 939 | GLFramebuffer mFramebuffer; |
| 940 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 941 | |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 942 | // Lookup the supported number of sample counts (rely on fact that ANGLE uses the same set of |
| 943 | // sample counts for textures and renderbuffers) |
| 944 | GLint numSampleCounts = 0; |
| 945 | std::vector<GLint> sampleCounts; |
| 946 | GLsizei queryBufferSize = 1; |
| 947 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, |
| 948 | queryBufferSize, &numSampleCounts); |
| 949 | ANGLE_SKIP_TEST_IF((numSampleCounts < 2)); |
| 950 | sampleCounts.resize(numSampleCounts); |
| 951 | queryBufferSize = numSampleCounts; |
| 952 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_SAMPLES, queryBufferSize, |
| 953 | sampleCounts.data()); |
| 954 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 955 | GLTexture mTexture; |
| 956 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get()); |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 957 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleCounts[0], GL_RGBA8, 1, 1, true); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 958 | |
| 959 | GLRenderbuffer mRenderbuffer; |
| 960 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get()); |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 961 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCounts[1], GL_RGBA8, 1, 1); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 962 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 963 | mTexture.get(), 0); |
| 964 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, |
| 965 | mRenderbuffer.get()); |
| 966 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 967 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 968 | |
| 969 | ASSERT_GL_NO_ERROR(); |
| 970 | } |
| 971 | |
| 972 | // Test that the sample count of texture attachments should be same. |
| 973 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountTex) |
| 974 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 975 | // anglebug.com/3565 |
| 976 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 977 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 978 | GLFramebuffer mFramebuffer; |
| 979 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 980 | |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 981 | // Lookup the supported number of sample counts |
| 982 | GLint numSampleCounts = 0; |
| 983 | std::vector<GLint> sampleCounts; |
| 984 | GLsizei queryBufferSize = 1; |
| 985 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, |
| 986 | queryBufferSize, &numSampleCounts); |
| 987 | ANGLE_SKIP_TEST_IF((numSampleCounts < 2)); |
| 988 | sampleCounts.resize(numSampleCounts); |
| 989 | queryBufferSize = numSampleCounts; |
| 990 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_SAMPLES, queryBufferSize, |
| 991 | sampleCounts.data()); |
| 992 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 993 | GLTexture mTextures[2]; |
| 994 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get()); |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 995 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleCounts[0], GL_RGBA8, 1, 1, true); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 996 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get()); |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 997 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleCounts[1], GL_RGBA8, 1, 1, true); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 998 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 999 | mTextures[0].get(), 0); |
| 1000 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, |
| 1001 | mTextures[1].get(), 0); |
| 1002 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 1003 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1004 | |
| 1005 | ASSERT_GL_NO_ERROR(); |
| 1006 | } |
| 1007 | |
| 1008 | // Test that if the attached images are a mix of renderbuffers and textures, the value of |
| 1009 | // TEXTURE_FIXED_SAMPLE_LOCATIONS must be TRUE for all attached textures. |
| 1010 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsMix) |
| 1011 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1012 | // anglebug.com/3565 |
| 1013 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 1014 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1015 | GLFramebuffer mFramebuffer; |
| 1016 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 1017 | |
| 1018 | GLTexture mTexture; |
| 1019 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get()); |
| 1020 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false); |
| 1021 | |
| 1022 | GLRenderbuffer mRenderbuffer; |
| 1023 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get()); |
| 1024 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 1, GL_RGBA8, 1, 1); |
| 1025 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 1026 | mTexture.get(), 0); |
| 1027 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, |
| 1028 | mRenderbuffer.get()); |
| 1029 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 1030 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1031 | |
| 1032 | ASSERT_GL_NO_ERROR(); |
| 1033 | } |
| 1034 | |
| 1035 | // Test that the value of TEXTURE_FIXED_SAMPLE_LOCATIONS is the same for all attached textures. |
| 1036 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsTex) |
| 1037 | { |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1038 | // anglebug.com/3565 |
| 1039 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 1040 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1041 | GLFramebuffer mFramebuffer; |
| 1042 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 1043 | |
| 1044 | GLTexture mTextures[2]; |
| 1045 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get()); |
| 1046 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false); |
| 1047 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 1048 | mTextures[0].get(), 0); |
| 1049 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get()); |
| 1050 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGB8, 1, 1, true); |
| 1051 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, |
| 1052 | mTextures[1].get(), 0); |
| 1053 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 1054 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1055 | |
| 1056 | ASSERT_GL_NO_ERROR(); |
| 1057 | } |
| 1058 | |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1059 | // If there are no attachments, rendering will be limited to a rectangle having a lower left of |
| 1060 | // (0, 0) and an upper right of(width, height), where width and height are the framebuffer |
| 1061 | // object's default width and height. |
JiangYizhou | 3db4072 | 2017-08-28 17:59:13 +0800 | [diff] [blame] | 1062 | TEST_P(FramebufferTest_ES31, RenderingLimitToDefaultFBOSizeWithNoAttachments) |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1063 | { |
Yuly Novikov | 98f9f53 | 2017-11-15 19:16:19 -0500 | [diff] [blame] | 1064 | // anglebug.com/2253 |
| 1065 | ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL()); |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1066 | // Occlusion query reports fragments outside the render area are still rendered |
| 1067 | ANGLE_SKIP_TEST_IF(IsAndroid() || (IsWindows() && (IsIntel() || IsAMD()))); |
Yuly Novikov | 98f9f53 | 2017-11-15 19:16:19 -0500 | [diff] [blame] | 1068 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1069 | constexpr char kVS1[] = R"(#version 310 es |
| 1070 | in layout(location = 0) highp vec2 a_position; |
| 1071 | void main() |
| 1072 | { |
| 1073 | gl_Position = vec4(a_position, 0.0, 1.0); |
| 1074 | })"; |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1075 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1076 | constexpr char kFS1[] = R"(#version 310 es |
| 1077 | uniform layout(location = 0) highp ivec2 u_expectedSize; |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1078 | out layout(location = 3) mediump vec4 f_color; |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1079 | void main() |
| 1080 | { |
| 1081 | if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; |
| 1082 | f_color = vec4(1.0, 0.5, 0.25, 1.0); |
| 1083 | })"; |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1084 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1085 | constexpr char kVS2[] = R"(#version 310 es |
| 1086 | in layout(location = 0) highp vec2 a_position; |
| 1087 | void main() |
| 1088 | { |
| 1089 | gl_Position = vec4(a_position, 0.0, 1.0); |
| 1090 | })"; |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1091 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1092 | constexpr char kFS2[] = R"(#version 310 es |
| 1093 | uniform layout(location = 0) highp ivec2 u_expectedSize; |
| 1094 | out layout(location = 2) mediump vec4 f_color; |
| 1095 | void main() |
| 1096 | { |
| 1097 | if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; |
| 1098 | f_color = vec4(1.0, 0.5, 0.25, 1.0); |
| 1099 | })"; |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1100 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1101 | GLuint program1 = CompileProgram(kVS1, kFS1); |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1102 | ASSERT_NE(program1, 0u); |
| 1103 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1104 | GLuint program2 = CompileProgram(kVS2, kFS2); |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1105 | ASSERT_NE(program2, 0u); |
| 1106 | |
| 1107 | glUseProgram(program1); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1108 | |
| 1109 | GLFramebuffer mFramebuffer; |
| 1110 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer); |
| 1111 | GLuint defaultWidth = 1; |
| 1112 | GLuint defaultHeight = 1; |
| 1113 | |
| 1114 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, defaultWidth); |
| 1115 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, defaultHeight); |
| 1116 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1117 | |
| 1118 | const float data[] = { |
| 1119 | 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, |
| 1120 | }; |
| 1121 | |
| 1122 | GLuint vertexArray = 0; |
| 1123 | GLuint vertexBuffer = 0; |
| 1124 | GLuint query = 0; |
| 1125 | GLuint passedCount = 0; |
| 1126 | |
| 1127 | glGenQueries(1, &query); |
| 1128 | glGenVertexArrays(1, &vertexArray); |
| 1129 | glBindVertexArray(vertexArray); |
| 1130 | |
| 1131 | glGenBuffers(1, &vertexBuffer); |
| 1132 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); |
| 1133 | glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); |
| 1134 | |
| 1135 | glEnableVertexAttribArray(0); |
| 1136 | glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1137 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1138 | |
| 1139 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1140 | |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1141 | glUseProgram(program2); |
| 1142 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1143 | |
| 1144 | glUseProgram(program1); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1145 | // If fbo has attachments, the rendering size should be the same as its attachment. |
| 1146 | GLTexture mTexture; |
| 1147 | GLuint width = 2; |
| 1148 | GLuint height = 2; |
| 1149 | glBindTexture(GL_TEXTURE_2D, mTexture.get()); |
| 1150 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1151 | |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1152 | const GLenum bufs[] = {GL_NONE, GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT3}; |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1153 | |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1154 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, mTexture.get(), |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1155 | 0); |
| 1156 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1157 | glDrawBuffers(4, bufs); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1158 | |
| 1159 | validateSamplePass(query, passedCount, width, height); |
| 1160 | |
| 1161 | // If fbo's attachment has been removed, the rendering size should be the same as framebuffer |
| 1162 | // default size. |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1163 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, 0, 0, 0); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1164 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1165 | |
| 1166 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1167 | |
| 1168 | glDisableVertexAttribArray(0); |
| 1169 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 1170 | glBindVertexArray(0); |
| 1171 | glDeleteBuffers(1, &vertexBuffer); |
| 1172 | glDeleteVertexArrays(1, &vertexArray); |
| 1173 | |
| 1174 | ASSERT_GL_NO_ERROR(); |
| 1175 | } |
| 1176 | |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1177 | class AddDummyTextureNoRenderTargetTest : public ANGLETest |
| 1178 | { |
| 1179 | public: |
| 1180 | AddDummyTextureNoRenderTargetTest() |
| 1181 | { |
| 1182 | setWindowWidth(512); |
| 1183 | setWindowHeight(512); |
| 1184 | setConfigRedBits(8); |
| 1185 | setConfigGreenBits(8); |
| 1186 | setConfigBlueBits(8); |
| 1187 | setConfigAlphaBits(8); |
| 1188 | } |
| 1189 | |
Jonah Ryan-Davis | eee67c6 | 2019-06-18 13:00:43 -0400 | [diff] [blame] | 1190 | void overrideWorkaroundsD3D(FeaturesD3D *features) override |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1191 | { |
Jonah Ryan-Davis | beb0eb2 | 2019-06-14 15:10:33 -0400 | [diff] [blame] | 1192 | features->overrideFeatures({"add_dummy_texture_no_render_target"}, true); |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1193 | } |
| 1194 | }; |
| 1195 | |
| 1196 | // Test to verify workaround succeeds when no program outputs exist http://anglebug.com/2283 |
| 1197 | TEST_P(AddDummyTextureNoRenderTargetTest, NoProgramOutputWorkaround) |
| 1198 | { |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1199 | constexpr char kVS[] = "void main() {}"; |
| 1200 | constexpr char kFS[] = "void main() {}"; |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1201 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1202 | ANGLE_GL_PROGRAM(drawProgram, kVS, kFS); |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1203 | |
| 1204 | glUseProgram(drawProgram); |
| 1205 | |
| 1206 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 1207 | |
| 1208 | ASSERT_GL_NO_ERROR(); |
| 1209 | } |
| 1210 | |
Jamie Madill | 4fb3c28 | 2020-03-19 19:10:45 -0400 | [diff] [blame] | 1211 | // Covers a bug in ANGLE's Vulkan back-end framebuffer cache which ignored depth/stencil after |
| 1212 | // calls to DrawBuffers. |
| 1213 | TEST_P(FramebufferTest_ES3, AttachmentStateChange) |
| 1214 | { |
| 1215 | constexpr GLuint kSize = 2; |
| 1216 | |
| 1217 | ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 1218 | |
| 1219 | GLTexture colorTexture; |
| 1220 | glBindTexture(GL_TEXTURE_2D, colorTexture); |
| 1221 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1222 | |
| 1223 | GLFramebuffer fbo; |
| 1224 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1225 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0); |
| 1226 | |
| 1227 | ASSERT_GL_NO_ERROR(); |
| 1228 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1229 | |
| 1230 | // First draw without a depth buffer. |
| 1231 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f); |
| 1232 | |
| 1233 | GLRenderbuffer depthBuffer; |
| 1234 | glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer); |
| 1235 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, kSize, kSize); |
| 1236 | |
| 1237 | // Bind just a renderbuffer and draw. |
| 1238 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer); |
| 1239 | |
| 1240 | ASSERT_GL_NO_ERROR(); |
| 1241 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1242 | |
| 1243 | glDrawBuffers(0, nullptr); |
| 1244 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f); |
| 1245 | |
| 1246 | // Re-enable color buffer and draw one final time. This previously triggered a crash. |
| 1247 | GLenum drawBuffs = {GL_COLOR_ATTACHMENT0}; |
| 1248 | glDrawBuffers(1, &drawBuffs); |
| 1249 | |
| 1250 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f); |
| 1251 | ASSERT_GL_NO_ERROR(); |
| 1252 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1253 | } |
| 1254 | |
Jamie Madill | d03b15b | 2020-03-26 17:22:18 -0400 | [diff] [blame] | 1255 | // Tests that we can support a feedback loop between a depth textures and the depth buffer. |
| 1256 | // Does not totally mirror the case used in Manhattan. The Manhattan case seems to handle |
| 1257 | // "clear" specially instead of rendering to depth in the same RP. |
| 1258 | TEST_P(FramebufferTest_ES3, DepthFeedbackLoopSupported) |
| 1259 | { |
| 1260 | // Feedback loops not supported on D3D11 and may not ever be. |
| 1261 | ANGLE_SKIP_TEST_IF(IsD3D11()); |
| 1262 | |
| 1263 | // Also this particular test doesn't work on Android despite similar support in Manhattan. |
| 1264 | ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES()); |
| 1265 | |
| 1266 | constexpr GLuint kSize = 2; |
| 1267 | glViewport(0, 0, kSize, kSize); |
| 1268 | |
| 1269 | constexpr char kFS[] = R"(precision mediump float; |
| 1270 | varying vec2 v_texCoord; |
| 1271 | uniform sampler2D depth; |
| 1272 | void main() |
| 1273 | { |
| 1274 | if (abs(texture2D(depth, v_texCoord).x - 0.5) < 0.1) |
| 1275 | { |
| 1276 | gl_FragColor = vec4(0, 1, 0, 1); |
| 1277 | } |
| 1278 | else |
| 1279 | { |
| 1280 | gl_FragColor = vec4(1, 0, 0, 1); |
| 1281 | } |
| 1282 | })"; |
| 1283 | |
| 1284 | ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Texture2D(), kFS); |
| 1285 | |
| 1286 | GLFramebuffer framebuffer; |
| 1287 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 1288 | |
| 1289 | GLTexture colorTexture; |
| 1290 | glBindTexture(GL_TEXTURE_2D, colorTexture); |
| 1291 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1292 | |
| 1293 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1294 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1295 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0); |
| 1296 | |
| 1297 | GLTexture depthTexture; |
| 1298 | glBindTexture(GL_TEXTURE_2D, depthTexture); |
| 1299 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, kSize, kSize, 0, GL_DEPTH_COMPONENT, |
| 1300 | GL_UNSIGNED_INT, nullptr); |
| 1301 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1302 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1303 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0); |
| 1304 | |
| 1305 | ASSERT_GL_NO_ERROR(); |
| 1306 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1307 | |
| 1308 | // Clear depth to 0.5. |
| 1309 | glClearDepthf(0.5f); |
| 1310 | glClear(GL_DEPTH_BUFFER_BIT); |
| 1311 | |
| 1312 | // Disable the depth mask. Although this does not remove the feedback loop as defined by the |
| 1313 | // spec it mimics what gfxbench does in its rendering tests. |
| 1314 | glDepthMask(false); |
| 1315 | |
| 1316 | // Verify we can sample the depth texture and get 0.5. |
| 1317 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5); |
| 1318 | |
| 1319 | ASSERT_GL_NO_ERROR(); |
| 1320 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1321 | } |
| 1322 | |
Jamie Madill | dd00f16 | 2020-04-02 14:04:44 -0400 | [diff] [blame] | 1323 | // Covers a bug in ANGLE's Vulkan back-end. Our VkFramebuffer cache would in some cases forget to |
| 1324 | // check the draw states when computing a cache key. |
| 1325 | TEST_P(FramebufferTest_ES3, DisabledAttachmentRedefinition) |
| 1326 | { |
| 1327 | constexpr GLuint kSize = 2; |
| 1328 | |
| 1329 | // Make a Framebuffer with two attachments with one enabled and one disabled. |
| 1330 | GLTexture texA, texB; |
| 1331 | glBindTexture(GL_TEXTURE_2D, texA); |
| 1332 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1333 | glBindTexture(GL_TEXTURE_2D, texB); |
| 1334 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1335 | |
| 1336 | GLFramebuffer fbo; |
| 1337 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1338 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0); |
| 1339 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texB, 0); |
| 1340 | |
| 1341 | // Mask out the second texture. |
| 1342 | constexpr GLenum kOneDrawBuf = GL_COLOR_ATTACHMENT0; |
| 1343 | glDrawBuffers(1, &kOneDrawBuf); |
| 1344 | |
| 1345 | ASSERT_GL_NO_ERROR(); |
| 1346 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1347 | |
| 1348 | // Set up a very simple shader. |
| 1349 | ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 1350 | glViewport(0, 0, kSize, kSize); |
| 1351 | |
| 1352 | // Draw |
| 1353 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 1354 | ASSERT_GL_NO_ERROR(); |
| 1355 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1356 | |
| 1357 | // Update the masked out attachment and draw again. |
| 1358 | std::vector<GLColor> redPixels(kSize * kSize, GLColor::red); |
| 1359 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kSize, kSize, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1360 | redPixels.data()); |
| 1361 | |
| 1362 | // Draw |
| 1363 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 1364 | ASSERT_GL_NO_ERROR(); |
| 1365 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1366 | |
| 1367 | glReadBuffer(GL_COLOR_ATTACHMENT1); |
| 1368 | ASSERT_GL_NO_ERROR(); |
| 1369 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 1370 | } |
| 1371 | |
Jamie Madill | c9c4e4e | 2020-04-02 10:29:52 -0400 | [diff] [blame^] | 1372 | class FramebufferTest : public ANGLETest |
| 1373 | {}; |
| 1374 | |
| 1375 | template <typename T> |
| 1376 | void FillTexture2D(GLuint texture, |
| 1377 | GLsizei width, |
| 1378 | GLsizei height, |
| 1379 | const T &onePixelData, |
| 1380 | GLint level, |
| 1381 | GLint internalFormat, |
| 1382 | GLenum format, |
| 1383 | GLenum type) |
| 1384 | { |
| 1385 | std::vector<T> allPixelsData(width * height, onePixelData); |
| 1386 | |
| 1387 | glBindTexture(GL_TEXTURE_2D, texture); |
| 1388 | glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, |
| 1389 | allPixelsData.data()); |
| 1390 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1391 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1392 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1393 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1394 | } |
| 1395 | |
| 1396 | // Multi-context uses of textures should not cause rendering feedback loops. |
| 1397 | TEST_P(FramebufferTest, MultiContextNoRenderingFeedbackLoops) |
| 1398 | { |
| 1399 | constexpr char kTextureVS[] = |
| 1400 | R"(attribute vec4 a_position; |
| 1401 | varying vec2 v_texCoord; |
| 1402 | void main() { |
| 1403 | gl_Position = a_position; |
| 1404 | v_texCoord = (a_position.xy * 0.5) + 0.5; |
| 1405 | })"; |
| 1406 | |
| 1407 | constexpr char kTextureFS[] = |
| 1408 | R"(precision mediump float; |
| 1409 | varying vec2 v_texCoord; |
| 1410 | uniform sampler2D u_texture; |
| 1411 | void main() { |
| 1412 | gl_FragColor = texture2D(u_texture, v_texCoord).rgba; |
| 1413 | })"; |
| 1414 | |
| 1415 | ANGLE_GL_PROGRAM(textureProgram, kTextureVS, kTextureFS); |
| 1416 | |
| 1417 | glUseProgram(textureProgram.get()); |
| 1418 | GLint uniformLoc = glGetUniformLocation(textureProgram.get(), "u_texture"); |
| 1419 | ASSERT_NE(-1, uniformLoc); |
| 1420 | glUniform1i(uniformLoc, 0); |
| 1421 | |
| 1422 | GLTexture texture; |
| 1423 | FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 1424 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 1425 | // Note that _texture_ is still bound to GL_TEXTURE_2D in this context at this point. |
| 1426 | |
| 1427 | EGLWindow *window = getEGLWindow(); |
| 1428 | EGLDisplay display = window->getDisplay(); |
| 1429 | EGLConfig config = window->getConfig(); |
| 1430 | EGLSurface surface = window->getSurface(); |
| 1431 | EGLint contextAttributes[] = { |
| 1432 | EGL_CONTEXT_MAJOR_VERSION_KHR, |
| 1433 | GetParam().majorVersion, |
| 1434 | EGL_CONTEXT_MINOR_VERSION_KHR, |
| 1435 | GetParam().minorVersion, |
| 1436 | EGL_NONE, |
| 1437 | }; |
| 1438 | EGLContext context1 = eglGetCurrentContext(); |
| 1439 | // Create context2, sharing resources with context1. |
| 1440 | EGLContext context2 = eglCreateContext(display, config, context1, contextAttributes); |
| 1441 | ASSERT_NE(context2, EGL_NO_CONTEXT); |
| 1442 | eglMakeCurrent(display, surface, surface, context2); |
| 1443 | |
| 1444 | constexpr char kVS[] = |
| 1445 | R"(attribute vec4 a_position; |
| 1446 | void main() { |
| 1447 | gl_Position = a_position; |
| 1448 | })"; |
| 1449 | |
| 1450 | constexpr char kFS[] = |
| 1451 | R"(precision mediump float; |
| 1452 | void main() { |
| 1453 | gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); |
| 1454 | })"; |
| 1455 | |
| 1456 | ANGLE_GL_PROGRAM(program, kVS, kFS); |
| 1457 | glUseProgram(program.get()); |
| 1458 | |
| 1459 | ASSERT_GL_NO_ERROR(); |
| 1460 | |
| 1461 | // Render to the texture in context2. |
| 1462 | GLFramebuffer framebuffer; |
| 1463 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1464 | // Texture is still a valid name in context2. |
| 1465 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
| 1466 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1467 | // There is no rendering feedback loop at this point. |
| 1468 | |
| 1469 | glDisable(GL_BLEND); |
| 1470 | glDisable(GL_DEPTH_TEST); |
| 1471 | ASSERT_GL_NO_ERROR(); |
| 1472 | |
| 1473 | // If draw is no-op'ed, texture will not be filled appropriately. |
| 1474 | drawQuad(program.get(), "a_position", 0.5f, 1.0f, true); |
| 1475 | ASSERT_GL_NO_ERROR(); |
| 1476 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1477 | |
| 1478 | // Make context1 current again. |
| 1479 | eglMakeCurrent(display, surface, surface, context1); |
| 1480 | |
| 1481 | // Render texture to screen. |
| 1482 | drawQuad(textureProgram.get(), "a_position", 0.5f, 1.0f, true); |
| 1483 | ASSERT_GL_NO_ERROR(); |
| 1484 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1485 | |
| 1486 | eglDestroyContext(display, context2); |
| 1487 | } |
| 1488 | |
Tobin Ehlis | 1a01b4b | 2019-11-11 16:41:07 -0700 | [diff] [blame] | 1489 | ANGLE_INSTANTIATE_TEST_ES2(AddDummyTextureNoRenderTargetTest); |
Jamie Madill | c9c4e4e | 2020-04-02 10:29:52 -0400 | [diff] [blame^] | 1490 | ANGLE_INSTANTIATE_TEST_ES2(FramebufferTest); |
Shahbaz Youssefi | e28883d | 2020-01-25 23:25:43 -0500 | [diff] [blame] | 1491 | ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(FramebufferFormatsTest); |
| 1492 | ANGLE_INSTANTIATE_TEST_ES3(FramebufferTest_ES3); |
| 1493 | ANGLE_INSTANTIATE_TEST_ES31(FramebufferTest_ES31); |