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