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