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