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. |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 298 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 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 | |
Le Hoang Quyen | 349b661 | 2020-07-08 12:50:00 +0800 | [diff] [blame] | 365 | // Test that a renderbuffer with RGB565 format works as expected. This test is intended for some |
| 366 | // back-end having no support for native RGB565 renderbuffer and thus having to emulate using RGBA |
| 367 | // format. |
| 368 | TEST_P(FramebufferFormatsTest, RGB565Renderbuffer) |
| 369 | { |
| 370 | GLRenderbuffer rbo; |
| 371 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 372 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 1, 1); |
| 373 | |
| 374 | GLFramebuffer completeFBO; |
| 375 | glBindFramebuffer(GL_FRAMEBUFFER, completeFBO); |
| 376 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 377 | |
| 378 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 379 | |
| 380 | ASSERT_GL_NO_ERROR(); |
| 381 | |
| 382 | glClearColor(1, 0, 0, 0.5f); |
| 383 | glClear(GL_COLOR_BUFFER_BIT); |
| 384 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 385 | } |
| 386 | |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 387 | class FramebufferTest_ES3 : public ANGLETest |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 388 | {}; |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 389 | |
| 390 | // 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] | 391 | TEST_P(FramebufferTest_ES3, InvalidateIncomplete) |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 392 | { |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 393 | GLFramebuffer framebuffer; |
| 394 | GLRenderbuffer renderbuffer; |
| 395 | |
| 396 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 397 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
| 398 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 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 | { |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 413 | GLFramebuffer framebuffer; |
| 414 | GLRenderbuffer renderbuffer; |
| 415 | |
| 416 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 417 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 418 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 4, 4); |
| 419 | |
| 420 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 421 | renderbuffer); |
Corentin Wallez | 57e6d50 | 2016-12-09 14:46:39 -0500 | [diff] [blame] | 422 | EXPECT_GLENUM_NE(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 423 | } |
| 424 | |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 425 | // Test that the framebuffer correctly returns that it is not complete if invalid texture mip levels |
| 426 | // are bound |
| 427 | TEST_P(FramebufferTest_ES3, TextureAttachmentMipLevels) |
| 428 | { |
| 429 | GLFramebuffer framebuffer; |
| 430 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 431 | |
| 432 | GLTexture texture; |
| 433 | glBindTexture(GL_TEXTURE_2D, texture); |
| 434 | |
| 435 | // Create a complete mip chain in mips 1 to 3 |
| 436 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 437 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 438 | glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 439 | |
| 440 | // Create another complete mip chain in mips 4 to 5 |
| 441 | glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 442 | glTexImage2D(GL_TEXTURE_2D, 5, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 443 | |
| 444 | // Create a non-complete mip chain in mip 6 |
| 445 | glTexImage2D(GL_TEXTURE_2D, 6, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 446 | |
| 447 | // Incomplete, mipLevel != baseLevel and texture is not mip complete |
| 448 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1); |
| 449 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 450 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 451 | |
| 452 | // Complete, mipLevel == baseLevel |
| 453 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 454 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 455 | |
| 456 | // Complete, mipLevel != baseLevel but texture is now mip complete |
| 457 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 2); |
| 458 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 459 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 3); |
| 460 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 461 | |
| 462 | // Incomplete, attached level below the base level |
| 463 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2); |
| 464 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1); |
| 465 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 466 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 467 | |
| 468 | // Incomplete, attached level is beyond effective max level |
| 469 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 4); |
| 470 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, |
| 471 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 472 | |
| 473 | // Complete, mipLevel == baseLevel |
| 474 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 4); |
| 475 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 476 | |
| 477 | // Complete, mipLevel != baseLevel but texture is now mip complete |
| 478 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 5); |
| 479 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 480 | |
| 481 | // Complete, mipLevel == baseLevel |
| 482 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 6); |
| 483 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 6); |
| 484 | ExpectFramebufferCompleteOrUnsupported(GL_FRAMEBUFFER); |
| 485 | } |
| 486 | |
Shahbaz Youssefi | dbb18b5 | 2020-06-05 15:23:17 -0400 | [diff] [blame] | 487 | TEST_P(FramebufferTest_ES3, TextureAttachmentMipLevelsReadBack) |
| 488 | { |
Kenneth Russell | 0bd0a91 | 2020-06-12 15:24:55 -0700 | [diff] [blame] | 489 | #if defined(ADDRESS_SANITIZER) |
| 490 | // http://anglebug.com/4737 |
| 491 | ANGLE_SKIP_TEST_IF(IsOSX()); |
| 492 | #endif |
| 493 | |
Shahbaz Youssefi | dbb18b5 | 2020-06-05 15:23:17 -0400 | [diff] [blame] | 494 | GLFramebuffer framebuffer; |
| 495 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 496 | |
| 497 | GLTexture texture; |
| 498 | glBindTexture(GL_TEXTURE_2D, texture); |
| 499 | |
| 500 | const std::array<GLColor, 2 * 2> mip0Data = {GLColor::red, GLColor::red, GLColor::red, |
| 501 | GLColor::red}; |
| 502 | const std::array<GLColor, 1 * 1> mip1Data = {GLColor::green}; |
| 503 | |
| 504 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip0Data.data()); |
| 505 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip1Data.data()); |
| 506 | |
| 507 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 508 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1); |
| 509 | EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 510 | |
| 511 | glClearColor(0, 0, 1.0f, 1.0f); |
| 512 | glClear(GL_COLOR_BUFFER_BIT); |
| 513 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 514 | } |
| 515 | |
Courtney Goeltzenleuchter | 9a9ef0a | 2020-07-15 16:50:32 -0600 | [diff] [blame] | 516 | // TextureAttachmentMipLevelsReadBackWithDraw is a copy of TextureAttachmentMipLevelsReadBack except |
| 517 | // for adding a draw after the last clear. The draw forces ANGLE's Vulkan backend to use the |
| 518 | // framebuffer that is level 1 of the texture which will trigger the mismatch use of the GL level |
| 519 | // and Vulkan level in referring to that rendertarget. |
| 520 | TEST_P(FramebufferTest_ES3, TextureAttachmentMipLevelsReadBackWithDraw) |
| 521 | { |
| 522 | #if defined(ADDRESS_SANITIZER) |
| 523 | // http://anglebug.com/4737 |
| 524 | ANGLE_SKIP_TEST_IF(IsOSX()); |
| 525 | #endif |
| 526 | |
| 527 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 528 | |
| 529 | GLFramebuffer framebuffer; |
| 530 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 531 | |
| 532 | GLTexture texture; |
| 533 | glBindTexture(GL_TEXTURE_2D, texture); |
| 534 | |
| 535 | const std::array<GLColor, 2 * 2> mip0Data = {GLColor::red, GLColor::red, GLColor::red, |
| 536 | GLColor::red}; |
| 537 | const std::array<GLColor, 1 * 1> mip1Data = {GLColor::green}; |
| 538 | |
| 539 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip0Data.data()); |
| 540 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip1Data.data()); |
| 541 | |
| 542 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 543 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1); |
| 544 | EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 545 | |
| 546 | glClearColor(0, 0, 1.0f, 1.0f); |
| 547 | glClear(GL_COLOR_BUFFER_BIT); |
| 548 | |
| 549 | // This draw triggers the use of the framebuffer |
| 550 | glUseProgram(greenProgram); |
| 551 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 552 | ASSERT_GL_NO_ERROR(); |
| 553 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 554 | } |
| 555 | |
Martin Radev | d178aa4 | 2017-07-13 14:03:22 +0300 | [diff] [blame] | 556 | // Test that passing an attachment COLOR_ATTACHMENTm where m is equal to MAX_COLOR_ATTACHMENTS |
| 557 | // generates an INVALID_OPERATION. |
| 558 | // OpenGL ES Version 3.0.5 (November 3, 2016), 4.4.2.4 Attaching Texture Images to a Framebuffer, p. |
| 559 | // 208 |
| 560 | TEST_P(FramebufferTest_ES3, ColorAttachmentIndexOutOfBounds) |
| 561 | { |
| 562 | GLFramebuffer framebuffer; |
| 563 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 564 | |
| 565 | GLint maxColorAttachments = 0; |
| 566 | glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments); |
| 567 | GLenum attachment = static_cast<GLenum>(maxColorAttachments + GL_COLOR_ATTACHMENT0); |
| 568 | |
| 569 | GLTexture texture; |
| 570 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 571 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, 1, 1); |
| 572 | glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture.get(), 0); |
| 573 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 574 | } |
| 575 | |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 576 | // Check that depth-only attachments report the correct number of samples. |
| 577 | TEST_P(FramebufferTest_ES3, MultisampleDepthOnly) |
| 578 | { |
| 579 | GLRenderbuffer renderbuffer; |
| 580 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
| 581 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 32, 32); |
| 582 | |
| 583 | GLFramebuffer framebuffer; |
| 584 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 585 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 586 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 587 | EXPECT_GL_NO_ERROR(); |
| 588 | |
| 589 | GLint samples = 0; |
| 590 | glGetIntegerv(GL_SAMPLES, &samples); |
| 591 | EXPECT_GL_NO_ERROR(); |
| 592 | EXPECT_GE(samples, 2); |
| 593 | } |
| 594 | |
Jeff Gilbert | 8f8edd6 | 2017-10-31 14:26:30 -0700 | [diff] [blame] | 595 | // Check that we only compare width and height of attachments, not depth. |
| 596 | TEST_P(FramebufferTest_ES3, AttachmentWith3DLayers) |
| 597 | { |
| 598 | GLTexture texA; |
| 599 | glBindTexture(GL_TEXTURE_2D, texA); |
| 600 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 601 | |
| 602 | GLTexture texB; |
| 603 | glBindTexture(GL_TEXTURE_3D, texB); |
| 604 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 605 | |
| 606 | GLFramebuffer framebuffer; |
| 607 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 608 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0); |
| 609 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, texB, 0, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 610 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Jeff Gilbert | 8f8edd6 | 2017-10-31 14:26:30 -0700 | [diff] [blame] | 611 | EXPECT_GL_NO_ERROR(); |
| 612 | } |
| 613 | |
Olli Etuaho | dbce1f8 | 2018-09-19 15:32:17 +0300 | [diff] [blame] | 614 | // Test that clearing the stencil buffer when the framebuffer only has a color attachment does not |
| 615 | // crash. |
| 616 | TEST_P(FramebufferTest_ES3, ClearNonexistentStencil) |
| 617 | { |
| 618 | GLRenderbuffer rbo; |
| 619 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 620 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 621 | |
| 622 | GLFramebuffer fbo; |
| 623 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 624 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 625 | |
| 626 | GLint clearValue = 0; |
| 627 | glClearBufferiv(GL_STENCIL, 0, &clearValue); |
| 628 | |
| 629 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 630 | EXPECT_GL_NO_ERROR(); |
| 631 | } |
| 632 | |
| 633 | // Test that clearing the depth buffer when the framebuffer only has a color attachment does not |
| 634 | // crash. |
| 635 | TEST_P(FramebufferTest_ES3, ClearNonexistentDepth) |
| 636 | { |
| 637 | GLRenderbuffer rbo; |
| 638 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 639 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 640 | |
| 641 | GLFramebuffer fbo; |
| 642 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 643 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 644 | |
| 645 | GLfloat clearValue = 0.0f; |
| 646 | glClearBufferfv(GL_DEPTH, 0, &clearValue); |
| 647 | |
| 648 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 649 | EXPECT_GL_NO_ERROR(); |
| 650 | } |
| 651 | |
| 652 | // Test that clearing a nonexistent color attachment does not crash. |
| 653 | TEST_P(FramebufferTest_ES3, ClearNonexistentColor) |
| 654 | { |
| 655 | GLRenderbuffer rbo; |
| 656 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 657 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 658 | |
| 659 | GLFramebuffer fbo; |
| 660 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 661 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 662 | |
| 663 | std::vector<GLfloat> clearValue = {{0.0f, 1.0f, 0.0f, 1.0f}}; |
| 664 | glClearBufferfv(GL_COLOR, 1, clearValue.data()); |
| 665 | |
| 666 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 667 | EXPECT_GL_NO_ERROR(); |
| 668 | } |
| 669 | |
| 670 | // Test that clearing the depth and stencil buffers when the framebuffer only has a color attachment |
| 671 | // does not crash. |
| 672 | TEST_P(FramebufferTest_ES3, ClearNonexistentDepthStencil) |
| 673 | { |
| 674 | GLRenderbuffer rbo; |
| 675 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 676 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 677 | |
| 678 | GLFramebuffer fbo; |
| 679 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 680 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 681 | |
| 682 | glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.0f, 0); |
| 683 | |
| 684 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op. |
| 685 | EXPECT_GL_NO_ERROR(); |
| 686 | } |
| 687 | |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 688 | // Test that clearing a color attachment that has been deleted doesn't crash. |
| 689 | TEST_P(FramebufferTest_ES3, ClearDeletedAttachment) |
| 690 | { |
| 691 | // An INVALID_FRAMEBUFFER_OPERATION error was seen in this test on Mac, not sure where it might |
| 692 | // be originating from. http://anglebug.com/2834 |
| 693 | ANGLE_SKIP_TEST_IF(IsOSX() && IsOpenGL()); |
| 694 | |
| 695 | GLFramebuffer fbo; |
| 696 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 697 | |
| 698 | // There used to be a bug where some draw buffer state used to remain set even after the |
| 699 | // attachment was detached via deletion. That's why we create, attach and delete this RBO here. |
| 700 | GLuint rbo = 0u; |
| 701 | glGenRenderbuffers(1, &rbo); |
| 702 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 703 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 704 | glDeleteRenderbuffers(1, &rbo); |
| 705 | |
| 706 | // There needs to be at least one color attachment to prevent early out from the clear calls. |
| 707 | GLRenderbuffer rbo2; |
| 708 | glBindRenderbuffer(GL_RENDERBUFFER, rbo2); |
| 709 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 710 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rbo2); |
| 711 | |
| 712 | ASSERT_GL_NO_ERROR(); |
| 713 | |
| 714 | // There's no error specified for clearing nonexistent buffers, it's simply a no-op, so we |
| 715 | // expect no GL errors below. |
| 716 | std::array<GLfloat, 4> floatClearValue = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 717 | glClearBufferfv(GL_COLOR, 0, floatClearValue.data()); |
| 718 | EXPECT_GL_NO_ERROR(); |
| 719 | std::array<GLuint, 4> uintClearValue = {0u, 0u, 0u, 0u}; |
| 720 | glClearBufferuiv(GL_COLOR, 0, uintClearValue.data()); |
| 721 | EXPECT_GL_NO_ERROR(); |
| 722 | std::array<GLint, 4> intClearValue = {0, 0, 0, 0}; |
| 723 | glClearBufferiv(GL_COLOR, 0, intClearValue.data()); |
| 724 | EXPECT_GL_NO_ERROR(); |
| 725 | } |
| 726 | |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 727 | // Test that resizing the color attachment is handled correctly. |
| 728 | TEST_P(FramebufferTest_ES3, ResizeColorAttachmentSmallToLarge) |
| 729 | { |
| 730 | GLFramebuffer fbo; |
| 731 | GLTexture smallTexture; |
| 732 | GLTexture largeTexture; |
| 733 | |
| 734 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 735 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 736 | |
| 737 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 738 | |
| 739 | // Bind the small texture |
| 740 | glBindTexture(GL_TEXTURE_2D, smallTexture); |
| 741 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 742 | GL_UNSIGNED_BYTE, nullptr); |
| 743 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 744 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 745 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, smallTexture, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 746 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 747 | |
| 748 | // Draw to FBO backed by the small texture |
| 749 | glUseProgram(greenProgram); |
| 750 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 751 | ASSERT_GL_NO_ERROR(); |
| 752 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 753 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 754 | |
| 755 | // Change the attachment to the larger texture that fills the window |
| 756 | glBindTexture(GL_TEXTURE_2D, largeTexture); |
| 757 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 758 | GL_UNSIGNED_BYTE, nullptr); |
| 759 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 760 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 761 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, largeTexture, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 762 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 763 | |
| 764 | // Draw to FBO backed by the large texture |
| 765 | glUseProgram(blueProgram); |
| 766 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 767 | ASSERT_GL_NO_ERROR(); |
| 768 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 769 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::blue); |
| 770 | } |
| 771 | |
| 772 | // Test that resizing the color attachment is handled correctly. |
| 773 | TEST_P(FramebufferTest_ES3, ResizeColorAttachmentLargeToSmall) |
| 774 | { |
| 775 | GLFramebuffer fbo; |
| 776 | GLTexture smallTexture; |
| 777 | GLTexture largeTexture; |
| 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 | // Bind the large texture |
| 785 | glBindTexture(GL_TEXTURE_2D, largeTexture); |
| 786 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 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, largeTexture, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 791 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 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() - 1, getWindowHeight() - 1, GLColor::blue); |
| 799 | |
| 800 | // Change the attachment to the smaller texture |
| 801 | glBindTexture(GL_TEXTURE_2D, smallTexture); |
| 802 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 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, smallTexture, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 807 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 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() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 815 | } |
| 816 | |
| 817 | // Test that resizing the texture is handled correctly. |
| 818 | TEST_P(FramebufferTest_ES3, ResizeTextureLargeToSmall) |
| 819 | { |
| 820 | GLFramebuffer fbo; |
| 821 | GLTexture texture; |
| 822 | |
| 823 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 824 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 825 | |
| 826 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 827 | |
| 828 | // Allocate a large texture |
| 829 | glBindTexture(GL_TEXTURE_2D, texture); |
| 830 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 831 | GL_UNSIGNED_BYTE, nullptr); |
| 832 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 833 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 834 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 835 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 836 | |
| 837 | // Draw to FBO backed by the large texture |
| 838 | glUseProgram(blueProgram); |
| 839 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 840 | ASSERT_GL_NO_ERROR(); |
| 841 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 842 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::blue); |
| 843 | |
| 844 | // Shrink the texture |
| 845 | glBindTexture(GL_TEXTURE_2D, texture); |
| 846 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 847 | GL_UNSIGNED_BYTE, nullptr); |
| 848 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 849 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 850 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 851 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 852 | |
| 853 | // Draw to FBO backed by the small texture |
| 854 | glUseProgram(greenProgram); |
| 855 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 856 | ASSERT_GL_NO_ERROR(); |
| 857 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 858 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::green); |
| 859 | } |
| 860 | |
| 861 | // Test that resizing the texture is handled correctly. |
| 862 | TEST_P(FramebufferTest_ES3, ResizeTextureSmallToLarge) |
| 863 | { |
| 864 | GLFramebuffer fbo; |
| 865 | GLTexture texture; |
| 866 | |
| 867 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 868 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 869 | |
| 870 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 871 | |
| 872 | // Allocate a small texture |
| 873 | glBindTexture(GL_TEXTURE_2D, texture); |
| 874 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGBA, |
| 875 | GL_UNSIGNED_BYTE, nullptr); |
| 876 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 877 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 878 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 879 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 880 | |
| 881 | // Draw to FBO backed by the large texture |
| 882 | glUseProgram(blueProgram); |
| 883 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 884 | ASSERT_GL_NO_ERROR(); |
| 885 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 886 | EXPECT_PIXEL_COLOR_EQ((getWindowWidth() / 2) - 1, (getWindowHeight() / 2) - 1, GLColor::blue); |
| 887 | |
| 888 | // Grow the texture |
| 889 | glBindTexture(GL_TEXTURE_2D, texture); |
| 890 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 891 | GL_UNSIGNED_BYTE, nullptr); |
| 892 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 893 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 894 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 895 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Tim Van Patten | e600ac2 | 2019-10-04 14:31:57 -0600 | [diff] [blame] | 896 | |
| 897 | // Draw to FBO backed by the small texture |
| 898 | glUseProgram(greenProgram); |
| 899 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 900 | ASSERT_GL_NO_ERROR(); |
| 901 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 902 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green); |
| 903 | } |
| 904 | |
Shahbaz Youssefi | e28883d | 2020-01-25 23:25:43 -0500 | [diff] [blame] | 905 | // Test that fewer outputs than framebuffer attachments doesn't crash. This causes a Vulkan |
| 906 | // validation warning, but should not be fatal. |
| 907 | TEST_P(FramebufferTest_ES3, FewerShaderOutputsThanAttachments) |
| 908 | { |
| 909 | constexpr char kFS[] = R"(#version 300 es |
| 910 | precision highp float; |
| 911 | |
| 912 | layout(location = 0) out vec4 color0; |
| 913 | layout(location = 1) out vec4 color1; |
| 914 | layout(location = 2) out vec4 color2; |
| 915 | |
| 916 | void main() |
| 917 | { |
| 918 | color0 = vec4(1.0, 0.0, 0.0, 1.0); |
| 919 | color1 = vec4(0.0, 1.0, 0.0, 1.0); |
| 920 | color2 = vec4(0.0, 0.0, 1.0, 1.0); |
| 921 | } |
| 922 | )"; |
| 923 | |
| 924 | ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); |
| 925 | |
| 926 | constexpr GLint kDrawBufferCount = 4; |
| 927 | |
| 928 | GLint maxDrawBuffers; |
| 929 | glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); |
| 930 | ASSERT_GE(maxDrawBuffers, kDrawBufferCount); |
| 931 | |
| 932 | GLTexture textures[kDrawBufferCount]; |
| 933 | |
| 934 | for (GLint texIndex = 0; texIndex < kDrawBufferCount; ++texIndex) |
| 935 | { |
| 936 | glBindTexture(GL_TEXTURE_2D, textures[texIndex]); |
| 937 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 938 | GL_UNSIGNED_BYTE, nullptr); |
| 939 | } |
| 940 | |
| 941 | GLenum allBufs[kDrawBufferCount] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, |
| 942 | GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3}; |
| 943 | |
| 944 | GLFramebuffer fbo; |
| 945 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); |
| 946 | |
| 947 | // Enable all draw buffers. |
| 948 | for (GLint texIndex = 0; texIndex < kDrawBufferCount; ++texIndex) |
| 949 | { |
| 950 | glBindTexture(GL_TEXTURE_2D, textures[texIndex]); |
| 951 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + texIndex, GL_TEXTURE_2D, |
| 952 | textures[texIndex], 0); |
| 953 | } |
| 954 | glDrawBuffers(kDrawBufferCount, allBufs); |
| 955 | |
| 956 | // Draw with simple program. |
| 957 | drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 958 | ASSERT_GL_NO_ERROR(); |
| 959 | } |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 960 | |
| 961 | class FramebufferTest_ES31 : public ANGLETest |
| 962 | { |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 963 | protected: |
| 964 | void validateSamplePass(GLuint &query, GLuint &passedCount, GLint width, GLint height) |
| 965 | { |
| 966 | glUniform2i(0, width - 1, height - 1); |
| 967 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 968 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 969 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 970 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 971 | EXPECT_GT(static_cast<GLint>(passedCount), 0); |
| 972 | |
| 973 | glUniform2i(0, width - 1, height); |
| 974 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 975 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 976 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 977 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 978 | EXPECT_EQ(static_cast<GLint>(passedCount), 0); |
| 979 | |
| 980 | glUniform2i(0, width, height - 1); |
| 981 | glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
| 982 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 983 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
| 984 | glGetQueryObjectuiv(query, GL_QUERY_RESULT, &passedCount); |
| 985 | EXPECT_EQ(static_cast<GLint>(passedCount), 0); |
| 986 | } |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 987 | }; |
| 988 | |
| 989 | // Test that without attachment, if either the value of FRAMEBUFFER_DEFAULT_WIDTH or |
| 990 | // FRAMEBUFFER_DEFAULT_HEIGHT parameters is zero, the framebuffer is incomplete. |
| 991 | TEST_P(FramebufferTest_ES31, IncompleteMissingAttachmentDefaultParam) |
| 992 | { |
| 993 | GLFramebuffer mFramebuffer; |
| 994 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 995 | |
| 996 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1); |
| 997 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1); |
| 998 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 999 | |
| 1000 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0); |
| 1001 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0); |
| 1002 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 1003 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1004 | |
| 1005 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 1); |
| 1006 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 0); |
| 1007 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 1008 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1009 | |
| 1010 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 0); |
| 1011 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 1); |
| 1012 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, |
| 1013 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1014 | |
| 1015 | ASSERT_GL_NO_ERROR(); |
| 1016 | } |
| 1017 | |
| 1018 | // Test that the sample count of a mix of texture and renderbuffer should be same. |
| 1019 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountMix) |
| 1020 | { |
| 1021 | GLFramebuffer mFramebuffer; |
| 1022 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 1023 | |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 1024 | // Lookup the supported number of sample counts (rely on fact that ANGLE uses the same set of |
| 1025 | // sample counts for textures and renderbuffers) |
| 1026 | GLint numSampleCounts = 0; |
| 1027 | std::vector<GLint> sampleCounts; |
| 1028 | GLsizei queryBufferSize = 1; |
| 1029 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, |
| 1030 | queryBufferSize, &numSampleCounts); |
| 1031 | ANGLE_SKIP_TEST_IF((numSampleCounts < 2)); |
| 1032 | sampleCounts.resize(numSampleCounts); |
| 1033 | queryBufferSize = numSampleCounts; |
| 1034 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_SAMPLES, queryBufferSize, |
| 1035 | sampleCounts.data()); |
| 1036 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1037 | GLTexture mTexture; |
| 1038 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get()); |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 1039 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleCounts[0], GL_RGBA8, 1, 1, true); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1040 | |
| 1041 | GLRenderbuffer mRenderbuffer; |
| 1042 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get()); |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 1043 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCounts[1], GL_RGBA8, 1, 1); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1044 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 1045 | mTexture.get(), 0); |
| 1046 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, |
| 1047 | mRenderbuffer.get()); |
| 1048 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 1049 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1050 | |
| 1051 | ASSERT_GL_NO_ERROR(); |
| 1052 | } |
| 1053 | |
| 1054 | // Test that the sample count of texture attachments should be same. |
| 1055 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleSampleCountTex) |
| 1056 | { |
| 1057 | GLFramebuffer mFramebuffer; |
| 1058 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 1059 | |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 1060 | // Lookup the supported number of sample counts |
| 1061 | GLint numSampleCounts = 0; |
| 1062 | std::vector<GLint> sampleCounts; |
| 1063 | GLsizei queryBufferSize = 1; |
| 1064 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, |
| 1065 | queryBufferSize, &numSampleCounts); |
| 1066 | ANGLE_SKIP_TEST_IF((numSampleCounts < 2)); |
| 1067 | sampleCounts.resize(numSampleCounts); |
| 1068 | queryBufferSize = numSampleCounts; |
| 1069 | glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE, GL_RGBA8, GL_SAMPLES, queryBufferSize, |
| 1070 | sampleCounts.data()); |
| 1071 | |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1072 | GLTexture mTextures[2]; |
| 1073 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get()); |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 1074 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleCounts[0], GL_RGBA8, 1, 1, true); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1075 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get()); |
Ian Elliott | 5f85783 | 2019-12-04 15:30:50 -0700 | [diff] [blame] | 1076 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleCounts[1], GL_RGBA8, 1, 1, true); |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1077 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 1078 | mTextures[0].get(), 0); |
| 1079 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, |
| 1080 | mTextures[1].get(), 0); |
| 1081 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 1082 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1083 | |
| 1084 | ASSERT_GL_NO_ERROR(); |
| 1085 | } |
| 1086 | |
| 1087 | // Test that if the attached images are a mix of renderbuffers and textures, the value of |
| 1088 | // TEXTURE_FIXED_SAMPLE_LOCATIONS must be TRUE for all attached textures. |
| 1089 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsMix) |
| 1090 | { |
| 1091 | GLFramebuffer mFramebuffer; |
| 1092 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 1093 | |
| 1094 | GLTexture mTexture; |
| 1095 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTexture.get()); |
| 1096 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false); |
| 1097 | |
| 1098 | GLRenderbuffer mRenderbuffer; |
| 1099 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer.get()); |
| 1100 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 1, GL_RGBA8, 1, 1); |
| 1101 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 1102 | mTexture.get(), 0); |
| 1103 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, |
| 1104 | mRenderbuffer.get()); |
| 1105 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 1106 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1107 | |
| 1108 | ASSERT_GL_NO_ERROR(); |
| 1109 | } |
| 1110 | |
| 1111 | // Test that the value of TEXTURE_FIXED_SAMPLE_LOCATIONS is the same for all attached textures. |
| 1112 | TEST_P(FramebufferTest_ES31, IncompleteMultisampleFixedSampleLocationsTex) |
| 1113 | { |
| 1114 | GLFramebuffer mFramebuffer; |
| 1115 | glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer.get()); |
| 1116 | |
| 1117 | GLTexture mTextures[2]; |
| 1118 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[0].get()); |
| 1119 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 1, 1, false); |
| 1120 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 1121 | mTextures[0].get(), 0); |
| 1122 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, mTextures[1].get()); |
| 1123 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGB8, 1, 1, true); |
| 1124 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, |
| 1125 | mTextures[1].get(), 0); |
| 1126 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, |
| 1127 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1128 | |
| 1129 | ASSERT_GL_NO_ERROR(); |
| 1130 | } |
| 1131 | |
Tim Van Patten | 5559351 | 2020-08-11 14:23:32 -0600 | [diff] [blame^] | 1132 | // Test resolving a multisampled texture into a mipmaped texture with blit |
| 1133 | TEST_P(FramebufferTest_ES31, MultisampleResolveIntoMipMapWithBlit) |
| 1134 | { |
| 1135 | // FBO 1 is attached to a 64x64 texture |
| 1136 | // FBO 2 attached to level 1 of a 128x128 texture |
| 1137 | |
| 1138 | constexpr int kSize = 64; |
| 1139 | glViewport(0, 0, kSize, kSize); |
| 1140 | |
| 1141 | // Create the textures early and call glGenerateMipmap() so it doesn't break the render pass |
| 1142 | // between the drawQuad() and glBlitFramebuffer(), so we can test the resolve with subpass path |
| 1143 | // in the Vulkan back end. |
| 1144 | GLTexture texture; |
| 1145 | glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture.get()); |
| 1146 | glTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA8, kSize, kSize, false); |
| 1147 | ASSERT_GL_NO_ERROR(); |
| 1148 | |
| 1149 | GLTexture resolveTexture; |
| 1150 | glBindTexture(GL_TEXTURE_2D, resolveTexture); |
| 1151 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1152 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1153 | ASSERT_GL_NO_ERROR(); |
| 1154 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 1155 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1156 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1157 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1158 | |
| 1159 | GLFramebuffer msaaFBO; |
| 1160 | glBindFramebuffer(GL_FRAMEBUFFER, msaaFBO.get()); |
| 1161 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, |
| 1162 | texture.get(), 0); |
| 1163 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1164 | |
| 1165 | ANGLE_GL_PROGRAM(gradientProgram, essl31_shaders::vs::Passthrough(), |
| 1166 | essl31_shaders::fs::RedGreenGradient()); |
| 1167 | drawQuad(gradientProgram, essl31_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 1168 | ASSERT_GL_NO_ERROR(); |
| 1169 | |
| 1170 | // Create another FBO to resolve the multisample buffer into. |
| 1171 | GLFramebuffer resolveFBO; |
| 1172 | glBindFramebuffer(GL_FRAMEBUFFER, resolveFBO); |
| 1173 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, resolveTexture, 1); |
| 1174 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1175 | |
| 1176 | glBindFramebuffer(GL_READ_FRAMEBUFFER, msaaFBO); |
| 1177 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolveFBO); |
| 1178 | glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1179 | ASSERT_GL_NO_ERROR(); |
| 1180 | |
| 1181 | glBindFramebuffer(GL_READ_FRAMEBUFFER, resolveFBO); |
| 1182 | EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 255, 1.0); // Black |
| 1183 | EXPECT_PIXEL_NEAR(kSize - 1, 1, 251, 0, 0, 255, 1.0); // Red |
| 1184 | EXPECT_PIXEL_NEAR(0, kSize - 1, 0, 251, 0, 255, 1.0); // Green |
| 1185 | EXPECT_PIXEL_NEAR(kSize - 1, kSize - 1, 251, 251, 0, 255, 1.0); // Yellow |
| 1186 | } |
| 1187 | |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1188 | // If there are no attachments, rendering will be limited to a rectangle having a lower left of |
| 1189 | // (0, 0) and an upper right of(width, height), where width and height are the framebuffer |
| 1190 | // object's default width and height. |
JiangYizhou | 3db4072 | 2017-08-28 17:59:13 +0800 | [diff] [blame] | 1191 | TEST_P(FramebufferTest_ES31, RenderingLimitToDefaultFBOSizeWithNoAttachments) |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1192 | { |
Yuly Novikov | 98f9f53 | 2017-11-15 19:16:19 -0500 | [diff] [blame] | 1193 | // anglebug.com/2253 |
| 1194 | ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL()); |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 1195 | // Occlusion query reports fragments outside the render area are still rendered |
| 1196 | ANGLE_SKIP_TEST_IF(IsAndroid() || (IsWindows() && (IsIntel() || IsAMD()))); |
Yuly Novikov | 98f9f53 | 2017-11-15 19:16:19 -0500 | [diff] [blame] | 1197 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1198 | constexpr char kVS1[] = R"(#version 310 es |
| 1199 | in layout(location = 0) highp vec2 a_position; |
| 1200 | void main() |
| 1201 | { |
| 1202 | gl_Position = vec4(a_position, 0.0, 1.0); |
| 1203 | })"; |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1204 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1205 | constexpr char kFS1[] = R"(#version 310 es |
| 1206 | uniform layout(location = 0) highp ivec2 u_expectedSize; |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1207 | out layout(location = 3) mediump vec4 f_color; |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1208 | void main() |
| 1209 | { |
| 1210 | if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; |
| 1211 | f_color = vec4(1.0, 0.5, 0.25, 1.0); |
| 1212 | })"; |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1213 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1214 | constexpr char kVS2[] = R"(#version 310 es |
| 1215 | in layout(location = 0) highp vec2 a_position; |
| 1216 | void main() |
| 1217 | { |
| 1218 | gl_Position = vec4(a_position, 0.0, 1.0); |
| 1219 | })"; |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1220 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1221 | constexpr char kFS2[] = R"(#version 310 es |
| 1222 | uniform layout(location = 0) highp ivec2 u_expectedSize; |
| 1223 | out layout(location = 2) mediump vec4 f_color; |
| 1224 | void main() |
| 1225 | { |
| 1226 | if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; |
| 1227 | f_color = vec4(1.0, 0.5, 0.25, 1.0); |
| 1228 | })"; |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1229 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1230 | GLuint program1 = CompileProgram(kVS1, kFS1); |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1231 | ASSERT_NE(program1, 0u); |
| 1232 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1233 | GLuint program2 = CompileProgram(kVS2, kFS2); |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1234 | ASSERT_NE(program2, 0u); |
| 1235 | |
| 1236 | glUseProgram(program1); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1237 | |
| 1238 | GLFramebuffer mFramebuffer; |
| 1239 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer); |
| 1240 | GLuint defaultWidth = 1; |
| 1241 | GLuint defaultHeight = 1; |
| 1242 | |
| 1243 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, defaultWidth); |
| 1244 | glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, defaultHeight); |
| 1245 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1246 | |
| 1247 | const float data[] = { |
| 1248 | 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, |
| 1249 | }; |
| 1250 | |
| 1251 | GLuint vertexArray = 0; |
| 1252 | GLuint vertexBuffer = 0; |
| 1253 | GLuint query = 0; |
| 1254 | GLuint passedCount = 0; |
| 1255 | |
| 1256 | glGenQueries(1, &query); |
| 1257 | glGenVertexArrays(1, &vertexArray); |
| 1258 | glBindVertexArray(vertexArray); |
| 1259 | |
| 1260 | glGenBuffers(1, &vertexBuffer); |
| 1261 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); |
| 1262 | glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); |
| 1263 | |
| 1264 | glEnableVertexAttribArray(0); |
| 1265 | glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1266 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1267 | |
| 1268 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1269 | |
JiangYizhou | 10d4139 | 2017-12-18 18:13:36 +0800 | [diff] [blame] | 1270 | glUseProgram(program2); |
| 1271 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1272 | |
| 1273 | glUseProgram(program1); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1274 | // If fbo has attachments, the rendering size should be the same as its attachment. |
| 1275 | GLTexture mTexture; |
| 1276 | GLuint width = 2; |
| 1277 | GLuint height = 2; |
| 1278 | glBindTexture(GL_TEXTURE_2D, mTexture.get()); |
| 1279 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1280 | |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1281 | const GLenum bufs[] = {GL_NONE, GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT3}; |
JiangYizhou | 38d92b5 | 2017-09-13 13:47:52 +0800 | [diff] [blame] | 1282 | |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1283 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, mTexture.get(), |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1284 | 0); |
| 1285 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1286 | glDrawBuffers(4, bufs); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1287 | |
| 1288 | validateSamplePass(query, passedCount, width, height); |
| 1289 | |
| 1290 | // If fbo's attachment has been removed, the rendering size should be the same as framebuffer |
| 1291 | // default size. |
Shahbaz Youssefi | 190d9a8 | 2019-11-29 09:57:40 -0500 | [diff] [blame] | 1292 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, 0, 0, 0); |
JiangYizhou | 511937d | 2017-08-03 15:41:29 +0800 | [diff] [blame] | 1293 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1294 | |
| 1295 | validateSamplePass(query, passedCount, defaultWidth, defaultHeight); |
| 1296 | |
| 1297 | glDisableVertexAttribArray(0); |
| 1298 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 1299 | glBindVertexArray(0); |
| 1300 | glDeleteBuffers(1, &vertexBuffer); |
| 1301 | glDeleteVertexArrays(1, &vertexArray); |
| 1302 | |
| 1303 | ASSERT_GL_NO_ERROR(); |
| 1304 | } |
| 1305 | |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1306 | class AddDummyTextureNoRenderTargetTest : public ANGLETest |
| 1307 | { |
| 1308 | public: |
| 1309 | AddDummyTextureNoRenderTargetTest() |
| 1310 | { |
| 1311 | setWindowWidth(512); |
| 1312 | setWindowHeight(512); |
| 1313 | setConfigRedBits(8); |
| 1314 | setConfigGreenBits(8); |
| 1315 | setConfigBlueBits(8); |
| 1316 | setConfigAlphaBits(8); |
| 1317 | } |
| 1318 | |
Jonah Ryan-Davis | eee67c6 | 2019-06-18 13:00:43 -0400 | [diff] [blame] | 1319 | void overrideWorkaroundsD3D(FeaturesD3D *features) override |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1320 | { |
Jonah Ryan-Davis | beb0eb2 | 2019-06-14 15:10:33 -0400 | [diff] [blame] | 1321 | features->overrideFeatures({"add_dummy_texture_no_render_target"}, true); |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1322 | } |
| 1323 | }; |
| 1324 | |
| 1325 | // Test to verify workaround succeeds when no program outputs exist http://anglebug.com/2283 |
| 1326 | TEST_P(AddDummyTextureNoRenderTargetTest, NoProgramOutputWorkaround) |
| 1327 | { |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1328 | constexpr char kVS[] = "void main() {}"; |
| 1329 | constexpr char kFS[] = "void main() {}"; |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1330 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 1331 | ANGLE_GL_PROGRAM(drawProgram, kVS, kFS); |
Brandon Jones | 9fc8733 | 2017-12-13 15:46:52 -0800 | [diff] [blame] | 1332 | |
| 1333 | glUseProgram(drawProgram); |
| 1334 | |
| 1335 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 1336 | |
| 1337 | ASSERT_GL_NO_ERROR(); |
| 1338 | } |
| 1339 | |
Jamie Madill | 4fb3c28 | 2020-03-19 19:10:45 -0400 | [diff] [blame] | 1340 | // Covers a bug in ANGLE's Vulkan back-end framebuffer cache which ignored depth/stencil after |
| 1341 | // calls to DrawBuffers. |
| 1342 | TEST_P(FramebufferTest_ES3, AttachmentStateChange) |
| 1343 | { |
| 1344 | constexpr GLuint kSize = 2; |
| 1345 | |
| 1346 | ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 1347 | |
| 1348 | GLTexture colorTexture; |
| 1349 | glBindTexture(GL_TEXTURE_2D, colorTexture); |
| 1350 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1351 | |
| 1352 | GLFramebuffer fbo; |
| 1353 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1354 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0); |
| 1355 | |
| 1356 | ASSERT_GL_NO_ERROR(); |
| 1357 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1358 | |
| 1359 | // First draw without a depth buffer. |
| 1360 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f); |
| 1361 | |
| 1362 | GLRenderbuffer depthBuffer; |
| 1363 | glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer); |
| 1364 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, kSize, kSize); |
| 1365 | |
| 1366 | // Bind just a renderbuffer and draw. |
| 1367 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer); |
| 1368 | |
| 1369 | ASSERT_GL_NO_ERROR(); |
| 1370 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1371 | |
| 1372 | glDrawBuffers(0, nullptr); |
| 1373 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f); |
| 1374 | |
| 1375 | // Re-enable color buffer and draw one final time. This previously triggered a crash. |
| 1376 | GLenum drawBuffs = {GL_COLOR_ATTACHMENT0}; |
| 1377 | glDrawBuffers(1, &drawBuffs); |
| 1378 | |
| 1379 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f); |
| 1380 | ASSERT_GL_NO_ERROR(); |
| 1381 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1382 | } |
| 1383 | |
Jamie Madill | d03b15b | 2020-03-26 17:22:18 -0400 | [diff] [blame] | 1384 | // Tests that we can support a feedback loop between a depth textures and the depth buffer. |
| 1385 | // Does not totally mirror the case used in Manhattan. The Manhattan case seems to handle |
| 1386 | // "clear" specially instead of rendering to depth in the same RP. |
| 1387 | TEST_P(FramebufferTest_ES3, DepthFeedbackLoopSupported) |
| 1388 | { |
| 1389 | // Feedback loops not supported on D3D11 and may not ever be. |
| 1390 | ANGLE_SKIP_TEST_IF(IsD3D11()); |
| 1391 | |
| 1392 | // Also this particular test doesn't work on Android despite similar support in Manhattan. |
| 1393 | ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES()); |
| 1394 | |
| 1395 | constexpr GLuint kSize = 2; |
| 1396 | glViewport(0, 0, kSize, kSize); |
| 1397 | |
| 1398 | constexpr char kFS[] = R"(precision mediump float; |
| 1399 | varying vec2 v_texCoord; |
| 1400 | uniform sampler2D depth; |
| 1401 | void main() |
| 1402 | { |
| 1403 | if (abs(texture2D(depth, v_texCoord).x - 0.5) < 0.1) |
| 1404 | { |
| 1405 | gl_FragColor = vec4(0, 1, 0, 1); |
| 1406 | } |
| 1407 | else |
| 1408 | { |
| 1409 | gl_FragColor = vec4(1, 0, 0, 1); |
| 1410 | } |
| 1411 | })"; |
| 1412 | |
| 1413 | ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Texture2D(), kFS); |
| 1414 | |
| 1415 | GLFramebuffer framebuffer; |
| 1416 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); |
| 1417 | |
| 1418 | GLTexture colorTexture; |
| 1419 | glBindTexture(GL_TEXTURE_2D, colorTexture); |
| 1420 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1421 | |
| 1422 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1423 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1424 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0); |
| 1425 | |
| 1426 | GLTexture depthTexture; |
| 1427 | glBindTexture(GL_TEXTURE_2D, depthTexture); |
| 1428 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, kSize, kSize, 0, GL_DEPTH_COMPONENT, |
| 1429 | GL_UNSIGNED_INT, nullptr); |
| 1430 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1431 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1432 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0); |
| 1433 | |
| 1434 | ASSERT_GL_NO_ERROR(); |
| 1435 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1436 | |
| 1437 | // Clear depth to 0.5. |
| 1438 | glClearDepthf(0.5f); |
| 1439 | glClear(GL_DEPTH_BUFFER_BIT); |
| 1440 | |
| 1441 | // Disable the depth mask. Although this does not remove the feedback loop as defined by the |
| 1442 | // spec it mimics what gfxbench does in its rendering tests. |
| 1443 | glDepthMask(false); |
| 1444 | |
| 1445 | // Verify we can sample the depth texture and get 0.5. |
| 1446 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5); |
| 1447 | |
| 1448 | ASSERT_GL_NO_ERROR(); |
| 1449 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1450 | } |
| 1451 | |
Jamie Madill | dd00f16 | 2020-04-02 14:04:44 -0400 | [diff] [blame] | 1452 | // Covers a bug in ANGLE's Vulkan back-end. Our VkFramebuffer cache would in some cases forget to |
| 1453 | // check the draw states when computing a cache key. |
| 1454 | TEST_P(FramebufferTest_ES3, DisabledAttachmentRedefinition) |
| 1455 | { |
| 1456 | constexpr GLuint kSize = 2; |
| 1457 | |
| 1458 | // Make a Framebuffer with two attachments with one enabled and one disabled. |
| 1459 | GLTexture texA, texB; |
| 1460 | glBindTexture(GL_TEXTURE_2D, texA); |
| 1461 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1462 | glBindTexture(GL_TEXTURE_2D, texB); |
| 1463 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1464 | |
| 1465 | GLFramebuffer fbo; |
| 1466 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1467 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texA, 0); |
| 1468 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texB, 0); |
| 1469 | |
| 1470 | // Mask out the second texture. |
| 1471 | constexpr GLenum kOneDrawBuf = GL_COLOR_ATTACHMENT0; |
| 1472 | glDrawBuffers(1, &kOneDrawBuf); |
| 1473 | |
| 1474 | ASSERT_GL_NO_ERROR(); |
| 1475 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1476 | |
| 1477 | // Set up a very simple shader. |
| 1478 | ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 1479 | glViewport(0, 0, kSize, kSize); |
| 1480 | |
| 1481 | // Draw |
| 1482 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 1483 | ASSERT_GL_NO_ERROR(); |
| 1484 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1485 | |
| 1486 | // Update the masked out attachment and draw again. |
| 1487 | std::vector<GLColor> redPixels(kSize * kSize, GLColor::red); |
| 1488 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kSize, kSize, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1489 | redPixels.data()); |
| 1490 | |
| 1491 | // Draw |
| 1492 | drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true); |
| 1493 | ASSERT_GL_NO_ERROR(); |
| 1494 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1495 | |
| 1496 | glReadBuffer(GL_COLOR_ATTACHMENT1); |
| 1497 | ASSERT_GL_NO_ERROR(); |
| 1498 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 1499 | } |
| 1500 | |
Jamie Madill | c9c4e4e | 2020-04-02 10:29:52 -0400 | [diff] [blame] | 1501 | class FramebufferTest : public ANGLETest |
| 1502 | {}; |
| 1503 | |
| 1504 | template <typename T> |
| 1505 | void FillTexture2D(GLuint texture, |
| 1506 | GLsizei width, |
| 1507 | GLsizei height, |
| 1508 | const T &onePixelData, |
| 1509 | GLint level, |
| 1510 | GLint internalFormat, |
| 1511 | GLenum format, |
| 1512 | GLenum type) |
| 1513 | { |
| 1514 | std::vector<T> allPixelsData(width * height, onePixelData); |
| 1515 | |
| 1516 | glBindTexture(GL_TEXTURE_2D, texture); |
| 1517 | glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, |
| 1518 | allPixelsData.data()); |
| 1519 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1520 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1521 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1522 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1523 | } |
| 1524 | |
| 1525 | // Multi-context uses of textures should not cause rendering feedback loops. |
| 1526 | TEST_P(FramebufferTest, MultiContextNoRenderingFeedbackLoops) |
| 1527 | { |
| 1528 | constexpr char kTextureVS[] = |
| 1529 | R"(attribute vec4 a_position; |
| 1530 | varying vec2 v_texCoord; |
| 1531 | void main() { |
| 1532 | gl_Position = a_position; |
| 1533 | v_texCoord = (a_position.xy * 0.5) + 0.5; |
| 1534 | })"; |
| 1535 | |
| 1536 | constexpr char kTextureFS[] = |
| 1537 | R"(precision mediump float; |
| 1538 | varying vec2 v_texCoord; |
| 1539 | uniform sampler2D u_texture; |
| 1540 | void main() { |
| 1541 | gl_FragColor = texture2D(u_texture, v_texCoord).rgba; |
| 1542 | })"; |
| 1543 | |
| 1544 | ANGLE_GL_PROGRAM(textureProgram, kTextureVS, kTextureFS); |
| 1545 | |
| 1546 | glUseProgram(textureProgram.get()); |
| 1547 | GLint uniformLoc = glGetUniformLocation(textureProgram.get(), "u_texture"); |
| 1548 | ASSERT_NE(-1, uniformLoc); |
| 1549 | glUniform1i(uniformLoc, 0); |
| 1550 | |
| 1551 | GLTexture texture; |
| 1552 | FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 1553 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 1554 | // Note that _texture_ is still bound to GL_TEXTURE_2D in this context at this point. |
| 1555 | |
| 1556 | EGLWindow *window = getEGLWindow(); |
| 1557 | EGLDisplay display = window->getDisplay(); |
| 1558 | EGLConfig config = window->getConfig(); |
| 1559 | EGLSurface surface = window->getSurface(); |
| 1560 | EGLint contextAttributes[] = { |
| 1561 | EGL_CONTEXT_MAJOR_VERSION_KHR, |
| 1562 | GetParam().majorVersion, |
| 1563 | EGL_CONTEXT_MINOR_VERSION_KHR, |
| 1564 | GetParam().minorVersion, |
| 1565 | EGL_NONE, |
| 1566 | }; |
| 1567 | EGLContext context1 = eglGetCurrentContext(); |
| 1568 | // Create context2, sharing resources with context1. |
| 1569 | EGLContext context2 = eglCreateContext(display, config, context1, contextAttributes); |
| 1570 | ASSERT_NE(context2, EGL_NO_CONTEXT); |
| 1571 | eglMakeCurrent(display, surface, surface, context2); |
| 1572 | |
| 1573 | constexpr char kVS[] = |
| 1574 | R"(attribute vec4 a_position; |
| 1575 | void main() { |
| 1576 | gl_Position = a_position; |
| 1577 | })"; |
| 1578 | |
| 1579 | constexpr char kFS[] = |
| 1580 | R"(precision mediump float; |
| 1581 | void main() { |
| 1582 | gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); |
| 1583 | })"; |
| 1584 | |
| 1585 | ANGLE_GL_PROGRAM(program, kVS, kFS); |
| 1586 | glUseProgram(program.get()); |
| 1587 | |
| 1588 | ASSERT_GL_NO_ERROR(); |
| 1589 | |
| 1590 | // Render to the texture in context2. |
| 1591 | GLFramebuffer framebuffer; |
| 1592 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1593 | // Texture is still a valid name in context2. |
| 1594 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 1595 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
Jamie Madill | c9c4e4e | 2020-04-02 10:29:52 -0400 | [diff] [blame] | 1596 | // There is no rendering feedback loop at this point. |
| 1597 | |
| 1598 | glDisable(GL_BLEND); |
| 1599 | glDisable(GL_DEPTH_TEST); |
| 1600 | ASSERT_GL_NO_ERROR(); |
| 1601 | |
| 1602 | // If draw is no-op'ed, texture will not be filled appropriately. |
| 1603 | drawQuad(program.get(), "a_position", 0.5f, 1.0f, true); |
| 1604 | ASSERT_GL_NO_ERROR(); |
| 1605 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1606 | |
| 1607 | // Make context1 current again. |
| 1608 | eglMakeCurrent(display, surface, surface, context1); |
| 1609 | |
| 1610 | // Render texture to screen. |
| 1611 | drawQuad(textureProgram.get(), "a_position", 0.5f, 1.0f, true); |
| 1612 | ASSERT_GL_NO_ERROR(); |
| 1613 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1614 | |
| 1615 | eglDestroyContext(display, context2); |
| 1616 | } |
| 1617 | |
Jamie Madill | 2a0c359 | 2020-03-31 15:36:45 -0400 | [diff] [blame] | 1618 | // Ensure cube-incomplete attachments cause incomplete Framebuffers. |
| 1619 | TEST_P(FramebufferTest, IncompleteCubeMap) |
| 1620 | { |
| 1621 | constexpr GLuint kSize = 2; |
| 1622 | |
| 1623 | GLTexture srcTex; |
| 1624 | glBindTexture(GL_TEXTURE_CUBE_MAP, srcTex); |
| 1625 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, |
| 1626 | GL_UNSIGNED_BYTE, nullptr); |
| 1627 | |
| 1628 | GLFramebuffer fbo; |
| 1629 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1630 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
| 1631 | srcTex, 0); |
| 1632 | |
| 1633 | ASSERT_GL_NO_ERROR(); |
| 1634 | ASSERT_GLENUM_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), |
| 1635 | GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT); |
| 1636 | } |
| 1637 | |
Tim Van Patten | e8789a5 | 2020-07-29 12:01:49 -0600 | [diff] [blame] | 1638 | // Test FBOs with different sizes are drawn correctly |
| 1639 | TEST_P(FramebufferTest, BindAndDrawDifferentSizedFBOs) |
| 1640 | { |
| 1641 | // 1. Create FBO 1 with dimensions 16x16 |
| 1642 | // 2. Draw red into FBO 1 (note, FramebufferVk::syncState is called) |
| 1643 | // 3. Create FBO 2 with dimensions 8x8 |
| 1644 | // 4. Draw green into FBO 2 (note, FramebufferVk::syncState is called) |
| 1645 | // 5. Bind FBO 1 (note, it's not dirty) |
| 1646 | // 6. Draw blue into FBO 1 |
| 1647 | // 7. Verify FBO 1 is entirely blue |
| 1648 | |
| 1649 | GLFramebuffer smallFbo; |
| 1650 | GLFramebuffer largeFbo; |
| 1651 | GLTexture smallTexture; |
| 1652 | GLTexture largeTexture; |
| 1653 | constexpr GLsizei kLargeWidth = 16; |
| 1654 | constexpr GLsizei kLargeHeight = 16; |
| 1655 | constexpr GLsizei kSmallWidth = 8; |
| 1656 | constexpr GLsizei kSmallHeight = 8; |
| 1657 | |
| 1658 | ANGLE_GL_PROGRAM(redProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red()); |
| 1659 | ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green()); |
| 1660 | ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
| 1661 | |
| 1662 | // 1. Create FBO 1 with dimensions 16x16 |
| 1663 | glBindFramebuffer(GL_FRAMEBUFFER, largeFbo); |
| 1664 | glBindTexture(GL_TEXTURE_2D, largeTexture); |
| 1665 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kLargeWidth, kLargeHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1666 | nullptr); |
| 1667 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1668 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1669 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, largeTexture, 0); |
| 1670 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1671 | |
| 1672 | // 2. Draw red into FBO 1 (note, FramebufferVk::syncState is called) |
| 1673 | glUseProgram(redProgram); |
| 1674 | drawQuad(redProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 1675 | ASSERT_GL_NO_ERROR(); |
| 1676 | |
| 1677 | // 3. Create FBO 2 with dimensions 8x8 |
| 1678 | glBindFramebuffer(GL_FRAMEBUFFER, smallFbo); |
| 1679 | glBindTexture(GL_TEXTURE_2D, smallTexture); |
| 1680 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSmallWidth, kSmallHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1681 | nullptr); |
| 1682 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1683 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1684 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, smallTexture, 0); |
| 1685 | ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER); |
| 1686 | |
| 1687 | // 4. Draw green into FBO 2 (note, FramebufferVk::syncState is called) |
| 1688 | glUseProgram(greenProgram); |
| 1689 | drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 1690 | ASSERT_GL_NO_ERROR(); |
| 1691 | |
| 1692 | // 5. Bind FBO 1 (note, it's not dirty) |
| 1693 | glBindFramebuffer(GL_FRAMEBUFFER, largeFbo); |
| 1694 | |
| 1695 | // 6. Draw blue into FBO 1 |
| 1696 | glUseProgram(blueProgram); |
| 1697 | drawQuad(blueProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f); |
| 1698 | ASSERT_GL_NO_ERROR(); |
| 1699 | |
| 1700 | // 7. Verify FBO 1 is entirely blue |
| 1701 | EXPECT_PIXEL_RECT_EQ(0, 0, kLargeWidth, kLargeHeight, GLColor::blue); |
| 1702 | } |
| 1703 | |
Tobin Ehlis | 1a01b4b | 2019-11-11 16:41:07 -0700 | [diff] [blame] | 1704 | ANGLE_INSTANTIATE_TEST_ES2(AddDummyTextureNoRenderTargetTest); |
Jamie Madill | c9c4e4e | 2020-04-02 10:29:52 -0400 | [diff] [blame] | 1705 | ANGLE_INSTANTIATE_TEST_ES2(FramebufferTest); |
Shahbaz Youssefi | e28883d | 2020-01-25 23:25:43 -0500 | [diff] [blame] | 1706 | ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(FramebufferFormatsTest); |
| 1707 | ANGLE_INSTANTIATE_TEST_ES3(FramebufferTest_ES3); |
| 1708 | ANGLE_INSTANTIATE_TEST_ES31(FramebufferTest_ES31); |