Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 1 | #include "ANGLETest.h" |
| 2 | |
| 3 | class BlitFramebufferANGLETest : public ANGLETest |
| 4 | { |
| 5 | protected: |
| 6 | BlitFramebufferANGLETest() |
| 7 | { |
| 8 | setWindowWidth(256); |
| 9 | setWindowHeight(256); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 10 | setConfigRedBits(8); |
| 11 | setConfigGreenBits(8); |
| 12 | setConfigBlueBits(8); |
| 13 | setConfigAlphaBits(8); |
| 14 | setConfigDepthBits(24); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 15 | |
| 16 | mCheckerProgram = 0; |
| 17 | mBlueProgram = 0; |
| 18 | |
| 19 | mOriginalFBO = 0; |
| 20 | |
| 21 | mUserFBO = 0; |
| 22 | mUserColorBuffer = 0; |
| 23 | mUserDepthStencilBuffer = 0; |
| 24 | |
| 25 | mSmallFBO = 0; |
| 26 | mSmallColorBuffer = 0; |
| 27 | mSmallDepthStencilBuffer = 0; |
| 28 | |
| 29 | mColorOnlyFBO = 0; |
| 30 | mColorOnlyColorBuffer = 0; |
| 31 | |
| 32 | mDiffFormatFBO = 0; |
| 33 | mDiffFormatColorBuffer = 0; |
| 34 | |
| 35 | mDiffSizeFBO = 0; |
| 36 | mDiffSizeColorBuffer = 0; |
| 37 | |
| 38 | mMRTFBO = 0; |
| 39 | mMRTColorBuffer0 = 0; |
| 40 | mMRTColorBuffer1 = 0; |
| 41 | } |
| 42 | |
| 43 | virtual void SetUp() |
| 44 | { |
| 45 | ANGLETest::SetUp(); |
| 46 | |
| 47 | const std::string passthroughVS = SHADER_SOURCE |
| 48 | ( |
| 49 | precision highp float; |
| 50 | attribute vec4 position; |
| 51 | varying vec4 pos; |
| 52 | |
| 53 | void main() |
| 54 | { |
| 55 | gl_Position = position; |
| 56 | pos = position; |
| 57 | } |
| 58 | ); |
| 59 | |
| 60 | const std::string checkeredFS = SHADER_SOURCE |
| 61 | ( |
| 62 | precision highp float; |
| 63 | varying vec4 pos; |
| 64 | |
| 65 | void main() |
| 66 | { |
| 67 | if (pos.x * pos.y > 0.0) |
| 68 | { |
| 69 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); |
| 74 | } |
| 75 | } |
| 76 | ); |
| 77 | |
| 78 | const std::string blueFS = SHADER_SOURCE |
| 79 | ( |
| 80 | precision highp float; |
| 81 | varying vec4 pos; |
| 82 | |
| 83 | void main() |
| 84 | { |
| 85 | gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); |
| 86 | } |
| 87 | ); |
| 88 | |
| 89 | mCheckerProgram = compileProgram(passthroughVS, checkeredFS); |
| 90 | mBlueProgram = compileProgram(passthroughVS, blueFS); |
| 91 | if (mCheckerProgram == 0 || mBlueProgram == 0) |
| 92 | { |
| 93 | FAIL() << "shader compilation failed."; |
| 94 | } |
| 95 | |
| 96 | EXPECT_GL_NO_ERROR(); |
| 97 | |
| 98 | GLint originalFBO; |
| 99 | glGetIntegerv(GL_FRAMEBUFFER_BINDING, &originalFBO); |
| 100 | if (originalFBO >= 0) |
| 101 | { |
| 102 | mOriginalFBO = (GLuint)originalFBO; |
| 103 | } |
| 104 | |
| 105 | GLenum format = GL_BGRA8_EXT; |
| 106 | |
| 107 | glGenFramebuffers(1, &mUserFBO); |
| 108 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 109 | glGenTextures(1, &mUserColorBuffer); |
| 110 | glGenRenderbuffers(1, &mUserDepthStencilBuffer); |
| 111 | glBindTexture(GL_TEXTURE_2D, mUserColorBuffer); |
| 112 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 113 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mUserColorBuffer, 0); |
| 114 | glBindRenderbuffer(GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 115 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth(), getWindowHeight()); |
| 116 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 117 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 118 | |
| 119 | ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GL_FRAMEBUFFER_COMPLETE); |
| 120 | ASSERT_GL_NO_ERROR(); |
| 121 | |
| 122 | glGenFramebuffers(1, &mSmallFBO); |
| 123 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 124 | glGenTextures(1, &mSmallColorBuffer); |
| 125 | glGenRenderbuffers(1, &mSmallDepthStencilBuffer); |
| 126 | glBindTexture(GL_TEXTURE_2D, mSmallColorBuffer); |
| 127 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth() / 2, getWindowHeight() / 2); |
| 128 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mSmallColorBuffer, 0); |
| 129 | glBindRenderbuffer(GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 130 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth() / 2, getWindowHeight() / 2); |
| 131 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 132 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 133 | |
| 134 | ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GL_FRAMEBUFFER_COMPLETE); |
| 135 | ASSERT_GL_NO_ERROR(); |
| 136 | |
| 137 | glGenFramebuffers(1, &mColorOnlyFBO); |
| 138 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 139 | glGenTextures(1, &mColorOnlyColorBuffer); |
| 140 | glBindTexture(GL_TEXTURE_2D, mColorOnlyColorBuffer); |
| 141 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 142 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorOnlyColorBuffer, 0); |
| 143 | |
| 144 | ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GL_FRAMEBUFFER_COMPLETE); |
| 145 | ASSERT_GL_NO_ERROR(); |
| 146 | |
| 147 | glGenFramebuffers(1, &mDiffFormatFBO); |
| 148 | glBindFramebuffer(GL_FRAMEBUFFER, mDiffFormatFBO); |
| 149 | glGenTextures(1, &mDiffFormatColorBuffer); |
| 150 | glBindTexture(GL_TEXTURE_2D, mDiffFormatColorBuffer); |
| 151 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB565, getWindowWidth(), getWindowHeight()); |
| 152 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffFormatColorBuffer, 0); |
| 153 | |
| 154 | ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GL_FRAMEBUFFER_COMPLETE); |
| 155 | ASSERT_GL_NO_ERROR(); |
| 156 | |
| 157 | glGenFramebuffers(1, &mDiffSizeFBO); |
| 158 | glBindFramebuffer(GL_FRAMEBUFFER, mDiffSizeFBO); |
| 159 | glGenTextures(1, &mDiffSizeColorBuffer); |
| 160 | glBindTexture(GL_TEXTURE_2D, mDiffSizeColorBuffer); |
| 161 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth()*2, getWindowHeight()*2); |
| 162 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffSizeColorBuffer, 0); |
| 163 | |
| 164 | ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GL_FRAMEBUFFER_COMPLETE); |
| 165 | ASSERT_GL_NO_ERROR(); |
| 166 | |
| 167 | if (extensionEnabled("GL_EXT_draw_buffers")) |
| 168 | { |
| 169 | glGenFramebuffers(1, &mMRTFBO); |
| 170 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 171 | glGenTextures(1, &mMRTColorBuffer0); |
| 172 | glGenTextures(1, &mMRTColorBuffer1); |
| 173 | glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer0); |
| 174 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 175 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 176 | glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer1); |
| 177 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 178 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 179 | |
| 180 | ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GL_FRAMEBUFFER_COMPLETE); |
| 181 | ASSERT_GL_NO_ERROR(); |
| 182 | } |
| 183 | |
| 184 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 185 | } |
| 186 | |
| 187 | virtual void TearDown() |
| 188 | { |
| 189 | glDeleteProgram(mCheckerProgram); |
| 190 | glDeleteProgram(mBlueProgram); |
| 191 | |
| 192 | glDeleteFramebuffers(1, &mUserFBO); |
| 193 | glDeleteTextures(1, &mUserColorBuffer); |
| 194 | glDeleteRenderbuffers(1, &mUserDepthStencilBuffer); |
| 195 | |
| 196 | glDeleteFramebuffers(1, &mSmallFBO); |
| 197 | glDeleteTextures(1, &mSmallColorBuffer); |
| 198 | glDeleteRenderbuffers(1, &mSmallDepthStencilBuffer); |
| 199 | |
| 200 | glDeleteFramebuffers(1, &mColorOnlyFBO); |
| 201 | glDeleteTextures(1, &mSmallDepthStencilBuffer); |
| 202 | |
| 203 | glDeleteFramebuffers(1, &mDiffFormatFBO); |
| 204 | glDeleteTextures(1, &mDiffFormatColorBuffer); |
| 205 | |
| 206 | glDeleteFramebuffers(1, &mDiffSizeFBO); |
| 207 | glDeleteTextures(1, &mDiffSizeColorBuffer); |
| 208 | |
| 209 | if (extensionEnabled("GL_EXT_draw_buffers")) |
| 210 | { |
| 211 | glDeleteFramebuffers(1, &mMRTFBO); |
| 212 | glDeleteTextures(1, &mMRTColorBuffer0); |
| 213 | glDeleteTextures(1, &mMRTColorBuffer1); |
| 214 | } |
| 215 | |
| 216 | ANGLETest::TearDown(); |
| 217 | } |
| 218 | |
| 219 | GLuint mCheckerProgram; |
| 220 | GLuint mBlueProgram; |
| 221 | |
| 222 | GLuint mOriginalFBO; |
| 223 | |
| 224 | GLuint mUserFBO; |
| 225 | GLuint mUserColorBuffer; |
| 226 | GLuint mUserDepthStencilBuffer; |
| 227 | |
| 228 | GLuint mSmallFBO; |
| 229 | GLuint mSmallColorBuffer; |
| 230 | GLuint mSmallDepthStencilBuffer; |
| 231 | |
| 232 | GLuint mColorOnlyFBO; |
| 233 | GLuint mColorOnlyColorBuffer; |
| 234 | |
| 235 | GLuint mDiffFormatFBO; |
| 236 | GLuint mDiffFormatColorBuffer; |
| 237 | |
| 238 | GLuint mDiffSizeFBO; |
| 239 | GLuint mDiffSizeColorBuffer; |
| 240 | |
| 241 | GLuint mMRTFBO; |
| 242 | GLuint mMRTColorBuffer0; |
| 243 | GLuint mMRTColorBuffer1; |
| 244 | }; |
| 245 | |
| 246 | // Draw to user-created framebuffer, blit whole-buffer color to original framebuffer. |
| 247 | TEST_F(BlitFramebufferANGLETest, blit_color_to_default) |
| 248 | { |
| 249 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 250 | |
| 251 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 252 | |
| 253 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 254 | |
| 255 | EXPECT_GL_NO_ERROR(); |
| 256 | |
| 257 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 258 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 259 | |
| 260 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 261 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 262 | |
| 263 | EXPECT_GL_NO_ERROR(); |
| 264 | |
| 265 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 266 | |
| 267 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 268 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 269 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 270 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 271 | } |
| 272 | |
| 273 | // Draw to system framebuffer, blit whole-buffer color to user-created framebuffer. |
| 274 | TEST_F(BlitFramebufferANGLETest, reverse_color_blit) |
| 275 | { |
| 276 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 277 | |
| 278 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 279 | |
| 280 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 281 | |
| 282 | EXPECT_GL_NO_ERROR(); |
| 283 | |
| 284 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 285 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 286 | |
| 287 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 288 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 289 | |
| 290 | EXPECT_GL_NO_ERROR(); |
| 291 | |
| 292 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 293 | |
| 294 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 295 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 296 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 297 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 298 | } |
| 299 | |
| 300 | // blit from user-created FBO to system framebuffer, with the scissor test enabled. |
| 301 | TEST_F(BlitFramebufferANGLETest, scissored_blit) |
| 302 | { |
| 303 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 304 | |
| 305 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 306 | |
| 307 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 308 | |
| 309 | EXPECT_GL_NO_ERROR(); |
| 310 | |
| 311 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 312 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 313 | |
| 314 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 315 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 316 | |
| 317 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 318 | glEnable(GL_SCISSOR_TEST); |
| 319 | |
| 320 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 321 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 322 | |
| 323 | EXPECT_GL_NO_ERROR(); |
| 324 | |
| 325 | glDisable(GL_SCISSOR_TEST); |
| 326 | |
| 327 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 328 | |
| 329 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 330 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 331 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 332 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 333 | } |
| 334 | |
| 335 | // blit from system FBO to user-created framebuffer, with the scissor test enabled. |
| 336 | TEST_F(BlitFramebufferANGLETest, reverse_scissored_blit) |
| 337 | { |
| 338 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 339 | |
| 340 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 341 | |
| 342 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 343 | |
| 344 | EXPECT_GL_NO_ERROR(); |
| 345 | |
| 346 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 347 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 348 | |
| 349 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 350 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 351 | |
| 352 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 353 | glEnable(GL_SCISSOR_TEST); |
| 354 | |
| 355 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 356 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 357 | |
| 358 | EXPECT_GL_NO_ERROR(); |
| 359 | |
| 360 | glDisable(GL_SCISSOR_TEST); |
| 361 | |
| 362 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 363 | |
| 364 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 365 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 366 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 367 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 368 | } |
| 369 | |
| 370 | // blit from user-created FBO to system framebuffer, using region larger than buffer. |
| 371 | TEST_F(BlitFramebufferANGLETest, oversized_blit) |
| 372 | { |
| 373 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 374 | |
| 375 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 376 | |
| 377 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 378 | |
| 379 | EXPECT_GL_NO_ERROR(); |
| 380 | |
| 381 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 382 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 383 | |
| 384 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 385 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 386 | |
| 387 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 388 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 389 | |
| 390 | EXPECT_GL_NO_ERROR(); |
| 391 | |
| 392 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 393 | |
| 394 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 395 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 396 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 397 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 398 | } |
| 399 | |
| 400 | // blit from system FBO to user-created framebuffer, using region larger than buffer. |
| 401 | TEST_F(BlitFramebufferANGLETest, reverse_oversized_blit) |
| 402 | { |
| 403 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 404 | |
| 405 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 406 | |
| 407 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 408 | |
| 409 | EXPECT_GL_NO_ERROR(); |
| 410 | |
| 411 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 412 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 413 | |
| 414 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 415 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 416 | |
| 417 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 418 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 419 | EXPECT_GL_NO_ERROR(); |
| 420 | |
| 421 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 422 | |
| 423 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 424 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 425 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 426 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 427 | } |
| 428 | |
| 429 | // blit from user-created FBO to system framebuffer, with depth buffer. |
| 430 | TEST_F(BlitFramebufferANGLETest, blit_with_depth) |
| 431 | { |
| 432 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 433 | |
| 434 | glDepthMask(GL_TRUE); |
| 435 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 436 | |
| 437 | glEnable(GL_DEPTH_TEST); |
| 438 | |
| 439 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 440 | |
| 441 | EXPECT_GL_NO_ERROR(); |
| 442 | |
| 443 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 444 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 445 | |
| 446 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 447 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 448 | |
| 449 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 450 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 451 | EXPECT_GL_NO_ERROR(); |
| 452 | |
| 453 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 454 | |
| 455 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 456 | drawQuad(mBlueProgram, "position", 0.8f); |
| 457 | |
| 458 | glDisable(GL_DEPTH_TEST); |
| 459 | |
| 460 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 461 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 462 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 463 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 464 | } |
| 465 | |
| 466 | // blit from system FBO to user-created framebuffer, with depth buffer. |
| 467 | TEST_F(BlitFramebufferANGLETest, reverse_blit_with_depth) |
| 468 | { |
| 469 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 470 | |
| 471 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 472 | |
| 473 | glEnable(GL_DEPTH_TEST); |
| 474 | |
| 475 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 476 | |
| 477 | EXPECT_GL_NO_ERROR(); |
| 478 | |
| 479 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 480 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 481 | |
| 482 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 483 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 484 | |
| 485 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 486 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 487 | EXPECT_GL_NO_ERROR(); |
| 488 | |
| 489 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 490 | |
| 491 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 492 | |
| 493 | drawQuad(mBlueProgram, "position", 0.8f); |
| 494 | |
| 495 | glDisable(GL_DEPTH_TEST); |
| 496 | |
| 497 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 498 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 499 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 500 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 501 | } |
| 502 | |
| 503 | // blit from one region of the system fbo to another-- this should fail. |
| 504 | TEST_F(BlitFramebufferANGLETest, blit_same_buffer_original) |
| 505 | { |
| 506 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 507 | |
| 508 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 509 | |
| 510 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 511 | |
| 512 | EXPECT_GL_NO_ERROR(); |
| 513 | |
| 514 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 515 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 516 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 517 | } |
| 518 | |
| 519 | // blit from one region of the system fbo to another. |
| 520 | TEST_F(BlitFramebufferANGLETest, blit_same_buffer_user) |
| 521 | { |
| 522 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 523 | |
| 524 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 525 | |
| 526 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 527 | |
| 528 | EXPECT_GL_NO_ERROR(); |
| 529 | |
| 530 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 531 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 532 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 533 | } |
| 534 | |
| 535 | TEST_F(BlitFramebufferANGLETest, blit_partial_color) |
| 536 | { |
| 537 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 538 | |
| 539 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 540 | |
| 541 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 542 | |
| 543 | EXPECT_GL_NO_ERROR(); |
| 544 | |
| 545 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 546 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 547 | |
| 548 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 549 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 550 | |
| 551 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight(), |
| 552 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 553 | |
| 554 | EXPECT_GL_NO_ERROR(); |
| 555 | |
| 556 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 557 | |
| 558 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 559 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 560 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 561 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 562 | } |
| 563 | |
| 564 | TEST_F(BlitFramebufferANGLETest, blit_different_sizes) |
| 565 | { |
| 566 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 567 | |
| 568 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 569 | |
| 570 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 571 | |
| 572 | EXPECT_GL_NO_ERROR(); |
| 573 | |
| 574 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mSmallFBO); |
| 575 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 576 | |
| 577 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 578 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 579 | |
| 580 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 581 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 582 | |
| 583 | EXPECT_GL_NO_ERROR(); |
| 584 | |
| 585 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 586 | |
| 587 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 588 | |
| 589 | EXPECT_GL_NO_ERROR(); |
| 590 | } |
| 591 | |
| 592 | TEST_F(BlitFramebufferANGLETest, blit_with_missing_attachments) |
| 593 | { |
| 594 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 595 | |
| 596 | glClear(GL_COLOR_BUFFER_BIT); |
| 597 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 598 | |
| 599 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 600 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 601 | |
| 602 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 603 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 604 | |
| 605 | // depth blit request should be silently ignored, because the read FBO has no depth attachment |
| 606 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 607 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 608 | |
| 609 | EXPECT_GL_NO_ERROR(); |
| 610 | |
| 611 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 612 | |
| 613 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 614 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 615 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 616 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 617 | |
| 618 | // unlike in the depth blit tests, this *should* draw a blue quad, because depth info |
| 619 | // has not been copied |
| 620 | glEnable(GL_DEPTH_TEST); |
| 621 | drawQuad(mBlueProgram, "position", 0.8f); |
| 622 | glDisable(GL_DEPTH_TEST); |
| 623 | |
| 624 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 625 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 626 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 627 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 628 | } |
| 629 | |
| 630 | TEST_F(BlitFramebufferANGLETest, blit_stencil) |
| 631 | { |
| 632 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 633 | |
| 634 | glClear(GL_COLOR_BUFFER_BIT); |
| 635 | // fill the stencil buffer with 0x1 |
| 636 | glStencilFunc(GL_ALWAYS, 0x1, 0xFF); |
| 637 | glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
| 638 | glEnable(GL_STENCIL_TEST); |
| 639 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 640 | |
| 641 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 642 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 643 | |
| 644 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 645 | glClearStencil(0x0); |
| 646 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 647 | |
| 648 | // depth blit request should be silently ignored, because the read FBO has no depth attachment |
| 649 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 650 | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); |
| 651 | |
| 652 | EXPECT_GL_NO_ERROR(); |
| 653 | |
| 654 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 655 | |
| 656 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 657 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 658 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 659 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 660 | |
| 661 | glStencilFunc(GL_EQUAL, 0x1, 0xFF); // only pass if stencil buffer at pixel reads 0x1 |
| 662 | drawQuad(mBlueProgram, "position", 0.8f); // blue quad will draw if stencil buffer was copied |
| 663 | glDisable(GL_STENCIL_TEST); |
| 664 | |
| 665 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 666 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 667 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 668 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 669 | } |
| 670 | |
| 671 | // make sure that attempting to blit a partial depth buffer issues an error |
| 672 | TEST_F(BlitFramebufferANGLETest, blit_partial_depth_stencil) |
| 673 | { |
| 674 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 675 | |
| 676 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 677 | |
| 678 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 679 | |
| 680 | EXPECT_GL_NO_ERROR(); |
| 681 | |
| 682 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 683 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 684 | |
| 685 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 686 | getWindowWidth() / 2, getWindowHeight() / 2, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 687 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 688 | } |
| 689 | |
| 690 | // Test blit with MRT framebuffers |
| 691 | TEST_F(BlitFramebufferANGLETest, blit_mrt) |
| 692 | { |
| 693 | if (!extensionEnabled("GL_EXT_draw_buffers")) |
| 694 | { |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; |
| 699 | |
| 700 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 701 | glDrawBuffersEXT(2, drawBuffers); |
| 702 | |
| 703 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 704 | |
| 705 | glClear(GL_COLOR_BUFFER_BIT); |
| 706 | |
| 707 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 708 | |
| 709 | EXPECT_GL_NO_ERROR(); |
| 710 | |
| 711 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 712 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mMRTFBO); |
| 713 | |
| 714 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 715 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 716 | |
| 717 | EXPECT_GL_NO_ERROR(); |
| 718 | |
| 719 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 720 | |
| 721 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 722 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 723 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 724 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 725 | |
| 726 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); |
| 727 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 728 | |
| 729 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 730 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 731 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 732 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 733 | |
| 734 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 735 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 736 | } |
| 737 | |
| 738 | // Make sure that attempts to stretch in a blit call issue an error |
| 739 | TEST_F(BlitFramebufferANGLETest, error_stretching) |
| 740 | { |
| 741 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 742 | |
| 743 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 744 | |
| 745 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 746 | |
| 747 | EXPECT_GL_NO_ERROR(); |
| 748 | |
| 749 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 750 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 751 | |
| 752 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 753 | getWindowWidth(), getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 754 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 755 | } |
| 756 | |
| 757 | // Make sure that attempts to flip in a blit call issue an error |
| 758 | TEST_F(BlitFramebufferANGLETest, error_flipping) |
| 759 | { |
| 760 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 761 | |
| 762 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 763 | |
| 764 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 765 | |
| 766 | EXPECT_GL_NO_ERROR(); |
| 767 | |
| 768 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 769 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 770 | |
| 771 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight() / 2, |
| 772 | 0, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 773 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 774 | } |
| 775 | |
| 776 | TEST_F(BlitFramebufferANGLETest, errors) |
| 777 | { |
| 778 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 779 | |
| 780 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 781 | |
| 782 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 783 | |
| 784 | EXPECT_GL_NO_ERROR(); |
| 785 | |
| 786 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 787 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 788 | |
| 789 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 790 | GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 791 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 792 | |
| 793 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 794 | GL_COLOR_BUFFER_BIT | 234, GL_NEAREST); |
| 795 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 796 | |
| 797 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mDiffFormatFBO); |
| 798 | |
| 799 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 800 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 801 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 802 | } |