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 | // |
| 6 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 8 | #include "test_utils/gl_raii.h" |
| 9 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 10 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 11 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 12 | class BlitFramebufferANGLETest : public ANGLETest |
| 13 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 14 | protected: |
| 15 | BlitFramebufferANGLETest() |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 16 | { |
| 17 | setWindowWidth(256); |
| 18 | setWindowHeight(256); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 19 | setConfigRedBits(8); |
| 20 | setConfigGreenBits(8); |
| 21 | setConfigBlueBits(8); |
| 22 | setConfigAlphaBits(8); |
| 23 | setConfigDepthBits(24); |
Geoff Lang | 784cc8f | 2015-02-05 09:00:54 -0500 | [diff] [blame] | 24 | setConfigStencilBits(8); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 25 | |
| 26 | mCheckerProgram = 0; |
| 27 | mBlueProgram = 0; |
| 28 | |
| 29 | mOriginalFBO = 0; |
| 30 | |
| 31 | mUserFBO = 0; |
| 32 | mUserColorBuffer = 0; |
| 33 | mUserDepthStencilBuffer = 0; |
| 34 | |
| 35 | mSmallFBO = 0; |
| 36 | mSmallColorBuffer = 0; |
| 37 | mSmallDepthStencilBuffer = 0; |
| 38 | |
| 39 | mColorOnlyFBO = 0; |
| 40 | mColorOnlyColorBuffer = 0; |
| 41 | |
| 42 | mDiffFormatFBO = 0; |
| 43 | mDiffFormatColorBuffer = 0; |
| 44 | |
| 45 | mDiffSizeFBO = 0; |
| 46 | mDiffSizeColorBuffer = 0; |
| 47 | |
| 48 | mMRTFBO = 0; |
| 49 | mMRTColorBuffer0 = 0; |
| 50 | mMRTColorBuffer1 = 0; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 51 | |
| 52 | mRGBAColorbuffer = 0; |
| 53 | mRGBAFBO = 0; |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 54 | mRGBAMultisampledRenderbuffer = 0; |
| 55 | mRGBAMultisampledFBO = 0; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 56 | |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 57 | mBGRAColorbuffer = 0; |
| 58 | mBGRAFBO = 0; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 59 | mBGRAMultisampledRenderbuffer = 0; |
| 60 | mBGRAMultisampledFBO = 0; |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | virtual void SetUp() |
| 64 | { |
| 65 | ANGLETest::SetUp(); |
| 66 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 67 | mCheckerProgram = |
| 68 | CompileProgram(essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Checkered()); |
| 69 | mBlueProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 70 | if (mCheckerProgram == 0 || mBlueProgram == 0) |
| 71 | { |
| 72 | FAIL() << "shader compilation failed."; |
| 73 | } |
| 74 | |
| 75 | EXPECT_GL_NO_ERROR(); |
| 76 | |
| 77 | GLint originalFBO; |
| 78 | glGetIntegerv(GL_FRAMEBUFFER_BINDING, &originalFBO); |
| 79 | if (originalFBO >= 0) |
| 80 | { |
| 81 | mOriginalFBO = (GLuint)originalFBO; |
| 82 | } |
| 83 | |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 84 | GLenum format = GL_BGRA_EXT; |
| 85 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 86 | glGenFramebuffers(1, &mUserFBO); |
| 87 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 88 | glGenTextures(1, &mUserColorBuffer); |
| 89 | glGenRenderbuffers(1, &mUserDepthStencilBuffer); |
| 90 | glBindTexture(GL_TEXTURE_2D, mUserColorBuffer); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 91 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mUserColorBuffer, 0); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 92 | glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth(), getWindowHeight(), 0, format, |
| 93 | GL_UNSIGNED_BYTE, nullptr); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 94 | glBindRenderbuffer(GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 95 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth(), getWindowHeight()); |
| 96 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 97 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 98 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 99 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 100 | ASSERT_GL_NO_ERROR(); |
| 101 | |
| 102 | glGenFramebuffers(1, &mSmallFBO); |
| 103 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 104 | glGenTextures(1, &mSmallColorBuffer); |
| 105 | glGenRenderbuffers(1, &mSmallDepthStencilBuffer); |
| 106 | glBindTexture(GL_TEXTURE_2D, mSmallColorBuffer); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 107 | glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth() / 2, getWindowHeight() / 2, 0, |
| 108 | format, GL_UNSIGNED_BYTE, nullptr); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 109 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mSmallColorBuffer, 0); |
| 110 | glBindRenderbuffer(GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 111 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth() / 2, getWindowHeight() / 2); |
| 112 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 113 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 114 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 115 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 116 | ASSERT_GL_NO_ERROR(); |
| 117 | |
| 118 | glGenFramebuffers(1, &mColorOnlyFBO); |
| 119 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 120 | glGenTextures(1, &mColorOnlyColorBuffer); |
| 121 | glBindTexture(GL_TEXTURE_2D, mColorOnlyColorBuffer); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 122 | glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth(), getWindowHeight(), 0, format, |
| 123 | GL_UNSIGNED_BYTE, nullptr); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 124 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorOnlyColorBuffer, 0); |
| 125 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 126 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 127 | ASSERT_GL_NO_ERROR(); |
| 128 | |
| 129 | glGenFramebuffers(1, &mDiffFormatFBO); |
| 130 | glBindFramebuffer(GL_FRAMEBUFFER, mDiffFormatFBO); |
| 131 | glGenTextures(1, &mDiffFormatColorBuffer); |
| 132 | glBindTexture(GL_TEXTURE_2D, mDiffFormatColorBuffer); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 133 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, |
| 134 | GL_UNSIGNED_SHORT_5_6_5, nullptr); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 135 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffFormatColorBuffer, 0); |
| 136 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 137 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 138 | ASSERT_GL_NO_ERROR(); |
| 139 | |
| 140 | glGenFramebuffers(1, &mDiffSizeFBO); |
| 141 | glBindFramebuffer(GL_FRAMEBUFFER, mDiffSizeFBO); |
| 142 | glGenTextures(1, &mDiffSizeColorBuffer); |
| 143 | glBindTexture(GL_TEXTURE_2D, mDiffSizeColorBuffer); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 144 | glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth() * 2, getWindowHeight() * 2, 0, |
| 145 | format, GL_UNSIGNED_BYTE, nullptr); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 146 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffSizeColorBuffer, 0); |
| 147 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 148 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 149 | ASSERT_GL_NO_ERROR(); |
| 150 | |
| 151 | if (extensionEnabled("GL_EXT_draw_buffers")) |
| 152 | { |
| 153 | glGenFramebuffers(1, &mMRTFBO); |
| 154 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 155 | glGenTextures(1, &mMRTColorBuffer0); |
| 156 | glGenTextures(1, &mMRTColorBuffer1); |
| 157 | glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer0); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 158 | glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth(), getWindowHeight(), 0, format, |
| 159 | GL_UNSIGNED_BYTE, nullptr); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 160 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 161 | glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer1); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 162 | glTexImage2D(GL_TEXTURE_2D, 0, format, getWindowWidth(), getWindowHeight(), 0, format, |
| 163 | GL_UNSIGNED_BYTE, nullptr); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 164 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 165 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 166 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 167 | ASSERT_GL_NO_ERROR(); |
| 168 | } |
| 169 | |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 170 | if (extensionEnabled("GL_ANGLE_framebuffer_multisample") && |
| 171 | extensionEnabled("GL_OES_rgb8_rgba8")) |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 172 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 173 | // RGBA single-sampled framebuffer |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 174 | glGenTextures(1, &mRGBAColorbuffer); |
| 175 | glBindTexture(GL_TEXTURE_2D, mRGBAColorbuffer); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 176 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 177 | GL_UNSIGNED_BYTE, nullptr); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 178 | |
| 179 | glGenFramebuffers(1, &mRGBAFBO); |
| 180 | glBindFramebuffer(GL_FRAMEBUFFER, mRGBAFBO); |
| 181 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mRGBAColorbuffer, 0); |
| 182 | |
| 183 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 184 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 185 | |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 186 | // RGBA multisampled framebuffer |
| 187 | glGenRenderbuffers(1, &mRGBAMultisampledRenderbuffer); |
| 188 | glBindRenderbuffer(GL_RENDERBUFFER, mRGBAMultisampledRenderbuffer); |
| 189 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_RGBA8, getWindowWidth(), |
| 190 | getWindowHeight()); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 191 | |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 192 | glGenFramebuffers(1, &mRGBAMultisampledFBO); |
| 193 | glBindFramebuffer(GL_FRAMEBUFFER, mRGBAMultisampledFBO); |
| 194 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, |
| 195 | mRGBAMultisampledRenderbuffer); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 196 | |
| 197 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 198 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 199 | |
| 200 | if (extensionEnabled("GL_EXT_texture_format_BGRA8888")) |
| 201 | { |
| 202 | // BGRA single-sampled framebuffer |
| 203 | glGenTextures(1, &mBGRAColorbuffer); |
| 204 | glBindTexture(GL_TEXTURE_2D, mBGRAColorbuffer); |
| 205 | glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, getWindowWidth(), getWindowHeight(), 0, |
| 206 | GL_BGRA_EXT, GL_UNSIGNED_BYTE, nullptr); |
| 207 | |
| 208 | glGenFramebuffers(1, &mBGRAFBO); |
| 209 | glBindFramebuffer(GL_FRAMEBUFFER, mBGRAFBO); |
| 210 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 211 | mBGRAColorbuffer, 0); |
| 212 | |
| 213 | ASSERT_GL_NO_ERROR(); |
| 214 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 215 | |
| 216 | // BGRA multisampled framebuffer |
| 217 | glGenRenderbuffers(1, &mBGRAMultisampledRenderbuffer); |
| 218 | glBindRenderbuffer(GL_RENDERBUFFER, mBGRAMultisampledRenderbuffer); |
| 219 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_BGRA8_EXT, |
| 220 | getWindowWidth(), getWindowHeight()); |
| 221 | |
| 222 | glGenFramebuffers(1, &mBGRAMultisampledFBO); |
| 223 | glBindFramebuffer(GL_FRAMEBUFFER, mBGRAMultisampledFBO); |
| 224 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, |
| 225 | mBGRAMultisampledRenderbuffer); |
| 226 | |
| 227 | ASSERT_GL_NO_ERROR(); |
| 228 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 229 | } |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 230 | } |
| 231 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 232 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 233 | } |
| 234 | |
| 235 | virtual void TearDown() |
| 236 | { |
| 237 | glDeleteProgram(mCheckerProgram); |
| 238 | glDeleteProgram(mBlueProgram); |
| 239 | |
| 240 | glDeleteFramebuffers(1, &mUserFBO); |
| 241 | glDeleteTextures(1, &mUserColorBuffer); |
| 242 | glDeleteRenderbuffers(1, &mUserDepthStencilBuffer); |
| 243 | |
| 244 | glDeleteFramebuffers(1, &mSmallFBO); |
| 245 | glDeleteTextures(1, &mSmallColorBuffer); |
| 246 | glDeleteRenderbuffers(1, &mSmallDepthStencilBuffer); |
| 247 | |
| 248 | glDeleteFramebuffers(1, &mColorOnlyFBO); |
| 249 | glDeleteTextures(1, &mSmallDepthStencilBuffer); |
| 250 | |
| 251 | glDeleteFramebuffers(1, &mDiffFormatFBO); |
| 252 | glDeleteTextures(1, &mDiffFormatColorBuffer); |
| 253 | |
| 254 | glDeleteFramebuffers(1, &mDiffSizeFBO); |
| 255 | glDeleteTextures(1, &mDiffSizeColorBuffer); |
| 256 | |
| 257 | if (extensionEnabled("GL_EXT_draw_buffers")) |
| 258 | { |
| 259 | glDeleteFramebuffers(1, &mMRTFBO); |
| 260 | glDeleteTextures(1, &mMRTColorBuffer0); |
| 261 | glDeleteTextures(1, &mMRTColorBuffer1); |
| 262 | } |
| 263 | |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 264 | if (mRGBAColorbuffer != 0) |
| 265 | { |
| 266 | glDeleteTextures(1, &mRGBAColorbuffer); |
| 267 | } |
| 268 | |
| 269 | if (mRGBAFBO != 0) |
| 270 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 271 | glDeleteFramebuffers(1, &mRGBAFBO); |
| 272 | } |
| 273 | |
| 274 | if (mRGBAMultisampledRenderbuffer != 0) |
| 275 | { |
| 276 | glDeleteRenderbuffers(1, &mRGBAMultisampledRenderbuffer); |
| 277 | } |
| 278 | |
| 279 | if (mRGBAMultisampledFBO != 0) |
| 280 | { |
| 281 | glDeleteFramebuffers(1, &mRGBAMultisampledFBO); |
| 282 | } |
| 283 | |
| 284 | if (mBGRAColorbuffer != 0) |
| 285 | { |
| 286 | glDeleteTextures(1, &mBGRAColorbuffer); |
| 287 | } |
| 288 | |
| 289 | if (mBGRAFBO != 0) |
| 290 | { |
| 291 | glDeleteFramebuffers(1, &mBGRAFBO); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | if (mBGRAMultisampledRenderbuffer != 0) |
| 295 | { |
| 296 | glDeleteRenderbuffers(1, &mBGRAMultisampledRenderbuffer); |
| 297 | } |
| 298 | |
| 299 | if (mBGRAMultisampledFBO != 0) |
| 300 | { |
| 301 | glDeleteFramebuffers(1, &mBGRAMultisampledFBO); |
| 302 | } |
| 303 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 304 | ANGLETest::TearDown(); |
| 305 | } |
| 306 | |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 307 | void multisampleTestHelper(GLuint readFramebuffer, GLuint drawFramebuffer) |
| 308 | { |
| 309 | glClearColor(0.0, 1.0, 0.0, 1.0); |
| 310 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, readFramebuffer); |
| 311 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 312 | EXPECT_GL_NO_ERROR(); |
| 313 | |
| 314 | glBindFramebuffer(GL_READ_FRAMEBUFFER, readFramebuffer); |
| 315 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFramebuffer); |
| 316 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), |
| 317 | getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 318 | EXPECT_GL_NO_ERROR(); |
| 319 | |
| 320 | glBindFramebuffer(GL_READ_FRAMEBUFFER, drawFramebuffer); |
| 321 | EXPECT_PIXEL_EQ(getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 322 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 323 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 324 | EXPECT_PIXEL_EQ(getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 325 | } |
| 326 | |
| 327 | bool checkExtension(const std::string &extension) |
| 328 | { |
| 329 | if (!extensionEnabled(extension)) |
| 330 | { |
| 331 | std::cout << "Test skipped because " << extension << " not supported." << std::endl; |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 338 | GLuint mCheckerProgram; |
| 339 | GLuint mBlueProgram; |
| 340 | |
| 341 | GLuint mOriginalFBO; |
| 342 | |
| 343 | GLuint mUserFBO; |
| 344 | GLuint mUserColorBuffer; |
| 345 | GLuint mUserDepthStencilBuffer; |
| 346 | |
| 347 | GLuint mSmallFBO; |
| 348 | GLuint mSmallColorBuffer; |
| 349 | GLuint mSmallDepthStencilBuffer; |
| 350 | |
| 351 | GLuint mColorOnlyFBO; |
| 352 | GLuint mColorOnlyColorBuffer; |
| 353 | |
| 354 | GLuint mDiffFormatFBO; |
| 355 | GLuint mDiffFormatColorBuffer; |
| 356 | |
| 357 | GLuint mDiffSizeFBO; |
| 358 | GLuint mDiffSizeColorBuffer; |
| 359 | |
| 360 | GLuint mMRTFBO; |
| 361 | GLuint mMRTColorBuffer0; |
| 362 | GLuint mMRTColorBuffer1; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 363 | |
| 364 | GLuint mRGBAColorbuffer; |
| 365 | GLuint mRGBAFBO; |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 366 | GLuint mRGBAMultisampledRenderbuffer; |
| 367 | GLuint mRGBAMultisampledFBO; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 368 | |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 369 | GLuint mBGRAColorbuffer; |
| 370 | GLuint mBGRAFBO; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 371 | GLuint mBGRAMultisampledRenderbuffer; |
| 372 | GLuint mBGRAMultisampledFBO; |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | // Draw to user-created framebuffer, blit whole-buffer color to original framebuffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 376 | TEST_P(BlitFramebufferANGLETest, BlitColorToDefault) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 377 | { |
| 378 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 379 | |
| 380 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 381 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 382 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 383 | |
| 384 | EXPECT_GL_NO_ERROR(); |
| 385 | |
| 386 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 387 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 388 | |
| 389 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 390 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 391 | |
| 392 | EXPECT_GL_NO_ERROR(); |
| 393 | |
| 394 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 395 | |
| 396 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 397 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 398 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 399 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 400 | } |
| 401 | |
| 402 | // Draw to system framebuffer, blit whole-buffer color to user-created framebuffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 403 | TEST_P(BlitFramebufferANGLETest, ReverseColorBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 404 | { |
| 405 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 406 | |
| 407 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 408 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 409 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 410 | |
| 411 | EXPECT_GL_NO_ERROR(); |
| 412 | |
| 413 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 414 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 415 | |
| 416 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 417 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 418 | |
| 419 | EXPECT_GL_NO_ERROR(); |
| 420 | |
| 421 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 422 | |
| 423 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 424 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 425 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 426 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 427 | } |
| 428 | |
| 429 | // blit from user-created FBO to system framebuffer, with the scissor test enabled. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 430 | TEST_P(BlitFramebufferANGLETest, ScissoredBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 431 | { |
| 432 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 433 | |
| 434 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 435 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 436 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 437 | |
| 438 | EXPECT_GL_NO_ERROR(); |
| 439 | |
| 440 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 441 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 442 | |
| 443 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 444 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 445 | |
| 446 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 447 | glEnable(GL_SCISSOR_TEST); |
| 448 | |
| 449 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 450 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 451 | |
| 452 | EXPECT_GL_NO_ERROR(); |
| 453 | |
| 454 | glDisable(GL_SCISSOR_TEST); |
| 455 | |
| 456 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 457 | |
| 458 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 459 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 460 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 461 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 462 | } |
| 463 | |
| 464 | // blit from system FBO to user-created framebuffer, with the scissor test enabled. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 465 | TEST_P(BlitFramebufferANGLETest, ReverseScissoredBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 466 | { |
| 467 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 468 | |
| 469 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 470 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 471 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 472 | |
| 473 | EXPECT_GL_NO_ERROR(); |
| 474 | |
| 475 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 476 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 477 | |
| 478 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 479 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 480 | |
| 481 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 482 | glEnable(GL_SCISSOR_TEST); |
| 483 | |
| 484 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 485 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 486 | |
| 487 | EXPECT_GL_NO_ERROR(); |
| 488 | |
| 489 | glDisable(GL_SCISSOR_TEST); |
| 490 | |
| 491 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 492 | |
| 493 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 494 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 495 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 496 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 497 | } |
| 498 | |
| 499 | // blit from user-created FBO to system framebuffer, using region larger than buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 500 | TEST_P(BlitFramebufferANGLETest, OversizedBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 501 | { |
| 502 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 503 | |
| 504 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 505 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 506 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 507 | |
| 508 | EXPECT_GL_NO_ERROR(); |
| 509 | |
| 510 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 511 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 512 | |
| 513 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 514 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 515 | |
| 516 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 517 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 518 | |
| 519 | EXPECT_GL_NO_ERROR(); |
| 520 | |
| 521 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 522 | |
| 523 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 524 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 525 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 526 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 527 | } |
| 528 | |
| 529 | // blit from system FBO to user-created framebuffer, using region larger than buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 530 | TEST_P(BlitFramebufferANGLETest, ReverseOversizedBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 531 | { |
| 532 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 533 | |
| 534 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 535 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 536 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 537 | |
| 538 | EXPECT_GL_NO_ERROR(); |
| 539 | |
| 540 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 541 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 542 | |
| 543 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 544 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 545 | |
| 546 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 547 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 548 | EXPECT_GL_NO_ERROR(); |
| 549 | |
| 550 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 551 | |
| 552 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 553 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 554 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 555 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 556 | } |
| 557 | |
| 558 | // blit from user-created FBO to system framebuffer, with depth buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 559 | TEST_P(BlitFramebufferANGLETest, BlitWithDepth) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 560 | { |
| 561 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 562 | |
| 563 | glDepthMask(GL_TRUE); |
| 564 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 565 | |
| 566 | glEnable(GL_DEPTH_TEST); |
| 567 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 568 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 569 | |
| 570 | EXPECT_GL_NO_ERROR(); |
| 571 | |
| 572 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 573 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 574 | |
| 575 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 576 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 577 | |
| 578 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 579 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 580 | EXPECT_GL_NO_ERROR(); |
| 581 | |
| 582 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 583 | |
| 584 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 585 | drawQuad(mBlueProgram, essl1_shaders::PositionAttrib(), 0.8f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 586 | |
| 587 | glDisable(GL_DEPTH_TEST); |
| 588 | |
| 589 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 590 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 591 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 592 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 593 | } |
| 594 | |
| 595 | // blit from system FBO to user-created framebuffer, with depth buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 596 | TEST_P(BlitFramebufferANGLETest, ReverseBlitWithDepth) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 597 | { |
| 598 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 599 | |
| 600 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 601 | |
| 602 | glEnable(GL_DEPTH_TEST); |
| 603 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 604 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 605 | |
| 606 | EXPECT_GL_NO_ERROR(); |
| 607 | |
| 608 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 609 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 610 | |
| 611 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 612 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 613 | |
| 614 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 615 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 616 | EXPECT_GL_NO_ERROR(); |
| 617 | |
| 618 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 619 | |
| 620 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 621 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 622 | drawQuad(mBlueProgram, essl1_shaders::PositionAttrib(), 0.8f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 623 | |
| 624 | glDisable(GL_DEPTH_TEST); |
| 625 | |
| 626 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 627 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 628 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 629 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 630 | } |
| 631 | |
| 632 | // blit from one region of the system fbo to another-- this should fail. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 633 | TEST_P(BlitFramebufferANGLETest, BlitSameBufferOriginal) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 634 | { |
| 635 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 636 | |
| 637 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 638 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 639 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 640 | |
| 641 | EXPECT_GL_NO_ERROR(); |
| 642 | |
| 643 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 644 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 645 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 646 | } |
| 647 | |
| 648 | // blit from one region of the system fbo to another. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 649 | TEST_P(BlitFramebufferANGLETest, BlitSameBufferUser) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 650 | { |
| 651 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 652 | |
| 653 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 654 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 655 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 656 | |
| 657 | EXPECT_GL_NO_ERROR(); |
| 658 | |
| 659 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 660 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 661 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 662 | } |
| 663 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 664 | TEST_P(BlitFramebufferANGLETest, BlitPartialColor) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 665 | { |
| 666 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 667 | |
| 668 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 669 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 670 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 671 | |
| 672 | EXPECT_GL_NO_ERROR(); |
| 673 | |
| 674 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 675 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 676 | |
| 677 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 678 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 679 | |
| 680 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight(), |
| 681 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 682 | |
| 683 | EXPECT_GL_NO_ERROR(); |
| 684 | |
| 685 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 686 | |
| 687 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 688 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 689 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 690 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 691 | } |
| 692 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 693 | TEST_P(BlitFramebufferANGLETest, BlitDifferentSizes) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 694 | { |
| 695 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 696 | |
| 697 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 698 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 699 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 700 | |
| 701 | EXPECT_GL_NO_ERROR(); |
| 702 | |
| 703 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mSmallFBO); |
| 704 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 705 | |
| 706 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 707 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 708 | |
| 709 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 710 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 711 | |
| 712 | EXPECT_GL_NO_ERROR(); |
| 713 | |
| 714 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 715 | |
| 716 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 717 | |
| 718 | EXPECT_GL_NO_ERROR(); |
| 719 | } |
| 720 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 721 | TEST_P(BlitFramebufferANGLETest, BlitWithMissingAttachments) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 722 | { |
| 723 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 724 | |
| 725 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 726 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 727 | |
| 728 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 729 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 730 | |
| 731 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 732 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 733 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 734 | // generate INVALID_OPERATION if the read FBO has no depth attachment |
| 735 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), |
| 736 | getWindowHeight(), GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, |
| 737 | GL_NEAREST); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 738 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 739 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 740 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 741 | // generate INVALID_OPERATION if the read FBO has no stencil attachment |
| 742 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), |
| 743 | getWindowHeight(), GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, |
| 744 | GL_NEAREST); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 745 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 746 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 747 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 748 | // generate INVALID_OPERATION if we read from a missing color attachment |
| 749 | glReadBuffer(GL_COLOR_ATTACHMENT1); |
| 750 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), |
| 751 | getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 752 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 753 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 754 | } |
| 755 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 756 | TEST_P(BlitFramebufferANGLETest, BlitStencil) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 757 | { |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame] | 758 | // TODO(jmadill): Figure out if we can fix this on D3D9. |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 759 | // https://code.google.com/p/angleproject/issues/detail?id=2205 |
| 760 | ANGLE_SKIP_TEST_IF(IsIntel() && IsD3D9()); |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame] | 761 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 762 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 763 | |
| 764 | glClear(GL_COLOR_BUFFER_BIT); |
| 765 | // fill the stencil buffer with 0x1 |
| 766 | glStencilFunc(GL_ALWAYS, 0x1, 0xFF); |
| 767 | glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 768 | glEnable(GL_STENCIL_TEST); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 769 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.3f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 770 | |
| 771 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 772 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 773 | |
| 774 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 775 | glClearStencil(0x0); |
| 776 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 777 | |
| 778 | // depth blit request should be silently ignored, because the read FBO has no depth attachment |
| 779 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 780 | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); |
| 781 | |
| 782 | EXPECT_GL_NO_ERROR(); |
| 783 | |
| 784 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 785 | |
| 786 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 787 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 788 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 789 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 790 | |
| 791 | glStencilFunc(GL_EQUAL, 0x1, 0xFF); // only pass if stencil buffer at pixel reads 0x1 |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 792 | drawQuad(mBlueProgram, essl1_shaders::PositionAttrib(), |
| 793 | 0.8f); // blue quad will draw if stencil buffer was copied |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 794 | glDisable(GL_STENCIL_TEST); |
| 795 | |
| 796 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 797 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 798 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 799 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 800 | } |
| 801 | |
| 802 | // make sure that attempting to blit a partial depth buffer issues an error |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 803 | TEST_P(BlitFramebufferANGLETest, BlitPartialDepthStencil) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 804 | { |
| 805 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 806 | |
| 807 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 808 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 809 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 810 | |
| 811 | EXPECT_GL_NO_ERROR(); |
| 812 | |
| 813 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 814 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 815 | |
| 816 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 817 | getWindowWidth() / 2, getWindowHeight() / 2, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 818 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 819 | } |
| 820 | |
| 821 | // Test blit with MRT framebuffers |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 822 | TEST_P(BlitFramebufferANGLETest, BlitMRT) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 823 | { |
| 824 | if (!extensionEnabled("GL_EXT_draw_buffers")) |
| 825 | { |
| 826 | return; |
| 827 | } |
| 828 | |
| 829 | GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; |
| 830 | |
| 831 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 832 | glDrawBuffersEXT(2, drawBuffers); |
| 833 | |
| 834 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 835 | |
| 836 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 837 | |
| 838 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.8f); |
| 839 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 840 | EXPECT_GL_NO_ERROR(); |
| 841 | |
| 842 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 843 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mMRTFBO); |
| 844 | |
| 845 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 846 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 847 | |
| 848 | EXPECT_GL_NO_ERROR(); |
| 849 | |
| 850 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 851 | |
| 852 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 853 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 854 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 855 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 856 | |
| 857 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); |
| 858 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 859 | |
| 860 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 861 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 862 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 863 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 864 | |
| 865 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 866 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 867 | } |
| 868 | |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 869 | // Test multisampled framebuffer blits if supported |
| 870 | TEST_P(BlitFramebufferANGLETest, MultisampledRGBAToRGBA) |
| 871 | { |
| 872 | if (!checkExtension("GL_ANGLE_framebuffer_multisample")) |
| 873 | return; |
| 874 | |
| 875 | if (!checkExtension("GL_OES_rgb8_rgba8")) |
| 876 | return; |
| 877 | |
| 878 | multisampleTestHelper(mRGBAMultisampledFBO, mRGBAFBO); |
| 879 | } |
| 880 | |
| 881 | TEST_P(BlitFramebufferANGLETest, MultisampledRGBAToBGRA) |
| 882 | { |
| 883 | if (!checkExtension("GL_ANGLE_framebuffer_multisample")) |
| 884 | return; |
| 885 | |
| 886 | if (!checkExtension("GL_OES_rgb8_rgba8")) |
| 887 | return; |
| 888 | |
| 889 | if (!checkExtension("GL_EXT_texture_format_BGRA8888")) |
| 890 | return; |
| 891 | |
| 892 | multisampleTestHelper(mRGBAMultisampledFBO, mBGRAFBO); |
| 893 | } |
| 894 | |
| 895 | TEST_P(BlitFramebufferANGLETest, MultisampledBGRAToRGBA) |
| 896 | { |
| 897 | if (!checkExtension("GL_ANGLE_framebuffer_multisample")) |
| 898 | return; |
| 899 | |
| 900 | if (!checkExtension("GL_OES_rgb8_rgba8")) |
| 901 | return; |
| 902 | |
| 903 | if (!checkExtension("GL_EXT_texture_format_BGRA8888")) |
| 904 | return; |
| 905 | |
| 906 | multisampleTestHelper(mBGRAMultisampledFBO, mRGBAFBO); |
| 907 | } |
| 908 | |
| 909 | TEST_P(BlitFramebufferANGLETest, MultisampledBGRAToBGRA) |
| 910 | { |
| 911 | if (!checkExtension("GL_ANGLE_framebuffer_multisample")) |
| 912 | return; |
| 913 | |
| 914 | if (!checkExtension("GL_OES_rgb8_rgba8")) |
| 915 | return; |
| 916 | |
| 917 | if (!checkExtension("GL_EXT_texture_format_BGRA8888")) |
| 918 | return; |
| 919 | |
| 920 | multisampleTestHelper(mBGRAMultisampledFBO, mBGRAFBO); |
| 921 | } |
| 922 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 923 | // Make sure that attempts to stretch in a blit call issue an error |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 924 | TEST_P(BlitFramebufferANGLETest, ErrorStretching) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 925 | { |
| 926 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 927 | |
| 928 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 929 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 930 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 931 | |
| 932 | EXPECT_GL_NO_ERROR(); |
| 933 | |
| 934 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 935 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 936 | |
| 937 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 938 | getWindowWidth(), getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 939 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 940 | } |
| 941 | |
| 942 | // Make sure that attempts to flip in a blit call issue an error |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 943 | TEST_P(BlitFramebufferANGLETest, ErrorFlipping) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 944 | { |
| 945 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 946 | |
| 947 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 948 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 949 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 950 | |
| 951 | EXPECT_GL_NO_ERROR(); |
| 952 | |
| 953 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 954 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 955 | |
| 956 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight() / 2, |
| 957 | 0, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 958 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 959 | } |
| 960 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 961 | TEST_P(BlitFramebufferANGLETest, Errors) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 962 | { |
| 963 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 964 | |
| 965 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 966 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 967 | drawQuad(mCheckerProgram, essl1_shaders::PositionAttrib(), 0.5f); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 968 | |
| 969 | EXPECT_GL_NO_ERROR(); |
| 970 | |
| 971 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 972 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 973 | |
| 974 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 975 | GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 976 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 977 | |
| 978 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 979 | GL_COLOR_BUFFER_BIT | 234, GL_NEAREST); |
| 980 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 981 | |
| 982 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mDiffFormatFBO); |
| 983 | |
| 984 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 985 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 986 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 987 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 988 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 989 | // TODO(geofflang): Fix the dependence on glBlitFramebufferANGLE without checks and assuming the |
| 990 | // default framebuffer is BGRA to enable the GL and GLES backends. (http://anglebug.com/1289) |
| 991 | |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 992 | class BlitFramebufferTest : public ANGLETest |
| 993 | { |
| 994 | protected: |
| 995 | BlitFramebufferTest() |
| 996 | { |
| 997 | setWindowWidth(256); |
| 998 | setWindowHeight(256); |
| 999 | setConfigRedBits(8); |
| 1000 | setConfigGreenBits(8); |
| 1001 | setConfigBlueBits(8); |
| 1002 | setConfigAlphaBits(8); |
| 1003 | setConfigDepthBits(24); |
| 1004 | setConfigStencilBits(8); |
| 1005 | } |
Olli Etuaho | de27959 | 2018-04-26 12:25:13 +0300 | [diff] [blame] | 1006 | |
| 1007 | void initColorFBO(GLFramebuffer *fbo, |
| 1008 | GLRenderbuffer *rbo, |
| 1009 | GLenum rboFormat, |
| 1010 | GLsizei width, |
| 1011 | GLsizei height) |
| 1012 | { |
| 1013 | glBindRenderbuffer(GL_RENDERBUFFER, *rbo); |
| 1014 | glRenderbufferStorage(GL_RENDERBUFFER, rboFormat, width, height); |
| 1015 | |
| 1016 | glBindFramebuffer(GL_FRAMEBUFFER, *fbo); |
| 1017 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, *rbo); |
| 1018 | } |
| 1019 | |
| 1020 | void initColorFBOWithCheckerPattern(GLFramebuffer *fbo, |
| 1021 | GLRenderbuffer *rbo, |
| 1022 | GLenum rboFormat, |
| 1023 | GLsizei width, |
| 1024 | GLsizei height) |
| 1025 | { |
| 1026 | initColorFBO(fbo, rbo, rboFormat, width, height); |
| 1027 | |
| 1028 | ANGLE_GL_PROGRAM(checkerProgram, essl1_shaders::vs::Passthrough(), |
| 1029 | essl1_shaders::fs::Checkered()); |
| 1030 | glViewport(0, 0, width, height); |
| 1031 | glBindFramebuffer(GL_FRAMEBUFFER, *fbo); |
| 1032 | drawQuad(checkerProgram.get(), essl1_shaders::PositionAttrib(), 0.5f); |
| 1033 | } |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1034 | }; |
| 1035 | |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1036 | // Tests resolving a multisample depth buffer. |
| 1037 | TEST_P(BlitFramebufferTest, MultisampleDepth) |
| 1038 | { |
Geoff Lang | f1bcd01 | 2018-04-27 14:21:55 -0400 | [diff] [blame^] | 1039 | // TODO(oetuaho@nvidia.com): http://crbug.com/837717 |
| 1040 | ANGLE_SKIP_TEST_IF(IsOpenGL() && IsOSX()); |
| 1041 | |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1042 | GLRenderbuffer renderbuf; |
| 1043 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get()); |
| 1044 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 256, 256); |
| 1045 | |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1046 | const std::string &fragment = |
| 1047 | "#version 300 es\n" |
| 1048 | "out mediump vec4 red;\n" |
| 1049 | "void main() {\n" |
| 1050 | " red = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1051 | " gl_FragDepth = 0.5;\n" |
| 1052 | "}"; |
| 1053 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1054 | ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), fragment); |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1055 | |
| 1056 | GLFramebuffer framebuffer; |
| 1057 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1058 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, |
| 1059 | renderbuf.get()); |
| 1060 | |
| 1061 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1062 | |
| 1063 | glClearDepthf(0.5f); |
| 1064 | glClear(GL_DEPTH_BUFFER_BIT); |
| 1065 | |
| 1066 | GLRenderbuffer destRenderbuf; |
| 1067 | glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get()); |
| 1068 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 256, 256); |
| 1069 | |
| 1070 | GLFramebuffer resolved; |
| 1071 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get()); |
| 1072 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, |
| 1073 | destRenderbuf.get()); |
| 1074 | |
| 1075 | glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get()); |
| 1076 | glBlitFramebuffer(0, 0, 256, 256, 0, 0, 256, 256, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 1077 | |
| 1078 | glBindFramebuffer(GL_FRAMEBUFFER, resolved.get()); |
| 1079 | |
| 1080 | GLTexture colorbuf; |
| 1081 | glBindTexture(GL_TEXTURE_2D, colorbuf.get()); |
| 1082 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256); |
| 1083 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuf.get(), 0); |
| 1084 | |
| 1085 | ASSERT_GL_NO_ERROR(); |
| 1086 | |
| 1087 | // Clear to green |
| 1088 | glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 1089 | glClear(GL_COLOR_BUFFER_BIT); |
| 1090 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1091 | |
| 1092 | // Draw with 0.5f test and the test should pass. |
| 1093 | glEnable(GL_DEPTH_TEST); |
| 1094 | glDepthFunc(GL_EQUAL); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1095 | drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f); |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1096 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 1097 | |
| 1098 | ASSERT_GL_NO_ERROR(); |
| 1099 | } |
| 1100 | |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1101 | // Test resolving a multisampled stencil buffer. |
| 1102 | TEST_P(BlitFramebufferTest, MultisampleStencil) |
| 1103 | { |
Olli Etuaho | de27959 | 2018-04-26 12:25:13 +0300 | [diff] [blame] | 1104 | // Incorrect rendering results seen on AMD Windows OpenGL. http://anglebug.com/2486 |
| 1105 | ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL() && IsWindows()); |
| 1106 | |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1107 | GLRenderbuffer renderbuf; |
| 1108 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get()); |
| 1109 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_STENCIL_INDEX8, 256, 256); |
| 1110 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1111 | ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), essl3_shaders::fs::Red()); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1112 | |
| 1113 | GLFramebuffer framebuffer; |
| 1114 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1115 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 1116 | renderbuf.get()); |
| 1117 | |
| 1118 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1119 | |
| 1120 | // fill the stencil buffer with 0x1 |
| 1121 | glStencilFunc(GL_ALWAYS, 0x1, 0xFF); |
| 1122 | glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
| 1123 | glEnable(GL_STENCIL_TEST); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1124 | drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1125 | |
| 1126 | GLTexture destColorbuf; |
| 1127 | glBindTexture(GL_TEXTURE_2D, destColorbuf.get()); |
| 1128 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256); |
| 1129 | |
| 1130 | GLRenderbuffer destRenderbuf; |
| 1131 | glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get()); |
| 1132 | glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 256, 256); |
| 1133 | |
| 1134 | GLFramebuffer resolved; |
| 1135 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get()); |
| 1136 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 1137 | destColorbuf.get(), 0); |
| 1138 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 1139 | destRenderbuf.get()); |
| 1140 | |
| 1141 | glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get()); |
| 1142 | glBlitFramebuffer(0, 0, 256, 256, 0, 0, 256, 256, GL_STENCIL_BUFFER_BIT, GL_NEAREST); |
| 1143 | |
| 1144 | glBindFramebuffer(GL_FRAMEBUFFER, resolved.get()); |
| 1145 | |
| 1146 | ASSERT_GL_NO_ERROR(); |
| 1147 | |
| 1148 | // Clear to green |
| 1149 | glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 1150 | glClear(GL_COLOR_BUFFER_BIT); |
| 1151 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1152 | |
| 1153 | // Draw red if the stencil is 0x1, which should be true after the blit/resolve. |
| 1154 | glStencilFunc(GL_EQUAL, 0x1, 0xFF); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1155 | drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1156 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 1157 | |
| 1158 | ASSERT_GL_NO_ERROR(); |
| 1159 | } |
| 1160 | |
Olli Etuaho | de27959 | 2018-04-26 12:25:13 +0300 | [diff] [blame] | 1161 | // Blit an SRGB framebuffer and scale it. |
| 1162 | TEST_P(BlitFramebufferTest, BlitSRGBToRGBAndScale) |
| 1163 | { |
| 1164 | constexpr const GLsizei kWidth = 256; |
| 1165 | constexpr const GLsizei kHeight = 256; |
| 1166 | |
| 1167 | GLRenderbuffer sourceRBO, targetRBO; |
| 1168 | GLFramebuffer sourceFBO, targetFBO; |
| 1169 | initColorFBOWithCheckerPattern(&sourceFBO, &sourceRBO, GL_SRGB8_ALPHA8, kWidth * 2, |
| 1170 | kHeight * 2); |
| 1171 | initColorFBO(&targetFBO, &targetRBO, GL_RGBA8, kWidth, kHeight); |
| 1172 | |
| 1173 | EXPECT_GL_NO_ERROR(); |
| 1174 | |
| 1175 | glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO); |
| 1176 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO); |
| 1177 | |
| 1178 | glViewport(0, 0, kWidth, kHeight); |
| 1179 | |
| 1180 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 1181 | glClear(GL_COLOR_BUFFER_BIT); |
| 1182 | |
| 1183 | // Scale down without flipping. |
| 1184 | glBlitFramebuffer(0, 0, kWidth * 2, kHeight * 2, 0, 0, kWidth, kHeight, GL_COLOR_BUFFER_BIT, |
| 1185 | GL_NEAREST); |
| 1186 | |
| 1187 | EXPECT_GL_NO_ERROR(); |
| 1188 | |
| 1189 | glBindFramebuffer(GL_FRAMEBUFFER, targetFBO); |
| 1190 | |
| 1191 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::red); |
| 1192 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::green); |
| 1193 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::red); |
| 1194 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::green); |
| 1195 | |
| 1196 | glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO); |
| 1197 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO); |
| 1198 | |
| 1199 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 1200 | glClear(GL_COLOR_BUFFER_BIT); |
| 1201 | |
| 1202 | // Scale down and flip in the X direction. |
| 1203 | glBlitFramebuffer(0, 0, kWidth * 2, kHeight * 2, kWidth, 0, 0, kHeight, GL_COLOR_BUFFER_BIT, |
| 1204 | GL_NEAREST); |
| 1205 | |
| 1206 | EXPECT_GL_NO_ERROR(); |
| 1207 | |
| 1208 | glBindFramebuffer(GL_FRAMEBUFFER, targetFBO); |
| 1209 | |
| 1210 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::green); |
| 1211 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::red); |
| 1212 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::green); |
| 1213 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::red); |
| 1214 | } |
| 1215 | |
| 1216 | // Blit a subregion of an SRGB framebuffer to an RGB framebuffer. |
| 1217 | TEST_P(BlitFramebufferTest, PartialBlitSRGBToRGB) |
| 1218 | { |
| 1219 | constexpr const GLsizei kWidth = 256; |
| 1220 | constexpr const GLsizei kHeight = 256; |
| 1221 | |
| 1222 | GLRenderbuffer sourceRBO, targetRBO; |
| 1223 | GLFramebuffer sourceFBO, targetFBO; |
| 1224 | initColorFBOWithCheckerPattern(&sourceFBO, &sourceRBO, GL_SRGB8_ALPHA8, kWidth * 2, |
| 1225 | kHeight * 2); |
| 1226 | initColorFBO(&targetFBO, &targetRBO, GL_RGBA8, kWidth, kHeight); |
| 1227 | |
| 1228 | EXPECT_GL_NO_ERROR(); |
| 1229 | |
| 1230 | glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO); |
| 1231 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO); |
| 1232 | |
| 1233 | glViewport(0, 0, kWidth, kHeight); |
| 1234 | |
| 1235 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 1236 | glClear(GL_COLOR_BUFFER_BIT); |
| 1237 | |
| 1238 | // Blit a part of the source FBO without flipping. |
| 1239 | glBlitFramebuffer(kWidth, kHeight, kWidth * 2, kHeight * 2, 0, 0, kWidth, kHeight, |
| 1240 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1241 | |
| 1242 | EXPECT_GL_NO_ERROR(); |
| 1243 | |
| 1244 | glBindFramebuffer(GL_FRAMEBUFFER, targetFBO); |
| 1245 | |
| 1246 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::red); |
| 1247 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::red); |
| 1248 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::red); |
| 1249 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::red); |
| 1250 | |
| 1251 | glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO); |
| 1252 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO); |
| 1253 | |
| 1254 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 1255 | glClear(GL_COLOR_BUFFER_BIT); |
| 1256 | |
| 1257 | // Blit a part of the source FBO and flip in the X direction. |
| 1258 | glBlitFramebuffer(kWidth * 2, 0, kWidth, kHeight, kWidth, 0, 0, kHeight, GL_COLOR_BUFFER_BIT, |
| 1259 | GL_NEAREST); |
| 1260 | |
| 1261 | EXPECT_GL_NO_ERROR(); |
| 1262 | |
| 1263 | glBindFramebuffer(GL_FRAMEBUFFER, targetFBO); |
| 1264 | |
| 1265 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::green); |
| 1266 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::green); |
| 1267 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::green); |
| 1268 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::green); |
| 1269 | } |
| 1270 | |
| 1271 | // Blit an SRGB framebuffer with an oversized source area (parts outside the source area should be |
| 1272 | // clipped out). |
| 1273 | TEST_P(BlitFramebufferTest, BlitSRGBToRGBOversizedSourceArea) |
| 1274 | { |
| 1275 | // D3D11 blit implementation seems to have a bug where the blit rectangles are computed |
| 1276 | // incorrectly. http://anglebug.com/2521 |
| 1277 | ANGLE_SKIP_TEST_IF(IsD3D11()); |
| 1278 | |
| 1279 | constexpr const GLsizei kWidth = 256; |
| 1280 | constexpr const GLsizei kHeight = 256; |
| 1281 | |
| 1282 | GLRenderbuffer sourceRBO, targetRBO; |
| 1283 | GLFramebuffer sourceFBO, targetFBO; |
| 1284 | initColorFBOWithCheckerPattern(&sourceFBO, &sourceRBO, GL_SRGB8_ALPHA8, kWidth, kHeight); |
| 1285 | initColorFBO(&targetFBO, &targetRBO, GL_RGBA8, kWidth, kHeight); |
| 1286 | |
| 1287 | EXPECT_GL_NO_ERROR(); |
| 1288 | |
| 1289 | glViewport(0, 0, kWidth, kHeight); |
| 1290 | |
| 1291 | glBindFramebuffer(GL_READ_FRAMEBUFFER, sourceFBO); |
| 1292 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFBO); |
| 1293 | |
| 1294 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 1295 | glClear(GL_COLOR_BUFFER_BIT); |
| 1296 | |
| 1297 | // Blit so that the source area gets placed at the center of the target FBO. |
| 1298 | // The width of the source area is 1/4 of the width of the target FBO. |
| 1299 | glBlitFramebuffer(-3 * kWidth / 2, -3 * kHeight / 2, 5 * kWidth / 2, 5 * kHeight / 2, 0, 0, |
| 1300 | kWidth, kHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1301 | |
| 1302 | EXPECT_GL_NO_ERROR(); |
| 1303 | |
| 1304 | glBindFramebuffer(GL_FRAMEBUFFER, targetFBO); |
| 1305 | |
| 1306 | // Source FBO colors can be found in the middle of the target FBO. |
| 1307 | EXPECT_PIXEL_COLOR_EQ(7 * kWidth / 16, 7 * kHeight / 16, GLColor::red); |
| 1308 | EXPECT_PIXEL_COLOR_EQ(9 * kWidth / 16, 7 * kHeight / 16, GLColor::green); |
| 1309 | EXPECT_PIXEL_COLOR_EQ(9 * kWidth / 16, 9 * kHeight / 16, GLColor::red); |
| 1310 | EXPECT_PIXEL_COLOR_EQ(7 * kWidth / 16, 9 * kHeight / 16, GLColor::green); |
| 1311 | |
| 1312 | // Clear color should remain around the edges of the target FBO (WebGL 2.0 spec explicitly |
| 1313 | // requires this and ANGLE is expected to follow that). |
| 1314 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, kHeight / 4, GLColor::black); |
| 1315 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, kHeight / 4, GLColor::black); |
| 1316 | EXPECT_PIXEL_COLOR_EQ(3 * kWidth / 4, 3 * kHeight / 4, GLColor::black); |
| 1317 | EXPECT_PIXEL_COLOR_EQ(kWidth / 4, 3 * kHeight / 4, GLColor::black); |
| 1318 | } |
| 1319 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1320 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Austin Kinross | 2a63b3f | 2016-02-08 12:29:08 -0800 | [diff] [blame] | 1321 | ANGLE_INSTANTIATE_TEST(BlitFramebufferANGLETest, |
| 1322 | ES2_D3D9(), |
| 1323 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE), |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1324 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE), |
| 1325 | ES2_OPENGL(), |
| 1326 | ES3_OPENGL()); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1327 | |
Olli Etuaho | de27959 | 2018-04-26 12:25:13 +0300 | [diff] [blame] | 1328 | // We're specifically testing GL 4.4 and GL 4.3 since on versions earlier than 4.4 FramebufferGL |
| 1329 | // takes a different path for blitting SRGB textures. |
| 1330 | ANGLE_INSTANTIATE_TEST(BlitFramebufferTest, ES3_D3D11(), ES3_OPENGL(4, 4), ES3_OPENGL(4, 3)); |