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 | } |
| 1006 | }; |
| 1007 | |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1008 | // Tests resolving a multisample depth buffer. |
| 1009 | TEST_P(BlitFramebufferTest, MultisampleDepth) |
| 1010 | { |
| 1011 | GLRenderbuffer renderbuf; |
| 1012 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get()); |
| 1013 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 256, 256); |
| 1014 | |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1015 | const std::string &fragment = |
| 1016 | "#version 300 es\n" |
| 1017 | "out mediump vec4 red;\n" |
| 1018 | "void main() {\n" |
| 1019 | " red = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1020 | " gl_FragDepth = 0.5;\n" |
| 1021 | "}"; |
| 1022 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1023 | ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), fragment); |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1024 | |
| 1025 | GLFramebuffer framebuffer; |
| 1026 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1027 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, |
| 1028 | renderbuf.get()); |
| 1029 | |
| 1030 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1031 | |
| 1032 | glClearDepthf(0.5f); |
| 1033 | glClear(GL_DEPTH_BUFFER_BIT); |
| 1034 | |
| 1035 | GLRenderbuffer destRenderbuf; |
| 1036 | glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get()); |
| 1037 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 256, 256); |
| 1038 | |
| 1039 | GLFramebuffer resolved; |
| 1040 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get()); |
| 1041 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, |
| 1042 | destRenderbuf.get()); |
| 1043 | |
| 1044 | glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get()); |
| 1045 | glBlitFramebuffer(0, 0, 256, 256, 0, 0, 256, 256, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 1046 | |
| 1047 | glBindFramebuffer(GL_FRAMEBUFFER, resolved.get()); |
| 1048 | |
| 1049 | GLTexture colorbuf; |
| 1050 | glBindTexture(GL_TEXTURE_2D, colorbuf.get()); |
| 1051 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256); |
| 1052 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuf.get(), 0); |
| 1053 | |
| 1054 | ASSERT_GL_NO_ERROR(); |
| 1055 | |
| 1056 | // Clear to green |
| 1057 | glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 1058 | glClear(GL_COLOR_BUFFER_BIT); |
| 1059 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1060 | |
| 1061 | // Draw with 0.5f test and the test should pass. |
| 1062 | glEnable(GL_DEPTH_TEST); |
| 1063 | glDepthFunc(GL_EQUAL); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1064 | drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f); |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 1065 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 1066 | |
| 1067 | ASSERT_GL_NO_ERROR(); |
| 1068 | } |
| 1069 | |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1070 | // Test resolving a multisampled stencil buffer. |
| 1071 | TEST_P(BlitFramebufferTest, MultisampleStencil) |
| 1072 | { |
| 1073 | GLRenderbuffer renderbuf; |
| 1074 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get()); |
| 1075 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_STENCIL_INDEX8, 256, 256); |
| 1076 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1077 | ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), essl3_shaders::fs::Red()); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1078 | |
| 1079 | GLFramebuffer framebuffer; |
| 1080 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1081 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 1082 | renderbuf.get()); |
| 1083 | |
| 1084 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1085 | |
| 1086 | // fill the stencil buffer with 0x1 |
| 1087 | glStencilFunc(GL_ALWAYS, 0x1, 0xFF); |
| 1088 | glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
| 1089 | glEnable(GL_STENCIL_TEST); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1090 | drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1091 | |
| 1092 | GLTexture destColorbuf; |
| 1093 | glBindTexture(GL_TEXTURE_2D, destColorbuf.get()); |
| 1094 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256); |
| 1095 | |
| 1096 | GLRenderbuffer destRenderbuf; |
| 1097 | glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get()); |
| 1098 | glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 256, 256); |
| 1099 | |
| 1100 | GLFramebuffer resolved; |
| 1101 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get()); |
| 1102 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 1103 | destColorbuf.get(), 0); |
| 1104 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 1105 | destRenderbuf.get()); |
| 1106 | |
| 1107 | glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get()); |
| 1108 | glBlitFramebuffer(0, 0, 256, 256, 0, 0, 256, 256, GL_STENCIL_BUFFER_BIT, GL_NEAREST); |
| 1109 | |
| 1110 | glBindFramebuffer(GL_FRAMEBUFFER, resolved.get()); |
| 1111 | |
| 1112 | ASSERT_GL_NO_ERROR(); |
| 1113 | |
| 1114 | // Clear to green |
| 1115 | glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 1116 | glClear(GL_COLOR_BUFFER_BIT); |
| 1117 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1118 | |
| 1119 | // Draw red if the stencil is 0x1, which should be true after the blit/resolve. |
| 1120 | glStencilFunc(GL_EQUAL, 0x1, 0xFF); |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 1121 | drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1122 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 1123 | |
| 1124 | ASSERT_GL_NO_ERROR(); |
| 1125 | } |
| 1126 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1127 | // 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] | 1128 | ANGLE_INSTANTIATE_TEST(BlitFramebufferANGLETest, |
| 1129 | ES2_D3D9(), |
| 1130 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE), |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1131 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE), |
| 1132 | ES2_OPENGL(), |
| 1133 | ES3_OPENGL()); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1134 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1135 | ANGLE_INSTANTIATE_TEST(BlitFramebufferTest, ES3_D3D11()); |