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