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 | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 10 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 11 | class BlitFramebufferANGLETest : public ANGLETest |
| 12 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 13 | protected: |
| 14 | BlitFramebufferANGLETest() |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 15 | { |
| 16 | setWindowWidth(256); |
| 17 | setWindowHeight(256); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 18 | setConfigRedBits(8); |
| 19 | setConfigGreenBits(8); |
| 20 | setConfigBlueBits(8); |
| 21 | setConfigAlphaBits(8); |
| 22 | setConfigDepthBits(24); |
Geoff Lang | 784cc8f | 2015-02-05 09:00:54 -0500 | [diff] [blame] | 23 | setConfigStencilBits(8); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 24 | |
| 25 | mCheckerProgram = 0; |
| 26 | mBlueProgram = 0; |
| 27 | |
| 28 | mOriginalFBO = 0; |
| 29 | |
| 30 | mUserFBO = 0; |
| 31 | mUserColorBuffer = 0; |
| 32 | mUserDepthStencilBuffer = 0; |
| 33 | |
| 34 | mSmallFBO = 0; |
| 35 | mSmallColorBuffer = 0; |
| 36 | mSmallDepthStencilBuffer = 0; |
| 37 | |
| 38 | mColorOnlyFBO = 0; |
| 39 | mColorOnlyColorBuffer = 0; |
| 40 | |
| 41 | mDiffFormatFBO = 0; |
| 42 | mDiffFormatColorBuffer = 0; |
| 43 | |
| 44 | mDiffSizeFBO = 0; |
| 45 | mDiffSizeColorBuffer = 0; |
| 46 | |
| 47 | mMRTFBO = 0; |
| 48 | mMRTColorBuffer0 = 0; |
| 49 | mMRTColorBuffer1 = 0; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 50 | |
| 51 | mRGBAColorbuffer = 0; |
| 52 | mRGBAFBO = 0; |
| 53 | |
| 54 | mBGRAMultisampledRenderbuffer = 0; |
| 55 | mBGRAMultisampledFBO = 0; |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | virtual void SetUp() |
| 59 | { |
| 60 | ANGLETest::SetUp(); |
| 61 | |
| 62 | const std::string passthroughVS = SHADER_SOURCE |
| 63 | ( |
| 64 | precision highp float; |
| 65 | attribute vec4 position; |
| 66 | varying vec4 pos; |
| 67 | |
| 68 | void main() |
| 69 | { |
| 70 | gl_Position = position; |
| 71 | pos = position; |
| 72 | } |
| 73 | ); |
| 74 | |
| 75 | const std::string checkeredFS = SHADER_SOURCE |
| 76 | ( |
| 77 | precision highp float; |
| 78 | varying vec4 pos; |
| 79 | |
| 80 | void main() |
| 81 | { |
| 82 | if (pos.x * pos.y > 0.0) |
| 83 | { |
| 84 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); |
| 89 | } |
| 90 | } |
| 91 | ); |
| 92 | |
| 93 | const std::string blueFS = SHADER_SOURCE |
| 94 | ( |
| 95 | precision highp float; |
| 96 | varying vec4 pos; |
| 97 | |
| 98 | void main() |
| 99 | { |
| 100 | gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); |
| 101 | } |
| 102 | ); |
| 103 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 104 | mCheckerProgram = CompileProgram(passthroughVS, checkeredFS); |
| 105 | mBlueProgram = CompileProgram(passthroughVS, blueFS); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 106 | if (mCheckerProgram == 0 || mBlueProgram == 0) |
| 107 | { |
| 108 | FAIL() << "shader compilation failed."; |
| 109 | } |
| 110 | |
| 111 | EXPECT_GL_NO_ERROR(); |
| 112 | |
| 113 | GLint originalFBO; |
| 114 | glGetIntegerv(GL_FRAMEBUFFER_BINDING, &originalFBO); |
| 115 | if (originalFBO >= 0) |
| 116 | { |
| 117 | mOriginalFBO = (GLuint)originalFBO; |
| 118 | } |
| 119 | |
| 120 | GLenum format = GL_BGRA8_EXT; |
| 121 | |
| 122 | glGenFramebuffers(1, &mUserFBO); |
| 123 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 124 | glGenTextures(1, &mUserColorBuffer); |
| 125 | glGenRenderbuffers(1, &mUserDepthStencilBuffer); |
| 126 | glBindTexture(GL_TEXTURE_2D, mUserColorBuffer); |
| 127 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 128 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mUserColorBuffer, 0); |
| 129 | glBindRenderbuffer(GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 130 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth(), getWindowHeight()); |
| 131 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 132 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 133 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 134 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 135 | ASSERT_GL_NO_ERROR(); |
| 136 | |
| 137 | glGenFramebuffers(1, &mSmallFBO); |
| 138 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 139 | glGenTextures(1, &mSmallColorBuffer); |
| 140 | glGenRenderbuffers(1, &mSmallDepthStencilBuffer); |
| 141 | glBindTexture(GL_TEXTURE_2D, mSmallColorBuffer); |
| 142 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth() / 2, getWindowHeight() / 2); |
| 143 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mSmallColorBuffer, 0); |
| 144 | glBindRenderbuffer(GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 145 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth() / 2, getWindowHeight() / 2); |
| 146 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 147 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 148 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 149 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 150 | ASSERT_GL_NO_ERROR(); |
| 151 | |
| 152 | glGenFramebuffers(1, &mColorOnlyFBO); |
| 153 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 154 | glGenTextures(1, &mColorOnlyColorBuffer); |
| 155 | glBindTexture(GL_TEXTURE_2D, mColorOnlyColorBuffer); |
| 156 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 157 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorOnlyColorBuffer, 0); |
| 158 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 159 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 160 | ASSERT_GL_NO_ERROR(); |
| 161 | |
| 162 | glGenFramebuffers(1, &mDiffFormatFBO); |
| 163 | glBindFramebuffer(GL_FRAMEBUFFER, mDiffFormatFBO); |
| 164 | glGenTextures(1, &mDiffFormatColorBuffer); |
| 165 | glBindTexture(GL_TEXTURE_2D, mDiffFormatColorBuffer); |
| 166 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB565, getWindowWidth(), getWindowHeight()); |
| 167 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffFormatColorBuffer, 0); |
| 168 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 169 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 170 | ASSERT_GL_NO_ERROR(); |
| 171 | |
| 172 | glGenFramebuffers(1, &mDiffSizeFBO); |
| 173 | glBindFramebuffer(GL_FRAMEBUFFER, mDiffSizeFBO); |
| 174 | glGenTextures(1, &mDiffSizeColorBuffer); |
| 175 | glBindTexture(GL_TEXTURE_2D, mDiffSizeColorBuffer); |
| 176 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth()*2, getWindowHeight()*2); |
| 177 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffSizeColorBuffer, 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 | if (extensionEnabled("GL_EXT_draw_buffers")) |
| 183 | { |
| 184 | glGenFramebuffers(1, &mMRTFBO); |
| 185 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 186 | glGenTextures(1, &mMRTColorBuffer0); |
| 187 | glGenTextures(1, &mMRTColorBuffer1); |
| 188 | glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer0); |
| 189 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 190 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 191 | glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer1); |
| 192 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 193 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 194 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 195 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 196 | ASSERT_GL_NO_ERROR(); |
| 197 | } |
| 198 | |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 199 | if (extensionEnabled("GL_ANGLE_framebuffer_multisample")) |
| 200 | { |
| 201 | // Test blit between RGBA and multisampled BGRA |
| 202 | glGenTextures(1, &mRGBAColorbuffer); |
| 203 | glBindTexture(GL_TEXTURE_2D, mRGBAColorbuffer); |
| 204 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, getWindowWidth(), getWindowHeight()); |
| 205 | |
| 206 | glGenFramebuffers(1, &mRGBAFBO); |
| 207 | glBindFramebuffer(GL_FRAMEBUFFER, mRGBAFBO); |
| 208 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mRGBAColorbuffer, 0); |
| 209 | |
| 210 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 211 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 212 | |
| 213 | glGenRenderbuffers(1, &mBGRAMultisampledRenderbuffer); |
| 214 | glBindRenderbuffer(GL_RENDERBUFFER, mBGRAMultisampledRenderbuffer); |
| 215 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_BGRA8_EXT, getWindowWidth(), getWindowHeight()); |
| 216 | |
| 217 | glGenFramebuffers(1, &mBGRAMultisampledFBO); |
| 218 | glBindFramebuffer(GL_FRAMEBUFFER, mBGRAMultisampledFBO); |
| 219 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, mBGRAMultisampledRenderbuffer); |
| 220 | |
| 221 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 222 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 223 | } |
| 224 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 225 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 226 | } |
| 227 | |
| 228 | virtual void TearDown() |
| 229 | { |
| 230 | glDeleteProgram(mCheckerProgram); |
| 231 | glDeleteProgram(mBlueProgram); |
| 232 | |
| 233 | glDeleteFramebuffers(1, &mUserFBO); |
| 234 | glDeleteTextures(1, &mUserColorBuffer); |
| 235 | glDeleteRenderbuffers(1, &mUserDepthStencilBuffer); |
| 236 | |
| 237 | glDeleteFramebuffers(1, &mSmallFBO); |
| 238 | glDeleteTextures(1, &mSmallColorBuffer); |
| 239 | glDeleteRenderbuffers(1, &mSmallDepthStencilBuffer); |
| 240 | |
| 241 | glDeleteFramebuffers(1, &mColorOnlyFBO); |
| 242 | glDeleteTextures(1, &mSmallDepthStencilBuffer); |
| 243 | |
| 244 | glDeleteFramebuffers(1, &mDiffFormatFBO); |
| 245 | glDeleteTextures(1, &mDiffFormatColorBuffer); |
| 246 | |
| 247 | glDeleteFramebuffers(1, &mDiffSizeFBO); |
| 248 | glDeleteTextures(1, &mDiffSizeColorBuffer); |
| 249 | |
| 250 | if (extensionEnabled("GL_EXT_draw_buffers")) |
| 251 | { |
| 252 | glDeleteFramebuffers(1, &mMRTFBO); |
| 253 | glDeleteTextures(1, &mMRTColorBuffer0); |
| 254 | glDeleteTextures(1, &mMRTColorBuffer1); |
| 255 | } |
| 256 | |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 257 | if (mRGBAColorbuffer != 0) |
| 258 | { |
| 259 | glDeleteTextures(1, &mRGBAColorbuffer); |
| 260 | } |
| 261 | |
| 262 | if (mRGBAFBO != 0) |
| 263 | { |
| 264 | glDeleteFramebuffers(1, &mBGRAMultisampledFBO); |
| 265 | } |
| 266 | |
| 267 | if (mBGRAMultisampledRenderbuffer != 0) |
| 268 | { |
| 269 | glDeleteRenderbuffers(1, &mBGRAMultisampledRenderbuffer); |
| 270 | } |
| 271 | |
| 272 | if (mBGRAMultisampledFBO != 0) |
| 273 | { |
| 274 | glDeleteFramebuffers(1, &mBGRAMultisampledFBO); |
| 275 | } |
| 276 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 277 | ANGLETest::TearDown(); |
| 278 | } |
| 279 | |
| 280 | GLuint mCheckerProgram; |
| 281 | GLuint mBlueProgram; |
| 282 | |
| 283 | GLuint mOriginalFBO; |
| 284 | |
| 285 | GLuint mUserFBO; |
| 286 | GLuint mUserColorBuffer; |
| 287 | GLuint mUserDepthStencilBuffer; |
| 288 | |
| 289 | GLuint mSmallFBO; |
| 290 | GLuint mSmallColorBuffer; |
| 291 | GLuint mSmallDepthStencilBuffer; |
| 292 | |
| 293 | GLuint mColorOnlyFBO; |
| 294 | GLuint mColorOnlyColorBuffer; |
| 295 | |
| 296 | GLuint mDiffFormatFBO; |
| 297 | GLuint mDiffFormatColorBuffer; |
| 298 | |
| 299 | GLuint mDiffSizeFBO; |
| 300 | GLuint mDiffSizeColorBuffer; |
| 301 | |
| 302 | GLuint mMRTFBO; |
| 303 | GLuint mMRTColorBuffer0; |
| 304 | GLuint mMRTColorBuffer1; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 305 | |
| 306 | GLuint mRGBAColorbuffer; |
| 307 | GLuint mRGBAFBO; |
| 308 | |
| 309 | GLuint mBGRAMultisampledRenderbuffer; |
| 310 | GLuint mBGRAMultisampledFBO; |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | // Draw to user-created framebuffer, blit whole-buffer color to original framebuffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 314 | TEST_P(BlitFramebufferANGLETest, BlitColorToDefault) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 315 | { |
| 316 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 317 | |
| 318 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 319 | |
| 320 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 321 | |
| 322 | EXPECT_GL_NO_ERROR(); |
| 323 | |
| 324 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 325 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 326 | |
| 327 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 328 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 329 | |
| 330 | EXPECT_GL_NO_ERROR(); |
| 331 | |
| 332 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 333 | |
| 334 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 335 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 336 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 337 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 338 | } |
| 339 | |
| 340 | // Draw to system framebuffer, blit whole-buffer color to user-created framebuffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 341 | TEST_P(BlitFramebufferANGLETest, ReverseColorBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 342 | { |
| 343 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 344 | |
| 345 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 346 | |
| 347 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 348 | |
| 349 | EXPECT_GL_NO_ERROR(); |
| 350 | |
| 351 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 352 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 353 | |
| 354 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 355 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 356 | |
| 357 | EXPECT_GL_NO_ERROR(); |
| 358 | |
| 359 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 360 | |
| 361 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 362 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 363 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 364 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 365 | } |
| 366 | |
| 367 | // 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] | 368 | TEST_P(BlitFramebufferANGLETest, ScissoredBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 369 | { |
| 370 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 371 | |
| 372 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 373 | |
| 374 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 375 | |
| 376 | EXPECT_GL_NO_ERROR(); |
| 377 | |
| 378 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 379 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 380 | |
| 381 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 382 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 383 | |
| 384 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 385 | glEnable(GL_SCISSOR_TEST); |
| 386 | |
| 387 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 388 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 389 | |
| 390 | EXPECT_GL_NO_ERROR(); |
| 391 | |
| 392 | glDisable(GL_SCISSOR_TEST); |
| 393 | |
| 394 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 395 | |
| 396 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 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, 255, 255, 255, 255); |
| 400 | } |
| 401 | |
| 402 | // 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] | 403 | TEST_P(BlitFramebufferANGLETest, ReverseScissoredBlit) |
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 | |
| 409 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 410 | |
| 411 | EXPECT_GL_NO_ERROR(); |
| 412 | |
| 413 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 414 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 415 | |
| 416 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 417 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 418 | |
| 419 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 420 | glEnable(GL_SCISSOR_TEST); |
| 421 | |
| 422 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 423 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 424 | |
| 425 | EXPECT_GL_NO_ERROR(); |
| 426 | |
| 427 | glDisable(GL_SCISSOR_TEST); |
| 428 | |
| 429 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 430 | |
| 431 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 432 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 433 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 434 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 435 | } |
| 436 | |
| 437 | // 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] | 438 | TEST_P(BlitFramebufferANGLETest, OversizedBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 439 | { |
| 440 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 441 | |
| 442 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 443 | |
| 444 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 445 | |
| 446 | EXPECT_GL_NO_ERROR(); |
| 447 | |
| 448 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 449 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 450 | |
| 451 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 452 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 453 | |
| 454 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 455 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 456 | |
| 457 | EXPECT_GL_NO_ERROR(); |
| 458 | |
| 459 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 460 | |
| 461 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 462 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 463 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 464 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 465 | } |
| 466 | |
| 467 | // 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] | 468 | TEST_P(BlitFramebufferANGLETest, ReverseOversizedBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 469 | { |
| 470 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 471 | |
| 472 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 473 | |
| 474 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 475 | |
| 476 | EXPECT_GL_NO_ERROR(); |
| 477 | |
| 478 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 479 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 480 | |
| 481 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 482 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 483 | |
| 484 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 485 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 486 | EXPECT_GL_NO_ERROR(); |
| 487 | |
| 488 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 489 | |
| 490 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 491 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 492 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 493 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 494 | } |
| 495 | |
| 496 | // blit from user-created FBO to system framebuffer, with depth buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 497 | TEST_P(BlitFramebufferANGLETest, BlitWithDepth) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 498 | { |
| 499 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 500 | |
| 501 | glDepthMask(GL_TRUE); |
| 502 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 503 | |
| 504 | glEnable(GL_DEPTH_TEST); |
| 505 | |
| 506 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 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(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 517 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 518 | EXPECT_GL_NO_ERROR(); |
| 519 | |
| 520 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 521 | |
| 522 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 523 | drawQuad(mBlueProgram, "position", 0.8f); |
| 524 | |
| 525 | glDisable(GL_DEPTH_TEST); |
| 526 | |
| 527 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 528 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 529 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 530 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 531 | } |
| 532 | |
| 533 | // blit from system FBO to user-created framebuffer, with depth buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 534 | TEST_P(BlitFramebufferANGLETest, ReverseBlitWithDepth) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 535 | { |
| 536 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 537 | |
| 538 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 539 | |
| 540 | glEnable(GL_DEPTH_TEST); |
| 541 | |
| 542 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 543 | |
| 544 | EXPECT_GL_NO_ERROR(); |
| 545 | |
| 546 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 547 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 548 | |
| 549 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 550 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 551 | |
| 552 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 553 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 554 | EXPECT_GL_NO_ERROR(); |
| 555 | |
| 556 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 557 | |
| 558 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 559 | |
| 560 | drawQuad(mBlueProgram, "position", 0.8f); |
| 561 | |
| 562 | glDisable(GL_DEPTH_TEST); |
| 563 | |
| 564 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 565 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 566 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 567 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 568 | } |
| 569 | |
| 570 | // 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] | 571 | TEST_P(BlitFramebufferANGLETest, BlitSameBufferOriginal) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 572 | { |
| 573 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 574 | |
| 575 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 576 | |
| 577 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 578 | |
| 579 | EXPECT_GL_NO_ERROR(); |
| 580 | |
| 581 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 582 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 583 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 584 | } |
| 585 | |
| 586 | // blit from one region of the system fbo to another. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 587 | TEST_P(BlitFramebufferANGLETest, BlitSameBufferUser) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 588 | { |
| 589 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 590 | |
| 591 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 592 | |
| 593 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 594 | |
| 595 | EXPECT_GL_NO_ERROR(); |
| 596 | |
| 597 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 598 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 599 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 600 | } |
| 601 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 602 | TEST_P(BlitFramebufferANGLETest, BlitPartialColor) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 603 | { |
| 604 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 605 | |
| 606 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 607 | |
| 608 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 609 | |
| 610 | EXPECT_GL_NO_ERROR(); |
| 611 | |
| 612 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 613 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 614 | |
| 615 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 616 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 617 | |
| 618 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight(), |
| 619 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 620 | |
| 621 | EXPECT_GL_NO_ERROR(); |
| 622 | |
| 623 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 624 | |
| 625 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 626 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 627 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 628 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 629 | } |
| 630 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 631 | TEST_P(BlitFramebufferANGLETest, BlitDifferentSizes) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 632 | { |
| 633 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 634 | |
| 635 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 636 | |
| 637 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 638 | |
| 639 | EXPECT_GL_NO_ERROR(); |
| 640 | |
| 641 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mSmallFBO); |
| 642 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 643 | |
| 644 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 645 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 646 | |
| 647 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 648 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 649 | |
| 650 | EXPECT_GL_NO_ERROR(); |
| 651 | |
| 652 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 653 | |
| 654 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 655 | |
| 656 | EXPECT_GL_NO_ERROR(); |
| 657 | } |
| 658 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 659 | TEST_P(BlitFramebufferANGLETest, BlitWithMissingAttachments) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 660 | { |
| 661 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 662 | |
| 663 | glClear(GL_COLOR_BUFFER_BIT); |
| 664 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 665 | |
| 666 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 667 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 668 | |
| 669 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 670 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 671 | |
| 672 | // depth blit request should be silently ignored, because the read FBO has no depth attachment |
| 673 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 674 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 675 | |
| 676 | EXPECT_GL_NO_ERROR(); |
| 677 | |
| 678 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 679 | |
| 680 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 681 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 682 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 683 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 684 | |
| 685 | // unlike in the depth blit tests, this *should* draw a blue quad, because depth info |
| 686 | // has not been copied |
| 687 | glEnable(GL_DEPTH_TEST); |
| 688 | drawQuad(mBlueProgram, "position", 0.8f); |
| 689 | glDisable(GL_DEPTH_TEST); |
| 690 | |
| 691 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 692 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 693 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 694 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 695 | } |
| 696 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 697 | TEST_P(BlitFramebufferANGLETest, BlitStencil) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 698 | { |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame] | 699 | // TODO(jmadill): Figure out if we can fix this on D3D9. |
| 700 | // https://code.google.com/p/angleproject/issues/detail?id=809 |
Jamie Madill | 7208f69 | 2016-02-29 10:47:35 -0500 | [diff] [blame^] | 701 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE) |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame] | 702 | { |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 703 | std::cout << "Test skipped on Intel D3D9." << std::endl; |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame] | 704 | return; |
| 705 | } |
| 706 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 707 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 708 | |
| 709 | glClear(GL_COLOR_BUFFER_BIT); |
| 710 | // fill the stencil buffer with 0x1 |
| 711 | glStencilFunc(GL_ALWAYS, 0x1, 0xFF); |
| 712 | glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
| 713 | glEnable(GL_STENCIL_TEST); |
| 714 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 715 | |
| 716 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 717 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 718 | |
| 719 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 720 | glClearStencil(0x0); |
| 721 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 722 | |
| 723 | // depth blit request should be silently ignored, because the read FBO has no depth attachment |
| 724 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 725 | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); |
| 726 | |
| 727 | EXPECT_GL_NO_ERROR(); |
| 728 | |
| 729 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 730 | |
| 731 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 732 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 733 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 734 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 735 | |
| 736 | glStencilFunc(GL_EQUAL, 0x1, 0xFF); // only pass if stencil buffer at pixel reads 0x1 |
| 737 | drawQuad(mBlueProgram, "position", 0.8f); // blue quad will draw if stencil buffer was copied |
| 738 | glDisable(GL_STENCIL_TEST); |
| 739 | |
| 740 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 741 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 742 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 743 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 744 | } |
| 745 | |
| 746 | // 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] | 747 | TEST_P(BlitFramebufferANGLETest, BlitPartialDepthStencil) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 748 | { |
| 749 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 750 | |
| 751 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 752 | |
| 753 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 754 | |
| 755 | EXPECT_GL_NO_ERROR(); |
| 756 | |
| 757 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 758 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 759 | |
| 760 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 761 | getWindowWidth() / 2, getWindowHeight() / 2, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 762 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 763 | } |
| 764 | |
| 765 | // Test blit with MRT framebuffers |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 766 | TEST_P(BlitFramebufferANGLETest, BlitMRT) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 767 | { |
| 768 | if (!extensionEnabled("GL_EXT_draw_buffers")) |
| 769 | { |
| 770 | return; |
| 771 | } |
| 772 | |
| 773 | GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; |
| 774 | |
| 775 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 776 | glDrawBuffersEXT(2, drawBuffers); |
| 777 | |
| 778 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 779 | |
| 780 | glClear(GL_COLOR_BUFFER_BIT); |
| 781 | |
| 782 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 783 | |
| 784 | EXPECT_GL_NO_ERROR(); |
| 785 | |
| 786 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 787 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mMRTFBO); |
| 788 | |
| 789 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 790 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 791 | |
| 792 | EXPECT_GL_NO_ERROR(); |
| 793 | |
| 794 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 795 | |
| 796 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 797 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 798 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 799 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 800 | |
| 801 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); |
| 802 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 803 | |
| 804 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 805 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 806 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 807 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 808 | |
| 809 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 810 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 811 | } |
| 812 | |
| 813 | // 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] | 814 | TEST_P(BlitFramebufferANGLETest, ErrorStretching) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 815 | { |
| 816 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 817 | |
| 818 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 819 | |
| 820 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 821 | |
| 822 | EXPECT_GL_NO_ERROR(); |
| 823 | |
| 824 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 825 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 826 | |
| 827 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 828 | getWindowWidth(), getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 829 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 830 | } |
| 831 | |
| 832 | // 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] | 833 | TEST_P(BlitFramebufferANGLETest, ErrorFlipping) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 834 | { |
| 835 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 836 | |
| 837 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 838 | |
| 839 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 840 | |
| 841 | EXPECT_GL_NO_ERROR(); |
| 842 | |
| 843 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 844 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 845 | |
| 846 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight() / 2, |
| 847 | 0, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 848 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 849 | } |
| 850 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 851 | TEST_P(BlitFramebufferANGLETest, Errors) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 852 | { |
| 853 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 854 | |
| 855 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 856 | |
| 857 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 858 | |
| 859 | EXPECT_GL_NO_ERROR(); |
| 860 | |
| 861 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 862 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 863 | |
| 864 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 865 | GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 866 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 867 | |
| 868 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 869 | GL_COLOR_BUFFER_BIT | 234, GL_NEAREST); |
| 870 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 871 | |
| 872 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mDiffFormatFBO); |
| 873 | |
| 874 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 875 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 876 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 877 | |
| 878 | if (extensionEnabled("GL_ANGLE_framebuffer_multisample")) |
| 879 | { |
| 880 | glBindFramebuffer(GL_READ_FRAMEBUFFER, mBGRAMultisampledFBO); |
| 881 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mRGBAFBO); |
| 882 | EXPECT_GL_NO_ERROR(); |
| 883 | |
| 884 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 885 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 886 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 887 | } |
| 888 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 889 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 890 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 891 | // TODO(geofflang): Fix the dependence on glBlitFramebufferANGLE without checks and assuming the |
| 892 | // default framebuffer is BGRA to enable the GL and GLES backends. (http://anglebug.com/1289) |
| 893 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 894 | // 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] | 895 | ANGLE_INSTANTIATE_TEST(BlitFramebufferANGLETest, |
| 896 | ES2_D3D9(), |
| 897 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE), |
| 898 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE)); |