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