| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Framebuffer.cpp: Implements the gl::Framebuffer class. Implements GL framebuffer |
| 8 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105. |
| 9 | |
| Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/Framebuffer.h" |
| Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 11 | |
| Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 12 | #include "common/Optional.h" |
| Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 13 | #include "common/bitset_utils.h" |
| Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 14 | #include "common/utilities.h" |
| 15 | #include "libANGLE/Config.h" |
| Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/Context.h" |
| Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 17 | #include "libANGLE/Display.h" |
| Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 18 | #include "libANGLE/FramebufferAttachment.h" |
| Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 19 | #include "libANGLE/Renderbuffer.h" |
| 20 | #include "libANGLE/Surface.h" |
| 21 | #include "libANGLE/Texture.h" |
| 22 | #include "libANGLE/formatutils.h" |
| Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 23 | #include "libANGLE/renderer/ContextImpl.h" |
| Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 24 | #include "libANGLE/renderer/FramebufferImpl.h" |
| Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 25 | #include "libANGLE/renderer/GLImplFactory.h" |
| Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 26 | #include "libANGLE/renderer/RenderbufferImpl.h" |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 27 | #include "libANGLE/renderer/SurfaceImpl.h" |
| Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 28 | |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 29 | using namespace angle; |
| 30 | |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 31 | namespace gl |
| 32 | { |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 33 | |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 34 | namespace |
| 35 | { |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 36 | |
| Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 37 | void BindResourceChannel(OnAttachmentDirtyBinding *binding, FramebufferAttachmentObject *resource) |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 38 | { |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 39 | binding->bind(resource ? resource->getDirtyChannel() : nullptr); |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 40 | } |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 41 | |
| Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 42 | bool CheckMultiviewStateMatchesForCompleteness(const FramebufferAttachment *firstAttachment, |
| 43 | const FramebufferAttachment *secondAttachment) |
| 44 | { |
| 45 | ASSERT(firstAttachment && secondAttachment); |
| 46 | ASSERT(firstAttachment->isAttached() && secondAttachment->isAttached()); |
| 47 | |
| 48 | if (firstAttachment->getNumViews() != secondAttachment->getNumViews()) |
| 49 | { |
| 50 | return false; |
| 51 | } |
| 52 | if (firstAttachment->getBaseViewIndex() != secondAttachment->getBaseViewIndex()) |
| 53 | { |
| 54 | return false; |
| 55 | } |
| 56 | if (firstAttachment->getMultiviewLayout() != secondAttachment->getMultiviewLayout()) |
| 57 | { |
| 58 | return false; |
| 59 | } |
| 60 | if (firstAttachment->getMultiviewViewportOffsets() != |
| 61 | secondAttachment->getMultiviewViewportOffsets()) |
| 62 | { |
| 63 | return false; |
| 64 | } |
| 65 | return true; |
| 66 | } |
| 67 | |
| Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 68 | bool CheckAttachmentCompleteness(const Context *context, const FramebufferAttachment &attachment) |
| 69 | { |
| 70 | ASSERT(attachment.isAttached()); |
| 71 | |
| 72 | const Extents &size = attachment.getSize(); |
| 73 | if (size.width == 0 || size.height == 0) |
| 74 | { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | const InternalFormat &format = *attachment.getFormat().info; |
| 79 | if (!format.renderSupport(context->getClientVersion(), context->getExtensions())) |
| 80 | { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | if (attachment.type() == GL_TEXTURE) |
| 85 | { |
| 86 | if (attachment.layer() >= size.depth) |
| 87 | { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | // ES3 specifies that cube map texture attachments must be cube complete. |
| 92 | // This language is missing from the ES2 spec, but we enforce it here because some |
| 93 | // desktop OpenGL drivers also enforce this validation. |
| 94 | // TODO(jmadill): Check if OpenGL ES2 drivers enforce cube completeness. |
| 95 | const Texture *texture = attachment.getTexture(); |
| 96 | ASSERT(texture); |
| 97 | if (texture->getTarget() == GL_TEXTURE_CUBE_MAP && |
| 98 | !texture->getTextureState().isCubeComplete()) |
| 99 | { |
| 100 | return false; |
| 101 | } |
| Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 102 | |
| 103 | if (!texture->getImmutableFormat()) |
| 104 | { |
| 105 | GLuint attachmentMipLevel = static_cast<GLuint>(attachment.mipLevel()); |
| 106 | |
| 107 | // From the ES 3.0 spec, pg 213: |
| 108 | // If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is TEXTURE and the value of |
| 109 | // FRAMEBUFFER_ATTACHMENT_OBJECT_NAME does not name an immutable-format texture, |
| 110 | // then the value of FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL must be in the |
| 111 | // range[levelbase, q], where levelbase is the value of TEXTURE_BASE_LEVEL and q is |
| 112 | // the effective maximum texture level defined in the Mipmapping discussion of |
| 113 | // section 3.8.10.4. |
| 114 | if (attachmentMipLevel < texture->getBaseLevel() || |
| 115 | attachmentMipLevel > texture->getMipmapMaxLevel()) |
| 116 | { |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | // Form the ES 3.0 spec, pg 213/214: |
| 121 | // If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is TEXTURE and the value of |
| 122 | // FRAMEBUFFER_ATTACHMENT_OBJECT_NAME does not name an immutable-format texture and |
| 123 | // the value of FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL is not levelbase, then the |
| 124 | // texture must be mipmap complete, and if FRAMEBUFFER_ATTACHMENT_OBJECT_NAME names |
| 125 | // a cubemap texture, the texture must also be cube complete. |
| 126 | if (attachmentMipLevel != texture->getBaseLevel() && !texture->isMipmapComplete()) |
| 127 | { |
| 128 | return false; |
| 129 | } |
| 130 | } |
| Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | return true; |
| 134 | }; |
| 135 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 136 | bool CheckAttachmentSampleCompleteness(const Context *context, |
| 137 | const FramebufferAttachment &attachment, |
| 138 | bool colorAttachment, |
| 139 | Optional<int> *samples, |
| 140 | Optional<GLboolean> *fixedSampleLocations) |
| 141 | { |
| 142 | ASSERT(attachment.isAttached()); |
| 143 | |
| 144 | if (attachment.type() == GL_TEXTURE) |
| 145 | { |
| 146 | const Texture *texture = attachment.getTexture(); |
| 147 | ASSERT(texture); |
| 148 | |
| 149 | const ImageIndex &attachmentImageIndex = attachment.getTextureImageIndex(); |
| 150 | |
| 151 | // ES3.1 (section 9.4) requires that the value of TEXTURE_FIXED_SAMPLE_LOCATIONS should be |
| 152 | // the same for all attached textures. |
| 153 | GLboolean fixedSampleloc = texture->getFixedSampleLocations(attachmentImageIndex.type, |
| 154 | attachmentImageIndex.mipIndex); |
| 155 | if (fixedSampleLocations->valid() && fixedSampleloc != fixedSampleLocations->value()) |
| 156 | { |
| 157 | return false; |
| 158 | } |
| 159 | else |
| 160 | { |
| 161 | *fixedSampleLocations = fixedSampleloc; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if (samples->valid()) |
| 166 | { |
| 167 | if (attachment.getSamples() != samples->value()) |
| 168 | { |
| 169 | if (colorAttachment) |
| 170 | { |
| 171 | // APPLE_framebuffer_multisample, which EXT_draw_buffers refers to, requires that |
| 172 | // all color attachments have the same number of samples for the FBO to be complete. |
| 173 | return false; |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | // CHROMIUM_framebuffer_mixed_samples allows a framebuffer to be considered complete |
| 178 | // when its depth or stencil samples are a multiple of the number of color samples. |
| 179 | if (!context->getExtensions().framebufferMixedSamples) |
| 180 | { |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | if ((attachment.getSamples() % std::max(samples->value(), 1)) != 0) |
| 185 | { |
| 186 | return false; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | *samples = attachment.getSamples(); |
| 194 | } |
| 195 | |
| 196 | return true; |
| 197 | } |
| 198 | |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 199 | } // anonymous namespace |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 200 | |
| Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 201 | // This constructor is only used for default framebuffers. |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 202 | FramebufferState::FramebufferState() |
| Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 203 | : mLabel(), |
| 204 | mColorAttachments(1), |
| Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 205 | mDrawBufferStates(1, GL_BACK), |
| Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 206 | mReadBufferState(GL_BACK), |
| JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 207 | mDefaultWidth(0), |
| 208 | mDefaultHeight(0), |
| 209 | mDefaultSamples(0), |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 210 | mDefaultFixedSampleLocations(GL_FALSE), |
| 211 | mWebGLDepthStencilConsistent(true) |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 212 | { |
| Geoff Lang | d90d388 | 2017-03-21 10:49:54 -0400 | [diff] [blame] | 213 | ASSERT(mDrawBufferStates.size() > 0); |
| Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 214 | mEnabledDrawBuffers.set(0); |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 215 | } |
| 216 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 217 | FramebufferState::FramebufferState(const Caps &caps) |
| Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 218 | : mLabel(), |
| 219 | mColorAttachments(caps.maxColorAttachments), |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 220 | mDrawBufferStates(caps.maxDrawBuffers, GL_NONE), |
| JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 221 | mReadBufferState(GL_COLOR_ATTACHMENT0_EXT), |
| 222 | mDefaultWidth(0), |
| 223 | mDefaultHeight(0), |
| 224 | mDefaultSamples(0), |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 225 | mDefaultFixedSampleLocations(GL_FALSE), |
| 226 | mWebGLDepthStencilConsistent(true) |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 227 | { |
| Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 228 | ASSERT(mDrawBufferStates.size() > 0); |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 229 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
| 230 | } |
| 231 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 232 | FramebufferState::~FramebufferState() |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 233 | { |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 236 | const std::string &FramebufferState::getLabel() |
| Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 237 | { |
| 238 | return mLabel; |
| 239 | } |
| 240 | |
| Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 241 | const FramebufferAttachment *FramebufferState::getAttachment(GLenum attachment) const |
| 242 | { |
| 243 | if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15) |
| 244 | { |
| 245 | return getColorAttachment(attachment - GL_COLOR_ATTACHMENT0); |
| 246 | } |
| 247 | |
| 248 | switch (attachment) |
| 249 | { |
| 250 | case GL_COLOR: |
| 251 | case GL_BACK: |
| 252 | return getColorAttachment(0); |
| 253 | case GL_DEPTH: |
| 254 | case GL_DEPTH_ATTACHMENT: |
| 255 | return getDepthAttachment(); |
| 256 | case GL_STENCIL: |
| 257 | case GL_STENCIL_ATTACHMENT: |
| 258 | return getStencilAttachment(); |
| 259 | case GL_DEPTH_STENCIL: |
| 260 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 261 | return getDepthStencilAttachment(); |
| 262 | default: |
| 263 | UNREACHABLE(); |
| 264 | return nullptr; |
| 265 | } |
| 266 | } |
| 267 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 268 | const FramebufferAttachment *FramebufferState::getReadAttachment() const |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 269 | { |
| Antoine Labour | 2ec65dc | 2016-11-30 16:28:58 -0800 | [diff] [blame] | 270 | if (mReadBufferState == GL_NONE) |
| 271 | { |
| 272 | return nullptr; |
| 273 | } |
| Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 274 | ASSERT(mReadBufferState == GL_BACK || |
| 275 | (mReadBufferState >= GL_COLOR_ATTACHMENT0 && mReadBufferState <= GL_COLOR_ATTACHMENT15)); |
| 276 | size_t readIndex = (mReadBufferState == GL_BACK |
| 277 | ? 0 |
| 278 | : static_cast<size_t>(mReadBufferState - GL_COLOR_ATTACHMENT0)); |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 279 | ASSERT(readIndex < mColorAttachments.size()); |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 280 | return mColorAttachments[readIndex].isAttached() ? &mColorAttachments[readIndex] : nullptr; |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 281 | } |
| 282 | |
| Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 283 | const FramebufferAttachment *FramebufferState::getFirstNonNullAttachment() const |
| 284 | { |
| 285 | auto *colorAttachment = getFirstColorAttachment(); |
| 286 | if (colorAttachment) |
| 287 | { |
| 288 | return colorAttachment; |
| 289 | } |
| 290 | return getDepthOrStencilAttachment(); |
| 291 | } |
| 292 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 293 | const FramebufferAttachment *FramebufferState::getFirstColorAttachment() const |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 294 | { |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 295 | for (const FramebufferAttachment &colorAttachment : mColorAttachments) |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 296 | { |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 297 | if (colorAttachment.isAttached()) |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 298 | { |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 299 | return &colorAttachment; |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
| 303 | return nullptr; |
| 304 | } |
| 305 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 306 | const FramebufferAttachment *FramebufferState::getDepthOrStencilAttachment() const |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 307 | { |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 308 | if (mDepthAttachment.isAttached()) |
| 309 | { |
| 310 | return &mDepthAttachment; |
| 311 | } |
| 312 | if (mStencilAttachment.isAttached()) |
| 313 | { |
| 314 | return &mStencilAttachment; |
| 315 | } |
| 316 | return nullptr; |
| Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 319 | const FramebufferAttachment *FramebufferState::getStencilOrDepthStencilAttachment() const |
| 320 | { |
| 321 | if (mStencilAttachment.isAttached()) |
| 322 | { |
| 323 | return &mStencilAttachment; |
| 324 | } |
| 325 | return getDepthStencilAttachment(); |
| 326 | } |
| 327 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 328 | const FramebufferAttachment *FramebufferState::getColorAttachment(size_t colorAttachment) const |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 329 | { |
| 330 | ASSERT(colorAttachment < mColorAttachments.size()); |
| Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 331 | return mColorAttachments[colorAttachment].isAttached() ? &mColorAttachments[colorAttachment] |
| 332 | : nullptr; |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 333 | } |
| 334 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 335 | const FramebufferAttachment *FramebufferState::getDepthAttachment() const |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 336 | { |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 337 | return mDepthAttachment.isAttached() ? &mDepthAttachment : nullptr; |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 338 | } |
| 339 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 340 | const FramebufferAttachment *FramebufferState::getStencilAttachment() const |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 341 | { |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 342 | return mStencilAttachment.isAttached() ? &mStencilAttachment : nullptr; |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 343 | } |
| 344 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 345 | const FramebufferAttachment *FramebufferState::getDepthStencilAttachment() const |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 346 | { |
| 347 | // A valid depth-stencil attachment has the same resource bound to both the |
| 348 | // depth and stencil attachment points. |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 349 | if (mDepthAttachment.isAttached() && mStencilAttachment.isAttached() && |
| Jamie Madill | 44f2648 | 2016-11-18 12:49:15 -0500 | [diff] [blame] | 350 | mDepthAttachment == mStencilAttachment) |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 351 | { |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 352 | return &mDepthAttachment; |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | return nullptr; |
| 356 | } |
| 357 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 358 | bool FramebufferState::attachmentsHaveSameDimensions() const |
| Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 359 | { |
| 360 | Optional<Extents> attachmentSize; |
| 361 | |
| Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 362 | auto hasMismatchedSize = [&attachmentSize](const FramebufferAttachment &attachment) { |
| Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 363 | if (!attachment.isAttached()) |
| 364 | { |
| 365 | return false; |
| 366 | } |
| 367 | |
| 368 | if (!attachmentSize.valid()) |
| 369 | { |
| 370 | attachmentSize = attachment.getSize(); |
| 371 | return false; |
| 372 | } |
| 373 | |
| 374 | return (attachment.getSize() != attachmentSize.value()); |
| 375 | }; |
| 376 | |
| 377 | for (const auto &attachment : mColorAttachments) |
| 378 | { |
| 379 | if (hasMismatchedSize(attachment)) |
| 380 | { |
| 381 | return false; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | if (hasMismatchedSize(mDepthAttachment)) |
| 386 | { |
| 387 | return false; |
| 388 | } |
| 389 | |
| 390 | return !hasMismatchedSize(mStencilAttachment); |
| 391 | } |
| 392 | |
| Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 393 | const gl::FramebufferAttachment *FramebufferState::getDrawBuffer(size_t drawBufferIdx) const |
| 394 | { |
| 395 | ASSERT(drawBufferIdx < mDrawBufferStates.size()); |
| 396 | if (mDrawBufferStates[drawBufferIdx] != GL_NONE) |
| 397 | { |
| 398 | // ES3 spec: "If the GL is bound to a draw framebuffer object, the ith buffer listed in bufs |
| 399 | // must be COLOR_ATTACHMENTi or NONE" |
| 400 | ASSERT(mDrawBufferStates[drawBufferIdx] == GL_COLOR_ATTACHMENT0 + drawBufferIdx || |
| 401 | (drawBufferIdx == 0 && mDrawBufferStates[drawBufferIdx] == GL_BACK)); |
| 402 | return getAttachment(mDrawBufferStates[drawBufferIdx]); |
| 403 | } |
| 404 | else |
| 405 | { |
| 406 | return nullptr; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | size_t FramebufferState::getDrawBufferCount() const |
| 411 | { |
| 412 | return mDrawBufferStates.size(); |
| 413 | } |
| 414 | |
| Geoff Lang | b21e20d | 2016-07-19 15:35:41 -0400 | [diff] [blame] | 415 | bool FramebufferState::colorAttachmentsAreUniqueImages() const |
| 416 | { |
| 417 | for (size_t firstAttachmentIdx = 0; firstAttachmentIdx < mColorAttachments.size(); |
| 418 | firstAttachmentIdx++) |
| 419 | { |
| 420 | const gl::FramebufferAttachment &firstAttachment = mColorAttachments[firstAttachmentIdx]; |
| 421 | if (!firstAttachment.isAttached()) |
| 422 | { |
| 423 | continue; |
| 424 | } |
| 425 | |
| 426 | for (size_t secondAttachmentIdx = firstAttachmentIdx + 1; |
| 427 | secondAttachmentIdx < mColorAttachments.size(); secondAttachmentIdx++) |
| 428 | { |
| 429 | const gl::FramebufferAttachment &secondAttachment = |
| 430 | mColorAttachments[secondAttachmentIdx]; |
| 431 | if (!secondAttachment.isAttached()) |
| 432 | { |
| 433 | continue; |
| 434 | } |
| 435 | |
| 436 | if (firstAttachment == secondAttachment) |
| 437 | { |
| 438 | return false; |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | return true; |
| 444 | } |
| 445 | |
| Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 446 | bool FramebufferState::hasDepth() const |
| 447 | { |
| 448 | return (mDepthAttachment.isAttached() && mDepthAttachment.getDepthSize() > 0); |
| 449 | } |
| 450 | |
| 451 | bool FramebufferState::hasStencil() const |
| 452 | { |
| 453 | return (mStencilAttachment.isAttached() && mStencilAttachment.getStencilSize() > 0); |
| 454 | } |
| 455 | |
| Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 456 | GLsizei FramebufferState::getNumViews() const |
| 457 | { |
| 458 | const FramebufferAttachment *attachment = getFirstNonNullAttachment(); |
| 459 | if (attachment == nullptr) |
| 460 | { |
| 461 | return FramebufferAttachment::kDefaultNumViews; |
| 462 | } |
| 463 | return attachment->getNumViews(); |
| 464 | } |
| 465 | |
| 466 | const std::vector<Offset> *FramebufferState::getViewportOffsets() const |
| 467 | { |
| 468 | const FramebufferAttachment *attachment = getFirstNonNullAttachment(); |
| 469 | if (attachment == nullptr) |
| 470 | { |
| 471 | return nullptr; |
| 472 | } |
| 473 | return &attachment->getMultiviewViewportOffsets(); |
| 474 | } |
| 475 | |
| 476 | GLenum FramebufferState::getMultiviewLayout() const |
| 477 | { |
| 478 | const FramebufferAttachment *attachment = getFirstNonNullAttachment(); |
| 479 | if (attachment == nullptr) |
| 480 | { |
| 481 | return GL_NONE; |
| 482 | } |
| 483 | return attachment->getMultiviewLayout(); |
| 484 | } |
| 485 | |
| Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 486 | int FramebufferState::getBaseViewIndex() const |
| 487 | { |
| 488 | const FramebufferAttachment *attachment = getFirstNonNullAttachment(); |
| 489 | if (attachment == nullptr) |
| 490 | { |
| 491 | return GL_NONE; |
| 492 | } |
| 493 | return attachment->getBaseViewIndex(); |
| 494 | } |
| 495 | |
| Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 496 | Framebuffer::Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id) |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 497 | : mState(caps), |
| 498 | mImpl(factory->createFramebuffer(mState)), |
| 499 | mId(id), |
| 500 | mCachedStatus(), |
| 501 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 502 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 503 | { |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 504 | ASSERT(mId != 0); |
| 505 | ASSERT(mImpl != nullptr); |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 506 | ASSERT(mState.mColorAttachments.size() == static_cast<size_t>(caps.maxColorAttachments)); |
| 507 | |
| Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 508 | for (uint32_t colorIndex = 0; |
| 509 | colorIndex < static_cast<uint32_t>(mState.mColorAttachments.size()); ++colorIndex) |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 510 | { |
| Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 511 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 512 | } |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 513 | } |
| 514 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 515 | Framebuffer::Framebuffer(const egl::Display *display, egl::Surface *surface) |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 516 | : mState(), |
| Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 517 | mImpl(surface->getImplementation()->createDefaultFramebuffer(mState)), |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 518 | mId(0), |
| 519 | mCachedStatus(GL_FRAMEBUFFER_COMPLETE), |
| 520 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 521 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 522 | { |
| Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 523 | ASSERT(mImpl != nullptr); |
| Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 524 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0); |
| Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 525 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 526 | const Context *proxyContext = display->getProxyContext(); |
| 527 | |
| 528 | setAttachmentImpl(proxyContext, GL_FRAMEBUFFER_DEFAULT, GL_BACK, gl::ImageIndex::MakeInvalid(), |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 529 | surface, FramebufferAttachment::kDefaultNumViews, |
| 530 | FramebufferAttachment::kDefaultBaseViewIndex, |
| 531 | FramebufferAttachment::kDefaultMultiviewLayout, |
| 532 | FramebufferAttachment::kDefaultViewportOffsets); |
| Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 533 | |
| 534 | if (surface->getConfig()->depthSize > 0) |
| 535 | { |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 536 | setAttachmentImpl( |
| 537 | proxyContext, GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, gl::ImageIndex::MakeInvalid(), surface, |
| 538 | FramebufferAttachment::kDefaultNumViews, FramebufferAttachment::kDefaultBaseViewIndex, |
| 539 | FramebufferAttachment::kDefaultMultiviewLayout, |
| 540 | FramebufferAttachment::kDefaultViewportOffsets); |
| Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | if (surface->getConfig()->stencilSize > 0) |
| 544 | { |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 545 | setAttachmentImpl(proxyContext, GL_FRAMEBUFFER_DEFAULT, GL_STENCIL, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 546 | gl::ImageIndex::MakeInvalid(), surface, |
| 547 | FramebufferAttachment::kDefaultNumViews, |
| 548 | FramebufferAttachment::kDefaultBaseViewIndex, |
| 549 | FramebufferAttachment::kDefaultMultiviewLayout, |
| 550 | FramebufferAttachment::kDefaultViewportOffsets); |
| Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 551 | } |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 554 | Framebuffer::Framebuffer(rx::GLImplFactory *factory) |
| 555 | : mState(), |
| 556 | mImpl(factory->createFramebuffer(mState)), |
| 557 | mId(0), |
| 558 | mCachedStatus(GL_FRAMEBUFFER_UNDEFINED_OES), |
| 559 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 560 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
| 561 | { |
| Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 562 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0); |
| Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 563 | } |
| 564 | |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 565 | Framebuffer::~Framebuffer() |
| 566 | { |
| Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 567 | SafeDelete(mImpl); |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 570 | void Framebuffer::onDestroy(const Context *context) |
| Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 571 | { |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 572 | for (auto &attachment : mState.mColorAttachments) |
| 573 | { |
| 574 | attachment.detach(context); |
| 575 | } |
| 576 | mState.mDepthAttachment.detach(context); |
| 577 | mState.mStencilAttachment.detach(context); |
| 578 | mState.mWebGLDepthAttachment.detach(context); |
| 579 | mState.mWebGLStencilAttachment.detach(context); |
| 580 | mState.mWebGLDepthStencilAttachment.detach(context); |
| 581 | |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 582 | mImpl->destroy(context); |
| Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | void Framebuffer::destroyDefault(const egl::Display *display) |
| 586 | { |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 587 | mImpl->destroyDefault(display); |
| Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 588 | } |
| 589 | |
| Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 590 | void Framebuffer::setLabel(const std::string &label) |
| 591 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 592 | mState.mLabel = label; |
| Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | const std::string &Framebuffer::getLabel() const |
| 596 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 597 | return mState.mLabel; |
| Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 598 | } |
| 599 | |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 600 | bool Framebuffer::detachTexture(const Context *context, GLuint textureId) |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 601 | { |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 602 | return detachResourceById(context, GL_TEXTURE, textureId); |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 605 | bool Framebuffer::detachRenderbuffer(const Context *context, GLuint renderbufferId) |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 606 | { |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 607 | return detachResourceById(context, GL_RENDERBUFFER, renderbufferId); |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 608 | } |
| Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 609 | |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 610 | bool Framebuffer::detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId) |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 611 | { |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 612 | bool found = false; |
| 613 | |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 614 | for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex) |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 615 | { |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 616 | if (detachMatchingAttachment(context, &mState.mColorAttachments[colorIndex], resourceType, |
| 617 | resourceId, DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex)) |
| 618 | { |
| 619 | found = true; |
| 620 | } |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 623 | if (context->isWebGL1()) |
| 624 | { |
| 625 | const std::array<FramebufferAttachment *, 3> attachments = { |
| 626 | {&mState.mWebGLDepthStencilAttachment, &mState.mWebGLDepthAttachment, |
| 627 | &mState.mWebGLStencilAttachment}}; |
| 628 | for (FramebufferAttachment *attachment : attachments) |
| 629 | { |
| 630 | if (attachment->isAttached() && attachment->type() == resourceType && |
| 631 | attachment->id() == resourceId) |
| 632 | { |
| 633 | resetAttachment(context, attachment->getBinding()); |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 634 | found = true; |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | } |
| 638 | else |
| 639 | { |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 640 | if (detachMatchingAttachment(context, &mState.mDepthAttachment, resourceType, resourceId, |
| 641 | DIRTY_BIT_DEPTH_ATTACHMENT)) |
| 642 | { |
| 643 | found = true; |
| 644 | } |
| 645 | if (detachMatchingAttachment(context, &mState.mStencilAttachment, resourceType, resourceId, |
| 646 | DIRTY_BIT_STENCIL_ATTACHMENT)) |
| 647 | { |
| 648 | found = true; |
| 649 | } |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 650 | } |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 651 | |
| 652 | return found; |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 653 | } |
| 654 | |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 655 | bool Framebuffer::detachMatchingAttachment(const Context *context, |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 656 | FramebufferAttachment *attachment, |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 657 | GLenum matchType, |
| 658 | GLuint matchId, |
| 659 | size_t dirtyBit) |
| 660 | { |
| 661 | if (attachment->isAttached() && attachment->type() == matchType && attachment->id() == matchId) |
| 662 | { |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 663 | attachment->detach(context); |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 664 | mDirtyBits.set(dirtyBit); |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 665 | return true; |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 666 | } |
| Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame^] | 667 | |
| 668 | return false; |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 671 | const FramebufferAttachment *Framebuffer::getColorbuffer(size_t colorAttachment) const |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 672 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 673 | return mState.getColorAttachment(colorAttachment); |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 676 | const FramebufferAttachment *Framebuffer::getDepthbuffer() const |
| Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 677 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 678 | return mState.getDepthAttachment(); |
| Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 679 | } |
| 680 | |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 681 | const FramebufferAttachment *Framebuffer::getStencilbuffer() const |
| 682 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 683 | return mState.getStencilAttachment(); |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 684 | } |
| 685 | |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 686 | const FramebufferAttachment *Framebuffer::getDepthStencilBuffer() const |
| 687 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 688 | return mState.getDepthStencilAttachment(); |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | const FramebufferAttachment *Framebuffer::getDepthOrStencilbuffer() const |
| daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 692 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 693 | return mState.getDepthOrStencilAttachment(); |
| daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 696 | const FramebufferAttachment *Framebuffer::getStencilOrDepthStencilAttachment() const |
| 697 | { |
| 698 | return mState.getStencilOrDepthStencilAttachment(); |
| 699 | } |
| 700 | |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 701 | const FramebufferAttachment *Framebuffer::getReadColorbuffer() const |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 702 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 703 | return mState.getReadAttachment(); |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 706 | GLenum Framebuffer::getReadColorbufferType() const |
| 707 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 708 | const FramebufferAttachment *readAttachment = mState.getReadAttachment(); |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 709 | return (readAttachment != nullptr ? readAttachment->type() : GL_NONE); |
| shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 712 | const FramebufferAttachment *Framebuffer::getFirstColorbuffer() const |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 713 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 714 | return mState.getFirstColorAttachment(); |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| Jamie Madill | 6dd06ea | 2017-07-19 13:47:55 -0400 | [diff] [blame] | 717 | const FramebufferAttachment *Framebuffer::getFirstNonNullAttachment() const |
| 718 | { |
| 719 | return mState.getFirstNonNullAttachment(); |
| 720 | } |
| 721 | |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 722 | const FramebufferAttachment *Framebuffer::getAttachment(GLenum attachment) const |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 723 | { |
| Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 724 | return mState.getAttachment(attachment); |
| Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 725 | } |
| 726 | |
| Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 727 | size_t Framebuffer::getDrawbufferStateCount() const |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 728 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 729 | return mState.mDrawBufferStates.size(); |
| Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | GLenum Framebuffer::getDrawBufferState(size_t drawBuffer) const |
| 733 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 734 | ASSERT(drawBuffer < mState.mDrawBufferStates.size()); |
| 735 | return mState.mDrawBufferStates[drawBuffer]; |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 738 | const std::vector<GLenum> &Framebuffer::getDrawBufferStates() const |
| 739 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 740 | return mState.getDrawBufferStates(); |
| Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 741 | } |
| 742 | |
| Geoff Lang | 164d54e | 2014-12-01 10:55:33 -0500 | [diff] [blame] | 743 | void Framebuffer::setDrawBuffers(size_t count, const GLenum *buffers) |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 744 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 745 | auto &drawStates = mState.mDrawBufferStates; |
| Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 746 | |
| 747 | ASSERT(count <= drawStates.size()); |
| 748 | std::copy(buffers, buffers + count, drawStates.begin()); |
| 749 | std::fill(drawStates.begin() + count, drawStates.end(), GL_NONE); |
| Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 750 | mDirtyBits.set(DIRTY_BIT_DRAW_BUFFERS); |
| Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 751 | |
| 752 | mState.mEnabledDrawBuffers.reset(); |
| 753 | for (size_t index = 0; index < count; ++index) |
| 754 | { |
| 755 | if (drawStates[index] != GL_NONE && mState.mColorAttachments[index].isAttached()) |
| 756 | { |
| 757 | mState.mEnabledDrawBuffers.set(index); |
| 758 | } |
| 759 | } |
| Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 760 | } |
| 761 | |
| Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 762 | const FramebufferAttachment *Framebuffer::getDrawBuffer(size_t drawBuffer) const |
| 763 | { |
| Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 764 | return mState.getDrawBuffer(drawBuffer); |
| Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 765 | } |
| 766 | |
| Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 767 | GLenum Framebuffer::getDrawbufferWriteType(size_t drawBuffer) const |
| 768 | { |
| 769 | const FramebufferAttachment *attachment = mState.getDrawBuffer(drawBuffer); |
| 770 | if (attachment == nullptr) |
| 771 | { |
| 772 | return GL_NONE; |
| 773 | } |
| 774 | |
| 775 | GLenum componentType = attachment->getFormat().info->componentType; |
| 776 | switch (componentType) |
| 777 | { |
| 778 | case GL_INT: |
| 779 | case GL_UNSIGNED_INT: |
| 780 | return componentType; |
| 781 | |
| 782 | default: |
| 783 | return GL_FLOAT; |
| 784 | } |
| 785 | } |
| 786 | |
| Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 787 | bool Framebuffer::hasEnabledDrawBuffer() const |
| 788 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 789 | for (size_t drawbufferIdx = 0; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
| Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 790 | { |
| 791 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
| 792 | { |
| 793 | return true; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | return false; |
| 798 | } |
| 799 | |
| Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 800 | GLenum Framebuffer::getReadBufferState() const |
| 801 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 802 | return mState.mReadBufferState; |
| Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | void Framebuffer::setReadBuffer(GLenum buffer) |
| 806 | { |
| Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 807 | ASSERT(buffer == GL_BACK || buffer == GL_NONE || |
| 808 | (buffer >= GL_COLOR_ATTACHMENT0 && |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 809 | (buffer - GL_COLOR_ATTACHMENT0) < mState.mColorAttachments.size())); |
| 810 | mState.mReadBufferState = buffer; |
| Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 811 | mDirtyBits.set(DIRTY_BIT_READ_BUFFER); |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 814 | size_t Framebuffer::getNumColorBuffers() const |
| 815 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 816 | return mState.mColorAttachments.size(); |
| Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 817 | } |
| 818 | |
| Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 819 | bool Framebuffer::hasDepth() const |
| 820 | { |
| Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 821 | return mState.hasDepth(); |
| Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 822 | } |
| 823 | |
| shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 824 | bool Framebuffer::hasStencil() const |
| daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 825 | { |
| Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 826 | return mState.hasStencil(); |
| daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 829 | bool Framebuffer::usingExtendedDrawBuffers() const |
| 830 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 831 | for (size_t drawbufferIdx = 1; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
| shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 832 | { |
| Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 833 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
| shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 834 | { |
| 835 | return true; |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | return false; |
| 840 | } |
| 841 | |
| Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 842 | void Framebuffer::invalidateCompletenessCache() |
| 843 | { |
| 844 | if (mId != 0) |
| 845 | { |
| 846 | mCachedStatus.reset(); |
| 847 | } |
| 848 | } |
| 849 | |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 850 | GLenum Framebuffer::checkStatus(const Context *context) |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 851 | { |
| Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 852 | // The default framebuffer is always complete except when it is surfaceless in which |
| 853 | // case it is always unsupported. We return early because the default framebuffer may |
| 854 | // not be subject to the same rules as application FBOs. ie, it could have 0x0 size. |
| Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 855 | if (mId == 0) |
| 856 | { |
| Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 857 | ASSERT(mCachedStatus.valid()); |
| 858 | ASSERT(mCachedStatus.value() == GL_FRAMEBUFFER_COMPLETE || |
| 859 | mCachedStatus.value() == GL_FRAMEBUFFER_UNDEFINED_OES); |
| 860 | return mCachedStatus.value(); |
| Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 861 | } |
| 862 | |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 863 | if (hasAnyDirtyBit() || !mCachedStatus.valid()) |
| 864 | { |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 865 | mCachedStatus = checkStatusImpl(context); |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | return mCachedStatus.value(); |
| 869 | } |
| 870 | |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 871 | GLenum Framebuffer::checkStatusImpl(const Context *context) |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 872 | { |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 873 | const ContextState &state = context->getContextState(); |
| 874 | |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 875 | ASSERT(mId != 0); |
| 876 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 877 | bool hasAttachments = false; |
| 878 | Optional<unsigned int> colorbufferSize; |
| 879 | Optional<int> samples; |
| JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 880 | Optional<GLboolean> fixedSampleLocations; |
| 881 | bool hasRenderbuffer = false; |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 882 | |
| Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 883 | const FramebufferAttachment *firstAttachment = getFirstNonNullAttachment(); |
| 884 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 885 | for (const FramebufferAttachment &colorAttachment : mState.mColorAttachments) |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 886 | { |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 887 | if (colorAttachment.isAttached()) |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 888 | { |
| Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 889 | if (!CheckAttachmentCompleteness(context, colorAttachment)) |
| daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 890 | { |
| 891 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 892 | } |
| daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 893 | |
| Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 894 | const InternalFormat &format = *colorAttachment.getFormat().info; |
| Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 895 | if (format.depthBits > 0 || format.stencilBits > 0) |
| 896 | { |
| 897 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 898 | } |
| 899 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 900 | if (!CheckAttachmentSampleCompleteness(context, colorAttachment, true, &samples, |
| 901 | &fixedSampleLocations)) |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 902 | { |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 903 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 906 | // in GLES 2.0, all color attachments attachments must have the same number of bitplanes |
| 907 | // in GLES 3.0, there is no such restriction |
| 908 | if (state.getClientMajorVersion() < 3) |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 909 | { |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 910 | if (colorbufferSize.valid()) |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 911 | { |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 912 | if (format.pixelBytes != colorbufferSize.value()) |
| shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 913 | { |
| 914 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 915 | } |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 916 | } |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 917 | else |
| 918 | { |
| 919 | colorbufferSize = format.pixelBytes; |
| 920 | } |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 921 | } |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 922 | |
| Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 923 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &colorAttachment)) |
| 924 | { |
| 925 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_ANGLE; |
| 926 | } |
| 927 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 928 | hasRenderbuffer = hasRenderbuffer || (colorAttachment.type() == GL_RENDERBUFFER); |
| 929 | hasAttachments = true; |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 930 | } |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 933 | const FramebufferAttachment &depthAttachment = mState.mDepthAttachment; |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 934 | if (depthAttachment.isAttached()) |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 935 | { |
| Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 936 | if (!CheckAttachmentCompleteness(context, depthAttachment)) |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 937 | { |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 938 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 941 | const InternalFormat &format = *depthAttachment.getFormat().info; |
| Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 942 | if (format.depthBits == 0) |
| 943 | { |
| 944 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 947 | if (!CheckAttachmentSampleCompleteness(context, depthAttachment, false, &samples, |
| 948 | &fixedSampleLocations)) |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 949 | { |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 950 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 951 | } |
| Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 952 | |
| Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 953 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &depthAttachment)) |
| 954 | { |
| 955 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_ANGLE; |
| 956 | } |
| 957 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 958 | hasRenderbuffer = hasRenderbuffer || (depthAttachment.type() == GL_RENDERBUFFER); |
| 959 | hasAttachments = true; |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 962 | const FramebufferAttachment &stencilAttachment = mState.mStencilAttachment; |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 963 | if (stencilAttachment.isAttached()) |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 964 | { |
| Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 965 | if (!CheckAttachmentCompleteness(context, stencilAttachment)) |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 966 | { |
| 967 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 968 | } |
| 969 | |
| Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 970 | const InternalFormat &format = *stencilAttachment.getFormat().info; |
| Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 971 | if (format.stencilBits == 0) |
| 972 | { |
| 973 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 976 | if (!CheckAttachmentSampleCompleteness(context, stencilAttachment, false, &samples, |
| 977 | &fixedSampleLocations)) |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 978 | { |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 979 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 980 | } |
| Corentin Wallez | 086d59a | 2016-04-29 09:06:49 -0400 | [diff] [blame] | 981 | |
| Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 982 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &stencilAttachment)) |
| 983 | { |
| 984 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_ANGLE; |
| 985 | } |
| 986 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 987 | hasRenderbuffer = hasRenderbuffer || (stencilAttachment.type() == GL_RENDERBUFFER); |
| 988 | hasAttachments = true; |
| 989 | } |
| 990 | |
| 991 | // Starting from ES 3.0 stencil and depth, if present, should be the same image |
| 992 | if (state.getClientMajorVersion() >= 3 && depthAttachment.isAttached() && |
| 993 | stencilAttachment.isAttached() && stencilAttachment != depthAttachment) |
| 994 | { |
| 995 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 998 | // Special additional validation for WebGL 1 DEPTH/STENCIL/DEPTH_STENCIL. |
| 999 | if (state.isWebGL1()) |
| 1000 | { |
| 1001 | if (!mState.mWebGLDepthStencilConsistent) |
| 1002 | { |
| 1003 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 1004 | } |
| 1005 | |
| 1006 | if (mState.mWebGLDepthStencilAttachment.isAttached()) |
| 1007 | { |
| 1008 | if (mState.mWebGLDepthStencilAttachment.getDepthSize() == 0 || |
| 1009 | mState.mWebGLDepthStencilAttachment.getStencilSize() == 0) |
| 1010 | { |
| 1011 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1012 | } |
| Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1013 | |
| 1014 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, |
| 1015 | &mState.mWebGLDepthStencilAttachment)) |
| 1016 | { |
| 1017 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_ANGLE; |
| 1018 | } |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1019 | } |
| 1020 | else if (mState.mStencilAttachment.isAttached() && |
| 1021 | mState.mStencilAttachment.getDepthSize() > 0) |
| 1022 | { |
| 1023 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1024 | } |
| 1025 | else if (mState.mDepthAttachment.isAttached() && |
| 1026 | mState.mDepthAttachment.getStencilSize() > 0) |
| 1027 | { |
| 1028 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1032 | // ES3.1(section 9.4) requires that if no image is attached to the framebuffer, and either the |
| 1033 | // value of the framebuffer's FRAMEBUFFER_DEFAULT_WIDTH or FRAMEBUFFER_DEFAULT_HEIGHT parameters |
| 1034 | // is zero, the framebuffer is considered incomplete. |
| JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1035 | GLint defaultWidth = mState.getDefaultWidth(); |
| 1036 | GLint defaultHeight = mState.getDefaultHeight(); |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1037 | if (!hasAttachments && (defaultWidth == 0 || defaultHeight == 0)) |
| daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1038 | { |
| 1039 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
| daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 1042 | // In ES 2.0 and WebGL, all color attachments must have the same width and height. |
| Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 1043 | // In ES 3.0, there is no such restriction. |
| Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 1044 | if ((state.getClientMajorVersion() < 3 || state.getExtensions().webglCompatibility) && |
| 1045 | !mState.attachmentsHaveSameDimensions()) |
| Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 1046 | { |
| 1047 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 1048 | } |
| 1049 | |
| Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1050 | // ES3.1(section 9.4) requires that if the attached images are a mix of renderbuffers and |
| 1051 | // textures, the value of TEXTURE_FIXED_SAMPLE_LOCATIONS must be TRUE for all attached textures. |
| JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1052 | if (fixedSampleLocations.valid() && hasRenderbuffer && !fixedSampleLocations.value()) |
| 1053 | { |
| 1054 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| 1055 | } |
| 1056 | |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1057 | syncState(context); |
| Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 1058 | if (!mImpl->checkStatus()) |
| 1059 | { |
| 1060 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 1061 | } |
| 1062 | |
| 1063 | return GL_FRAMEBUFFER_COMPLETE; |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1064 | } |
| daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1065 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1066 | Error Framebuffer::discard(const Context *context, size_t count, const GLenum *attachments) |
| Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1067 | { |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1068 | return mImpl->discard(context, count, attachments); |
| Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1071 | Error Framebuffer::invalidate(const Context *context, size_t count, const GLenum *attachments) |
| Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 1072 | { |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1073 | return mImpl->invalidate(context, count, attachments); |
| Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 1074 | } |
| 1075 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1076 | Error Framebuffer::invalidateSub(const Context *context, |
| 1077 | size_t count, |
| 1078 | const GLenum *attachments, |
| 1079 | const gl::Rectangle &area) |
| Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 1080 | { |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1081 | return mImpl->invalidateSub(context, count, attachments, area); |
| Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 1082 | } |
| 1083 | |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1084 | Error Framebuffer::clear(const gl::Context *context, GLbitfield mask) |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1085 | { |
| Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1086 | if (context->getGLState().isRasterizerDiscardEnabled()) |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1087 | { |
| Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1088 | return NoError(); |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1089 | } |
| 1090 | |
| Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1091 | return mImpl->clear(context, mask); |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1092 | } |
| 1093 | |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1094 | Error Framebuffer::clearBufferfv(const gl::Context *context, |
| Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1095 | GLenum buffer, |
| 1096 | GLint drawbuffer, |
| 1097 | const GLfloat *values) |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1098 | { |
| Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1099 | if (context->getGLState().isRasterizerDiscardEnabled()) |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1100 | { |
| Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1101 | return NoError(); |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1102 | } |
| 1103 | |
| Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1104 | return mImpl->clearBufferfv(context, buffer, drawbuffer, values); |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1105 | } |
| 1106 | |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1107 | Error Framebuffer::clearBufferuiv(const gl::Context *context, |
| Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1108 | GLenum buffer, |
| 1109 | GLint drawbuffer, |
| 1110 | const GLuint *values) |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1111 | { |
| Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1112 | if (context->getGLState().isRasterizerDiscardEnabled()) |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1113 | { |
| Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1114 | return NoError(); |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1115 | } |
| 1116 | |
| Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1117 | return mImpl->clearBufferuiv(context, buffer, drawbuffer, values); |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1118 | } |
| 1119 | |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1120 | Error Framebuffer::clearBufferiv(const gl::Context *context, |
| Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1121 | GLenum buffer, |
| 1122 | GLint drawbuffer, |
| 1123 | const GLint *values) |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1124 | { |
| Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1125 | if (context->getGLState().isRasterizerDiscardEnabled()) |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1126 | { |
| Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1127 | return NoError(); |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1128 | } |
| 1129 | |
| Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1130 | return mImpl->clearBufferiv(context, buffer, drawbuffer, values); |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1131 | } |
| 1132 | |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1133 | Error Framebuffer::clearBufferfi(const gl::Context *context, |
| Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1134 | GLenum buffer, |
| 1135 | GLint drawbuffer, |
| 1136 | GLfloat depth, |
| 1137 | GLint stencil) |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1138 | { |
| Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1139 | if (context->getGLState().isRasterizerDiscardEnabled()) |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1140 | { |
| Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1141 | return NoError(); |
| Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1142 | } |
| 1143 | |
| Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1144 | return mImpl->clearBufferfi(context, buffer, drawbuffer, depth, stencil); |
| Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1145 | } |
| 1146 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1147 | GLenum Framebuffer::getImplementationColorReadFormat(const Context *context) const |
| Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1148 | { |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1149 | return mImpl->getImplementationColorReadFormat(context); |
| Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1150 | } |
| 1151 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1152 | GLenum Framebuffer::getImplementationColorReadType(const Context *context) const |
| Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1153 | { |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1154 | return mImpl->getImplementationColorReadType(context); |
| Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1155 | } |
| 1156 | |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1157 | Error Framebuffer::readPixels(const gl::Context *context, |
| Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1158 | const Rectangle &area, |
| Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1159 | GLenum format, |
| 1160 | GLenum type, |
| Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1161 | void *pixels) const |
| Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1162 | { |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1163 | ANGLE_TRY(mImpl->readPixels(context, area, format, type, pixels)); |
| Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1164 | |
| Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1165 | Buffer *unpackBuffer = context->getGLState().getUnpackState().pixelBuffer.get(); |
| Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1166 | if (unpackBuffer) |
| 1167 | { |
| 1168 | unpackBuffer->onPixelUnpack(); |
| 1169 | } |
| 1170 | |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1171 | return NoError(); |
| Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1172 | } |
| 1173 | |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1174 | Error Framebuffer::blit(const gl::Context *context, |
| Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1175 | const Rectangle &sourceArea, |
| 1176 | const Rectangle &destArea, |
| Geoff Lang | 242468f | 2015-09-24 14:15:41 -0400 | [diff] [blame] | 1177 | GLbitfield mask, |
| Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1178 | GLenum filter) |
| Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 1179 | { |
| He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 1180 | GLbitfield blitMask = mask; |
| 1181 | |
| 1182 | // Note that blitting is called against draw framebuffer. |
| 1183 | // See the code in gl::Context::blitFramebuffer. |
| 1184 | if ((mask & GL_COLOR_BUFFER_BIT) && !hasEnabledDrawBuffer()) |
| 1185 | { |
| 1186 | blitMask &= ~GL_COLOR_BUFFER_BIT; |
| 1187 | } |
| 1188 | |
| 1189 | if ((mask & GL_STENCIL_BUFFER_BIT) && mState.getStencilAttachment() == nullptr) |
| 1190 | { |
| 1191 | blitMask &= ~GL_STENCIL_BUFFER_BIT; |
| 1192 | } |
| 1193 | |
| 1194 | if ((mask & GL_DEPTH_BUFFER_BIT) && mState.getDepthAttachment() == nullptr) |
| 1195 | { |
| 1196 | blitMask &= ~GL_DEPTH_BUFFER_BIT; |
| 1197 | } |
| 1198 | |
| 1199 | if (!blitMask) |
| 1200 | { |
| 1201 | return NoError(); |
| 1202 | } |
| 1203 | |
| 1204 | return mImpl->blit(context, sourceArea, destArea, blitMask, filter); |
| Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 1205 | } |
| 1206 | |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1207 | int Framebuffer::getSamples(const Context *context) |
| daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1208 | { |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1209 | if (complete(context)) |
| daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1210 | { |
| Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 1211 | return getCachedSamples(context); |
| daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1212 | } |
| shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1213 | |
| 1214 | return 0; |
| daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 1217 | int Framebuffer::getCachedSamples(const Context *context) |
| 1218 | { |
| 1219 | // For a complete framebuffer, all attachments must have the same sample count. |
| 1220 | // In this case return the first nonzero sample size. |
| 1221 | const auto *firstNonNullAttachment = mState.getFirstNonNullAttachment(); |
| 1222 | if (firstNonNullAttachment) |
| 1223 | { |
| 1224 | ASSERT(firstNonNullAttachment->isAttached()); |
| 1225 | return firstNonNullAttachment->getSamples(); |
| 1226 | } |
| 1227 | |
| 1228 | // No attachments found. |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1232 | Error Framebuffer::getSamplePosition(size_t index, GLfloat *xy) const |
| 1233 | { |
| 1234 | ANGLE_TRY(mImpl->getSamplePosition(index, xy)); |
| Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1235 | return NoError(); |
| Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1236 | } |
| 1237 | |
| Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 1238 | bool Framebuffer::hasValidDepthStencil() const |
| 1239 | { |
| Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1240 | return mState.getDepthStencilAttachment() != nullptr; |
| Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 1241 | } |
| 1242 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1243 | void Framebuffer::setAttachment(const Context *context, |
| 1244 | GLenum type, |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1245 | GLenum binding, |
| 1246 | const ImageIndex &textureIndex, |
| 1247 | FramebufferAttachmentObject *resource) |
| Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 1248 | { |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1249 | setAttachment(context, type, binding, textureIndex, resource, |
| 1250 | FramebufferAttachment::kDefaultNumViews, |
| 1251 | FramebufferAttachment::kDefaultBaseViewIndex, |
| 1252 | FramebufferAttachment::kDefaultMultiviewLayout, |
| 1253 | FramebufferAttachment::kDefaultViewportOffsets); |
| 1254 | } |
| 1255 | |
| 1256 | void Framebuffer::setAttachment(const Context *context, |
| 1257 | GLenum type, |
| 1258 | GLenum binding, |
| 1259 | const ImageIndex &textureIndex, |
| 1260 | FramebufferAttachmentObject *resource, |
| 1261 | GLsizei numViews, |
| 1262 | GLuint baseViewIndex, |
| 1263 | GLenum multiviewLayout, |
| 1264 | const GLint *viewportOffsets) |
| 1265 | { |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1266 | // Context may be null in unit tests. |
| 1267 | if (!context || !context->isWebGL1()) |
| 1268 | { |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1269 | setAttachmentImpl(context, type, binding, textureIndex, resource, numViews, baseViewIndex, |
| 1270 | multiviewLayout, viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1271 | return; |
| 1272 | } |
| 1273 | |
| 1274 | switch (binding) |
| 1275 | { |
| 1276 | case GL_DEPTH_STENCIL: |
| 1277 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1278 | mState.mWebGLDepthStencilAttachment.attach(context, type, binding, textureIndex, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1279 | resource, numViews, baseViewIndex, |
| 1280 | multiviewLayout, viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1281 | break; |
| 1282 | case GL_DEPTH: |
| 1283 | case GL_DEPTH_ATTACHMENT: |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1284 | mState.mWebGLDepthAttachment.attach(context, type, binding, textureIndex, resource, |
| 1285 | numViews, baseViewIndex, multiviewLayout, |
| 1286 | viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1287 | break; |
| 1288 | case GL_STENCIL: |
| 1289 | case GL_STENCIL_ATTACHMENT: |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1290 | mState.mWebGLStencilAttachment.attach(context, type, binding, textureIndex, resource, |
| 1291 | numViews, baseViewIndex, multiviewLayout, |
| 1292 | viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1293 | break; |
| 1294 | default: |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1295 | setAttachmentImpl(context, type, binding, textureIndex, resource, numViews, |
| 1296 | baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1297 | return; |
| 1298 | } |
| 1299 | |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1300 | commitWebGL1DepthStencilIfConsistent(context, numViews, baseViewIndex, multiviewLayout, |
| 1301 | viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1302 | } |
| 1303 | |
| Martin Radev | 82ef774 | 2017-08-08 17:44:58 +0300 | [diff] [blame] | 1304 | void Framebuffer::setAttachmentMultiviewLayered(const Context *context, |
| 1305 | GLenum type, |
| 1306 | GLenum binding, |
| 1307 | const ImageIndex &textureIndex, |
| 1308 | FramebufferAttachmentObject *resource, |
| 1309 | GLsizei numViews, |
| 1310 | GLint baseViewIndex) |
| 1311 | { |
| 1312 | setAttachment(context, type, binding, textureIndex, resource, numViews, baseViewIndex, |
| 1313 | GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE, |
| 1314 | FramebufferAttachment::kDefaultViewportOffsets); |
| 1315 | } |
| 1316 | |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1317 | void Framebuffer::setAttachmentMultiviewSideBySide(const Context *context, |
| 1318 | GLenum type, |
| 1319 | GLenum binding, |
| 1320 | const ImageIndex &textureIndex, |
| 1321 | FramebufferAttachmentObject *resource, |
| 1322 | GLsizei numViews, |
| 1323 | const GLint *viewportOffsets) |
| 1324 | { |
| 1325 | setAttachment(context, type, binding, textureIndex, resource, numViews, |
| 1326 | FramebufferAttachment::kDefaultBaseViewIndex, |
| 1327 | GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE, viewportOffsets); |
| 1328 | } |
| 1329 | |
| 1330 | void Framebuffer::commitWebGL1DepthStencilIfConsistent(const Context *context, |
| 1331 | GLsizei numViews, |
| 1332 | GLuint baseViewIndex, |
| 1333 | GLenum multiviewLayout, |
| 1334 | const GLint *viewportOffsets) |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1335 | { |
| 1336 | int count = 0; |
| 1337 | |
| 1338 | std::array<FramebufferAttachment *, 3> attachments = {{&mState.mWebGLDepthStencilAttachment, |
| 1339 | &mState.mWebGLDepthAttachment, |
| 1340 | &mState.mWebGLStencilAttachment}}; |
| 1341 | for (FramebufferAttachment *attachment : attachments) |
| 1342 | { |
| 1343 | if (attachment->isAttached()) |
| 1344 | { |
| 1345 | count++; |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | mState.mWebGLDepthStencilConsistent = (count <= 1); |
| 1350 | if (!mState.mWebGLDepthStencilConsistent) |
| 1351 | { |
| 1352 | // Inconsistent. |
| 1353 | return; |
| 1354 | } |
| 1355 | |
| Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1356 | auto getImageIndexIfTextureAttachment = [](const FramebufferAttachment &attachment) { |
| 1357 | if (attachment.type() == GL_TEXTURE) |
| 1358 | { |
| 1359 | return attachment.getTextureImageIndex(); |
| 1360 | } |
| 1361 | else |
| 1362 | { |
| 1363 | return ImageIndex::MakeInvalid(); |
| 1364 | } |
| 1365 | }; |
| 1366 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1367 | if (mState.mWebGLDepthAttachment.isAttached()) |
| 1368 | { |
| 1369 | const auto &depth = mState.mWebGLDepthAttachment; |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1370 | setAttachmentImpl(context, depth.type(), GL_DEPTH_ATTACHMENT, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1371 | getImageIndexIfTextureAttachment(depth), depth.getResource(), numViews, |
| 1372 | baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1373 | setAttachmentImpl(context, GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1374 | nullptr, numViews, baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1375 | } |
| 1376 | else if (mState.mWebGLStencilAttachment.isAttached()) |
| 1377 | { |
| 1378 | const auto &stencil = mState.mWebGLStencilAttachment; |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1379 | setAttachmentImpl(context, GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr, |
| 1380 | numViews, baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1381 | setAttachmentImpl(context, stencil.type(), GL_STENCIL_ATTACHMENT, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1382 | getImageIndexIfTextureAttachment(stencil), stencil.getResource(), |
| 1383 | numViews, baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1384 | } |
| 1385 | else if (mState.mWebGLDepthStencilAttachment.isAttached()) |
| 1386 | { |
| 1387 | const auto &depthStencil = mState.mWebGLDepthStencilAttachment; |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1388 | setAttachmentImpl(context, depthStencil.type(), GL_DEPTH_ATTACHMENT, |
| Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1389 | getImageIndexIfTextureAttachment(depthStencil), |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1390 | depthStencil.getResource(), numViews, baseViewIndex, multiviewLayout, |
| 1391 | viewportOffsets); |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1392 | setAttachmentImpl(context, depthStencil.type(), GL_STENCIL_ATTACHMENT, |
| Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1393 | getImageIndexIfTextureAttachment(depthStencil), |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1394 | depthStencil.getResource(), numViews, baseViewIndex, multiviewLayout, |
| 1395 | viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1396 | } |
| 1397 | else |
| 1398 | { |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1399 | setAttachmentImpl(context, GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr, |
| 1400 | numViews, baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1401 | setAttachmentImpl(context, GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1402 | nullptr, numViews, baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1406 | void Framebuffer::setAttachmentImpl(const Context *context, |
| 1407 | GLenum type, |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1408 | GLenum binding, |
| 1409 | const ImageIndex &textureIndex, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1410 | FramebufferAttachmentObject *resource, |
| 1411 | GLsizei numViews, |
| 1412 | GLuint baseViewIndex, |
| 1413 | GLenum multiviewLayout, |
| 1414 | const GLint *viewportOffsets) |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1415 | { |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1416 | switch (binding) |
| 1417 | { |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1418 | case GL_DEPTH_STENCIL: |
| 1419 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1420 | { |
| 1421 | // ensure this is a legitimate depth+stencil format |
| 1422 | FramebufferAttachmentObject *attachmentObj = resource; |
| 1423 | if (resource) |
| 1424 | { |
| Jamie Madill | 4fd95d5 | 2017-04-05 11:22:18 -0400 | [diff] [blame] | 1425 | const Format &format = resource->getAttachmentFormat(binding, textureIndex); |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1426 | if (format.info->depthBits == 0 || format.info->stencilBits == 0) |
| 1427 | { |
| 1428 | // Attaching nullptr detaches the current attachment. |
| 1429 | attachmentObj = nullptr; |
| 1430 | } |
| 1431 | } |
| 1432 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1433 | updateAttachment(context, &mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT, |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1434 | &mDirtyDepthAttachmentBinding, type, binding, textureIndex, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1435 | attachmentObj, numViews, baseViewIndex, multiviewLayout, |
| 1436 | viewportOffsets); |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1437 | updateAttachment(context, &mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT, |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1438 | &mDirtyStencilAttachmentBinding, type, binding, textureIndex, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1439 | attachmentObj, numViews, baseViewIndex, multiviewLayout, |
| 1440 | viewportOffsets); |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1441 | return; |
| 1442 | } |
| 1443 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1444 | case GL_DEPTH: |
| 1445 | case GL_DEPTH_ATTACHMENT: |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1446 | updateAttachment(context, &mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1447 | &mDirtyDepthAttachmentBinding, type, binding, textureIndex, resource, |
| 1448 | numViews, baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1449 | break; |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1450 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1451 | case GL_STENCIL: |
| 1452 | case GL_STENCIL_ATTACHMENT: |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1453 | updateAttachment(context, &mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1454 | &mDirtyStencilAttachmentBinding, type, binding, textureIndex, resource, |
| 1455 | numViews, baseViewIndex, multiviewLayout, viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1456 | break; |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1457 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1458 | case GL_BACK: |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1459 | mState.mColorAttachments[0].attach(context, type, binding, textureIndex, resource, |
| 1460 | numViews, baseViewIndex, multiviewLayout, |
| 1461 | viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1462 | mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 1463 | // No need for a resource binding for the default FBO, it's always complete. |
| 1464 | break; |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1465 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1466 | default: |
| 1467 | { |
| 1468 | size_t colorIndex = binding - GL_COLOR_ATTACHMENT0; |
| 1469 | ASSERT(colorIndex < mState.mColorAttachments.size()); |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1470 | size_t dirtyBit = DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex; |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1471 | updateAttachment(context, &mState.mColorAttachments[colorIndex], dirtyBit, |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1472 | &mDirtyColorAttachmentBindings[colorIndex], type, binding, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1473 | textureIndex, resource, numViews, baseViewIndex, multiviewLayout, |
| 1474 | viewportOffsets); |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1475 | |
| Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 1476 | // TODO(jmadill): ASSERT instead of checking the attachment exists in |
| 1477 | // formsRenderingFeedbackLoopWith |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1478 | bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE); |
| 1479 | mState.mEnabledDrawBuffers.set(colorIndex, enabled); |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1480 | } |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1481 | break; |
| Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
| Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1485 | void Framebuffer::updateAttachment(const Context *context, |
| 1486 | FramebufferAttachment *attachment, |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1487 | size_t dirtyBit, |
| 1488 | OnAttachmentDirtyBinding *onDirtyBinding, |
| 1489 | GLenum type, |
| 1490 | GLenum binding, |
| 1491 | const ImageIndex &textureIndex, |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1492 | FramebufferAttachmentObject *resource, |
| 1493 | GLsizei numViews, |
| 1494 | GLuint baseViewIndex, |
| 1495 | GLenum multiviewLayout, |
| 1496 | const GLint *viewportOffsets) |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1497 | { |
| Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1498 | attachment->attach(context, type, binding, textureIndex, resource, numViews, baseViewIndex, |
| 1499 | multiviewLayout, viewportOffsets); |
| Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1500 | mDirtyBits.set(dirtyBit); |
| 1501 | BindResourceChannel(onDirtyBinding, resource); |
| 1502 | } |
| 1503 | |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1504 | void Framebuffer::resetAttachment(const Context *context, GLenum binding) |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1505 | { |
| Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1506 | setAttachment(context, GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr); |
| Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1507 | } |
| 1508 | |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1509 | void Framebuffer::syncState(const Context *context) |
| Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1510 | { |
| 1511 | if (mDirtyBits.any()) |
| 1512 | { |
| Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1513 | mImpl->syncState(context, mDirtyBits); |
| Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1514 | mDirtyBits.reset(); |
| Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1515 | if (mId != 0) |
| 1516 | { |
| 1517 | mCachedStatus.reset(); |
| 1518 | } |
| Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1519 | } |
| daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1520 | } |
| Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1521 | |
| Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 1522 | void Framebuffer::signal(uint32_t token) |
| Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1523 | { |
| Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1524 | // TOOD(jmadill): Make this only update individual attachments to do less work. |
| 1525 | mCachedStatus.reset(); |
| Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1526 | } |
| 1527 | |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1528 | bool Framebuffer::complete(const Context *context) |
| Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1529 | { |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1530 | return (checkStatus(context) == GL_FRAMEBUFFER_COMPLETE); |
| 1531 | } |
| 1532 | |
| 1533 | bool Framebuffer::cachedComplete() const |
| 1534 | { |
| 1535 | return (mCachedStatus.valid() && mCachedStatus == GL_FRAMEBUFFER_COMPLETE); |
| Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1536 | } |
| 1537 | |
| Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1538 | bool Framebuffer::formsRenderingFeedbackLoopWith(const State &state) const |
| 1539 | { |
| 1540 | const Program *program = state.getProgram(); |
| 1541 | |
| 1542 | // TODO(jmadill): Default framebuffer feedback loops. |
| 1543 | if (mId == 0) |
| 1544 | { |
| 1545 | return false; |
| 1546 | } |
| 1547 | |
| 1548 | // The bitset will skip inactive draw buffers. |
| Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1549 | for (size_t drawIndex : mState.mEnabledDrawBuffers) |
| Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1550 | { |
| Jamie Madill | 5aca193 | 2017-07-21 12:22:01 -0400 | [diff] [blame] | 1551 | const FramebufferAttachment &attachment = mState.mColorAttachments[drawIndex]; |
| 1552 | ASSERT(attachment.isAttached()); |
| 1553 | if (attachment.type() == GL_TEXTURE) |
| Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1554 | { |
| 1555 | // Validate the feedback loop. |
| Jamie Madill | 5aca193 | 2017-07-21 12:22:01 -0400 | [diff] [blame] | 1556 | if (program->samplesFromTexture(state, attachment.id())) |
| Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1557 | { |
| 1558 | return true; |
| 1559 | } |
| 1560 | } |
| 1561 | } |
| 1562 | |
| Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1563 | // Validate depth-stencil feedback loop. |
| 1564 | const auto &dsState = state.getDepthStencilState(); |
| 1565 | |
| 1566 | // We can skip the feedback loop checks if depth/stencil is masked out or disabled. |
| 1567 | const FramebufferAttachment *depth = getDepthbuffer(); |
| 1568 | if (depth && depth->type() == GL_TEXTURE && dsState.depthTest && dsState.depthMask) |
| 1569 | { |
| 1570 | if (program->samplesFromTexture(state, depth->id())) |
| 1571 | { |
| 1572 | return true; |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | // Note: we assume the front and back masks are the same for WebGL. |
| 1577 | const FramebufferAttachment *stencil = getStencilbuffer(); |
| 1578 | ASSERT(dsState.stencilBackWritemask == dsState.stencilWritemask); |
| 1579 | if (stencil && stencil->type() == GL_TEXTURE && dsState.stencilTest && |
| 1580 | dsState.stencilWritemask != 0) |
| 1581 | { |
| 1582 | // Skip the feedback loop check if depth/stencil point to the same resource. |
| 1583 | if (!depth || *stencil != *depth) |
| 1584 | { |
| 1585 | if (program->samplesFromTexture(state, stencil->id())) |
| 1586 | { |
| 1587 | return true; |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | |
| Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1592 | return false; |
| 1593 | } |
| 1594 | |
| Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1595 | bool Framebuffer::formsCopyingFeedbackLoopWith(GLuint copyTextureID, |
| 1596 | GLint copyTextureLevel, |
| 1597 | GLint copyTextureLayer) const |
| Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1598 | { |
| 1599 | if (mId == 0) |
| 1600 | { |
| 1601 | // It seems impossible to form a texture copying feedback loop with the default FBO. |
| 1602 | return false; |
| 1603 | } |
| 1604 | |
| 1605 | const FramebufferAttachment *readAttachment = getReadColorbuffer(); |
| 1606 | ASSERT(readAttachment); |
| 1607 | |
| 1608 | if (readAttachment->isTextureWithId(copyTextureID)) |
| 1609 | { |
| Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1610 | const auto &imageIndex = readAttachment->getTextureImageIndex(); |
| 1611 | if (imageIndex.mipIndex == copyTextureLevel) |
| Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1612 | { |
| Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1613 | // Check 3D/Array texture layers. |
| 1614 | return imageIndex.layerIndex == ImageIndex::ENTIRE_LEVEL || |
| 1615 | copyTextureLayer == ImageIndex::ENTIRE_LEVEL || |
| 1616 | imageIndex.layerIndex == copyTextureLayer; |
| Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1617 | } |
| 1618 | } |
| 1619 | return false; |
| 1620 | } |
| 1621 | |
| JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1622 | GLint Framebuffer::getDefaultWidth() const |
| 1623 | { |
| 1624 | return mState.getDefaultWidth(); |
| 1625 | } |
| 1626 | |
| 1627 | GLint Framebuffer::getDefaultHeight() const |
| 1628 | { |
| 1629 | return mState.getDefaultHeight(); |
| 1630 | } |
| 1631 | |
| 1632 | GLint Framebuffer::getDefaultSamples() const |
| 1633 | { |
| 1634 | return mState.getDefaultSamples(); |
| 1635 | } |
| 1636 | |
| 1637 | GLboolean Framebuffer::getDefaultFixedSampleLocations() const |
| 1638 | { |
| 1639 | return mState.getDefaultFixedSampleLocations(); |
| 1640 | } |
| 1641 | |
| 1642 | void Framebuffer::setDefaultWidth(GLint defaultWidth) |
| 1643 | { |
| 1644 | mState.mDefaultWidth = defaultWidth; |
| 1645 | mDirtyBits.set(DIRTY_BIT_DEFAULT_WIDTH); |
| 1646 | } |
| 1647 | |
| 1648 | void Framebuffer::setDefaultHeight(GLint defaultHeight) |
| 1649 | { |
| 1650 | mState.mDefaultHeight = defaultHeight; |
| 1651 | mDirtyBits.set(DIRTY_BIT_DEFAULT_HEIGHT); |
| 1652 | } |
| 1653 | |
| 1654 | void Framebuffer::setDefaultSamples(GLint defaultSamples) |
| 1655 | { |
| 1656 | mState.mDefaultSamples = defaultSamples; |
| 1657 | mDirtyBits.set(DIRTY_BIT_DEFAULT_SAMPLES); |
| 1658 | } |
| 1659 | |
| 1660 | void Framebuffer::setDefaultFixedSampleLocations(GLboolean defaultFixedSampleLocations) |
| 1661 | { |
| 1662 | mState.mDefaultFixedSampleLocations = defaultFixedSampleLocations; |
| 1663 | mDirtyBits.set(DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS); |
| 1664 | } |
| 1665 | |
| Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1666 | // TODO(jmadill): Remove this kludge. |
| 1667 | GLenum Framebuffer::checkStatus(const ValidationContext *context) |
| 1668 | { |
| 1669 | return checkStatus(static_cast<const Context *>(context)); |
| 1670 | } |
| 1671 | |
| 1672 | int Framebuffer::getSamples(const ValidationContext *context) |
| 1673 | { |
| 1674 | return getSamples(static_cast<const Context *>(context)); |
| 1675 | } |
| 1676 | |
| Martin Radev | 14a26ae | 2017-07-24 15:56:29 +0300 | [diff] [blame] | 1677 | GLsizei Framebuffer::getNumViews() const |
| 1678 | { |
| Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 1679 | return mState.getNumViews(); |
| Martin Radev | 14a26ae | 2017-07-24 15:56:29 +0300 | [diff] [blame] | 1680 | } |
| 1681 | |
| Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 1682 | GLint Framebuffer::getBaseViewIndex() const |
| 1683 | { |
| 1684 | return mState.getBaseViewIndex(); |
| 1685 | } |
| 1686 | |
| Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 1687 | const std::vector<Offset> *Framebuffer::getViewportOffsets() const |
| 1688 | { |
| Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 1689 | return mState.getViewportOffsets(); |
| Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | GLenum Framebuffer::getMultiviewLayout() const |
| 1693 | { |
| Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 1694 | return mState.getMultiviewLayout(); |
| Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 1695 | } |
| 1696 | |
| Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1697 | } // namespace gl |