Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 8 | |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 9 | #include "test_utils/gl_raii.h" |
| 10 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 11 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 12 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 13 | class BlitFramebufferANGLETest : public ANGLETest |
| 14 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 15 | protected: |
| 16 | BlitFramebufferANGLETest() |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 17 | { |
| 18 | setWindowWidth(256); |
| 19 | setWindowHeight(256); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 20 | setConfigRedBits(8); |
| 21 | setConfigGreenBits(8); |
| 22 | setConfigBlueBits(8); |
| 23 | setConfigAlphaBits(8); |
| 24 | setConfigDepthBits(24); |
Geoff Lang | 784cc8f | 2015-02-05 09:00:54 -0500 | [diff] [blame] | 25 | setConfigStencilBits(8); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 26 | |
| 27 | mCheckerProgram = 0; |
| 28 | mBlueProgram = 0; |
| 29 | |
| 30 | mOriginalFBO = 0; |
| 31 | |
| 32 | mUserFBO = 0; |
| 33 | mUserColorBuffer = 0; |
| 34 | mUserDepthStencilBuffer = 0; |
| 35 | |
| 36 | mSmallFBO = 0; |
| 37 | mSmallColorBuffer = 0; |
| 38 | mSmallDepthStencilBuffer = 0; |
| 39 | |
| 40 | mColorOnlyFBO = 0; |
| 41 | mColorOnlyColorBuffer = 0; |
| 42 | |
| 43 | mDiffFormatFBO = 0; |
| 44 | mDiffFormatColorBuffer = 0; |
| 45 | |
| 46 | mDiffSizeFBO = 0; |
| 47 | mDiffSizeColorBuffer = 0; |
| 48 | |
| 49 | mMRTFBO = 0; |
| 50 | mMRTColorBuffer0 = 0; |
| 51 | mMRTColorBuffer1 = 0; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 52 | |
| 53 | mRGBAColorbuffer = 0; |
| 54 | mRGBAFBO = 0; |
| 55 | |
| 56 | mBGRAMultisampledRenderbuffer = 0; |
| 57 | mBGRAMultisampledFBO = 0; |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | virtual void SetUp() |
| 61 | { |
| 62 | ANGLETest::SetUp(); |
| 63 | |
| 64 | const std::string passthroughVS = SHADER_SOURCE |
| 65 | ( |
| 66 | precision highp float; |
| 67 | attribute vec4 position; |
| 68 | varying vec4 pos; |
| 69 | |
| 70 | void main() |
| 71 | { |
| 72 | gl_Position = position; |
| 73 | pos = position; |
| 74 | } |
| 75 | ); |
| 76 | |
| 77 | const std::string checkeredFS = SHADER_SOURCE |
| 78 | ( |
| 79 | precision highp float; |
| 80 | varying vec4 pos; |
| 81 | |
| 82 | void main() |
| 83 | { |
| 84 | if (pos.x * pos.y > 0.0) |
| 85 | { |
| 86 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); |
| 91 | } |
| 92 | } |
| 93 | ); |
| 94 | |
| 95 | const std::string blueFS = SHADER_SOURCE |
| 96 | ( |
| 97 | precision highp float; |
| 98 | varying vec4 pos; |
| 99 | |
| 100 | void main() |
| 101 | { |
| 102 | gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); |
| 103 | } |
| 104 | ); |
| 105 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 106 | mCheckerProgram = CompileProgram(passthroughVS, checkeredFS); |
| 107 | mBlueProgram = CompileProgram(passthroughVS, blueFS); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 108 | if (mCheckerProgram == 0 || mBlueProgram == 0) |
| 109 | { |
| 110 | FAIL() << "shader compilation failed."; |
| 111 | } |
| 112 | |
| 113 | EXPECT_GL_NO_ERROR(); |
| 114 | |
| 115 | GLint originalFBO; |
| 116 | glGetIntegerv(GL_FRAMEBUFFER_BINDING, &originalFBO); |
| 117 | if (originalFBO >= 0) |
| 118 | { |
| 119 | mOriginalFBO = (GLuint)originalFBO; |
| 120 | } |
| 121 | |
| 122 | GLenum format = GL_BGRA8_EXT; |
| 123 | |
| 124 | glGenFramebuffers(1, &mUserFBO); |
| 125 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 126 | glGenTextures(1, &mUserColorBuffer); |
| 127 | glGenRenderbuffers(1, &mUserDepthStencilBuffer); |
| 128 | glBindTexture(GL_TEXTURE_2D, mUserColorBuffer); |
| 129 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 130 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mUserColorBuffer, 0); |
| 131 | glBindRenderbuffer(GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 132 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth(), getWindowHeight()); |
| 133 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 134 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mUserDepthStencilBuffer); |
| 135 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 136 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 137 | ASSERT_GL_NO_ERROR(); |
| 138 | |
| 139 | glGenFramebuffers(1, &mSmallFBO); |
| 140 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 141 | glGenTextures(1, &mSmallColorBuffer); |
| 142 | glGenRenderbuffers(1, &mSmallDepthStencilBuffer); |
| 143 | glBindTexture(GL_TEXTURE_2D, mSmallColorBuffer); |
| 144 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth() / 2, getWindowHeight() / 2); |
| 145 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mSmallColorBuffer, 0); |
| 146 | glBindRenderbuffer(GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 147 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth() / 2, getWindowHeight() / 2); |
| 148 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 149 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, mSmallDepthStencilBuffer); |
| 150 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 151 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 152 | ASSERT_GL_NO_ERROR(); |
| 153 | |
| 154 | glGenFramebuffers(1, &mColorOnlyFBO); |
| 155 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 156 | glGenTextures(1, &mColorOnlyColorBuffer); |
| 157 | glBindTexture(GL_TEXTURE_2D, mColorOnlyColorBuffer); |
| 158 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 159 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorOnlyColorBuffer, 0); |
| 160 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 161 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 162 | ASSERT_GL_NO_ERROR(); |
| 163 | |
| 164 | glGenFramebuffers(1, &mDiffFormatFBO); |
| 165 | glBindFramebuffer(GL_FRAMEBUFFER, mDiffFormatFBO); |
| 166 | glGenTextures(1, &mDiffFormatColorBuffer); |
| 167 | glBindTexture(GL_TEXTURE_2D, mDiffFormatColorBuffer); |
| 168 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB565, getWindowWidth(), getWindowHeight()); |
| 169 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffFormatColorBuffer, 0); |
| 170 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 171 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 172 | ASSERT_GL_NO_ERROR(); |
| 173 | |
| 174 | glGenFramebuffers(1, &mDiffSizeFBO); |
| 175 | glBindFramebuffer(GL_FRAMEBUFFER, mDiffSizeFBO); |
| 176 | glGenTextures(1, &mDiffSizeColorBuffer); |
| 177 | glBindTexture(GL_TEXTURE_2D, mDiffSizeColorBuffer); |
| 178 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth()*2, getWindowHeight()*2); |
| 179 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mDiffSizeColorBuffer, 0); |
| 180 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 181 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 182 | ASSERT_GL_NO_ERROR(); |
| 183 | |
| 184 | if (extensionEnabled("GL_EXT_draw_buffers")) |
| 185 | { |
| 186 | glGenFramebuffers(1, &mMRTFBO); |
| 187 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 188 | glGenTextures(1, &mMRTColorBuffer0); |
| 189 | glGenTextures(1, &mMRTColorBuffer1); |
| 190 | glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer0); |
| 191 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 192 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 193 | glBindTexture(GL_TEXTURE_2D, mMRTColorBuffer1); |
| 194 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, format, getWindowWidth(), getWindowHeight()); |
| 195 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 196 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 197 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 198 | ASSERT_GL_NO_ERROR(); |
| 199 | } |
| 200 | |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 201 | if (extensionEnabled("GL_ANGLE_framebuffer_multisample")) |
| 202 | { |
| 203 | // Test blit between RGBA and multisampled BGRA |
| 204 | glGenTextures(1, &mRGBAColorbuffer); |
| 205 | glBindTexture(GL_TEXTURE_2D, mRGBAColorbuffer); |
| 206 | glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, getWindowWidth(), getWindowHeight()); |
| 207 | |
| 208 | glGenFramebuffers(1, &mRGBAFBO); |
| 209 | glBindFramebuffer(GL_FRAMEBUFFER, mRGBAFBO); |
| 210 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mRGBAColorbuffer, 0); |
| 211 | |
| 212 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 213 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 214 | |
| 215 | glGenRenderbuffers(1, &mBGRAMultisampledRenderbuffer); |
| 216 | glBindRenderbuffer(GL_RENDERBUFFER, mBGRAMultisampledRenderbuffer); |
| 217 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_BGRA8_EXT, getWindowWidth(), getWindowHeight()); |
| 218 | |
| 219 | glGenFramebuffers(1, &mBGRAMultisampledFBO); |
| 220 | glBindFramebuffer(GL_FRAMEBUFFER, mBGRAMultisampledFBO); |
| 221 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, mBGRAMultisampledRenderbuffer); |
| 222 | |
| 223 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 224 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 227 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 228 | } |
| 229 | |
| 230 | virtual void TearDown() |
| 231 | { |
| 232 | glDeleteProgram(mCheckerProgram); |
| 233 | glDeleteProgram(mBlueProgram); |
| 234 | |
| 235 | glDeleteFramebuffers(1, &mUserFBO); |
| 236 | glDeleteTextures(1, &mUserColorBuffer); |
| 237 | glDeleteRenderbuffers(1, &mUserDepthStencilBuffer); |
| 238 | |
| 239 | glDeleteFramebuffers(1, &mSmallFBO); |
| 240 | glDeleteTextures(1, &mSmallColorBuffer); |
| 241 | glDeleteRenderbuffers(1, &mSmallDepthStencilBuffer); |
| 242 | |
| 243 | glDeleteFramebuffers(1, &mColorOnlyFBO); |
| 244 | glDeleteTextures(1, &mSmallDepthStencilBuffer); |
| 245 | |
| 246 | glDeleteFramebuffers(1, &mDiffFormatFBO); |
| 247 | glDeleteTextures(1, &mDiffFormatColorBuffer); |
| 248 | |
| 249 | glDeleteFramebuffers(1, &mDiffSizeFBO); |
| 250 | glDeleteTextures(1, &mDiffSizeColorBuffer); |
| 251 | |
| 252 | if (extensionEnabled("GL_EXT_draw_buffers")) |
| 253 | { |
| 254 | glDeleteFramebuffers(1, &mMRTFBO); |
| 255 | glDeleteTextures(1, &mMRTColorBuffer0); |
| 256 | glDeleteTextures(1, &mMRTColorBuffer1); |
| 257 | } |
| 258 | |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 259 | if (mRGBAColorbuffer != 0) |
| 260 | { |
| 261 | glDeleteTextures(1, &mRGBAColorbuffer); |
| 262 | } |
| 263 | |
| 264 | if (mRGBAFBO != 0) |
| 265 | { |
| 266 | glDeleteFramebuffers(1, &mBGRAMultisampledFBO); |
| 267 | } |
| 268 | |
| 269 | if (mBGRAMultisampledRenderbuffer != 0) |
| 270 | { |
| 271 | glDeleteRenderbuffers(1, &mBGRAMultisampledRenderbuffer); |
| 272 | } |
| 273 | |
| 274 | if (mBGRAMultisampledFBO != 0) |
| 275 | { |
| 276 | glDeleteFramebuffers(1, &mBGRAMultisampledFBO); |
| 277 | } |
| 278 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 279 | ANGLETest::TearDown(); |
| 280 | } |
| 281 | |
| 282 | GLuint mCheckerProgram; |
| 283 | GLuint mBlueProgram; |
| 284 | |
| 285 | GLuint mOriginalFBO; |
| 286 | |
| 287 | GLuint mUserFBO; |
| 288 | GLuint mUserColorBuffer; |
| 289 | GLuint mUserDepthStencilBuffer; |
| 290 | |
| 291 | GLuint mSmallFBO; |
| 292 | GLuint mSmallColorBuffer; |
| 293 | GLuint mSmallDepthStencilBuffer; |
| 294 | |
| 295 | GLuint mColorOnlyFBO; |
| 296 | GLuint mColorOnlyColorBuffer; |
| 297 | |
| 298 | GLuint mDiffFormatFBO; |
| 299 | GLuint mDiffFormatColorBuffer; |
| 300 | |
| 301 | GLuint mDiffSizeFBO; |
| 302 | GLuint mDiffSizeColorBuffer; |
| 303 | |
| 304 | GLuint mMRTFBO; |
| 305 | GLuint mMRTColorBuffer0; |
| 306 | GLuint mMRTColorBuffer1; |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 307 | |
| 308 | GLuint mRGBAColorbuffer; |
| 309 | GLuint mRGBAFBO; |
| 310 | |
| 311 | GLuint mBGRAMultisampledRenderbuffer; |
| 312 | GLuint mBGRAMultisampledFBO; |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | // Draw to user-created framebuffer, blit whole-buffer color to original framebuffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 316 | TEST_P(BlitFramebufferANGLETest, BlitColorToDefault) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 317 | { |
| 318 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 319 | |
| 320 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 321 | |
| 322 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 323 | |
| 324 | EXPECT_GL_NO_ERROR(); |
| 325 | |
| 326 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 327 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 328 | |
| 329 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 330 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 331 | |
| 332 | EXPECT_GL_NO_ERROR(); |
| 333 | |
| 334 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 335 | |
| 336 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 337 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 338 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 339 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 340 | } |
| 341 | |
| 342 | // Draw to system framebuffer, blit whole-buffer color to user-created framebuffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 343 | TEST_P(BlitFramebufferANGLETest, ReverseColorBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 344 | { |
| 345 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 346 | |
| 347 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 348 | |
| 349 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 350 | |
| 351 | EXPECT_GL_NO_ERROR(); |
| 352 | |
| 353 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 354 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 355 | |
| 356 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 357 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 358 | |
| 359 | EXPECT_GL_NO_ERROR(); |
| 360 | |
| 361 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 362 | |
| 363 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 364 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 365 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 366 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 367 | } |
| 368 | |
| 369 | // blit from user-created FBO to system framebuffer, with the scissor test enabled. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 370 | TEST_P(BlitFramebufferANGLETest, ScissoredBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 371 | { |
| 372 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 373 | |
| 374 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 375 | |
| 376 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 377 | |
| 378 | EXPECT_GL_NO_ERROR(); |
| 379 | |
| 380 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 381 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 382 | |
| 383 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 384 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 385 | |
| 386 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 387 | glEnable(GL_SCISSOR_TEST); |
| 388 | |
| 389 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 390 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 391 | |
| 392 | EXPECT_GL_NO_ERROR(); |
| 393 | |
| 394 | glDisable(GL_SCISSOR_TEST); |
| 395 | |
| 396 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 397 | |
| 398 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 399 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 400 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 401 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 402 | } |
| 403 | |
| 404 | // blit from system FBO to user-created framebuffer, with the scissor test enabled. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 405 | TEST_P(BlitFramebufferANGLETest, ReverseScissoredBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 406 | { |
Jamie Madill | 1200c41 | 2016-08-16 14:09:14 -0400 | [diff] [blame] | 407 | // TODO(jmadill): Triage this driver bug. |
| 408 | if (IsAMD() && IsD3D11()) |
| 409 | { |
| 410 | std::cout << "Test skipped on AMD D3D11." << std::endl; |
| 411 | return; |
| 412 | } |
| 413 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 414 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 415 | |
| 416 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 417 | |
| 418 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 419 | |
| 420 | EXPECT_GL_NO_ERROR(); |
| 421 | |
| 422 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 423 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 424 | |
| 425 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 426 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 427 | |
| 428 | glScissor(getWindowWidth() / 2, 0, getWindowWidth() / 2, getWindowHeight()); |
| 429 | glEnable(GL_SCISSOR_TEST); |
| 430 | |
| 431 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 432 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 433 | |
| 434 | EXPECT_GL_NO_ERROR(); |
| 435 | |
| 436 | glDisable(GL_SCISSOR_TEST); |
| 437 | |
| 438 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 439 | |
| 440 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 441 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 442 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 443 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 444 | } |
| 445 | |
| 446 | // blit from user-created FBO to system framebuffer, using region larger than buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 447 | TEST_P(BlitFramebufferANGLETest, OversizedBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 448 | { |
| 449 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 450 | |
| 451 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 452 | |
| 453 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 454 | |
| 455 | EXPECT_GL_NO_ERROR(); |
| 456 | |
| 457 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 458 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 459 | |
| 460 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 461 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 462 | |
| 463 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 464 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 465 | |
| 466 | EXPECT_GL_NO_ERROR(); |
| 467 | |
| 468 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 469 | |
| 470 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 471 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 472 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 473 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 474 | } |
| 475 | |
| 476 | // blit from system FBO to user-created framebuffer, using region larger than buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 477 | TEST_P(BlitFramebufferANGLETest, ReverseOversizedBlit) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 478 | { |
| 479 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 480 | |
| 481 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 482 | |
| 483 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 484 | |
| 485 | EXPECT_GL_NO_ERROR(); |
| 486 | |
| 487 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 488 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 489 | |
| 490 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 491 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 492 | |
| 493 | glBlitFramebufferANGLE(0, 0, getWindowWidth() * 2, getWindowHeight() * 2, 0, 0, getWindowWidth() * 2, getWindowHeight() * 2, |
| 494 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 495 | EXPECT_GL_NO_ERROR(); |
| 496 | |
| 497 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 498 | |
| 499 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 500 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 501 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 502 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 503 | } |
| 504 | |
| 505 | // blit from user-created FBO to system framebuffer, with depth buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 506 | TEST_P(BlitFramebufferANGLETest, BlitWithDepth) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 507 | { |
| 508 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 509 | |
| 510 | glDepthMask(GL_TRUE); |
| 511 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 512 | |
| 513 | glEnable(GL_DEPTH_TEST); |
| 514 | |
| 515 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 516 | |
| 517 | EXPECT_GL_NO_ERROR(); |
| 518 | |
| 519 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 520 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 521 | |
| 522 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 523 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 524 | |
| 525 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 526 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 527 | EXPECT_GL_NO_ERROR(); |
| 528 | |
| 529 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 530 | |
| 531 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 532 | drawQuad(mBlueProgram, "position", 0.8f); |
| 533 | |
| 534 | glDisable(GL_DEPTH_TEST); |
| 535 | |
| 536 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 537 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 538 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 539 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 540 | } |
| 541 | |
| 542 | // blit from system FBO to user-created framebuffer, with depth buffer. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 543 | TEST_P(BlitFramebufferANGLETest, ReverseBlitWithDepth) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 544 | { |
| 545 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 546 | |
| 547 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 548 | |
| 549 | glEnable(GL_DEPTH_TEST); |
| 550 | |
| 551 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 552 | |
| 553 | EXPECT_GL_NO_ERROR(); |
| 554 | |
| 555 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mUserFBO); |
| 556 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 557 | |
| 558 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 559 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 560 | |
| 561 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 562 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 563 | EXPECT_GL_NO_ERROR(); |
| 564 | |
| 565 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 566 | |
| 567 | // if blit is happening correctly, this quad will not draw, because it is behind the blitted one |
| 568 | |
| 569 | drawQuad(mBlueProgram, "position", 0.8f); |
| 570 | |
| 571 | glDisable(GL_DEPTH_TEST); |
| 572 | |
| 573 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 574 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 575 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 576 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 577 | } |
| 578 | |
| 579 | // blit from one region of the system fbo to another-- this should fail. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 580 | TEST_P(BlitFramebufferANGLETest, BlitSameBufferOriginal) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 581 | { |
| 582 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 583 | |
| 584 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 585 | |
| 586 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 587 | |
| 588 | EXPECT_GL_NO_ERROR(); |
| 589 | |
| 590 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 591 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 592 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 593 | } |
| 594 | |
| 595 | // blit from one region of the system fbo to another. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 596 | TEST_P(BlitFramebufferANGLETest, BlitSameBufferUser) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 597 | { |
| 598 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 599 | |
| 600 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 601 | |
| 602 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 603 | |
| 604 | EXPECT_GL_NO_ERROR(); |
| 605 | |
| 606 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight(), getWindowWidth() / 2, 0, getWindowWidth(), getWindowHeight(), |
| 607 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 608 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 609 | } |
| 610 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 611 | TEST_P(BlitFramebufferANGLETest, BlitPartialColor) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 612 | { |
| 613 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 614 | |
| 615 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 616 | |
| 617 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 618 | |
| 619 | EXPECT_GL_NO_ERROR(); |
| 620 | |
| 621 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 622 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 623 | |
| 624 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 625 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 626 | |
| 627 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight(), |
| 628 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 629 | |
| 630 | EXPECT_GL_NO_ERROR(); |
| 631 | |
| 632 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 633 | |
| 634 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 635 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 255, 255, 255, 255); |
| 636 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 255, 255, 255); |
| 637 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 638 | } |
| 639 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 640 | TEST_P(BlitFramebufferANGLETest, BlitDifferentSizes) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 641 | { |
| 642 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 643 | |
| 644 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 645 | |
| 646 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 647 | |
| 648 | EXPECT_GL_NO_ERROR(); |
| 649 | |
| 650 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mSmallFBO); |
| 651 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 652 | |
| 653 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 654 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 655 | |
| 656 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 657 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 658 | |
| 659 | EXPECT_GL_NO_ERROR(); |
| 660 | |
| 661 | glBindFramebuffer(GL_FRAMEBUFFER, mSmallFBO); |
| 662 | |
| 663 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 664 | |
| 665 | EXPECT_GL_NO_ERROR(); |
| 666 | } |
| 667 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 668 | TEST_P(BlitFramebufferANGLETest, BlitWithMissingAttachments) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 669 | { |
| 670 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 671 | |
| 672 | glClear(GL_COLOR_BUFFER_BIT); |
| 673 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 674 | |
| 675 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 676 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 677 | |
| 678 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 679 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 680 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame^] | 681 | // generate INVALID_OPERATION if the read FBO has no depth attachment |
| 682 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), |
| 683 | getWindowHeight(), GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, |
| 684 | GL_NEAREST); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 685 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame^] | 686 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 687 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame^] | 688 | // generate INVALID_OPERATION if the read FBO has no stencil attachment |
| 689 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), |
| 690 | getWindowHeight(), GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, |
| 691 | GL_NEAREST); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 692 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame^] | 693 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 694 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame^] | 695 | // generate INVALID_OPERATION if we read from a missing color attachment |
| 696 | glReadBuffer(GL_COLOR_ATTACHMENT1); |
| 697 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), |
| 698 | getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 699 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame^] | 700 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 701 | } |
| 702 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 703 | TEST_P(BlitFramebufferANGLETest, BlitStencil) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 704 | { |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame] | 705 | // TODO(jmadill): Figure out if we can fix this on D3D9. |
| 706 | // https://code.google.com/p/angleproject/issues/detail?id=809 |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 707 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE) |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame] | 708 | { |
Jamie Madill | c3b9b26 | 2015-01-30 14:00:51 -0500 | [diff] [blame] | 709 | std::cout << "Test skipped on Intel D3D9." << std::endl; |
Jamie Madill | 8e1936c | 2014-12-03 15:20:12 -0500 | [diff] [blame] | 710 | return; |
| 711 | } |
| 712 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 713 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 714 | |
| 715 | glClear(GL_COLOR_BUFFER_BIT); |
| 716 | // fill the stencil buffer with 0x1 |
| 717 | glStencilFunc(GL_ALWAYS, 0x1, 0xFF); |
| 718 | glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
| 719 | glEnable(GL_STENCIL_TEST); |
| 720 | drawQuad(mCheckerProgram, "position", 0.3f); |
| 721 | |
| 722 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 723 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 724 | |
| 725 | glClearColor(1.0, 1.0, 1.0, 1.0); |
| 726 | glClearStencil(0x0); |
| 727 | glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 728 | |
| 729 | // depth blit request should be silently ignored, because the read FBO has no depth attachment |
| 730 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 731 | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); |
| 732 | |
| 733 | EXPECT_GL_NO_ERROR(); |
| 734 | |
| 735 | glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO); |
| 736 | |
| 737 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 738 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 739 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 740 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 741 | |
| 742 | glStencilFunc(GL_EQUAL, 0x1, 0xFF); // only pass if stencil buffer at pixel reads 0x1 |
| 743 | drawQuad(mBlueProgram, "position", 0.8f); // blue quad will draw if stencil buffer was copied |
| 744 | glDisable(GL_STENCIL_TEST); |
| 745 | |
| 746 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 747 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 0, 255, 255); |
| 748 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 749 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 0, 255, 255); |
| 750 | } |
| 751 | |
| 752 | // make sure that attempting to blit a partial depth buffer issues an error |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 753 | TEST_P(BlitFramebufferANGLETest, BlitPartialDepthStencil) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 754 | { |
| 755 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 756 | |
| 757 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 758 | |
| 759 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 760 | |
| 761 | EXPECT_GL_NO_ERROR(); |
| 762 | |
| 763 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 764 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 765 | |
| 766 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 767 | getWindowWidth() / 2, getWindowHeight() / 2, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 768 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 769 | } |
| 770 | |
| 771 | // Test blit with MRT framebuffers |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 772 | TEST_P(BlitFramebufferANGLETest, BlitMRT) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 773 | { |
| 774 | if (!extensionEnabled("GL_EXT_draw_buffers")) |
| 775 | { |
| 776 | return; |
| 777 | } |
| 778 | |
| 779 | GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; |
| 780 | |
| 781 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 782 | glDrawBuffersEXT(2, drawBuffers); |
| 783 | |
| 784 | glBindFramebuffer(GL_FRAMEBUFFER, mColorOnlyFBO); |
| 785 | |
| 786 | glClear(GL_COLOR_BUFFER_BIT); |
| 787 | |
| 788 | drawQuad(mCheckerProgram, "position", 0.8f); |
| 789 | |
| 790 | EXPECT_GL_NO_ERROR(); |
| 791 | |
| 792 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mColorOnlyFBO); |
| 793 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mMRTFBO); |
| 794 | |
| 795 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 796 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 797 | |
| 798 | EXPECT_GL_NO_ERROR(); |
| 799 | |
| 800 | glBindFramebuffer(GL_FRAMEBUFFER, mMRTFBO); |
| 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_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); |
| 808 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 809 | |
| 810 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, getWindowHeight() / 4, 255, 0, 0, 255); |
| 811 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, getWindowHeight() / 4, 0, 255, 0, 255); |
| 812 | EXPECT_PIXEL_EQ(3 * getWindowWidth() / 4, 3 * getWindowHeight() / 4, 255, 0, 0, 255); |
| 813 | EXPECT_PIXEL_EQ( getWindowWidth() / 4, 3 * getWindowHeight() / 4, 0, 255, 0, 255); |
| 814 | |
| 815 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mMRTColorBuffer0, 0); |
| 816 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, mMRTColorBuffer1, 0); |
| 817 | } |
| 818 | |
| 819 | // Make sure that attempts to stretch in a blit call issue an error |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 820 | TEST_P(BlitFramebufferANGLETest, ErrorStretching) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 821 | { |
| 822 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 823 | |
| 824 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 825 | |
| 826 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 827 | |
| 828 | EXPECT_GL_NO_ERROR(); |
| 829 | |
| 830 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 831 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 832 | |
| 833 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, |
| 834 | getWindowWidth(), getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 835 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 836 | } |
| 837 | |
| 838 | // Make sure that attempts to flip in a blit call issue an error |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 839 | TEST_P(BlitFramebufferANGLETest, ErrorFlipping) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 840 | { |
| 841 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 842 | |
| 843 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 844 | |
| 845 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 846 | |
| 847 | EXPECT_GL_NO_ERROR(); |
| 848 | |
| 849 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 850 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 851 | |
| 852 | glBlitFramebufferANGLE(0, 0, getWindowWidth() / 2, getWindowHeight() / 2, getWindowWidth() / 2, getWindowHeight() / 2, |
| 853 | 0, 0, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 854 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 855 | } |
| 856 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 857 | TEST_P(BlitFramebufferANGLETest, Errors) |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 858 | { |
| 859 | glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO); |
| 860 | |
| 861 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 862 | |
| 863 | drawQuad(mCheckerProgram, "position", 0.5f); |
| 864 | |
| 865 | EXPECT_GL_NO_ERROR(); |
| 866 | |
| 867 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mOriginalFBO); |
| 868 | glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, mUserFBO); |
| 869 | |
| 870 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 871 | GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 872 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 873 | |
| 874 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 875 | GL_COLOR_BUFFER_BIT | 234, GL_NEAREST); |
| 876 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 877 | |
| 878 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, mDiffFormatFBO); |
| 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); |
Jamie Madill | c93d6f3 | 2014-04-15 16:12:41 -0400 | [diff] [blame] | 883 | |
| 884 | if (extensionEnabled("GL_ANGLE_framebuffer_multisample")) |
| 885 | { |
| 886 | glBindFramebuffer(GL_READ_FRAMEBUFFER, mBGRAMultisampledFBO); |
| 887 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mRGBAFBO); |
| 888 | EXPECT_GL_NO_ERROR(); |
| 889 | |
| 890 | glBlitFramebufferANGLE(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(), getWindowHeight(), |
| 891 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 892 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 893 | } |
| 894 | |
Geoff Lang | e8a1f78 | 2013-10-18 16:14:30 -0400 | [diff] [blame] | 895 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 896 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 897 | // TODO(geofflang): Fix the dependence on glBlitFramebufferANGLE without checks and assuming the |
| 898 | // default framebuffer is BGRA to enable the GL and GLES backends. (http://anglebug.com/1289) |
| 899 | |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 900 | class BlitFramebufferTest : public ANGLETest |
| 901 | { |
| 902 | protected: |
| 903 | BlitFramebufferTest() |
| 904 | { |
| 905 | setWindowWidth(256); |
| 906 | setWindowHeight(256); |
| 907 | setConfigRedBits(8); |
| 908 | setConfigGreenBits(8); |
| 909 | setConfigBlueBits(8); |
| 910 | setConfigAlphaBits(8); |
| 911 | setConfigDepthBits(24); |
| 912 | setConfigStencilBits(8); |
| 913 | } |
| 914 | }; |
| 915 | |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 916 | // Tests resolving a multisample depth buffer. |
| 917 | TEST_P(BlitFramebufferTest, MultisampleDepth) |
| 918 | { |
Jamie Madill | 1200c41 | 2016-08-16 14:09:14 -0400 | [diff] [blame] | 919 | // TODO(jmadill): Triage this driver bug. |
| 920 | if (IsAMD() && IsD3D11()) |
| 921 | { |
| 922 | std::cout << "Test skipped on AMD D3D11." << std::endl; |
| 923 | return; |
| 924 | } |
| 925 | |
Jamie Madill | 196ca36 | 2016-07-12 10:54:04 -0400 | [diff] [blame] | 926 | GLRenderbuffer renderbuf; |
| 927 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get()); |
| 928 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 256, 256); |
| 929 | |
| 930 | const std::string &vertex = |
| 931 | "#version 300 es\n" |
| 932 | "in vec2 position;\n" |
| 933 | "void main() {\n" |
| 934 | " gl_Position = vec4(position, 0.0, 0.5);\n" |
| 935 | "}"; |
| 936 | const std::string &fragment = |
| 937 | "#version 300 es\n" |
| 938 | "out mediump vec4 red;\n" |
| 939 | "void main() {\n" |
| 940 | " red = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 941 | " gl_FragDepth = 0.5;\n" |
| 942 | "}"; |
| 943 | |
| 944 | ANGLE_GL_PROGRAM(drawRed, vertex, fragment); |
| 945 | |
| 946 | GLFramebuffer framebuffer; |
| 947 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 948 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, |
| 949 | renderbuf.get()); |
| 950 | |
| 951 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 952 | |
| 953 | glClearDepthf(0.5f); |
| 954 | glClear(GL_DEPTH_BUFFER_BIT); |
| 955 | |
| 956 | GLRenderbuffer destRenderbuf; |
| 957 | glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get()); |
| 958 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 256, 256); |
| 959 | |
| 960 | GLFramebuffer resolved; |
| 961 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get()); |
| 962 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, |
| 963 | destRenderbuf.get()); |
| 964 | |
| 965 | glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get()); |
| 966 | glBlitFramebuffer(0, 0, 256, 256, 0, 0, 256, 256, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 967 | |
| 968 | glBindFramebuffer(GL_FRAMEBUFFER, resolved.get()); |
| 969 | |
| 970 | GLTexture colorbuf; |
| 971 | glBindTexture(GL_TEXTURE_2D, colorbuf.get()); |
| 972 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256); |
| 973 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuf.get(), 0); |
| 974 | |
| 975 | ASSERT_GL_NO_ERROR(); |
| 976 | |
| 977 | // Clear to green |
| 978 | glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 979 | glClear(GL_COLOR_BUFFER_BIT); |
| 980 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 981 | |
| 982 | // Draw with 0.5f test and the test should pass. |
| 983 | glEnable(GL_DEPTH_TEST); |
| 984 | glDepthFunc(GL_EQUAL); |
| 985 | drawQuad(drawRed.get(), "position", 0.5f); |
| 986 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 987 | |
| 988 | ASSERT_GL_NO_ERROR(); |
| 989 | } |
| 990 | |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 991 | // Test resolving a multisampled stencil buffer. |
| 992 | TEST_P(BlitFramebufferTest, MultisampleStencil) |
| 993 | { |
| 994 | GLRenderbuffer renderbuf; |
| 995 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get()); |
| 996 | glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_STENCIL_INDEX8, 256, 256); |
| 997 | |
| 998 | const std::string &vertex = |
| 999 | "#version 300 es\n" |
| 1000 | "in vec2 position;\n" |
| 1001 | "void main() {\n" |
| 1002 | " gl_Position = vec4(position, 0.0, 1.0);\n" |
| 1003 | "}"; |
| 1004 | const std::string &fragment = |
| 1005 | "#version 300 es\n" |
| 1006 | "out mediump vec4 red;\n" |
| 1007 | "void main() {\n" |
| 1008 | " red = vec4(1.0, 0.0, 0.0, 1.0);\n" |
| 1009 | "}"; |
| 1010 | |
| 1011 | ANGLE_GL_PROGRAM(drawRed, vertex, fragment); |
| 1012 | |
| 1013 | GLFramebuffer framebuffer; |
| 1014 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1015 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 1016 | renderbuf.get()); |
| 1017 | |
| 1018 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1019 | |
| 1020 | // fill the stencil buffer with 0x1 |
| 1021 | glStencilFunc(GL_ALWAYS, 0x1, 0xFF); |
| 1022 | glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
| 1023 | glEnable(GL_STENCIL_TEST); |
| 1024 | drawQuad(drawRed.get(), "position", 0.5f); |
| 1025 | |
| 1026 | GLTexture destColorbuf; |
| 1027 | glBindTexture(GL_TEXTURE_2D, destColorbuf.get()); |
| 1028 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 256, 256); |
| 1029 | |
| 1030 | GLRenderbuffer destRenderbuf; |
| 1031 | glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get()); |
| 1032 | glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 256, 256); |
| 1033 | |
| 1034 | GLFramebuffer resolved; |
| 1035 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get()); |
| 1036 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 1037 | destColorbuf.get(), 0); |
| 1038 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 1039 | destRenderbuf.get()); |
| 1040 | |
| 1041 | glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer.get()); |
| 1042 | glBlitFramebuffer(0, 0, 256, 256, 0, 0, 256, 256, GL_STENCIL_BUFFER_BIT, GL_NEAREST); |
| 1043 | |
| 1044 | glBindFramebuffer(GL_FRAMEBUFFER, resolved.get()); |
| 1045 | |
| 1046 | ASSERT_GL_NO_ERROR(); |
| 1047 | |
| 1048 | // Clear to green |
| 1049 | glClearColor(0.0f, 1.0f, 0.0f, 1.0f); |
| 1050 | glClear(GL_COLOR_BUFFER_BIT); |
| 1051 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1052 | |
| 1053 | // Draw red if the stencil is 0x1, which should be true after the blit/resolve. |
| 1054 | glStencilFunc(GL_EQUAL, 0x1, 0xFF); |
| 1055 | drawQuad(drawRed.get(), "position", 0.5f); |
| 1056 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 1057 | |
| 1058 | ASSERT_GL_NO_ERROR(); |
| 1059 | } |
| 1060 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1061 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Austin Kinross | 2a63b3f | 2016-02-08 12:29:08 -0800 | [diff] [blame] | 1062 | ANGLE_INSTANTIATE_TEST(BlitFramebufferANGLETest, |
| 1063 | ES2_D3D9(), |
| 1064 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE), |
| 1065 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE)); |
Jamie Madill | 78a9c73 | 2016-07-15 11:22:43 -0400 | [diff] [blame] | 1066 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame^] | 1067 | ANGLE_INSTANTIATE_TEST(BlitFramebufferTest, ES3_D3D11()); |