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