daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Stuart Morgan | 9d73796 | 2019-08-14 12:25:12 -0700 | [diff] [blame] | 2 | // Copyright 2002 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" |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 22 | #include "libANGLE/angletypes.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 23 | #include "libANGLE/formatutils.h" |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 24 | #include "libANGLE/renderer/ContextImpl.h" |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 25 | #include "libANGLE/renderer/FramebufferImpl.h" |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 26 | #include "libANGLE/renderer/GLImplFactory.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 27 | #include "libANGLE/renderer/RenderbufferImpl.h" |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 28 | #include "libANGLE/renderer/SurfaceImpl.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 29 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 30 | using namespace angle; |
| 31 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 32 | namespace gl |
| 33 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 34 | |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 35 | namespace |
| 36 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 37 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 38 | bool CheckMultiviewStateMatchesForCompleteness(const FramebufferAttachment *firstAttachment, |
| 39 | const FramebufferAttachment *secondAttachment) |
| 40 | { |
| 41 | ASSERT(firstAttachment && secondAttachment); |
| 42 | ASSERT(firstAttachment->isAttached() && secondAttachment->isAttached()); |
| 43 | |
| 44 | if (firstAttachment->getNumViews() != secondAttachment->getNumViews()) |
| 45 | { |
| 46 | return false; |
| 47 | } |
| 48 | if (firstAttachment->getBaseViewIndex() != secondAttachment->getBaseViewIndex()) |
| 49 | { |
| 50 | return false; |
| 51 | } |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 52 | if (firstAttachment->isMultiview() != secondAttachment->isMultiview()) |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 53 | { |
| 54 | return false; |
| 55 | } |
| 56 | return true; |
| 57 | } |
| 58 | |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 59 | bool CheckAttachmentCompleteness(const Context *context, const FramebufferAttachment &attachment) |
| 60 | { |
| 61 | ASSERT(attachment.isAttached()); |
| 62 | |
| 63 | const Extents &size = attachment.getSize(); |
| 64 | if (size.width == 0 || size.height == 0) |
| 65 | { |
| 66 | return false; |
| 67 | } |
| 68 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 69 | if (!attachment.isRenderable(context)) |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 70 | { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | if (attachment.type() == GL_TEXTURE) |
| 75 | { |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 76 | // [EXT_geometry_shader] Section 9.4.1, "Framebuffer Completeness" |
| 77 | // If <image> is a three-dimensional texture or a two-dimensional array texture and the |
| 78 | // attachment is not layered, the selected layer is less than the depth or layer count, |
| 79 | // respectively, of the texture. |
| 80 | if (!attachment.isLayered()) |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 81 | { |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 82 | if (attachment.layer() >= size.depth) |
| 83 | { |
| 84 | return false; |
| 85 | } |
| 86 | } |
| 87 | // If <image> is a three-dimensional texture or a two-dimensional array texture and the |
| 88 | // attachment is layered, the depth or layer count, respectively, of the texture is less |
| 89 | // than or equal to the value of MAX_FRAMEBUFFER_LAYERS_EXT. |
| 90 | else |
| 91 | { |
| 92 | if (static_cast<GLuint>(size.depth) >= context->getCaps().maxFramebufferLayers) |
| 93 | { |
| 94 | return false; |
| 95 | } |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | // ES3 specifies that cube map texture attachments must be cube complete. |
| 99 | // This language is missing from the ES2 spec, but we enforce it here because some |
| 100 | // desktop OpenGL drivers also enforce this validation. |
| 101 | // TODO(jmadill): Check if OpenGL ES2 drivers enforce cube completeness. |
| 102 | const Texture *texture = attachment.getTexture(); |
| 103 | ASSERT(texture); |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 104 | if (texture->getType() == TextureType::CubeMap && |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 105 | !texture->getTextureState().isCubeComplete()) |
| 106 | { |
| 107 | return false; |
| 108 | } |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 109 | |
| 110 | if (!texture->getImmutableFormat()) |
| 111 | { |
| 112 | GLuint attachmentMipLevel = static_cast<GLuint>(attachment.mipLevel()); |
| 113 | |
| 114 | // From the ES 3.0 spec, pg 213: |
| 115 | // If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is TEXTURE and the value of |
| 116 | // FRAMEBUFFER_ATTACHMENT_OBJECT_NAME does not name an immutable-format texture, |
| 117 | // then the value of FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL must be in the |
| 118 | // range[levelbase, q], where levelbase is the value of TEXTURE_BASE_LEVEL and q is |
| 119 | // the effective maximum texture level defined in the Mipmapping discussion of |
| 120 | // section 3.8.10.4. |
| 121 | if (attachmentMipLevel < texture->getBaseLevel() || |
| 122 | attachmentMipLevel > texture->getMipmapMaxLevel()) |
| 123 | { |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | // Form the ES 3.0 spec, pg 213/214: |
| 128 | // If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is TEXTURE and the value of |
| 129 | // FRAMEBUFFER_ATTACHMENT_OBJECT_NAME does not name an immutable-format texture and |
| 130 | // the value of FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL is not levelbase, then the |
| 131 | // texture must be mipmap complete, and if FRAMEBUFFER_ATTACHMENT_OBJECT_NAME names |
| 132 | // a cubemap texture, the texture must also be cube complete. |
| 133 | if (attachmentMipLevel != texture->getBaseLevel() && !texture->isMipmapComplete()) |
| 134 | { |
| 135 | return false; |
| 136 | } |
| 137 | } |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | return true; |
Jamie Madill | c09ae15 | 2019-02-01 14:16:32 -0500 | [diff] [blame] | 141 | } |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 142 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 143 | bool CheckAttachmentSampleCompleteness(const Context *context, |
| 144 | const FramebufferAttachment &attachment, |
| 145 | bool colorAttachment, |
| 146 | Optional<int> *samples, |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 147 | Optional<bool> *fixedSampleLocations) |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 148 | { |
| 149 | ASSERT(attachment.isAttached()); |
| 150 | |
| 151 | if (attachment.type() == GL_TEXTURE) |
| 152 | { |
| 153 | const Texture *texture = attachment.getTexture(); |
| 154 | ASSERT(texture); |
| 155 | |
| 156 | const ImageIndex &attachmentImageIndex = attachment.getTextureImageIndex(); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 157 | bool fixedSampleloc = texture->getAttachmentFixedSampleLocations(attachmentImageIndex); |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 158 | if (fixedSampleLocations->valid() && fixedSampleloc != fixedSampleLocations->value()) |
| 159 | { |
| 160 | return false; |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | *fixedSampleLocations = fixedSampleloc; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (samples->valid()) |
| 169 | { |
| 170 | if (attachment.getSamples() != samples->value()) |
| 171 | { |
| 172 | if (colorAttachment) |
| 173 | { |
| 174 | // APPLE_framebuffer_multisample, which EXT_draw_buffers refers to, requires that |
| 175 | // all color attachments have the same number of samples for the FBO to be complete. |
| 176 | return false; |
| 177 | } |
| 178 | else |
| 179 | { |
| 180 | // CHROMIUM_framebuffer_mixed_samples allows a framebuffer to be considered complete |
| 181 | // when its depth or stencil samples are a multiple of the number of color samples. |
| 182 | if (!context->getExtensions().framebufferMixedSamples) |
| 183 | { |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | if ((attachment.getSamples() % std::max(samples->value(), 1)) != 0) |
| 188 | { |
| 189 | return false; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | *samples = attachment.getSamples(); |
| 197 | } |
| 198 | |
| 199 | return true; |
| 200 | } |
| 201 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 202 | // Needed to index into the attachment arrays/bitsets. |
Jamie Madill | 682efdc | 2017-10-03 14:10:29 -0400 | [diff] [blame] | 203 | static_assert(static_cast<size_t>(IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS) == |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 204 | Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX, |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 205 | "Framebuffer Dirty bit mismatch"); |
Jamie Madill | 682efdc | 2017-10-03 14:10:29 -0400 | [diff] [blame] | 206 | static_assert(static_cast<size_t>(IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS) == |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 207 | Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT, |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 208 | "Framebuffer Dirty bit mismatch"); |
Jamie Madill | 682efdc | 2017-10-03 14:10:29 -0400 | [diff] [blame] | 209 | static_assert(static_cast<size_t>(IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS + 1) == |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 210 | Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT, |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 211 | "Framebuffer Dirty bit mismatch"); |
| 212 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 213 | angle::Result InitAttachment(const Context *context, FramebufferAttachment *attachment) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 214 | { |
| 215 | ASSERT(attachment->isAttached()); |
| 216 | if (attachment->initState() == InitState::MayNeedInit) |
| 217 | { |
| 218 | ANGLE_TRY(attachment->initializeContents(context)); |
| 219 | } |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 220 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | bool IsColorMaskedOut(const BlendState &blend) |
| 224 | { |
| 225 | return (!blend.colorMaskRed && !blend.colorMaskGreen && !blend.colorMaskBlue && |
| 226 | !blend.colorMaskAlpha); |
| 227 | } |
| 228 | |
| 229 | bool IsDepthMaskedOut(const DepthStencilState &depthStencil) |
| 230 | { |
| 231 | return !depthStencil.depthMask; |
| 232 | } |
| 233 | |
| 234 | bool IsStencilMaskedOut(const DepthStencilState &depthStencil) |
| 235 | { |
| 236 | return ((depthStencil.stencilMask & depthStencil.stencilWritemask) == 0); |
| 237 | } |
| 238 | |
| 239 | bool IsClearBufferMaskedOut(const Context *context, GLenum buffer) |
| 240 | { |
| 241 | switch (buffer) |
| 242 | { |
| 243 | case GL_COLOR: |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 244 | return IsColorMaskedOut(context->getState().getBlendState()); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 245 | case GL_DEPTH: |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 246 | return IsDepthMaskedOut(context->getState().getDepthStencilState()); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 247 | case GL_STENCIL: |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 248 | return IsStencilMaskedOut(context->getState().getDepthStencilState()); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 249 | case GL_DEPTH_STENCIL: |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 250 | return IsDepthMaskedOut(context->getState().getDepthStencilState()) && |
| 251 | IsStencilMaskedOut(context->getState().getDepthStencilState()); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 252 | default: |
| 253 | UNREACHABLE(); |
| 254 | return true; |
| 255 | } |
| 256 | } |
| 257 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 258 | } // anonymous namespace |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 259 | |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 260 | // This constructor is only used for default framebuffers. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 261 | FramebufferState::FramebufferState() |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 262 | : mId(Framebuffer::kDefaultDrawFramebufferHandle), |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 263 | mLabel(), |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 264 | mColorAttachments(1), |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 265 | mDrawBufferStates(1, GL_BACK), |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 266 | mReadBufferState(GL_BACK), |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 267 | mDrawBufferTypeMask(), |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 268 | mDefaultWidth(0), |
| 269 | mDefaultHeight(0), |
| 270 | mDefaultSamples(0), |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 271 | mDefaultFixedSampleLocations(GL_FALSE), |
Jiawei Shao | b1e9138 | 2018-05-17 14:33:55 +0800 | [diff] [blame] | 272 | mDefaultLayers(0), |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 273 | mWebGLDepthStencilConsistent(true), |
| 274 | mDefaultFramebufferReadAttachmentInitialized(false) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 275 | { |
Geoff Lang | d90d388 | 2017-03-21 10:49:54 -0400 | [diff] [blame] | 276 | ASSERT(mDrawBufferStates.size() > 0); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 277 | mEnabledDrawBuffers.set(0); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 280 | FramebufferState::FramebufferState(const Caps &caps, FramebufferID id) |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 281 | : mId(id), |
| 282 | mLabel(), |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 283 | mColorAttachments(caps.maxColorAttachments), |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 284 | mDrawBufferStates(caps.maxDrawBuffers, GL_NONE), |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 285 | mReadBufferState(GL_COLOR_ATTACHMENT0_EXT), |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 286 | mDrawBufferTypeMask(), |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 287 | mDefaultWidth(0), |
| 288 | mDefaultHeight(0), |
| 289 | mDefaultSamples(0), |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 290 | mDefaultFixedSampleLocations(GL_FALSE), |
Jiawei Shao | b1e9138 | 2018-05-17 14:33:55 +0800 | [diff] [blame] | 291 | mDefaultLayers(0), |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 292 | mWebGLDepthStencilConsistent(true), |
| 293 | mDefaultFramebufferReadAttachmentInitialized(false) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 294 | { |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 295 | ASSERT(mId != Framebuffer::kDefaultDrawFramebufferHandle); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 296 | ASSERT(mDrawBufferStates.size() > 0); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 297 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
| 298 | } |
| 299 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 300 | FramebufferState::~FramebufferState() {} |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 301 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 302 | const std::string &FramebufferState::getLabel() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 303 | { |
| 304 | return mLabel; |
| 305 | } |
| 306 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 307 | const FramebufferAttachment *FramebufferState::getAttachment(const Context *context, |
| 308 | GLenum attachment) const |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 309 | { |
| 310 | if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15) |
| 311 | { |
| 312 | return getColorAttachment(attachment - GL_COLOR_ATTACHMENT0); |
| 313 | } |
| 314 | |
Bryan Bernhart (Intel Americas Inc) | 5f19810 | 2017-12-12 14:21:39 -0800 | [diff] [blame] | 315 | // WebGL1 allows a developer to query for attachment parameters even when "inconsistant" (i.e. |
| 316 | // multiple conflicting attachment points) and requires us to return the framebuffer attachment |
| 317 | // associated with WebGL. |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 318 | switch (attachment) |
| 319 | { |
| 320 | case GL_COLOR: |
| 321 | case GL_BACK: |
| 322 | return getColorAttachment(0); |
| 323 | case GL_DEPTH: |
| 324 | case GL_DEPTH_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 5f19810 | 2017-12-12 14:21:39 -0800 | [diff] [blame] | 325 | if (context->isWebGL1()) |
| 326 | { |
| 327 | return getWebGLDepthAttachment(); |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | return getDepthAttachment(); |
| 332 | } |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 333 | case GL_STENCIL: |
| 334 | case GL_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 5f19810 | 2017-12-12 14:21:39 -0800 | [diff] [blame] | 335 | if (context->isWebGL1()) |
| 336 | { |
| 337 | return getWebGLStencilAttachment(); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | return getStencilAttachment(); |
| 342 | } |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 343 | case GL_DEPTH_STENCIL: |
| 344 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 345 | if (context->isWebGL1()) |
| 346 | { |
| 347 | return getWebGLDepthStencilAttachment(); |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | return getDepthStencilAttachment(); |
| 352 | } |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 353 | default: |
| 354 | UNREACHABLE(); |
| 355 | return nullptr; |
| 356 | } |
| 357 | } |
| 358 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 359 | size_t FramebufferState::getReadIndex() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 360 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 361 | ASSERT(mReadBufferState == GL_BACK || |
| 362 | (mReadBufferState >= GL_COLOR_ATTACHMENT0 && mReadBufferState <= GL_COLOR_ATTACHMENT15)); |
| 363 | size_t readIndex = (mReadBufferState == GL_BACK |
| 364 | ? 0 |
| 365 | : static_cast<size_t>(mReadBufferState - GL_COLOR_ATTACHMENT0)); |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 366 | ASSERT(readIndex < mColorAttachments.size()); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 367 | return readIndex; |
| 368 | } |
| 369 | |
| 370 | const FramebufferAttachment *FramebufferState::getReadAttachment() const |
| 371 | { |
| 372 | if (mReadBufferState == GL_NONE) |
| 373 | { |
| 374 | return nullptr; |
| 375 | } |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 376 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 377 | size_t readIndex = getReadIndex(); |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 378 | const gl::FramebufferAttachment &framebufferAttachment = |
| 379 | isDefault() ? mDefaultFramebufferReadAttachment : mColorAttachments[readIndex]; |
| 380 | |
| 381 | return framebufferAttachment.isAttached() ? &framebufferAttachment : nullptr; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 384 | const FramebufferAttachment *FramebufferState::getFirstNonNullAttachment() const |
| 385 | { |
| 386 | auto *colorAttachment = getFirstColorAttachment(); |
| 387 | if (colorAttachment) |
| 388 | { |
| 389 | return colorAttachment; |
| 390 | } |
| 391 | return getDepthOrStencilAttachment(); |
| 392 | } |
| 393 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 394 | const FramebufferAttachment *FramebufferState::getFirstColorAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 395 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 396 | for (const FramebufferAttachment &colorAttachment : mColorAttachments) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 397 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 398 | if (colorAttachment.isAttached()) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 399 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 400 | return &colorAttachment; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
| 404 | return nullptr; |
| 405 | } |
| 406 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 407 | const FramebufferAttachment *FramebufferState::getDepthOrStencilAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 408 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 409 | if (mDepthAttachment.isAttached()) |
| 410 | { |
| 411 | return &mDepthAttachment; |
| 412 | } |
| 413 | if (mStencilAttachment.isAttached()) |
| 414 | { |
| 415 | return &mStencilAttachment; |
| 416 | } |
| 417 | return nullptr; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 418 | } |
| 419 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 420 | const FramebufferAttachment *FramebufferState::getStencilOrDepthStencilAttachment() const |
| 421 | { |
| 422 | if (mStencilAttachment.isAttached()) |
| 423 | { |
| 424 | return &mStencilAttachment; |
| 425 | } |
| 426 | return getDepthStencilAttachment(); |
| 427 | } |
| 428 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 429 | const FramebufferAttachment *FramebufferState::getColorAttachment(size_t colorAttachment) const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 430 | { |
| 431 | ASSERT(colorAttachment < mColorAttachments.size()); |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 432 | return mColorAttachments[colorAttachment].isAttached() ? &mColorAttachments[colorAttachment] |
| 433 | : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 434 | } |
| 435 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 436 | const FramebufferAttachment *FramebufferState::getDepthAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 437 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 438 | return mDepthAttachment.isAttached() ? &mDepthAttachment : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 439 | } |
| 440 | |
Bryan Bernhart (Intel Americas Inc) | 5f19810 | 2017-12-12 14:21:39 -0800 | [diff] [blame] | 441 | const FramebufferAttachment *FramebufferState::getWebGLDepthAttachment() const |
| 442 | { |
| 443 | return mWebGLDepthAttachment.isAttached() ? &mWebGLDepthAttachment : nullptr; |
| 444 | } |
| 445 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 446 | const FramebufferAttachment *FramebufferState::getWebGLDepthStencilAttachment() const |
| 447 | { |
| 448 | return mWebGLDepthStencilAttachment.isAttached() ? &mWebGLDepthStencilAttachment : nullptr; |
| 449 | } |
| 450 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 451 | const FramebufferAttachment *FramebufferState::getStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 452 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 453 | return mStencilAttachment.isAttached() ? &mStencilAttachment : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 454 | } |
| 455 | |
Bryan Bernhart (Intel Americas Inc) | 5f19810 | 2017-12-12 14:21:39 -0800 | [diff] [blame] | 456 | const FramebufferAttachment *FramebufferState::getWebGLStencilAttachment() const |
| 457 | { |
| 458 | return mWebGLStencilAttachment.isAttached() ? &mWebGLStencilAttachment : nullptr; |
| 459 | } |
| 460 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 461 | const FramebufferAttachment *FramebufferState::getDepthStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 462 | { |
| 463 | // A valid depth-stencil attachment has the same resource bound to both the |
| 464 | // depth and stencil attachment points. |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 465 | if (mDepthAttachment.isAttached() && mStencilAttachment.isAttached() && |
Jamie Madill | 44f2648 | 2016-11-18 12:49:15 -0500 | [diff] [blame] | 466 | mDepthAttachment == mStencilAttachment) |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 467 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 468 | return &mDepthAttachment; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | return nullptr; |
| 472 | } |
| 473 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 474 | bool FramebufferState::attachmentsHaveSameDimensions() const |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 475 | { |
| 476 | Optional<Extents> attachmentSize; |
| 477 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 478 | auto hasMismatchedSize = [&attachmentSize](const FramebufferAttachment &attachment) { |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 479 | if (!attachment.isAttached()) |
| 480 | { |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | if (!attachmentSize.valid()) |
| 485 | { |
| 486 | attachmentSize = attachment.getSize(); |
| 487 | return false; |
| 488 | } |
| 489 | |
Jeff Gilbert | 8f8edd6 | 2017-10-31 14:26:30 -0700 | [diff] [blame] | 490 | const auto &prevSize = attachmentSize.value(); |
| 491 | const auto &curSize = attachment.getSize(); |
| 492 | return (curSize.width != prevSize.width || curSize.height != prevSize.height); |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 493 | }; |
| 494 | |
| 495 | for (const auto &attachment : mColorAttachments) |
| 496 | { |
| 497 | if (hasMismatchedSize(attachment)) |
| 498 | { |
| 499 | return false; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | if (hasMismatchedSize(mDepthAttachment)) |
| 504 | { |
| 505 | return false; |
| 506 | } |
| 507 | |
| 508 | return !hasMismatchedSize(mStencilAttachment); |
| 509 | } |
| 510 | |
Luc Ferron | 5bdf8bd | 2018-06-20 09:51:37 -0400 | [diff] [blame] | 511 | bool FramebufferState::hasSeparateDepthAndStencilAttachments() const |
| 512 | { |
| 513 | // if we have both a depth and stencil buffer, they must refer to the same object |
| 514 | // since we only support packed_depth_stencil and not separate depth and stencil |
| 515 | return (getDepthAttachment() != nullptr && getStencilAttachment() != nullptr && |
| 516 | getDepthStencilAttachment() == nullptr); |
| 517 | } |
| 518 | |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 519 | const FramebufferAttachment *FramebufferState::getDrawBuffer(size_t drawBufferIdx) const |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 520 | { |
| 521 | ASSERT(drawBufferIdx < mDrawBufferStates.size()); |
| 522 | if (mDrawBufferStates[drawBufferIdx] != GL_NONE) |
| 523 | { |
| 524 | // ES3 spec: "If the GL is bound to a draw framebuffer object, the ith buffer listed in bufs |
| 525 | // must be COLOR_ATTACHMENTi or NONE" |
| 526 | ASSERT(mDrawBufferStates[drawBufferIdx] == GL_COLOR_ATTACHMENT0 + drawBufferIdx || |
| 527 | (drawBufferIdx == 0 && mDrawBufferStates[drawBufferIdx] == GL_BACK)); |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 528 | |
| 529 | if (mDrawBufferStates[drawBufferIdx] == GL_BACK) |
| 530 | { |
| 531 | return getColorAttachment(0); |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | return getColorAttachment(mDrawBufferStates[drawBufferIdx] - GL_COLOR_ATTACHMENT0); |
| 536 | } |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 537 | } |
| 538 | else |
| 539 | { |
| 540 | return nullptr; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | size_t FramebufferState::getDrawBufferCount() const |
| 545 | { |
| 546 | return mDrawBufferStates.size(); |
| 547 | } |
| 548 | |
Geoff Lang | b21e20d | 2016-07-19 15:35:41 -0400 | [diff] [blame] | 549 | bool FramebufferState::colorAttachmentsAreUniqueImages() const |
| 550 | { |
| 551 | for (size_t firstAttachmentIdx = 0; firstAttachmentIdx < mColorAttachments.size(); |
| 552 | firstAttachmentIdx++) |
| 553 | { |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 554 | const FramebufferAttachment &firstAttachment = mColorAttachments[firstAttachmentIdx]; |
Geoff Lang | b21e20d | 2016-07-19 15:35:41 -0400 | [diff] [blame] | 555 | if (!firstAttachment.isAttached()) |
| 556 | { |
| 557 | continue; |
| 558 | } |
| 559 | |
| 560 | for (size_t secondAttachmentIdx = firstAttachmentIdx + 1; |
| 561 | secondAttachmentIdx < mColorAttachments.size(); secondAttachmentIdx++) |
| 562 | { |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 563 | const FramebufferAttachment &secondAttachment = mColorAttachments[secondAttachmentIdx]; |
Geoff Lang | b21e20d | 2016-07-19 15:35:41 -0400 | [diff] [blame] | 564 | if (!secondAttachment.isAttached()) |
| 565 | { |
| 566 | continue; |
| 567 | } |
| 568 | |
| 569 | if (firstAttachment == secondAttachment) |
| 570 | { |
| 571 | return false; |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | return true; |
| 577 | } |
| 578 | |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 579 | bool FramebufferState::hasDepth() const |
| 580 | { |
| 581 | return (mDepthAttachment.isAttached() && mDepthAttachment.getDepthSize() > 0); |
| 582 | } |
| 583 | |
| 584 | bool FramebufferState::hasStencil() const |
| 585 | { |
| 586 | return (mStencilAttachment.isAttached() && mStencilAttachment.getStencilSize() > 0); |
| 587 | } |
| 588 | |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 589 | bool FramebufferState::isMultiview() const |
Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 590 | { |
| 591 | const FramebufferAttachment *attachment = getFirstNonNullAttachment(); |
| 592 | if (attachment == nullptr) |
| 593 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 594 | return false; |
Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 595 | } |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 596 | return attachment->isMultiview(); |
Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 597 | } |
| 598 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 599 | int FramebufferState::getBaseViewIndex() const |
| 600 | { |
| 601 | const FramebufferAttachment *attachment = getFirstNonNullAttachment(); |
| 602 | if (attachment == nullptr) |
| 603 | { |
| 604 | return GL_NONE; |
| 605 | } |
| 606 | return attachment->getBaseViewIndex(); |
| 607 | } |
| 608 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 609 | Box FramebufferState::getDimensions() const |
| 610 | { |
Jonah Ryan-Davis | 7151fe5 | 2019-07-17 15:15:27 -0400 | [diff] [blame] | 611 | Extents extents = getExtents(); |
| 612 | return Box(0, 0, 0, extents.width, extents.height, extents.depth); |
| 613 | } |
| 614 | |
| 615 | Extents FramebufferState::getExtents() const |
| 616 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 617 | ASSERT(attachmentsHaveSameDimensions()); |
Tim Van Patten | 626a728 | 2019-07-08 15:11:59 -0600 | [diff] [blame] | 618 | const FramebufferAttachment *first = getFirstNonNullAttachment(); |
| 619 | if (first) |
| 620 | { |
| 621 | return first->getSize(); |
| 622 | } |
| 623 | return Extents(getDefaultWidth(), getDefaultHeight(), 0); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 624 | } |
| 625 | |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 626 | bool FramebufferState::isDefault() const |
| 627 | { |
| 628 | return mId == Framebuffer::kDefaultDrawFramebufferHandle; |
| 629 | } |
| 630 | |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 631 | const FramebufferID Framebuffer::kDefaultDrawFramebufferHandle = {0}; |
| 632 | |
| 633 | Framebuffer::Framebuffer(const Caps &caps, rx::GLImplFactory *factory, FramebufferID id) |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 634 | : mState(caps, id), |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 635 | mImpl(factory->createFramebuffer(mState)), |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 636 | mCachedStatus(), |
| 637 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 638 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 639 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 640 | ASSERT(mImpl != nullptr); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 641 | ASSERT(mState.mColorAttachments.size() == static_cast<size_t>(caps.maxColorAttachments)); |
| 642 | |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 643 | for (uint32_t colorIndex = 0; |
| 644 | colorIndex < static_cast<uint32_t>(mState.mColorAttachments.size()); ++colorIndex) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 645 | { |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 646 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 647 | } |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 648 | mDirtyBits.set(DIRTY_BIT_READ_BUFFER); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 651 | Framebuffer::Framebuffer(const Context *context, egl::Surface *surface, egl::Surface *readSurface) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 652 | : mState(), |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 653 | mImpl(surface->getImplementation()->createDefaultFramebuffer(context, mState)), |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 654 | mCachedStatus(GL_FRAMEBUFFER_COMPLETE), |
| 655 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 656 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 657 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 658 | ASSERT(mImpl != nullptr); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 659 | |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 660 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0); |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 661 | setAttachmentImpl(context, GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex(), surface, |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 662 | FramebufferAttachment::kDefaultNumViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 663 | FramebufferAttachment::kDefaultBaseViewIndex, false, |
| 664 | FramebufferAttachment::kDefaultRenderToTextureSamples); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 665 | |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 666 | setReadSurface(context, readSurface); |
| 667 | |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 668 | if (surface->getConfig()->depthSize > 0) |
| 669 | { |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 670 | setAttachmentImpl(context, GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, ImageIndex(), surface, |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 671 | FramebufferAttachment::kDefaultNumViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 672 | FramebufferAttachment::kDefaultBaseViewIndex, false, |
| 673 | FramebufferAttachment::kDefaultRenderToTextureSamples); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | if (surface->getConfig()->stencilSize > 0) |
| 677 | { |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 678 | setAttachmentImpl(context, GL_FRAMEBUFFER_DEFAULT, GL_STENCIL, ImageIndex(), surface, |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 679 | FramebufferAttachment::kDefaultNumViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 680 | FramebufferAttachment::kDefaultBaseViewIndex, false, |
| 681 | FramebufferAttachment::kDefaultRenderToTextureSamples); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 682 | } |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 683 | SetComponentTypeMask(getDrawbufferWriteType(0), 0, &mState.mDrawBufferTypeMask); |
Geoff Lang | ee244c7 | 2019-05-06 10:30:18 -0400 | [diff] [blame] | 684 | |
| 685 | // Ensure the backend has a chance to synchronize its content for a new backbuffer. |
| 686 | mDirtyBits.set(DIRTY_BIT_COLOR_BUFFER_CONTENTS_0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 689 | Framebuffer::Framebuffer(const Context *context, |
| 690 | rx::GLImplFactory *factory, |
| 691 | egl::Surface *readSurface) |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 692 | : mState(), |
| 693 | mImpl(factory->createFramebuffer(mState)), |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 694 | mCachedStatus(GL_FRAMEBUFFER_UNDEFINED_OES), |
| 695 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 696 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
| 697 | { |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 698 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0); |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 699 | SetComponentTypeMask(getDrawbufferWriteType(0), 0, &mState.mDrawBufferTypeMask); |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 700 | |
| 701 | setReadSurface(context, readSurface); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 702 | } |
| 703 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 704 | Framebuffer::~Framebuffer() |
| 705 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 706 | SafeDelete(mImpl); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 709 | void Framebuffer::onDestroy(const Context *context) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 710 | { |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 711 | if (isDefault()) |
| 712 | { |
| 713 | mState.mDefaultFramebufferReadAttachment.detach(context); |
| 714 | mState.mDefaultFramebufferReadAttachmentInitialized = false; |
| 715 | } |
| 716 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 717 | for (auto &attachment : mState.mColorAttachments) |
| 718 | { |
| 719 | attachment.detach(context); |
| 720 | } |
| 721 | mState.mDepthAttachment.detach(context); |
| 722 | mState.mStencilAttachment.detach(context); |
| 723 | mState.mWebGLDepthAttachment.detach(context); |
| 724 | mState.mWebGLStencilAttachment.detach(context); |
| 725 | mState.mWebGLDepthStencilAttachment.detach(context); |
| 726 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 727 | mImpl->destroy(context); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 728 | } |
| 729 | |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 730 | void Framebuffer::setReadSurface(const Context *context, egl::Surface *readSurface) |
| 731 | { |
| 732 | // updateAttachment() without mState.mResourceNeedsInit.set() |
| 733 | mState.mDefaultFramebufferReadAttachment.attach( |
| 734 | context, GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex(), readSurface, |
| 735 | FramebufferAttachment::kDefaultNumViews, FramebufferAttachment::kDefaultBaseViewIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 736 | false, FramebufferAttachment::kDefaultRenderToTextureSamples); |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 737 | mDirtyBits.set(DIRTY_BIT_READ_BUFFER); |
| 738 | } |
| 739 | |
Jamie Madill | e90d4ee | 2018-11-28 14:04:00 -0500 | [diff] [blame] | 740 | void Framebuffer::setLabel(const Context *context, const std::string &label) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 741 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 742 | mState.mLabel = label; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | const std::string &Framebuffer::getLabel() const |
| 746 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 747 | return mState.mLabel; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 748 | } |
| 749 | |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 750 | bool Framebuffer::detachTexture(const Context *context, TextureID textureId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 751 | { |
Jamie Madill | 2ab08ed | 2019-08-12 16:20:21 -0400 | [diff] [blame] | 752 | return detachResourceById(context, GL_TEXTURE, textureId.value); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 755 | bool Framebuffer::detachRenderbuffer(const Context *context, RenderbufferID renderbufferId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 756 | { |
Jamie Madill | 7c7dec0 | 2019-08-06 17:44:11 -0400 | [diff] [blame] | 757 | return detachResourceById(context, GL_RENDERBUFFER, renderbufferId.value); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 758 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 759 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 760 | bool Framebuffer::detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 761 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 762 | bool found = false; |
| 763 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 764 | for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 765 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 766 | if (detachMatchingAttachment(context, &mState.mColorAttachments[colorIndex], resourceType, |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 767 | resourceId)) |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 768 | { |
| 769 | found = true; |
| 770 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 773 | if (context->isWebGL1()) |
| 774 | { |
| 775 | const std::array<FramebufferAttachment *, 3> attachments = { |
| 776 | {&mState.mWebGLDepthStencilAttachment, &mState.mWebGLDepthAttachment, |
| 777 | &mState.mWebGLStencilAttachment}}; |
| 778 | for (FramebufferAttachment *attachment : attachments) |
| 779 | { |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 780 | if (detachMatchingAttachment(context, attachment, resourceType, resourceId)) |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 781 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 782 | found = true; |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | } |
| 786 | else |
| 787 | { |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 788 | if (detachMatchingAttachment(context, &mState.mDepthAttachment, resourceType, resourceId)) |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 789 | { |
| 790 | found = true; |
| 791 | } |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 792 | if (detachMatchingAttachment(context, &mState.mStencilAttachment, resourceType, resourceId)) |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 793 | { |
| 794 | found = true; |
| 795 | } |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 796 | } |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 797 | |
| 798 | return found; |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 799 | } |
| 800 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 801 | bool Framebuffer::detachMatchingAttachment(const Context *context, |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 802 | FramebufferAttachment *attachment, |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 803 | GLenum matchType, |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 804 | GLuint matchId) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 805 | { |
| 806 | if (attachment->isAttached() && attachment->type() == matchType && attachment->id() == matchId) |
| 807 | { |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 808 | // We go through resetAttachment to make sure that all the required bookkeeping will be done |
| 809 | // such as updating enabled draw buffer state. |
| 810 | resetAttachment(context, attachment->getBinding()); |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 811 | return true; |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 812 | } |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 813 | |
| 814 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 817 | const FramebufferAttachment *Framebuffer::getColorAttachment(size_t colorAttachment) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 818 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 819 | return mState.getColorAttachment(colorAttachment); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 822 | const FramebufferAttachment *Framebuffer::getDepthAttachment() const |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 823 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 824 | return mState.getDepthAttachment(); |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 825 | } |
| 826 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 827 | const FramebufferAttachment *Framebuffer::getStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 828 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 829 | return mState.getStencilAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 830 | } |
| 831 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 832 | const FramebufferAttachment *Framebuffer::getDepthStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 833 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 834 | return mState.getDepthStencilAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 835 | } |
| 836 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 837 | const FramebufferAttachment *Framebuffer::getDepthOrStencilAttachment() const |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 838 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 839 | return mState.getDepthOrStencilAttachment(); |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 842 | const FramebufferAttachment *Framebuffer::getStencilOrDepthStencilAttachment() const |
| 843 | { |
| 844 | return mState.getStencilOrDepthStencilAttachment(); |
| 845 | } |
| 846 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 847 | const FramebufferAttachment *Framebuffer::getReadColorAttachment() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 848 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 849 | return mState.getReadAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 852 | GLenum Framebuffer::getReadColorAttachmentType() const |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 853 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 854 | const FramebufferAttachment *readAttachment = mState.getReadAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 855 | return (readAttachment != nullptr ? readAttachment->type() : GL_NONE); |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 858 | const FramebufferAttachment *Framebuffer::getFirstColorAttachment() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 859 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 860 | return mState.getFirstColorAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 861 | } |
| 862 | |
Jamie Madill | 6dd06ea | 2017-07-19 13:47:55 -0400 | [diff] [blame] | 863 | const FramebufferAttachment *Framebuffer::getFirstNonNullAttachment() const |
| 864 | { |
| 865 | return mState.getFirstNonNullAttachment(); |
| 866 | } |
| 867 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 868 | const FramebufferAttachment *Framebuffer::getAttachment(const Context *context, |
| 869 | GLenum attachment) const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 870 | { |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 871 | return mState.getAttachment(context, attachment); |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 872 | } |
| 873 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 874 | size_t Framebuffer::getDrawbufferStateCount() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 875 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 876 | return mState.mDrawBufferStates.size(); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | GLenum Framebuffer::getDrawBufferState(size_t drawBuffer) const |
| 880 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 881 | ASSERT(drawBuffer < mState.mDrawBufferStates.size()); |
| 882 | return mState.mDrawBufferStates[drawBuffer]; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 885 | const std::vector<GLenum> &Framebuffer::getDrawBufferStates() const |
| 886 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 887 | return mState.getDrawBufferStates(); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 888 | } |
| 889 | |
Geoff Lang | 164d54e | 2014-12-01 10:55:33 -0500 | [diff] [blame] | 890 | 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] | 891 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 892 | auto &drawStates = mState.mDrawBufferStates; |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 893 | |
| 894 | ASSERT(count <= drawStates.size()); |
| 895 | std::copy(buffers, buffers + count, drawStates.begin()); |
| 896 | std::fill(drawStates.begin() + count, drawStates.end(), GL_NONE); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 897 | mDirtyBits.set(DIRTY_BIT_DRAW_BUFFERS); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 898 | |
| 899 | mState.mEnabledDrawBuffers.reset(); |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 900 | mState.mDrawBufferTypeMask.reset(); |
| 901 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 902 | for (size_t index = 0; index < count; ++index) |
| 903 | { |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 904 | SetComponentTypeMask(getDrawbufferWriteType(index), index, &mState.mDrawBufferTypeMask); |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 905 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 906 | if (drawStates[index] != GL_NONE && mState.mColorAttachments[index].isAttached()) |
| 907 | { |
| 908 | mState.mEnabledDrawBuffers.set(index); |
| 909 | } |
| 910 | } |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 911 | } |
| 912 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 913 | const FramebufferAttachment *Framebuffer::getDrawBuffer(size_t drawBuffer) const |
| 914 | { |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 915 | return mState.getDrawBuffer(drawBuffer); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 916 | } |
| 917 | |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 918 | ComponentType Framebuffer::getDrawbufferWriteType(size_t drawBuffer) const |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 919 | { |
| 920 | const FramebufferAttachment *attachment = mState.getDrawBuffer(drawBuffer); |
| 921 | if (attachment == nullptr) |
| 922 | { |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 923 | return ComponentType::NoType; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | GLenum componentType = attachment->getFormat().info->componentType; |
| 927 | switch (componentType) |
| 928 | { |
| 929 | case GL_INT: |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 930 | return ComponentType::Int; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 931 | case GL_UNSIGNED_INT: |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 932 | return ComponentType::UnsignedInt; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 933 | |
| 934 | default: |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 935 | return ComponentType::Float; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 939 | ComponentTypeMask Framebuffer::getDrawBufferTypeMask() const |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 940 | { |
| 941 | return mState.mDrawBufferTypeMask; |
| 942 | } |
| 943 | |
| 944 | DrawBufferMask Framebuffer::getDrawBufferMask() const |
| 945 | { |
| 946 | return mState.mEnabledDrawBuffers; |
| 947 | } |
| 948 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 949 | bool Framebuffer::hasEnabledDrawBuffer() const |
| 950 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 951 | for (size_t drawbufferIdx = 0; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 952 | { |
| 953 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
| 954 | { |
| 955 | return true; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | return false; |
| 960 | } |
| 961 | |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 962 | GLenum Framebuffer::getReadBufferState() const |
| 963 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 964 | return mState.mReadBufferState; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | void Framebuffer::setReadBuffer(GLenum buffer) |
| 968 | { |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 969 | ASSERT(buffer == GL_BACK || buffer == GL_NONE || |
| 970 | (buffer >= GL_COLOR_ATTACHMENT0 && |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 971 | (buffer - GL_COLOR_ATTACHMENT0) < mState.mColorAttachments.size())); |
| 972 | mState.mReadBufferState = buffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 973 | mDirtyBits.set(DIRTY_BIT_READ_BUFFER); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 976 | size_t Framebuffer::getNumColorAttachments() const |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 977 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 978 | return mState.mColorAttachments.size(); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 979 | } |
| 980 | |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 981 | bool Framebuffer::hasDepth() const |
| 982 | { |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 983 | return mState.hasDepth(); |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 984 | } |
| 985 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 986 | bool Framebuffer::hasStencil() const |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 987 | { |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 988 | return mState.hasStencil(); |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 989 | } |
| 990 | |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 991 | bool Framebuffer::usingExtendedDrawBuffers() const |
| 992 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 993 | for (size_t drawbufferIdx = 1; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 994 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 995 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 996 | { |
| 997 | return true; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | return false; |
| 1002 | } |
| 1003 | |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 1004 | void Framebuffer::invalidateCompletenessCache() |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 1005 | { |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 1006 | if (!isDefault()) |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 1007 | { |
| 1008 | mCachedStatus.reset(); |
| 1009 | } |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 1010 | onStateChange(angle::SubjectMessage::DirtyBitsFlagged); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 1011 | } |
| 1012 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 1013 | GLenum Framebuffer::checkStatusImpl(const Context *context) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1014 | { |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 1015 | ASSERT(!isDefault()); |
| 1016 | ASSERT(hasAnyDirtyBit() || !mCachedStatus.valid()); |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 1017 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 1018 | mCachedStatus = checkStatusWithGLFrontEnd(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1019 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 1020 | if (mCachedStatus.value() == GL_FRAMEBUFFER_COMPLETE) |
| 1021 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1022 | // We can skip syncState on several back-ends. |
| 1023 | if (mImpl->shouldSyncStateBeforeCheckStatus()) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1024 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1025 | angle::Result err = syncState(context); |
| 1026 | if (err != angle::Result::Continue) |
| 1027 | { |
| 1028 | return 0; |
| 1029 | } |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 1030 | } |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1031 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 1032 | if (!mImpl->checkStatus(context)) |
| 1033 | { |
| 1034 | mCachedStatus = GL_FRAMEBUFFER_UNSUPPORTED; |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1035 | } |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1038 | return mCachedStatus.value(); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1039 | } |
| 1040 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1041 | GLenum Framebuffer::checkStatusWithGLFrontEnd(const Context *context) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1042 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1043 | const State &state = context->getState(); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1044 | |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 1045 | ASSERT(!isDefault()); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1046 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1047 | bool hasAttachments = false; |
| 1048 | Optional<unsigned int> colorbufferSize; |
| 1049 | Optional<int> samples; |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 1050 | Optional<bool> fixedSampleLocations; |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1051 | bool hasRenderbuffer = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1052 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1053 | const FramebufferAttachment *firstAttachment = getFirstNonNullAttachment(); |
| 1054 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 1055 | Optional<bool> isLayered; |
| 1056 | Optional<TextureType> colorAttachmentsTextureType; |
| 1057 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1058 | for (const FramebufferAttachment &colorAttachment : mState.mColorAttachments) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1059 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1060 | if (colorAttachment.isAttached()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1061 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 1062 | if (!CheckAttachmentCompleteness(context, colorAttachment)) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1063 | { |
| 1064 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1065 | } |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 1066 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1067 | const InternalFormat &format = *colorAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1068 | if (format.depthBits > 0 || format.stencilBits > 0) |
| 1069 | { |
| 1070 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1071 | } |
| 1072 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1073 | if (!CheckAttachmentSampleCompleteness(context, colorAttachment, true, &samples, |
| 1074 | &fixedSampleLocations)) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1075 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1076 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1079 | // in GLES 2.0, all color attachments attachments must have the same number of bitplanes |
| 1080 | // in GLES 3.0, there is no such restriction |
| 1081 | if (state.getClientMajorVersion() < 3) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1082 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1083 | if (colorbufferSize.valid()) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1084 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1085 | if (format.pixelBytes != colorbufferSize.value()) |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 1086 | { |
| 1087 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 1088 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1089 | } |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1090 | else |
| 1091 | { |
| 1092 | colorbufferSize = format.pixelBytes; |
| 1093 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1094 | } |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1095 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1096 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &colorAttachment)) |
| 1097 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1098 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR; |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1099 | } |
| 1100 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1101 | hasRenderbuffer = hasRenderbuffer || (colorAttachment.type() == GL_RENDERBUFFER); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 1102 | |
| 1103 | if (!hasAttachments) |
| 1104 | { |
| 1105 | isLayered = colorAttachment.isLayered(); |
| 1106 | if (isLayered.value()) |
| 1107 | { |
| 1108 | colorAttachmentsTextureType = colorAttachment.getTextureImageIndex().getType(); |
| 1109 | } |
| 1110 | hasAttachments = true; |
| 1111 | } |
| 1112 | else |
| 1113 | { |
| 1114 | // [EXT_geometry_shader] section 9.4.1, "Framebuffer Completeness" |
| 1115 | // If any framebuffer attachment is layered, all populated attachments |
| 1116 | // must be layered. Additionally, all populated color attachments must |
| 1117 | // be from textures of the same target. {FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT } |
| 1118 | ASSERT(isLayered.valid()); |
| 1119 | if (isLayered.value() != colorAttachment.isLayered()) |
| 1120 | { |
| 1121 | return GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT; |
| 1122 | } |
| 1123 | else if (isLayered.value()) |
| 1124 | { |
| 1125 | ASSERT(colorAttachmentsTextureType.valid()); |
| 1126 | if (colorAttachmentsTextureType.value() != |
| 1127 | colorAttachment.getTextureImageIndex().getType()) |
| 1128 | { |
| 1129 | return GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT; |
| 1130 | } |
| 1131 | } |
| 1132 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1133 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1136 | const FramebufferAttachment &depthAttachment = mState.mDepthAttachment; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1137 | if (depthAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1138 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 1139 | if (!CheckAttachmentCompleteness(context, depthAttachment)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1140 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1141 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1144 | const InternalFormat &format = *depthAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1145 | if (format.depthBits == 0) |
| 1146 | { |
| 1147 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1150 | if (!CheckAttachmentSampleCompleteness(context, depthAttachment, false, &samples, |
| 1151 | &fixedSampleLocations)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1152 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1153 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1154 | } |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1155 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1156 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &depthAttachment)) |
| 1157 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1158 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR; |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1159 | } |
| 1160 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1161 | hasRenderbuffer = hasRenderbuffer || (depthAttachment.type() == GL_RENDERBUFFER); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 1162 | |
| 1163 | if (!hasAttachments) |
| 1164 | { |
| 1165 | isLayered = depthAttachment.isLayered(); |
| 1166 | hasAttachments = true; |
| 1167 | } |
| 1168 | else |
| 1169 | { |
| 1170 | // [EXT_geometry_shader] section 9.4.1, "Framebuffer Completeness" |
| 1171 | // If any framebuffer attachment is layered, all populated attachments |
| 1172 | // must be layered. {FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT } |
| 1173 | ASSERT(isLayered.valid()); |
| 1174 | if (isLayered.value() != depthAttachment.isLayered()) |
| 1175 | { |
| 1176 | return GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT; |
| 1177 | } |
| 1178 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1181 | const FramebufferAttachment &stencilAttachment = mState.mStencilAttachment; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1182 | if (stencilAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1183 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 1184 | if (!CheckAttachmentCompleteness(context, stencilAttachment)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1185 | { |
| 1186 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1187 | } |
| 1188 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1189 | const InternalFormat &format = *stencilAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1190 | if (format.stencilBits == 0) |
| 1191 | { |
| 1192 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1195 | if (!CheckAttachmentSampleCompleteness(context, stencilAttachment, false, &samples, |
| 1196 | &fixedSampleLocations)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1197 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1198 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1199 | } |
Corentin Wallez | 086d59a | 2016-04-29 09:06:49 -0400 | [diff] [blame] | 1200 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1201 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &stencilAttachment)) |
| 1202 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1203 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR; |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1204 | } |
| 1205 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1206 | hasRenderbuffer = hasRenderbuffer || (stencilAttachment.type() == GL_RENDERBUFFER); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 1207 | |
| 1208 | if (!hasAttachments) |
| 1209 | { |
| 1210 | hasAttachments = true; |
| 1211 | } |
| 1212 | else |
| 1213 | { |
| 1214 | // [EXT_geometry_shader] section 9.4.1, "Framebuffer Completeness" |
| 1215 | // If any framebuffer attachment is layered, all populated attachments |
| 1216 | // must be layered. |
| 1217 | // {FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT } |
| 1218 | ASSERT(isLayered.valid()); |
| 1219 | if (isLayered.value() != stencilAttachment.isLayered()) |
| 1220 | { |
| 1221 | return GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT; |
| 1222 | } |
| 1223 | } |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | // Starting from ES 3.0 stencil and depth, if present, should be the same image |
| 1227 | if (state.getClientMajorVersion() >= 3 && depthAttachment.isAttached() && |
| 1228 | stencilAttachment.isAttached() && stencilAttachment != depthAttachment) |
| 1229 | { |
| 1230 | return GL_FRAMEBUFFER_UNSUPPORTED; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1233 | // Special additional validation for WebGL 1 DEPTH/STENCIL/DEPTH_STENCIL. |
| 1234 | if (state.isWebGL1()) |
| 1235 | { |
| 1236 | if (!mState.mWebGLDepthStencilConsistent) |
| 1237 | { |
| 1238 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 1239 | } |
| 1240 | |
| 1241 | if (mState.mWebGLDepthStencilAttachment.isAttached()) |
| 1242 | { |
| 1243 | if (mState.mWebGLDepthStencilAttachment.getDepthSize() == 0 || |
| 1244 | mState.mWebGLDepthStencilAttachment.getStencilSize() == 0) |
| 1245 | { |
| 1246 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1247 | } |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1248 | |
| 1249 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, |
| 1250 | &mState.mWebGLDepthStencilAttachment)) |
| 1251 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1252 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR; |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1253 | } |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1254 | } |
| 1255 | else if (mState.mStencilAttachment.isAttached() && |
| 1256 | mState.mStencilAttachment.getDepthSize() > 0) |
| 1257 | { |
| 1258 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1259 | } |
| 1260 | else if (mState.mDepthAttachment.isAttached() && |
| 1261 | mState.mDepthAttachment.getStencilSize() > 0) |
| 1262 | { |
| 1263 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1264 | } |
| 1265 | } |
| 1266 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1267 | // ES3.1(section 9.4) requires that if no image is attached to the framebuffer, and either the |
| 1268 | // value of the framebuffer's FRAMEBUFFER_DEFAULT_WIDTH or FRAMEBUFFER_DEFAULT_HEIGHT parameters |
| 1269 | // is zero, the framebuffer is considered incomplete. |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1270 | GLint defaultWidth = mState.getDefaultWidth(); |
| 1271 | GLint defaultHeight = mState.getDefaultHeight(); |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1272 | if (!hasAttachments && (defaultWidth == 0 || defaultHeight == 0)) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1273 | { |
| 1274 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 1277 | // 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] | 1278 | // In ES 3.0, there is no such restriction. |
Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 1279 | if ((state.getClientMajorVersion() < 3 || state.getExtensions().webglCompatibility) && |
| 1280 | !mState.attachmentsHaveSameDimensions()) |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 1281 | { |
| 1282 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 1283 | } |
| 1284 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1285 | // ES3.1(section 9.4) requires that if the attached images are a mix of renderbuffers and |
| 1286 | // 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] | 1287 | if (fixedSampleLocations.valid() && hasRenderbuffer && !fixedSampleLocations.value()) |
| 1288 | { |
| 1289 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| 1290 | } |
| 1291 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 1292 | // The WebGL conformance tests implicitly define that all framebuffer |
| 1293 | // attachments must be unique. For example, the same level of a texture can |
| 1294 | // not be attached to two different color attachments. |
| 1295 | if (state.getExtensions().webglCompatibility) |
| 1296 | { |
| 1297 | if (!mState.colorAttachmentsAreUniqueImages()) |
| 1298 | { |
| 1299 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 1300 | } |
| 1301 | } |
| 1302 | |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 1303 | return GL_FRAMEBUFFER_COMPLETE; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1304 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1305 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1306 | angle::Result Framebuffer::discard(const Context *context, size_t count, const GLenum *attachments) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1307 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1308 | // Back-ends might make the contents of the FBO undefined. In WebGL 2.0, invalidate operations |
| 1309 | // can be no-ops, so we should probably do that to ensure consistency. |
| 1310 | // TODO(jmadill): WebGL behaviour, and robust resource init behaviour without WebGL. |
| 1311 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1312 | return mImpl->discard(context, count, attachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1315 | angle::Result Framebuffer::invalidate(const Context *context, |
| 1316 | size_t count, |
| 1317 | const GLenum *attachments) |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 1318 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1319 | // Back-ends might make the contents of the FBO undefined. In WebGL 2.0, invalidate operations |
| 1320 | // can be no-ops, so we should probably do that to ensure consistency. |
| 1321 | // TODO(jmadill): WebGL behaviour, and robust resource init behaviour without WebGL. |
| 1322 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1323 | return mImpl->invalidate(context, count, attachments); |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 1324 | } |
| 1325 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1326 | bool Framebuffer::partialClearNeedsInit(const Context *context, |
| 1327 | bool color, |
| 1328 | bool depth, |
| 1329 | bool stencil) |
| 1330 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1331 | const auto &glState = context->getState(); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1332 | |
| 1333 | if (!glState.isRobustResourceInitEnabled()) |
| 1334 | { |
| 1335 | return false; |
| 1336 | } |
| 1337 | |
| 1338 | // Scissors can affect clearing. |
| 1339 | // TODO(jmadill): Check for complete scissor overlap. |
| 1340 | if (glState.isScissorTestEnabled()) |
| 1341 | { |
| 1342 | return true; |
| 1343 | } |
| 1344 | |
| 1345 | // If colors masked, we must clear before we clear. Do a simple check. |
| 1346 | // TODO(jmadill): Filter out unused color channels from the test. |
| 1347 | if (color) |
| 1348 | { |
| 1349 | const auto &blend = glState.getBlendState(); |
| 1350 | if (!(blend.colorMaskRed && blend.colorMaskGreen && blend.colorMaskBlue && |
| 1351 | blend.colorMaskAlpha)) |
| 1352 | { |
| 1353 | return true; |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | const auto &depthStencil = glState.getDepthStencilState(); |
Yuly Novikov | 21edf3d | 2018-07-23 16:44:16 -0400 | [diff] [blame] | 1358 | if (stencil && (depthStencil.stencilMask != depthStencil.stencilWritemask || |
| 1359 | depthStencil.stencilBackMask != depthStencil.stencilBackWritemask)) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1360 | { |
| 1361 | return true; |
| 1362 | } |
| 1363 | |
| 1364 | return false; |
| 1365 | } |
| 1366 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1367 | angle::Result Framebuffer::invalidateSub(const Context *context, |
| 1368 | size_t count, |
| 1369 | const GLenum *attachments, |
| 1370 | const Rectangle &area) |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 1371 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1372 | // Back-ends might make the contents of the FBO undefined. In WebGL 2.0, invalidate operations |
| 1373 | // can be no-ops, so we should probably do that to ensure consistency. |
| 1374 | // TODO(jmadill): Make a invalidate no-op in WebGL 2.0. |
| 1375 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1376 | return mImpl->invalidateSub(context, count, attachments, area); |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 1377 | } |
| 1378 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1379 | angle::Result Framebuffer::clear(const Context *context, GLbitfield mask) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1380 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1381 | const auto &glState = context->getState(); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1382 | if (glState.isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1383 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1384 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1385 | } |
| 1386 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1387 | // Remove clear bits that are ineffective. An effective clear changes at least one fragment. If |
| 1388 | // color/depth/stencil masks make the clear ineffective we skip it altogether. |
| 1389 | |
| 1390 | // If all color channels are masked, don't attempt to clear color. |
| 1391 | if (context->getState().getBlendState().allChannelsMasked()) |
| 1392 | { |
| 1393 | mask &= ~GL_COLOR_BUFFER_BIT; |
| 1394 | } |
| 1395 | |
| 1396 | // If depth write is disabled, don't attempt to clear depth. |
| 1397 | if (!context->getState().getDepthStencilState().depthMask) |
| 1398 | { |
| 1399 | mask &= ~GL_DEPTH_BUFFER_BIT; |
| 1400 | } |
| 1401 | |
| 1402 | // If all stencil bits are masked, don't attempt to clear stencil. |
| 1403 | if (context->getState().getDepthStencilState().stencilWritemask == 0) |
| 1404 | { |
| 1405 | mask &= ~GL_STENCIL_BUFFER_BIT; |
| 1406 | } |
| 1407 | |
| 1408 | if (mask != 0) |
| 1409 | { |
| 1410 | ANGLE_TRY(mImpl->clear(context, mask)); |
| 1411 | } |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1412 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1413 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1414 | } |
| 1415 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1416 | angle::Result Framebuffer::clearBufferfv(const Context *context, |
| 1417 | GLenum buffer, |
| 1418 | GLint drawbuffer, |
| 1419 | const GLfloat *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1420 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1421 | if (context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1422 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1423 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1424 | } |
| 1425 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1426 | if (buffer == GL_DEPTH) |
| 1427 | { |
| 1428 | // If depth write is disabled, don't attempt to clear depth. |
| 1429 | if (!context->getState().getDepthStencilState().depthMask) |
| 1430 | { |
| 1431 | return angle::Result::Continue; |
| 1432 | } |
| 1433 | } |
| 1434 | else |
| 1435 | { |
| 1436 | // If all color channels are masked, don't attempt to clear color. |
| 1437 | if (context->getState().getBlendState().allChannelsMasked()) |
| 1438 | { |
| 1439 | return angle::Result::Continue; |
| 1440 | } |
| 1441 | } |
| 1442 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1443 | ANGLE_TRY(mImpl->clearBufferfv(context, buffer, drawbuffer, values)); |
| 1444 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1445 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1446 | } |
| 1447 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1448 | angle::Result Framebuffer::clearBufferuiv(const Context *context, |
| 1449 | GLenum buffer, |
| 1450 | GLint drawbuffer, |
| 1451 | const GLuint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1452 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1453 | if (context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1454 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1455 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1456 | } |
| 1457 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1458 | // If all color channels are masked, don't attempt to clear color. |
| 1459 | if (context->getState().getBlendState().allChannelsMasked()) |
| 1460 | { |
| 1461 | return angle::Result::Continue; |
| 1462 | } |
| 1463 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1464 | ANGLE_TRY(mImpl->clearBufferuiv(context, buffer, drawbuffer, values)); |
| 1465 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1466 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1467 | } |
| 1468 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1469 | angle::Result Framebuffer::clearBufferiv(const Context *context, |
| 1470 | GLenum buffer, |
| 1471 | GLint drawbuffer, |
| 1472 | const GLint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1473 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1474 | if (context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1475 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1476 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1477 | } |
| 1478 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1479 | if (buffer == GL_STENCIL) |
| 1480 | { |
| 1481 | // If all stencil bits are masked, don't attempt to clear stencil. |
| 1482 | if (context->getState().getDepthStencilState().stencilWritemask == 0) |
| 1483 | { |
| 1484 | return angle::Result::Continue; |
| 1485 | } |
| 1486 | } |
| 1487 | else |
| 1488 | { |
| 1489 | // If all color channels are masked, don't attempt to clear color. |
| 1490 | if (context->getState().getBlendState().allChannelsMasked()) |
| 1491 | { |
| 1492 | return angle::Result::Continue; |
| 1493 | } |
| 1494 | } |
| 1495 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1496 | ANGLE_TRY(mImpl->clearBufferiv(context, buffer, drawbuffer, values)); |
| 1497 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1498 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1499 | } |
| 1500 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1501 | angle::Result Framebuffer::clearBufferfi(const Context *context, |
| 1502 | GLenum buffer, |
| 1503 | GLint drawbuffer, |
| 1504 | GLfloat depth, |
| 1505 | GLint stencil) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1506 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1507 | if (context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1508 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1509 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1510 | } |
| 1511 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1512 | bool clearDepth = context->getState().getDepthStencilState().depthMask; |
| 1513 | bool clearStencil = context->getState().getDepthStencilState().stencilWritemask != 0; |
| 1514 | |
| 1515 | if (clearDepth && clearStencil) |
| 1516 | { |
| 1517 | ASSERT(buffer == GL_DEPTH_STENCIL); |
| 1518 | ANGLE_TRY(mImpl->clearBufferfi(context, GL_DEPTH_STENCIL, drawbuffer, depth, stencil)); |
| 1519 | } |
| 1520 | else if (clearDepth && !clearStencil) |
| 1521 | { |
| 1522 | ANGLE_TRY(mImpl->clearBufferfv(context, GL_DEPTH, drawbuffer, &depth)); |
| 1523 | } |
| 1524 | else if (!clearDepth && clearStencil) |
| 1525 | { |
| 1526 | ANGLE_TRY(mImpl->clearBufferiv(context, GL_STENCIL, drawbuffer, &stencil)); |
| 1527 | } |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1528 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1529 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1530 | } |
| 1531 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1532 | angle::Result Framebuffer::getImplementationColorReadFormat(const Context *context, |
| 1533 | GLenum *formatOut) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1534 | { |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 1535 | ANGLE_TRY(syncState(context)); |
| 1536 | *formatOut = mImpl->getImplementationColorReadFormat(context); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1537 | return angle::Result::Continue; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1538 | } |
| 1539 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1540 | angle::Result Framebuffer::getImplementationColorReadType(const Context *context, GLenum *typeOut) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1541 | { |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 1542 | ANGLE_TRY(syncState(context)); |
| 1543 | *typeOut = mImpl->getImplementationColorReadType(context); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1544 | return angle::Result::Continue; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1545 | } |
| 1546 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1547 | angle::Result Framebuffer::readPixels(const Context *context, |
| 1548 | const Rectangle &area, |
| 1549 | GLenum format, |
| 1550 | GLenum type, |
| 1551 | void *pixels) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1552 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1553 | ANGLE_TRY(mImpl->readPixels(context, area, format, type, pixels)); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1554 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1555 | Buffer *unpackBuffer = context->getState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1556 | if (unpackBuffer) |
| 1557 | { |
James Dong | 020abb8 | 2019-07-24 11:33:49 -0600 | [diff] [blame] | 1558 | unpackBuffer->onDataChanged(); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1559 | } |
| 1560 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1561 | return angle::Result::Continue; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1564 | angle::Result Framebuffer::blit(const Context *context, |
| 1565 | const Rectangle &sourceArea, |
| 1566 | const Rectangle &destArea, |
| 1567 | GLbitfield mask, |
| 1568 | GLenum filter) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 1569 | { |
He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 1570 | GLbitfield blitMask = mask; |
| 1571 | |
| 1572 | // Note that blitting is called against draw framebuffer. |
| 1573 | // See the code in gl::Context::blitFramebuffer. |
| 1574 | if ((mask & GL_COLOR_BUFFER_BIT) && !hasEnabledDrawBuffer()) |
| 1575 | { |
| 1576 | blitMask &= ~GL_COLOR_BUFFER_BIT; |
| 1577 | } |
| 1578 | |
| 1579 | if ((mask & GL_STENCIL_BUFFER_BIT) && mState.getStencilAttachment() == nullptr) |
| 1580 | { |
| 1581 | blitMask &= ~GL_STENCIL_BUFFER_BIT; |
| 1582 | } |
| 1583 | |
| 1584 | if ((mask & GL_DEPTH_BUFFER_BIT) && mState.getDepthAttachment() == nullptr) |
| 1585 | { |
| 1586 | blitMask &= ~GL_DEPTH_BUFFER_BIT; |
| 1587 | } |
| 1588 | |
| 1589 | if (!blitMask) |
| 1590 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1591 | return angle::Result::Continue; |
He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | return mImpl->blit(context, sourceArea, destArea, blitMask, filter); |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 1595 | } |
| 1596 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1597 | int Framebuffer::getSamples(const Context *context) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1598 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1599 | return (isComplete(context) ? getCachedSamples(context) : 0); |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Shahbaz Youssefi | f2a1c38 | 2019-05-21 16:32:49 -0400 | [diff] [blame] | 1602 | int Framebuffer::getCachedSamples(const Context *context) const |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 1603 | { |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1604 | ASSERT(mCachedStatus.valid() && mCachedStatus.value() == GL_FRAMEBUFFER_COMPLETE); |
| 1605 | |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 1606 | // For a complete framebuffer, all attachments must have the same sample count. |
| 1607 | // In this case return the first nonzero sample size. |
| 1608 | const auto *firstNonNullAttachment = mState.getFirstNonNullAttachment(); |
| 1609 | if (firstNonNullAttachment) |
| 1610 | { |
| 1611 | ASSERT(firstNonNullAttachment->isAttached()); |
| 1612 | return firstNonNullAttachment->getSamples(); |
| 1613 | } |
| 1614 | |
| 1615 | // No attachments found. |
| 1616 | return 0; |
| 1617 | } |
| 1618 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1619 | angle::Result Framebuffer::getSamplePosition(const Context *context, |
| 1620 | size_t index, |
| 1621 | GLfloat *xy) const |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1622 | { |
Geoff Lang | 1345507 | 2018-05-09 11:24:43 -0400 | [diff] [blame] | 1623 | ANGLE_TRY(mImpl->getSamplePosition(context, index, xy)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1624 | return angle::Result::Continue; |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1625 | } |
| 1626 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 1627 | bool Framebuffer::hasValidDepthStencil() const |
| 1628 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1629 | return mState.getDepthStencilAttachment() != nullptr; |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 1630 | } |
| 1631 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1632 | void Framebuffer::setAttachment(const Context *context, |
| 1633 | GLenum type, |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1634 | GLenum binding, |
| 1635 | const ImageIndex &textureIndex, |
| 1636 | FramebufferAttachmentObject *resource) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 1637 | { |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1638 | setAttachment(context, type, binding, textureIndex, resource, |
| 1639 | FramebufferAttachment::kDefaultNumViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1640 | FramebufferAttachment::kDefaultBaseViewIndex, false, |
| 1641 | FramebufferAttachment::kDefaultRenderToTextureSamples); |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | void Framebuffer::setAttachment(const Context *context, |
| 1645 | GLenum type, |
| 1646 | GLenum binding, |
| 1647 | const ImageIndex &textureIndex, |
| 1648 | FramebufferAttachmentObject *resource, |
| 1649 | GLsizei numViews, |
| 1650 | GLuint baseViewIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1651 | bool isMultiview, |
| 1652 | GLsizei samples) |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1653 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1654 | // Context may be null in unit tests. |
| 1655 | if (!context || !context->isWebGL1()) |
| 1656 | { |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1657 | setAttachmentImpl(context, type, binding, textureIndex, resource, numViews, baseViewIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1658 | isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1659 | return; |
| 1660 | } |
| 1661 | |
| 1662 | switch (binding) |
| 1663 | { |
| 1664 | case GL_DEPTH_STENCIL: |
| 1665 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1666 | mState.mWebGLDepthStencilAttachment.attach(context, type, binding, textureIndex, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1667 | resource, numViews, baseViewIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1668 | isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1669 | break; |
| 1670 | case GL_DEPTH: |
| 1671 | case GL_DEPTH_ATTACHMENT: |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1672 | mState.mWebGLDepthAttachment.attach(context, type, binding, textureIndex, resource, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1673 | numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1674 | break; |
| 1675 | case GL_STENCIL: |
| 1676 | case GL_STENCIL_ATTACHMENT: |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1677 | mState.mWebGLStencilAttachment.attach(context, type, binding, textureIndex, resource, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1678 | numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1679 | break; |
| 1680 | default: |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1681 | setAttachmentImpl(context, type, binding, textureIndex, resource, numViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1682 | baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1683 | return; |
| 1684 | } |
| 1685 | |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1686 | commitWebGL1DepthStencilIfConsistent(context, numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1687 | } |
| 1688 | |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1689 | void Framebuffer::setAttachmentMultiview(const Context *context, |
| 1690 | GLenum type, |
| 1691 | GLenum binding, |
| 1692 | const ImageIndex &textureIndex, |
| 1693 | FramebufferAttachmentObject *resource, |
| 1694 | GLsizei numViews, |
| 1695 | GLint baseViewIndex) |
Martin Radev | 82ef774 | 2017-08-08 17:44:58 +0300 | [diff] [blame] | 1696 | { |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1697 | setAttachment(context, type, binding, textureIndex, resource, numViews, baseViewIndex, true, |
| 1698 | FramebufferAttachment::kDefaultRenderToTextureSamples); |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | void Framebuffer::commitWebGL1DepthStencilIfConsistent(const Context *context, |
| 1702 | GLsizei numViews, |
| 1703 | GLuint baseViewIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1704 | bool isMultiview, |
| 1705 | GLsizei samples) |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1706 | { |
| 1707 | int count = 0; |
| 1708 | |
| 1709 | std::array<FramebufferAttachment *, 3> attachments = {{&mState.mWebGLDepthStencilAttachment, |
| 1710 | &mState.mWebGLDepthAttachment, |
| 1711 | &mState.mWebGLStencilAttachment}}; |
| 1712 | for (FramebufferAttachment *attachment : attachments) |
| 1713 | { |
| 1714 | if (attachment->isAttached()) |
| 1715 | { |
| 1716 | count++; |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | mState.mWebGLDepthStencilConsistent = (count <= 1); |
| 1721 | if (!mState.mWebGLDepthStencilConsistent) |
| 1722 | { |
| 1723 | // Inconsistent. |
| 1724 | return; |
| 1725 | } |
| 1726 | |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1727 | auto getImageIndexIfTextureAttachment = [](const FramebufferAttachment &attachment) { |
| 1728 | if (attachment.type() == GL_TEXTURE) |
| 1729 | { |
| 1730 | return attachment.getTextureImageIndex(); |
| 1731 | } |
| 1732 | else |
| 1733 | { |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1734 | return ImageIndex(); |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1735 | } |
| 1736 | }; |
| 1737 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1738 | if (mState.mWebGLDepthAttachment.isAttached()) |
| 1739 | { |
| 1740 | const auto &depth = mState.mWebGLDepthAttachment; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1741 | setAttachmentImpl(context, depth.type(), GL_DEPTH_ATTACHMENT, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1742 | getImageIndexIfTextureAttachment(depth), depth.getResource(), numViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1743 | baseViewIndex, isMultiview, samples); |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1744 | setAttachmentImpl(context, GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex(), nullptr, numViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1745 | baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1746 | } |
| 1747 | else if (mState.mWebGLStencilAttachment.isAttached()) |
| 1748 | { |
| 1749 | const auto &stencil = mState.mWebGLStencilAttachment; |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1750 | setAttachmentImpl(context, GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex(), nullptr, numViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1751 | baseViewIndex, isMultiview, samples); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1752 | setAttachmentImpl(context, stencil.type(), GL_STENCIL_ATTACHMENT, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1753 | getImageIndexIfTextureAttachment(stencil), stencil.getResource(), |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1754 | numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1755 | } |
| 1756 | else if (mState.mWebGLDepthStencilAttachment.isAttached()) |
| 1757 | { |
| 1758 | const auto &depthStencil = mState.mWebGLDepthStencilAttachment; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1759 | setAttachmentImpl(context, depthStencil.type(), GL_DEPTH_ATTACHMENT, |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1760 | getImageIndexIfTextureAttachment(depthStencil), |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1761 | depthStencil.getResource(), numViews, baseViewIndex, isMultiview, |
| 1762 | samples); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1763 | setAttachmentImpl(context, depthStencil.type(), GL_STENCIL_ATTACHMENT, |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1764 | getImageIndexIfTextureAttachment(depthStencil), |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1765 | depthStencil.getResource(), numViews, baseViewIndex, isMultiview, |
| 1766 | samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1767 | } |
| 1768 | else |
| 1769 | { |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1770 | setAttachmentImpl(context, GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex(), nullptr, numViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1771 | baseViewIndex, isMultiview, samples); |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1772 | setAttachmentImpl(context, GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex(), nullptr, numViews, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1773 | baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1774 | } |
| 1775 | } |
| 1776 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1777 | void Framebuffer::setAttachmentImpl(const Context *context, |
| 1778 | GLenum type, |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1779 | GLenum binding, |
| 1780 | const ImageIndex &textureIndex, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1781 | FramebufferAttachmentObject *resource, |
| 1782 | GLsizei numViews, |
| 1783 | GLuint baseViewIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1784 | bool isMultiview, |
| 1785 | GLsizei samples) |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1786 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1787 | switch (binding) |
| 1788 | { |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1789 | case GL_DEPTH_STENCIL: |
| 1790 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1791 | updateAttachment(context, &mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT, |
Geoff Lang | 32d6006 | 2019-09-06 10:10:08 -0400 | [diff] [blame] | 1792 | &mDirtyDepthAttachmentBinding, type, binding, textureIndex, resource, |
| 1793 | numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1794 | updateAttachment(context, &mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT, |
Geoff Lang | 32d6006 | 2019-09-06 10:10:08 -0400 | [diff] [blame] | 1795 | &mDirtyStencilAttachmentBinding, type, binding, textureIndex, resource, |
| 1796 | numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 1797 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1798 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1799 | case GL_DEPTH: |
| 1800 | case GL_DEPTH_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1801 | updateAttachment(context, &mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1802 | &mDirtyDepthAttachmentBinding, type, binding, textureIndex, resource, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1803 | numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1804 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1805 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1806 | case GL_STENCIL: |
| 1807 | case GL_STENCIL_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1808 | updateAttachment(context, &mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1809 | &mDirtyStencilAttachmentBinding, type, binding, textureIndex, resource, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1810 | numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1811 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1812 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1813 | case GL_BACK: |
Geoff Lang | 8170eab | 2017-09-21 13:59:04 -0400 | [diff] [blame] | 1814 | updateAttachment(context, &mState.mColorAttachments[0], DIRTY_BIT_COLOR_ATTACHMENT_0, |
| 1815 | &mDirtyColorAttachmentBindings[0], type, binding, textureIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1816 | resource, numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1817 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1818 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1819 | default: |
| 1820 | { |
| 1821 | size_t colorIndex = binding - GL_COLOR_ATTACHMENT0; |
| 1822 | ASSERT(colorIndex < mState.mColorAttachments.size()); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1823 | size_t dirtyBit = DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1824 | updateAttachment(context, &mState.mColorAttachments[colorIndex], dirtyBit, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1825 | &mDirtyColorAttachmentBindings[colorIndex], type, binding, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1826 | textureIndex, resource, numViews, baseViewIndex, isMultiview, samples); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1827 | |
shrekshao | c87e005 | 2019-02-21 11:40:28 -0800 | [diff] [blame] | 1828 | if (!resource) |
| 1829 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1830 | mColorAttachmentBits.reset(colorIndex); |
shrekshao | c87e005 | 2019-02-21 11:40:28 -0800 | [diff] [blame] | 1831 | mFloat32ColorAttachmentBits.reset(colorIndex); |
| 1832 | } |
| 1833 | else |
| 1834 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1835 | mColorAttachmentBits.set(colorIndex); |
shrekshao | c87e005 | 2019-02-21 11:40:28 -0800 | [diff] [blame] | 1836 | updateFloat32ColorAttachmentBits( |
| 1837 | colorIndex, resource->getAttachmentFormat(binding, textureIndex).info); |
| 1838 | } |
| 1839 | |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 1840 | // TODO(jmadill): ASSERT instead of checking the attachment exists in |
| 1841 | // formsRenderingFeedbackLoopWith |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1842 | bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE); |
| 1843 | mState.mEnabledDrawBuffers.set(colorIndex, enabled); |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 1844 | SetComponentTypeMask(getDrawbufferWriteType(colorIndex), colorIndex, |
| 1845 | &mState.mDrawBufferTypeMask); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1846 | } |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1847 | break; |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 1848 | } |
| 1849 | } |
| 1850 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1851 | void Framebuffer::updateAttachment(const Context *context, |
| 1852 | FramebufferAttachment *attachment, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1853 | size_t dirtyBit, |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1854 | angle::ObserverBinding *onDirtyBinding, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1855 | GLenum type, |
| 1856 | GLenum binding, |
| 1857 | const ImageIndex &textureIndex, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1858 | FramebufferAttachmentObject *resource, |
| 1859 | GLsizei numViews, |
| 1860 | GLuint baseViewIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1861 | bool isMultiview, |
| 1862 | GLsizei samples) |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1863 | { |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1864 | attachment->attach(context, type, binding, textureIndex, resource, numViews, baseViewIndex, |
Mingyu Hu | 7e44ec2 | 2019-08-26 15:59:48 -0700 | [diff] [blame] | 1865 | isMultiview, samples); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1866 | mDirtyBits.set(dirtyBit); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1867 | mState.mResourceNeedsInit.set(dirtyBit, attachment->initState() == InitState::MayNeedInit); |
Jamie Madill | 66f0d2c | 2018-11-30 15:25:36 -0500 | [diff] [blame] | 1868 | onDirtyBinding->bind(resource); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1869 | |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 1870 | invalidateCompletenessCache(); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1871 | } |
| 1872 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1873 | void Framebuffer::resetAttachment(const Context *context, GLenum binding) |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1874 | { |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1875 | setAttachment(context, GL_NONE, binding, ImageIndex(), nullptr); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1876 | } |
| 1877 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 1878 | angle::Result Framebuffer::syncState(const Context *context) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1879 | { |
| 1880 | if (mDirtyBits.any()) |
| 1881 | { |
Jamie Madill | 888081d | 2018-02-27 00:24:46 -0500 | [diff] [blame] | 1882 | mDirtyBitsGuard = mDirtyBits; |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 1883 | ANGLE_TRY(mImpl->syncState(context, mDirtyBits)); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1884 | mDirtyBits.reset(); |
Jamie Madill | 888081d | 2018-02-27 00:24:46 -0500 | [diff] [blame] | 1885 | mDirtyBitsGuard.reset(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1886 | } |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1887 | return angle::Result::Continue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1888 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1889 | |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 1890 | void Framebuffer::onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1891 | { |
Jamie Madill | e4faae2 | 2019-05-10 08:27:00 -0400 | [diff] [blame] | 1892 | if (message != angle::SubjectMessage::SubjectChanged) |
Jamie Madill | f668a4b | 2018-09-23 17:01:20 -0400 | [diff] [blame] | 1893 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1894 | // This can be triggered by SubImage calls for Textures. |
| 1895 | if (message == angle::SubjectMessage::ContentsChanged) |
| 1896 | { |
| 1897 | mDirtyBits.set(DIRTY_BIT_COLOR_BUFFER_CONTENTS_0 + index); |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 1898 | onStateChange(angle::SubjectMessage::DirtyBitsFlagged); |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame] | 1899 | return; |
| 1900 | } |
| 1901 | |
Jamie Madill | f668a4b | 2018-09-23 17:01:20 -0400 | [diff] [blame] | 1902 | // This can be triggered by the GL back-end TextureGL class. |
Jamie Madill | e4faae2 | 2019-05-10 08:27:00 -0400 | [diff] [blame] | 1903 | ASSERT(message == angle::SubjectMessage::DirtyBitsFlagged); |
Jamie Madill | f668a4b | 2018-09-23 17:01:20 -0400 | [diff] [blame] | 1904 | return; |
| 1905 | } |
Jamie Madill | 55e57f9 | 2018-09-18 11:32:43 -0400 | [diff] [blame] | 1906 | |
| 1907 | ASSERT(!mDirtyBitsGuard.valid() || mDirtyBitsGuard.value().test(index)); |
| 1908 | mDirtyBits.set(index); |
Jamie Madill | 888081d | 2018-02-27 00:24:46 -0500 | [diff] [blame] | 1909 | |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 1910 | invalidateCompletenessCache(); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1911 | |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1912 | FramebufferAttachment *attachment = getAttachmentFromSubjectIndex(index); |
| 1913 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1914 | // Mark the appropriate init flag. |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1915 | mState.mResourceNeedsInit.set(index, attachment->initState() == InitState::MayNeedInit); |
shrekshao | c87e005 | 2019-02-21 11:40:28 -0800 | [diff] [blame] | 1916 | |
| 1917 | // Update mFloat32ColorAttachmentBits Cache |
| 1918 | if (index < DIRTY_BIT_COLOR_ATTACHMENT_MAX) |
| 1919 | { |
| 1920 | ASSERT(index != DIRTY_BIT_DEPTH_ATTACHMENT); |
| 1921 | ASSERT(index != DIRTY_BIT_STENCIL_ATTACHMENT); |
| 1922 | updateFloat32ColorAttachmentBits(index - DIRTY_BIT_COLOR_ATTACHMENT_0, |
| 1923 | attachment->getFormat().info); |
| 1924 | } |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | FramebufferAttachment *Framebuffer::getAttachmentFromSubjectIndex(angle::SubjectIndex index) |
| 1928 | { |
| 1929 | switch (index) |
| 1930 | { |
| 1931 | case DIRTY_BIT_DEPTH_ATTACHMENT: |
| 1932 | return &mState.mDepthAttachment; |
| 1933 | case DIRTY_BIT_STENCIL_ATTACHMENT: |
| 1934 | return &mState.mStencilAttachment; |
| 1935 | default: |
| 1936 | size_t colorIndex = (index - DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 1937 | ASSERT(colorIndex < mState.mColorAttachments.size()); |
| 1938 | return &mState.mColorAttachments[colorIndex]; |
| 1939 | } |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1940 | } |
| 1941 | |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1942 | bool Framebuffer::formsRenderingFeedbackLoopWith(const Context *context) const |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1943 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1944 | const State &state = context->getState(); |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1945 | const Program *program = state.getProgram(); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1946 | |
| 1947 | // TODO(jmadill): Default framebuffer feedback loops. |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 1948 | if (mState.isDefault()) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1949 | { |
| 1950 | return false; |
| 1951 | } |
| 1952 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 1953 | const FramebufferAttachment *depth = getDepthAttachment(); |
| 1954 | const FramebufferAttachment *stencil = getStencilAttachment(); |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1955 | |
| 1956 | const bool checkDepth = depth && depth->type() == GL_TEXTURE; |
| 1957 | // Skip the feedback loop check for stencil if depth/stencil point to the same resource. |
| 1958 | const bool checkStencil = |
| 1959 | (stencil && stencil->type() == GL_TEXTURE) && (!depth || *stencil != *depth); |
| 1960 | |
| 1961 | const gl::ActiveTextureMask &activeTextures = program->getActiveSamplersMask(); |
| 1962 | const gl::ActiveTexturePointerArray &textures = state.getActiveTexturesCache(); |
| 1963 | |
| 1964 | for (size_t textureUnit : activeTextures) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1965 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1966 | Texture *texture = textures[textureUnit]; |
| 1967 | |
| 1968 | if (texture == nullptr) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1969 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1970 | continue; |
| 1971 | } |
| 1972 | |
| 1973 | // Depth and stencil attachment form feedback loops |
| 1974 | // Regardless of if enabled or masked. |
| 1975 | if (checkDepth) |
| 1976 | { |
Jamie Madill | f703443 | 2019-09-21 14:10:35 -0400 | [diff] [blame^] | 1977 | if (texture->getId() == depth->id()) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1978 | { |
| 1979 | return true; |
| 1980 | } |
| 1981 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1982 | |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1983 | if (checkStencil) |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1984 | { |
Jamie Madill | f703443 | 2019-09-21 14:10:35 -0400 | [diff] [blame^] | 1985 | if (texture->getId() == stencil->id()) |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1986 | { |
Jamie Madill | 38fe684 | 2018-09-19 07:20:00 -0400 | [diff] [blame] | 1987 | return true; |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1988 | } |
| 1989 | } |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1990 | |
| 1991 | // Check if any color attachment forms a feedback loop. |
| 1992 | for (size_t drawIndex : mColorAttachmentBits) |
| 1993 | { |
| 1994 | const FramebufferAttachment &attachment = mState.mColorAttachments[drawIndex]; |
| 1995 | ASSERT(attachment.isAttached()); |
| 1996 | |
| 1997 | if (attachment.isTextureWithId(texture->id())) |
| 1998 | { |
| 1999 | // TODO(jmadill): Check for appropriate overlap. |
| 2000 | return true; |
| 2001 | } |
| 2002 | } |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 2003 | } |
| 2004 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2005 | return false; |
| 2006 | } |
| 2007 | |
Jamie Madill | f703443 | 2019-09-21 14:10:35 -0400 | [diff] [blame^] | 2008 | bool Framebuffer::formsCopyingFeedbackLoopWith(TextureID copyTextureID, |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2009 | GLint copyTextureLevel, |
| 2010 | GLint copyTextureLayer) const |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2011 | { |
Jiacheng Lu | 2c5d48a | 2019-08-23 09:28:35 -0600 | [diff] [blame] | 2012 | if (mState.isDefault()) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2013 | { |
| 2014 | // It seems impossible to form a texture copying feedback loop with the default FBO. |
| 2015 | return false; |
| 2016 | } |
| 2017 | |
Jamie Madill | 4e71b2b | 2019-07-08 13:23:38 -0400 | [diff] [blame] | 2018 | const FramebufferAttachment *readAttachment = getReadColorAttachment(); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2019 | ASSERT(readAttachment); |
| 2020 | |
| 2021 | if (readAttachment->isTextureWithId(copyTextureID)) |
| 2022 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2023 | const auto &imageIndex = readAttachment->getTextureImageIndex(); |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2024 | if (imageIndex.getLevelIndex() == copyTextureLevel) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2025 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2026 | // Check 3D/Array texture layers. |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 2027 | return !imageIndex.hasLayer() || copyTextureLayer == ImageIndex::kEntireLevel || |
| 2028 | imageIndex.getLayerIndex() == copyTextureLayer; |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2029 | } |
| 2030 | } |
| 2031 | return false; |
| 2032 | } |
| 2033 | |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2034 | GLint Framebuffer::getDefaultWidth() const |
| 2035 | { |
| 2036 | return mState.getDefaultWidth(); |
| 2037 | } |
| 2038 | |
| 2039 | GLint Framebuffer::getDefaultHeight() const |
| 2040 | { |
| 2041 | return mState.getDefaultHeight(); |
| 2042 | } |
| 2043 | |
| 2044 | GLint Framebuffer::getDefaultSamples() const |
| 2045 | { |
| 2046 | return mState.getDefaultSamples(); |
| 2047 | } |
| 2048 | |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2049 | bool Framebuffer::getDefaultFixedSampleLocations() const |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2050 | { |
| 2051 | return mState.getDefaultFixedSampleLocations(); |
| 2052 | } |
| 2053 | |
Jiawei Shao | b1e9138 | 2018-05-17 14:33:55 +0800 | [diff] [blame] | 2054 | GLint Framebuffer::getDefaultLayers() const |
| 2055 | { |
| 2056 | return mState.getDefaultLayers(); |
| 2057 | } |
| 2058 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2059 | void Framebuffer::setDefaultWidth(const Context *context, GLint defaultWidth) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2060 | { |
| 2061 | mState.mDefaultWidth = defaultWidth; |
| 2062 | mDirtyBits.set(DIRTY_BIT_DEFAULT_WIDTH); |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 2063 | invalidateCompletenessCache(); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2064 | } |
| 2065 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2066 | void Framebuffer::setDefaultHeight(const Context *context, GLint defaultHeight) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2067 | { |
| 2068 | mState.mDefaultHeight = defaultHeight; |
| 2069 | mDirtyBits.set(DIRTY_BIT_DEFAULT_HEIGHT); |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 2070 | invalidateCompletenessCache(); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2071 | } |
| 2072 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2073 | void Framebuffer::setDefaultSamples(const Context *context, GLint defaultSamples) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2074 | { |
| 2075 | mState.mDefaultSamples = defaultSamples; |
| 2076 | mDirtyBits.set(DIRTY_BIT_DEFAULT_SAMPLES); |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 2077 | invalidateCompletenessCache(); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2078 | } |
| 2079 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2080 | void Framebuffer::setDefaultFixedSampleLocations(const Context *context, |
| 2081 | bool defaultFixedSampleLocations) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2082 | { |
| 2083 | mState.mDefaultFixedSampleLocations = defaultFixedSampleLocations; |
| 2084 | mDirtyBits.set(DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS); |
Jamie Madill | 124f78c | 2019-06-18 11:48:24 -0400 | [diff] [blame] | 2085 | invalidateCompletenessCache(); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2086 | } |
| 2087 | |
Jiawei Shao | b1e9138 | 2018-05-17 14:33:55 +0800 | [diff] [blame] | 2088 | void Framebuffer::setDefaultLayers(GLint defaultLayers) |
| 2089 | { |
| 2090 | mState.mDefaultLayers = defaultLayers; |
| 2091 | mDirtyBits.set(DIRTY_BIT_DEFAULT_LAYERS); |
| 2092 | } |
| 2093 | |
Martin Radev | 14a26ae | 2017-07-24 15:56:29 +0300 | [diff] [blame] | 2094 | GLsizei Framebuffer::getNumViews() const |
| 2095 | { |
Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 2096 | return mState.getNumViews(); |
Martin Radev | 14a26ae | 2017-07-24 15:56:29 +0300 | [diff] [blame] | 2097 | } |
| 2098 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 2099 | GLint Framebuffer::getBaseViewIndex() const |
| 2100 | { |
| 2101 | return mState.getBaseViewIndex(); |
| 2102 | } |
| 2103 | |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 2104 | bool Framebuffer::isMultiview() const |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 2105 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 2106 | return mState.isMultiview(); |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 2107 | } |
| 2108 | |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 2109 | bool Framebuffer::readDisallowedByMultiview() const |
| 2110 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 2111 | return (mState.isMultiview() && mState.getNumViews() > 1); |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 2112 | } |
| 2113 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 2114 | angle::Result Framebuffer::ensureClearAttachmentsInitialized(const Context *context, |
| 2115 | GLbitfield mask) |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2116 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2117 | const auto &glState = context->getState(); |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2118 | if (!context->isRobustResourceInitEnabled() || glState.isRasterizerDiscardEnabled()) |
| 2119 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2120 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2121 | } |
| 2122 | |
Geoff Lang | a36483f | 2018-03-09 16:11:21 -0500 | [diff] [blame] | 2123 | const BlendState &blend = glState.getBlendState(); |
| 2124 | const DepthStencilState &depthStencil = glState.getDepthStencilState(); |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2125 | |
| 2126 | bool color = (mask & GL_COLOR_BUFFER_BIT) != 0 && !IsColorMaskedOut(blend); |
| 2127 | bool depth = (mask & GL_DEPTH_BUFFER_BIT) != 0 && !IsDepthMaskedOut(depthStencil); |
| 2128 | bool stencil = (mask & GL_STENCIL_BUFFER_BIT) != 0 && !IsStencilMaskedOut(depthStencil); |
| 2129 | |
| 2130 | if (!color && !depth && !stencil) |
| 2131 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2132 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | if (partialClearNeedsInit(context, color, depth, stencil)) |
| 2136 | { |
| 2137 | ANGLE_TRY(ensureDrawAttachmentsInitialized(context)); |
| 2138 | } |
| 2139 | |
| 2140 | // If the impl encounters an error during a a full (non-partial) clear, the attachments will |
| 2141 | // still be marked initialized. This simplifies design, allowing this method to be called before |
| 2142 | // the clear. |
| 2143 | markDrawAttachmentsInitialized(color, depth, stencil); |
| 2144 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2145 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2146 | } |
| 2147 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 2148 | angle::Result Framebuffer::ensureClearBufferAttachmentsInitialized(const Context *context, |
| 2149 | GLenum buffer, |
| 2150 | GLint drawbuffer) |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2151 | { |
| 2152 | if (!context->isRobustResourceInitEnabled() || |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2153 | context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2154 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2155 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | if (partialBufferClearNeedsInit(context, buffer)) |
| 2159 | { |
| 2160 | ANGLE_TRY(ensureBufferInitialized(context, buffer, drawbuffer)); |
| 2161 | } |
| 2162 | |
| 2163 | // If the impl encounters an error during a a full (non-partial) clear, the attachments will |
| 2164 | // still be marked initialized. This simplifies design, allowing this method to be called before |
| 2165 | // the clear. |
| 2166 | markBufferInitialized(buffer, drawbuffer); |
| 2167 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2168 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2169 | } |
| 2170 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 2171 | angle::Result Framebuffer::ensureDrawAttachmentsInitialized(const Context *context) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2172 | { |
| 2173 | if (!context->isRobustResourceInitEnabled()) |
| 2174 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2175 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | // Note: we don't actually filter by the draw attachment enum. Just init everything. |
| 2179 | for (size_t bit : mState.mResourceNeedsInit) |
| 2180 | { |
| 2181 | switch (bit) |
| 2182 | { |
| 2183 | case DIRTY_BIT_DEPTH_ATTACHMENT: |
| 2184 | ANGLE_TRY(InitAttachment(context, &mState.mDepthAttachment)); |
| 2185 | break; |
| 2186 | case DIRTY_BIT_STENCIL_ATTACHMENT: |
| 2187 | ANGLE_TRY(InitAttachment(context, &mState.mStencilAttachment)); |
| 2188 | break; |
| 2189 | default: |
| 2190 | ANGLE_TRY(InitAttachment(context, &mState.mColorAttachments[bit])); |
| 2191 | break; |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | mState.mResourceNeedsInit.reset(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2196 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2197 | } |
| 2198 | |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2199 | angle::Result Framebuffer::ensureReadAttachmentsInitialized(const Context *context) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2200 | { |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2201 | ASSERT(context->isRobustResourceInitEnabled()); |
| 2202 | |
| 2203 | if (mState.mResourceNeedsInit.none()) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2204 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2205 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2206 | } |
| 2207 | |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2208 | if (mState.mReadBufferState != GL_NONE) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2209 | { |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 2210 | if (isDefault()) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2211 | { |
Tim Van Patten | 56ba54c | 2019-08-08 13:03:34 -0600 | [diff] [blame] | 2212 | if (!mState.mDefaultFramebufferReadAttachmentInitialized) |
| 2213 | { |
| 2214 | ANGLE_TRY(InitAttachment(context, &mState.mDefaultFramebufferReadAttachment)); |
| 2215 | mState.mDefaultFramebufferReadAttachmentInitialized = true; |
| 2216 | } |
| 2217 | } |
| 2218 | else |
| 2219 | { |
| 2220 | size_t readIndex = mState.getReadIndex(); |
| 2221 | if (mState.mResourceNeedsInit[readIndex]) |
| 2222 | { |
| 2223 | ANGLE_TRY(InitAttachment(context, &mState.mColorAttachments[readIndex])); |
| 2224 | mState.mResourceNeedsInit.reset(readIndex); |
| 2225 | } |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2226 | } |
| 2227 | } |
| 2228 | |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2229 | // Conservatively init depth since it can be read by BlitFramebuffer. |
| 2230 | if (hasDepth()) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2231 | { |
| 2232 | if (mState.mResourceNeedsInit[DIRTY_BIT_DEPTH_ATTACHMENT]) |
| 2233 | { |
| 2234 | ANGLE_TRY(InitAttachment(context, &mState.mDepthAttachment)); |
| 2235 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2236 | } |
| 2237 | } |
| 2238 | |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2239 | // Conservatively init stencil since it can be read by BlitFramebuffer. |
| 2240 | if (hasStencil()) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2241 | { |
| 2242 | if (mState.mResourceNeedsInit[DIRTY_BIT_STENCIL_ATTACHMENT]) |
| 2243 | { |
| 2244 | ANGLE_TRY(InitAttachment(context, &mState.mStencilAttachment)); |
| 2245 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2246 | } |
| 2247 | } |
| 2248 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2249 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | void Framebuffer::markDrawAttachmentsInitialized(bool color, bool depth, bool stencil) |
| 2253 | { |
| 2254 | // Mark attachments as initialized. |
| 2255 | if (color) |
| 2256 | { |
| 2257 | for (auto colorIndex : mState.mEnabledDrawBuffers) |
| 2258 | { |
| 2259 | auto &colorAttachment = mState.mColorAttachments[colorIndex]; |
| 2260 | ASSERT(colorAttachment.isAttached()); |
| 2261 | colorAttachment.setInitState(InitState::Initialized); |
| 2262 | mState.mResourceNeedsInit.reset(colorIndex); |
| 2263 | } |
| 2264 | } |
| 2265 | |
| 2266 | if (depth && mState.mDepthAttachment.isAttached()) |
| 2267 | { |
| 2268 | mState.mDepthAttachment.setInitState(InitState::Initialized); |
| 2269 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2270 | } |
| 2271 | |
| 2272 | if (stencil && mState.mStencilAttachment.isAttached()) |
| 2273 | { |
| 2274 | mState.mStencilAttachment.setInitState(InitState::Initialized); |
| 2275 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | void Framebuffer::markBufferInitialized(GLenum bufferType, GLint bufferIndex) |
| 2280 | { |
| 2281 | switch (bufferType) |
| 2282 | { |
| 2283 | case GL_COLOR: |
| 2284 | { |
| 2285 | ASSERT(bufferIndex < static_cast<GLint>(mState.mColorAttachments.size())); |
| 2286 | if (mState.mColorAttachments[bufferIndex].isAttached()) |
| 2287 | { |
| 2288 | mState.mColorAttachments[bufferIndex].setInitState(InitState::Initialized); |
| 2289 | mState.mResourceNeedsInit.reset(bufferIndex); |
| 2290 | } |
| 2291 | break; |
| 2292 | } |
| 2293 | case GL_DEPTH: |
| 2294 | { |
| 2295 | if (mState.mDepthAttachment.isAttached()) |
| 2296 | { |
| 2297 | mState.mDepthAttachment.setInitState(InitState::Initialized); |
| 2298 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2299 | } |
| 2300 | break; |
| 2301 | } |
| 2302 | case GL_STENCIL: |
| 2303 | { |
| 2304 | if (mState.mStencilAttachment.isAttached()) |
| 2305 | { |
| 2306 | mState.mStencilAttachment.setInitState(InitState::Initialized); |
| 2307 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2308 | } |
| 2309 | break; |
| 2310 | } |
| 2311 | case GL_DEPTH_STENCIL: |
| 2312 | { |
| 2313 | if (mState.mDepthAttachment.isAttached()) |
| 2314 | { |
| 2315 | mState.mDepthAttachment.setInitState(InitState::Initialized); |
| 2316 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2317 | } |
| 2318 | if (mState.mStencilAttachment.isAttached()) |
| 2319 | { |
| 2320 | mState.mStencilAttachment.setInitState(InitState::Initialized); |
| 2321 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2322 | } |
| 2323 | break; |
| 2324 | } |
| 2325 | default: |
| 2326 | UNREACHABLE(); |
| 2327 | break; |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | Box Framebuffer::getDimensions() const |
| 2332 | { |
| 2333 | return mState.getDimensions(); |
| 2334 | } |
| 2335 | |
Jonah Ryan-Davis | 7151fe5 | 2019-07-17 15:15:27 -0400 | [diff] [blame] | 2336 | Extents Framebuffer::getExtents() const |
| 2337 | { |
| 2338 | return mState.getExtents(); |
| 2339 | } |
| 2340 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 2341 | angle::Result Framebuffer::ensureBufferInitialized(const Context *context, |
| 2342 | GLenum bufferType, |
| 2343 | GLint bufferIndex) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2344 | { |
| 2345 | ASSERT(context->isRobustResourceInitEnabled()); |
| 2346 | |
| 2347 | if (mState.mResourceNeedsInit.none()) |
| 2348 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2349 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | switch (bufferType) |
| 2353 | { |
| 2354 | case GL_COLOR: |
| 2355 | { |
| 2356 | ASSERT(bufferIndex < static_cast<GLint>(mState.mColorAttachments.size())); |
| 2357 | if (mState.mResourceNeedsInit[bufferIndex]) |
| 2358 | { |
| 2359 | ANGLE_TRY(InitAttachment(context, &mState.mColorAttachments[bufferIndex])); |
| 2360 | mState.mResourceNeedsInit.reset(bufferIndex); |
| 2361 | } |
| 2362 | break; |
| 2363 | } |
| 2364 | case GL_DEPTH: |
| 2365 | { |
| 2366 | if (mState.mResourceNeedsInit[DIRTY_BIT_DEPTH_ATTACHMENT]) |
| 2367 | { |
| 2368 | ANGLE_TRY(InitAttachment(context, &mState.mDepthAttachment)); |
| 2369 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2370 | } |
| 2371 | break; |
| 2372 | } |
| 2373 | case GL_STENCIL: |
| 2374 | { |
| 2375 | if (mState.mResourceNeedsInit[DIRTY_BIT_STENCIL_ATTACHMENT]) |
| 2376 | { |
| 2377 | ANGLE_TRY(InitAttachment(context, &mState.mStencilAttachment)); |
| 2378 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2379 | } |
| 2380 | break; |
| 2381 | } |
| 2382 | case GL_DEPTH_STENCIL: |
| 2383 | { |
| 2384 | if (mState.mResourceNeedsInit[DIRTY_BIT_DEPTH_ATTACHMENT]) |
| 2385 | { |
| 2386 | ANGLE_TRY(InitAttachment(context, &mState.mDepthAttachment)); |
| 2387 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2388 | } |
| 2389 | if (mState.mResourceNeedsInit[DIRTY_BIT_STENCIL_ATTACHMENT]) |
| 2390 | { |
| 2391 | ANGLE_TRY(InitAttachment(context, &mState.mStencilAttachment)); |
| 2392 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2393 | } |
| 2394 | break; |
| 2395 | } |
| 2396 | default: |
| 2397 | UNREACHABLE(); |
| 2398 | break; |
| 2399 | } |
| 2400 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2401 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | bool Framebuffer::partialBufferClearNeedsInit(const Context *context, GLenum bufferType) |
| 2405 | { |
| 2406 | if (!context->isRobustResourceInitEnabled() || mState.mResourceNeedsInit.none()) |
| 2407 | { |
| 2408 | return false; |
| 2409 | } |
| 2410 | |
| 2411 | switch (bufferType) |
| 2412 | { |
| 2413 | case GL_COLOR: |
| 2414 | return partialClearNeedsInit(context, true, false, false); |
| 2415 | case GL_DEPTH: |
| 2416 | return partialClearNeedsInit(context, false, true, false); |
| 2417 | case GL_STENCIL: |
| 2418 | return partialClearNeedsInit(context, false, false, true); |
| 2419 | case GL_DEPTH_STENCIL: |
| 2420 | return partialClearNeedsInit(context, false, true, true); |
| 2421 | default: |
| 2422 | UNREACHABLE(); |
| 2423 | return false; |
| 2424 | } |
| 2425 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2426 | } // namespace gl |