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