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; |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame^] | 306 | |
| 307 | T mFixtureType; |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | // Draw to user-created framebuffer, blit whole-buffer color to original framebuffer. |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 311 | TYPED_TEST(BlitFramebufferANGLETest, BlitColorToDefault) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 312 | { |
| 313 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 314 | |
| 315 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 316 | |
| 317 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 318 | |
| 319 | EXPECT_GL_NO_ERROR(); |
| 320 | |
| 321 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 322 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 323 | |
| 324 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 325 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 326 | |
| 327 | EXPECT_GL_NO_ERROR(); |
| 328 | |
| 329 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 330 | |
| 331 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 332 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 333 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 334 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 335 | } |
| 336 | |
| 337 | // Draw to system framebuffer, blit whole-buffer color to user-created framebuffer. |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 338 | TYPED_TEST(BlitFramebufferANGLETest, ReverseColorBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 339 | { |
| 340 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 341 | |
| 342 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 343 | |
| 344 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 345 | |
| 346 | EXPECT_GL_NO_ERROR(); |
| 347 | |
| 348 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 349 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 350 | |
| 351 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 352 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 353 | |
| 354 | EXPECT_GL_NO_ERROR(); |
| 355 | |
| 356 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 357 | |
| 358 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 359 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 360 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 361 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 362 | } |
| 363 | |
| 364 | // 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] | 365 | TYPED_TEST(BlitFramebufferANGLETest, ScissoredBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 366 | { |
| 367 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 368 | |
| 369 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 370 | |
| 371 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 372 | |
| 373 | EXPECT_GL_NO_ERROR(); |
| 374 | |
| 375 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 376 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 377 | |
| 378 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 379 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 380 | |
| 381 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 382 | glEnable(GL_SCISSOR_TEST); |
| 383 | |
| 384 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 385 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 386 | |
| 387 | EXPECT_GL_NO_ERROR(); |
| 388 | |
| 389 | glDisable(GL_SCISSOR_TEST); |
| 390 | |
| 391 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 392 | |
| 393 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 394 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 395 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 396 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 397 | } |
| 398 | |
| 399 | // 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] | 400 | TYPED_TEST(BlitFramebufferANGLETest, ReverseScissoredBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 401 | { |
| 402 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 403 | |
| 404 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 405 | |
| 406 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 407 | |
| 408 | EXPECT_GL_NO_ERROR(); |
| 409 | |
| 410 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 411 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 412 | |
| 413 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 414 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 415 | |
| 416 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 417 | glEnable(GL_SCISSOR_TEST); |
| 418 | |
| 419 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 420 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 421 | |
| 422 | EXPECT_GL_NO_ERROR(); |
| 423 | |
| 424 | glDisable(GL_SCISSOR_TEST); |
| 425 | |
| 426 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 427 | |
| 428 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 429 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 430 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 431 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 432 | } |
| 433 | |
| 434 | // 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] | 435 | TYPED_TEST(BlitFramebufferANGLETest, OversizedBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 436 | { |
| 437 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 438 | |
| 439 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 440 | |
| 441 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 442 | |
| 443 | EXPECT_GL_NO_ERROR(); |
| 444 | |
| 445 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 446 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 447 | |
| 448 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 449 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 450 | |
| 451 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 452 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 453 | |
| 454 | EXPECT_GL_NO_ERROR(); |
| 455 | |
| 456 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 457 | |
| 458 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 459 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 460 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 461 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 462 | } |
| 463 | |
| 464 | // 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] | 465 | TYPED_TEST(BlitFramebufferANGLETest, ReverseOversizedBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 466 | { |
| 467 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 468 | |
| 469 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 470 | |
| 471 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 472 | |
| 473 | EXPECT_GL_NO_ERROR(); |
| 474 | |
| 475 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 476 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 477 | |
| 478 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 479 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 480 | |
| 481 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 482 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 483 | EXPECT_GL_NO_ERROR(); |
| 484 | |
| 485 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 486 | |
| 487 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 488 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 489 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 490 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 491 | } |
| 492 | |
| 493 | // blit from user-created FBO to system framebuffer, with depth buffer. |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 494 | TYPED_TEST(BlitFramebufferANGLETest, BlitWithDepth) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 495 | { |
| 496 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 497 | |
| 498 | glDepthMask(GL_TRUE); |
| 499 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 500 | |
| 501 | glEnable(GL_DEPTH_TEST); |
| 502 | |
| 503 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 504 | |
| 505 | EXPECT_GL_NO_ERROR(); |
| 506 | |
| 507 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 508 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 509 | |
| 510 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 511 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 512 | |
| 513 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 514 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 515 | EXPECT_GL_NO_ERROR(); |
| 516 | |
| 517 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 518 | |
| 519 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 520 | drawQuad(mBlueProgram, "position", 0.8f); |
| 521 | |
| 522 | glDisable(GL_DEPTH_TEST); |
| 523 | |
| 524 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 525 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 526 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 527 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 528 | } |
| 529 | |
| 530 | // blit from system FBO to user-created framebuffer, with depth buffer. |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 531 | TYPED_TEST(BlitFramebufferANGLETest, ReverseBlitWithDepth) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 532 | { |
| 533 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 534 | |
| 535 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 536 | |
| 537 | glEnable(GL_DEPTH_TEST); |
| 538 | |
| 539 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 540 | |
| 541 | EXPECT_GL_NO_ERROR(); |
| 542 | |
| 543 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 544 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 545 | |
| 546 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 547 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 548 | |
| 549 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 550 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 551 | EXPECT_GL_NO_ERROR(); |
| 552 | |
| 553 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 554 | |
| 555 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 556 | |
| 557 | drawQuad(mBlueProgram, "position", 0.8f); |
| 558 | |
| 559 | glDisable(GL_DEPTH_TEST); |
| 560 | |
| 561 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 562 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 563 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 564 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 565 | } |
| 566 | |
| 567 | // 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] | 568 | TYPED_TEST(BlitFramebufferANGLETest, BlitSameBufferOriginal) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 569 | { |
| 570 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 571 | |
| 572 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 573 | |
| 574 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 575 | |
| 576 | EXPECT_GL_NO_ERROR(); |
| 577 | |
| 578 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 579 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 580 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 581 | } |
| 582 | |
| 583 | // blit from one region of the system fbo to another. |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 584 | TYPED_TEST(BlitFramebufferANGLETest, BlitSameBufferUser) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 585 | { |
| 586 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 587 | |
| 588 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 589 | |
| 590 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 591 | |
| 592 | EXPECT_GL_NO_ERROR(); |
| 593 | |
| 594 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 595 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 596 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 597 | } |
| 598 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 599 | TYPED_TEST(BlitFramebufferANGLETest, BlitPartialColor) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 600 | { |
| 601 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 602 | |
| 603 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 604 | |
| 605 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 606 | |
| 607 | EXPECT_GL_NO_ERROR(); |
| 608 | |
| 609 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 610 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 611 | |
| 612 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 613 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 614 | |
| 615 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight(), |
| 616 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 617 | |
| 618 | EXPECT_GL_NO_ERROR(); |
| 619 | |
| 620 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 621 | |
| 622 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 623 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 624 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 625 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 626 | } |
| 627 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 628 | TYPED_TEST(BlitFramebufferANGLETest, BlitDifferentSizes) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 629 | { |
| 630 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 631 | |
| 632 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 633 | |
| 634 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 635 | |
| 636 | EXPECT_GL_NO_ERROR(); |
| 637 | |
| 638 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mSmallFBO); |
| 639 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 640 | |
| 641 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 642 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 643 | |
| 644 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 645 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 646 | |
| 647 | EXPECT_GL_NO_ERROR(); |
| 648 | |
| 649 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 650 | |
| 651 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 652 | |
| 653 | EXPECT_GL_NO_ERROR(); |
| 654 | } |
| 655 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 656 | TYPED_TEST(BlitFramebufferANGLETest, BlitWithMissingAttachments) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 657 | { |
| 658 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 659 | |
| 660 | glClear(GL_COLOR_BUFFER_BIT); |
| 661 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 662 | |
| 663 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 664 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 665 | |
| 666 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 667 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 668 | |
| 669 | // depth blit request should be silently ignored, because the read FBO has no depth attachment |
| 670 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 671 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 672 | |
| 673 | EXPECT_GL_NO_ERROR(); |
| 674 | |
| 675 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 676 | |
| 677 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 678 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 679 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 680 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 681 | |
| 682 | // unlike in the depth blit tests, this *should* draw a blue quad, because depth info |
| 683 | // has not been copied |
| 684 | glEnable(GL_DEPTH_TEST); |
| 685 | drawQuad(mBlueProgram, "position", 0.8f); |
| 686 | glDisable(GL_DEPTH_TEST); |
| 687 | |
| 688 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 689 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 690 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 691 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 692 | } |
| 693 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 694 | TYPED_TEST(BlitFramebufferANGLETest, BlitStencil) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 695 | { |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame^] | 696 | // TODO(jmadill): Figure out if we can fix this on D3D9. |
| 697 | // https://code.google.com/p/angleproject/issues/detail?id=809 |
| 698 | std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER))); |
| 699 | if (rendererString.find("Intel") != std::string::npos && |
| 700 | mFixtureType.GetPlatform().renderer == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE) |
| 701 | { |
| 702 | return; |
| 703 | } |
| 704 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 705 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 706 | |
| 707 | glClear(GL_COLOR_BUFFER_BIT); |
| 708 | // fill the stencil buffer with 0x1 |
| 709 | glStencilFunc(GL_ALWAYS, 0x1, 0xFF); |
| 710 | glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
| 711 | glEnable(GL_STENCIL_TEST); |
| 712 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 713 | |
| 714 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 715 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 716 | |
| 717 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 718 | glClearStencil(0x0); |
| 719 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 720 | |
| 721 | // depth blit request should be silently ignored, because the read FBO has no depth attachment |
| 722 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 723 | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); |
| 724 | |
| 725 | EXPECT_GL_NO_ERROR(); |
| 726 | |
| 727 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 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 | glStencilFunc(GL_EQUAL, 0x1, 0xFF); // only pass if stencil buffer at pixel reads 0x1 |
| 735 | drawQuad(mBlueProgram, "position", 0.8f); // blue quad will draw if stencil buffer was copied |
| 736 | glDisable(GL_STENCIL_TEST); |
| 737 | |
| 738 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 739 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 740 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 741 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 742 | } |
| 743 | |
| 744 | // 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] | 745 | TYPED_TEST(BlitFramebufferANGLETest, BlitPartialDepthStencil) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 746 | { |
| 747 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 748 | |
| 749 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 750 | |
| 751 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 752 | |
| 753 | EXPECT_GL_NO_ERROR(); |
| 754 | |
| 755 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 756 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 757 | |
| 758 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 759 | getWindowWidth() / 2, getWindowHeight() / 2, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 760 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 761 | } |
| 762 | |
| 763 | // Test blit with MRT framebuffers |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 764 | TYPED_TEST(BlitFramebufferANGLETest, BlitMRT) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 765 | { |
| 766 | if (!extensionEnabled("GL_EXT_draw_buffers")) |
| 767 | { |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; |
| 772 | |
| 773 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 774 | glDrawBuffersEXT(2, drawBuffers); |
| 775 | |
| 776 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 777 | |
| 778 | glClear(GL_COLOR_BUFFER_BIT); |
| 779 | |
| 780 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 781 | |
| 782 | EXPECT_GL_NO_ERROR(); |
| 783 | |
| 784 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 785 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mMRTFBO); |
| 786 | |
| 787 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 788 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 789 | |
| 790 | EXPECT_GL_NO_ERROR(); |
| 791 | |
| 792 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 793 | |
| 794 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 795 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 796 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 797 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 798 | |
| 799 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); |
| 800 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 801 | |
| 802 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 803 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 804 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 805 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 806 | |
| 807 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 808 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 809 | } |
| 810 | |
| 811 | // 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] | 812 | TYPED_TEST(BlitFramebufferANGLETest, ErrorStretching) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 813 | { |
| 814 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 815 | |
| 816 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 817 | |
| 818 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 819 | |
| 820 | EXPECT_GL_NO_ERROR(); |
| 821 | |
| 822 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 823 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 824 | |
| 825 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 826 | getWindowWidth(), getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 827 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 828 | } |
| 829 | |
| 830 | // 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] | 831 | TYPED_TEST(BlitFramebufferANGLETest, ErrorFlipping) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 832 | { |
| 833 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 834 | |
| 835 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 836 | |
| 837 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 838 | |
| 839 | EXPECT_GL_NO_ERROR(); |
| 840 | |
| 841 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 842 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 843 | |
| 844 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight() / 2, |
| 845 | 0, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 846 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 847 | } |
| 848 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 849 | TYPED_TEST(BlitFramebufferANGLETest, Errors) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 850 | { |
| 851 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 852 | |
| 853 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 854 | |
| 855 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 856 | |
| 857 | EXPECT_GL_NO_ERROR(); |
| 858 | |
| 859 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 860 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 861 | |
| 862 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 863 | GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 864 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 865 | |
| 866 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 867 | GL_COLOR_BUFFER_BIT | 234, GL_NEAREST); |
| 868 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 869 | |
| 870 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mDiffFormatFBO); |
| 871 | |
| 872 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 873 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 874 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 875 | |
| 876 | if (extensionEnabled("GL_ANGLE_framebuffer_multisample")) |
| 877 | { |
| 878 | glBindFramebuffer(GL_READ_FRAMEBUFFER, mBGRAMultisampledFBO); |
| 879 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mRGBAFBO); |
| 880 | EXPECT_GL_NO_ERROR(); |
| 881 | |
| 882 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 883 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 884 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 885 | } |
| 886 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 887 | } |