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 | { |
| 605 | ASSERT(attachmentsHaveSameDimensions()); |
| 606 | ASSERT(getFirstNonNullAttachment() != nullptr); |
| 607 | Extents extents = getFirstNonNullAttachment()->getSize(); |
| 608 | return Box(0, 0, 0, extents.width, extents.height, extents.depth); |
| 609 | } |
| 610 | |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 611 | Framebuffer::Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id) |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 612 | : mState(caps, id), |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 613 | mImpl(factory->createFramebuffer(mState)), |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 614 | mCachedStatus(), |
| 615 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 616 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 617 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 618 | ASSERT(mImpl != nullptr); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 619 | ASSERT(mState.mColorAttachments.size() == static_cast<size_t>(caps.maxColorAttachments)); |
| 620 | |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 621 | for (uint32_t colorIndex = 0; |
| 622 | colorIndex < static_cast<uint32_t>(mState.mColorAttachments.size()); ++colorIndex) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 623 | { |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 624 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 625 | } |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 626 | } |
| 627 | |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 628 | Framebuffer::Framebuffer(const Context *context, egl::Surface *surface) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 629 | : mState(), |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 630 | mImpl(surface->getImplementation()->createDefaultFramebuffer(context, mState)), |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 631 | mCachedStatus(GL_FRAMEBUFFER_COMPLETE), |
| 632 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 633 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 634 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 635 | ASSERT(mImpl != nullptr); |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 636 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 637 | |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 638 | setAttachmentImpl(context, GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex(), surface, |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 639 | FramebufferAttachment::kDefaultNumViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 640 | FramebufferAttachment::kDefaultBaseViewIndex, false); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 641 | |
| 642 | if (surface->getConfig()->depthSize > 0) |
| 643 | { |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 644 | setAttachmentImpl(context, GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, ImageIndex(), surface, |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 645 | FramebufferAttachment::kDefaultNumViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 646 | FramebufferAttachment::kDefaultBaseViewIndex, false); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | if (surface->getConfig()->stencilSize > 0) |
| 650 | { |
Geoff Lang | bf7b95d | 2018-05-01 16:48:21 -0400 | [diff] [blame] | 651 | setAttachmentImpl(context, GL_FRAMEBUFFER_DEFAULT, GL_STENCIL, ImageIndex(), surface, |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 652 | FramebufferAttachment::kDefaultNumViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 653 | FramebufferAttachment::kDefaultBaseViewIndex, false); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 654 | } |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 655 | SetComponentTypeMask(getDrawbufferWriteType(0), 0, &mState.mDrawBufferTypeMask); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 658 | Framebuffer::Framebuffer(rx::GLImplFactory *factory) |
| 659 | : mState(), |
| 660 | mImpl(factory->createFramebuffer(mState)), |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 661 | mCachedStatus(GL_FRAMEBUFFER_UNDEFINED_OES), |
| 662 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 663 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
| 664 | { |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 665 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0); |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 666 | SetComponentTypeMask(getDrawbufferWriteType(0), 0, &mState.mDrawBufferTypeMask); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 667 | } |
| 668 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 669 | Framebuffer::~Framebuffer() |
| 670 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 671 | SafeDelete(mImpl); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 674 | void Framebuffer::onDestroy(const Context *context) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 675 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 676 | for (auto &attachment : mState.mColorAttachments) |
| 677 | { |
| 678 | attachment.detach(context); |
| 679 | } |
| 680 | mState.mDepthAttachment.detach(context); |
| 681 | mState.mStencilAttachment.detach(context); |
| 682 | mState.mWebGLDepthAttachment.detach(context); |
| 683 | mState.mWebGLStencilAttachment.detach(context); |
| 684 | mState.mWebGLDepthStencilAttachment.detach(context); |
| 685 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 686 | mImpl->destroy(context); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 687 | } |
| 688 | |
Jamie Madill | e90d4ee | 2018-11-28 14:04:00 -0500 | [diff] [blame] | 689 | void Framebuffer::setLabel(const Context *context, const std::string &label) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 690 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 691 | mState.mLabel = label; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | const std::string &Framebuffer::getLabel() const |
| 695 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 696 | return mState.mLabel; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 697 | } |
| 698 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 699 | bool Framebuffer::detachTexture(const Context *context, GLuint textureId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 700 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 701 | return detachResourceById(context, GL_TEXTURE, textureId); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 704 | bool Framebuffer::detachRenderbuffer(const Context *context, GLuint renderbufferId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 705 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 706 | return detachResourceById(context, GL_RENDERBUFFER, renderbufferId); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 707 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 708 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 709 | bool Framebuffer::detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 710 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 711 | bool found = false; |
| 712 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 713 | for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 714 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 715 | if (detachMatchingAttachment(context, &mState.mColorAttachments[colorIndex], resourceType, |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 716 | resourceId)) |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 717 | { |
| 718 | found = true; |
| 719 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 722 | if (context->isWebGL1()) |
| 723 | { |
| 724 | const std::array<FramebufferAttachment *, 3> attachments = { |
| 725 | {&mState.mWebGLDepthStencilAttachment, &mState.mWebGLDepthAttachment, |
| 726 | &mState.mWebGLStencilAttachment}}; |
| 727 | for (FramebufferAttachment *attachment : attachments) |
| 728 | { |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 729 | if (detachMatchingAttachment(context, attachment, resourceType, resourceId)) |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 730 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 731 | found = true; |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | } |
| 735 | else |
| 736 | { |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 737 | if (detachMatchingAttachment(context, &mState.mDepthAttachment, resourceType, resourceId)) |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 738 | { |
| 739 | found = true; |
| 740 | } |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 741 | if (detachMatchingAttachment(context, &mState.mStencilAttachment, resourceType, resourceId)) |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 742 | { |
| 743 | found = true; |
| 744 | } |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 745 | } |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 746 | |
| 747 | return found; |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 748 | } |
| 749 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 750 | bool Framebuffer::detachMatchingAttachment(const Context *context, |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 751 | FramebufferAttachment *attachment, |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 752 | GLenum matchType, |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 753 | GLuint matchId) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 754 | { |
| 755 | if (attachment->isAttached() && attachment->type() == matchType && attachment->id() == matchId) |
| 756 | { |
Olli Etuaho | 4ebd8f3 | 2018-09-20 11:12:46 +0300 | [diff] [blame] | 757 | // We go through resetAttachment to make sure that all the required bookkeeping will be done |
| 758 | // such as updating enabled draw buffer state. |
| 759 | resetAttachment(context, attachment->getBinding()); |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 760 | return true; |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 761 | } |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 762 | |
| 763 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 766 | const FramebufferAttachment *Framebuffer::getColorbuffer(size_t colorAttachment) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 767 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 768 | return mState.getColorAttachment(colorAttachment); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 771 | const FramebufferAttachment *Framebuffer::getDepthbuffer() const |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 772 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 773 | return mState.getDepthAttachment(); |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 774 | } |
| 775 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 776 | const FramebufferAttachment *Framebuffer::getStencilbuffer() const |
| 777 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 778 | return mState.getStencilAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 779 | } |
| 780 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 781 | const FramebufferAttachment *Framebuffer::getDepthStencilBuffer() const |
| 782 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 783 | return mState.getDepthStencilAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | const FramebufferAttachment *Framebuffer::getDepthOrStencilbuffer() const |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 787 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 788 | return mState.getDepthOrStencilAttachment(); |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 791 | const FramebufferAttachment *Framebuffer::getStencilOrDepthStencilAttachment() const |
| 792 | { |
| 793 | return mState.getStencilOrDepthStencilAttachment(); |
| 794 | } |
| 795 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 796 | const FramebufferAttachment *Framebuffer::getReadColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 797 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 798 | return mState.getReadAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 799 | } |
| 800 | |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 801 | GLenum Framebuffer::getReadColorbufferType() const |
| 802 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 803 | const FramebufferAttachment *readAttachment = mState.getReadAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 804 | return (readAttachment != nullptr ? readAttachment->type() : GL_NONE); |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 807 | const FramebufferAttachment *Framebuffer::getFirstColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 808 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 809 | return mState.getFirstColorAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Jamie Madill | 6dd06ea | 2017-07-19 13:47:55 -0400 | [diff] [blame] | 812 | const FramebufferAttachment *Framebuffer::getFirstNonNullAttachment() const |
| 813 | { |
| 814 | return mState.getFirstNonNullAttachment(); |
| 815 | } |
| 816 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 817 | const FramebufferAttachment *Framebuffer::getAttachment(const Context *context, |
| 818 | GLenum attachment) const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 819 | { |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 820 | return mState.getAttachment(context, attachment); |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 821 | } |
| 822 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 823 | size_t Framebuffer::getDrawbufferStateCount() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 824 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 825 | return mState.mDrawBufferStates.size(); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | GLenum Framebuffer::getDrawBufferState(size_t drawBuffer) const |
| 829 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 830 | ASSERT(drawBuffer < mState.mDrawBufferStates.size()); |
| 831 | return mState.mDrawBufferStates[drawBuffer]; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 834 | const std::vector<GLenum> &Framebuffer::getDrawBufferStates() const |
| 835 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 836 | return mState.getDrawBufferStates(); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 837 | } |
| 838 | |
Geoff Lang | 164d54e | 2014-12-01 10:55:33 -0500 | [diff] [blame] | 839 | 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] | 840 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 841 | auto &drawStates = mState.mDrawBufferStates; |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 842 | |
| 843 | ASSERT(count <= drawStates.size()); |
| 844 | std::copy(buffers, buffers + count, drawStates.begin()); |
| 845 | std::fill(drawStates.begin() + count, drawStates.end(), GL_NONE); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 846 | mDirtyBits.set(DIRTY_BIT_DRAW_BUFFERS); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 847 | |
| 848 | mState.mEnabledDrawBuffers.reset(); |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 849 | mState.mDrawBufferTypeMask.reset(); |
| 850 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 851 | for (size_t index = 0; index < count; ++index) |
| 852 | { |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 853 | SetComponentTypeMask(getDrawbufferWriteType(index), index, &mState.mDrawBufferTypeMask); |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 854 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 855 | if (drawStates[index] != GL_NONE && mState.mColorAttachments[index].isAttached()) |
| 856 | { |
| 857 | mState.mEnabledDrawBuffers.set(index); |
| 858 | } |
| 859 | } |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 860 | } |
| 861 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 862 | const FramebufferAttachment *Framebuffer::getDrawBuffer(size_t drawBuffer) const |
| 863 | { |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 864 | return mState.getDrawBuffer(drawBuffer); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 865 | } |
| 866 | |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 867 | ComponentType Framebuffer::getDrawbufferWriteType(size_t drawBuffer) const |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 868 | { |
| 869 | const FramebufferAttachment *attachment = mState.getDrawBuffer(drawBuffer); |
| 870 | if (attachment == nullptr) |
| 871 | { |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 872 | return ComponentType::NoType; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | GLenum componentType = attachment->getFormat().info->componentType; |
| 876 | switch (componentType) |
| 877 | { |
| 878 | case GL_INT: |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 879 | return ComponentType::Int; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 880 | case GL_UNSIGNED_INT: |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 881 | return ComponentType::UnsignedInt; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 882 | |
| 883 | default: |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 884 | return ComponentType::Float; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 888 | ComponentTypeMask Framebuffer::getDrawBufferTypeMask() const |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 889 | { |
| 890 | return mState.mDrawBufferTypeMask; |
| 891 | } |
| 892 | |
| 893 | DrawBufferMask Framebuffer::getDrawBufferMask() const |
| 894 | { |
| 895 | return mState.mEnabledDrawBuffers; |
| 896 | } |
| 897 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 898 | bool Framebuffer::hasEnabledDrawBuffer() const |
| 899 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 900 | for (size_t drawbufferIdx = 0; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 901 | { |
| 902 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
| 903 | { |
| 904 | return true; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | return false; |
| 909 | } |
| 910 | |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 911 | GLenum Framebuffer::getReadBufferState() const |
| 912 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 913 | return mState.mReadBufferState; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | void Framebuffer::setReadBuffer(GLenum buffer) |
| 917 | { |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 918 | ASSERT(buffer == GL_BACK || buffer == GL_NONE || |
| 919 | (buffer >= GL_COLOR_ATTACHMENT0 && |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 920 | (buffer - GL_COLOR_ATTACHMENT0) < mState.mColorAttachments.size())); |
| 921 | mState.mReadBufferState = buffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 922 | mDirtyBits.set(DIRTY_BIT_READ_BUFFER); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 925 | size_t Framebuffer::getNumColorBuffers() const |
| 926 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 927 | return mState.mColorAttachments.size(); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 928 | } |
| 929 | |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 930 | bool Framebuffer::hasDepth() const |
| 931 | { |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 932 | return mState.hasDepth(); |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 933 | } |
| 934 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 935 | bool Framebuffer::hasStencil() const |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 936 | { |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 937 | return mState.hasStencil(); |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 938 | } |
| 939 | |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 940 | bool Framebuffer::usingExtendedDrawBuffers() const |
| 941 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 942 | for (size_t drawbufferIdx = 1; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 943 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 944 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 945 | { |
| 946 | return true; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | return false; |
| 951 | } |
| 952 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 953 | void Framebuffer::invalidateCompletenessCache(const Context *context) |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 954 | { |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 955 | if (mState.mId != 0) |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 956 | { |
| 957 | mCachedStatus.reset(); |
| 958 | } |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 959 | onStateChange(context, angle::SubjectMessage::DirtyBitsFlagged); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 960 | } |
| 961 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 962 | GLenum Framebuffer::checkStatusImpl(const Context *context) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 963 | { |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 964 | ASSERT(!isDefault()); |
| 965 | ASSERT(hasAnyDirtyBit() || !mCachedStatus.valid()); |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 966 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 967 | mCachedStatus = checkStatusWithGLFrontEnd(context); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 968 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 969 | if (mCachedStatus.value() == GL_FRAMEBUFFER_COMPLETE) |
| 970 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame^] | 971 | // We can skip syncState on several back-ends. |
| 972 | if (mImpl->shouldSyncStateBeforeCheckStatus()) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 973 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame^] | 974 | angle::Result err = syncState(context); |
| 975 | if (err != angle::Result::Continue) |
| 976 | { |
| 977 | return 0; |
| 978 | } |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 979 | } |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame^] | 980 | |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 981 | if (!mImpl->checkStatus(context)) |
| 982 | { |
| 983 | mCachedStatus = GL_FRAMEBUFFER_UNSUPPORTED; |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 984 | } |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 985 | } |
| 986 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 987 | return mCachedStatus.value(); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 988 | } |
| 989 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 990 | GLenum Framebuffer::checkStatusWithGLFrontEnd(const Context *context) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 991 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 992 | const State &state = context->getState(); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 993 | |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 994 | ASSERT(mState.mId != 0); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 995 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 996 | bool hasAttachments = false; |
| 997 | Optional<unsigned int> colorbufferSize; |
| 998 | Optional<int> samples; |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 999 | Optional<bool> fixedSampleLocations; |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1000 | bool hasRenderbuffer = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1001 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1002 | const FramebufferAttachment *firstAttachment = getFirstNonNullAttachment(); |
| 1003 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 1004 | Optional<bool> isLayered; |
| 1005 | Optional<TextureType> colorAttachmentsTextureType; |
| 1006 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1007 | for (const FramebufferAttachment &colorAttachment : mState.mColorAttachments) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1008 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1009 | if (colorAttachment.isAttached()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1010 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 1011 | if (!CheckAttachmentCompleteness(context, colorAttachment)) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1012 | { |
| 1013 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1014 | } |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 1015 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1016 | const InternalFormat &format = *colorAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1017 | if (format.depthBits > 0 || format.stencilBits > 0) |
| 1018 | { |
| 1019 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1020 | } |
| 1021 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1022 | if (!CheckAttachmentSampleCompleteness(context, colorAttachment, true, &samples, |
| 1023 | &fixedSampleLocations)) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1024 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1025 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1028 | // in GLES 2.0, all color attachments attachments must have the same number of bitplanes |
| 1029 | // in GLES 3.0, there is no such restriction |
| 1030 | if (state.getClientMajorVersion() < 3) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1031 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1032 | if (colorbufferSize.valid()) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1033 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1034 | if (format.pixelBytes != colorbufferSize.value()) |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 1035 | { |
| 1036 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 1037 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1038 | } |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1039 | else |
| 1040 | { |
| 1041 | colorbufferSize = format.pixelBytes; |
| 1042 | } |
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 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1045 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &colorAttachment)) |
| 1046 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1047 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR; |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1048 | } |
| 1049 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1050 | hasRenderbuffer = hasRenderbuffer || (colorAttachment.type() == GL_RENDERBUFFER); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 1051 | |
| 1052 | if (!hasAttachments) |
| 1053 | { |
| 1054 | isLayered = colorAttachment.isLayered(); |
| 1055 | if (isLayered.value()) |
| 1056 | { |
| 1057 | colorAttachmentsTextureType = colorAttachment.getTextureImageIndex().getType(); |
| 1058 | } |
| 1059 | hasAttachments = true; |
| 1060 | } |
| 1061 | else |
| 1062 | { |
| 1063 | // [EXT_geometry_shader] section 9.4.1, "Framebuffer Completeness" |
| 1064 | // If any framebuffer attachment is layered, all populated attachments |
| 1065 | // must be layered. Additionally, all populated color attachments must |
| 1066 | // be from textures of the same target. {FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT } |
| 1067 | ASSERT(isLayered.valid()); |
| 1068 | if (isLayered.value() != colorAttachment.isLayered()) |
| 1069 | { |
| 1070 | return GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT; |
| 1071 | } |
| 1072 | else if (isLayered.value()) |
| 1073 | { |
| 1074 | ASSERT(colorAttachmentsTextureType.valid()); |
| 1075 | if (colorAttachmentsTextureType.value() != |
| 1076 | colorAttachment.getTextureImageIndex().getType()) |
| 1077 | { |
| 1078 | return GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT; |
| 1079 | } |
| 1080 | } |
| 1081 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1082 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1085 | const FramebufferAttachment &depthAttachment = mState.mDepthAttachment; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1086 | if (depthAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1087 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 1088 | if (!CheckAttachmentCompleteness(context, depthAttachment)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1089 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1090 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1093 | const InternalFormat &format = *depthAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1094 | if (format.depthBits == 0) |
| 1095 | { |
| 1096 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1099 | if (!CheckAttachmentSampleCompleteness(context, depthAttachment, false, &samples, |
| 1100 | &fixedSampleLocations)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1101 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1102 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1103 | } |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1104 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1105 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &depthAttachment)) |
| 1106 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1107 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR; |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1108 | } |
| 1109 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1110 | hasRenderbuffer = hasRenderbuffer || (depthAttachment.type() == GL_RENDERBUFFER); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 1111 | |
| 1112 | if (!hasAttachments) |
| 1113 | { |
| 1114 | isLayered = depthAttachment.isLayered(); |
| 1115 | hasAttachments = true; |
| 1116 | } |
| 1117 | else |
| 1118 | { |
| 1119 | // [EXT_geometry_shader] section 9.4.1, "Framebuffer Completeness" |
| 1120 | // If any framebuffer attachment is layered, all populated attachments |
| 1121 | // must be layered. {FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT } |
| 1122 | ASSERT(isLayered.valid()); |
| 1123 | if (isLayered.value() != depthAttachment.isLayered()) |
| 1124 | { |
| 1125 | return GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT; |
| 1126 | } |
| 1127 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1130 | const FramebufferAttachment &stencilAttachment = mState.mStencilAttachment; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1131 | if (stencilAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1132 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 1133 | if (!CheckAttachmentCompleteness(context, stencilAttachment)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1134 | { |
| 1135 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1136 | } |
| 1137 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1138 | const InternalFormat &format = *stencilAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1139 | if (format.stencilBits == 0) |
| 1140 | { |
| 1141 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1144 | if (!CheckAttachmentSampleCompleteness(context, stencilAttachment, false, &samples, |
| 1145 | &fixedSampleLocations)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1146 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1147 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1148 | } |
Corentin Wallez | 086d59a | 2016-04-29 09:06:49 -0400 | [diff] [blame] | 1149 | |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1150 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, &stencilAttachment)) |
| 1151 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1152 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR; |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1153 | } |
| 1154 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1155 | hasRenderbuffer = hasRenderbuffer || (stencilAttachment.type() == GL_RENDERBUFFER); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 1156 | |
| 1157 | if (!hasAttachments) |
| 1158 | { |
| 1159 | hasAttachments = true; |
| 1160 | } |
| 1161 | else |
| 1162 | { |
| 1163 | // [EXT_geometry_shader] section 9.4.1, "Framebuffer Completeness" |
| 1164 | // If any framebuffer attachment is layered, all populated attachments |
| 1165 | // must be layered. |
| 1166 | // {FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT } |
| 1167 | ASSERT(isLayered.valid()); |
| 1168 | if (isLayered.value() != stencilAttachment.isLayered()) |
| 1169 | { |
| 1170 | return GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT; |
| 1171 | } |
| 1172 | } |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | // Starting from ES 3.0 stencil and depth, if present, should be the same image |
| 1176 | if (state.getClientMajorVersion() >= 3 && depthAttachment.isAttached() && |
| 1177 | stencilAttachment.isAttached() && stencilAttachment != depthAttachment) |
| 1178 | { |
| 1179 | return GL_FRAMEBUFFER_UNSUPPORTED; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1182 | // Special additional validation for WebGL 1 DEPTH/STENCIL/DEPTH_STENCIL. |
| 1183 | if (state.isWebGL1()) |
| 1184 | { |
| 1185 | if (!mState.mWebGLDepthStencilConsistent) |
| 1186 | { |
| 1187 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 1188 | } |
| 1189 | |
| 1190 | if (mState.mWebGLDepthStencilAttachment.isAttached()) |
| 1191 | { |
| 1192 | if (mState.mWebGLDepthStencilAttachment.getDepthSize() == 0 || |
| 1193 | mState.mWebGLDepthStencilAttachment.getStencilSize() == 0) |
| 1194 | { |
| 1195 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1196 | } |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1197 | |
| 1198 | if (!CheckMultiviewStateMatchesForCompleteness(firstAttachment, |
| 1199 | &mState.mWebGLDepthStencilAttachment)) |
| 1200 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1201 | return GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR; |
Martin Radev | 9bc9a32 | 2017-07-21 14:28:17 +0300 | [diff] [blame] | 1202 | } |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1203 | } |
| 1204 | else if (mState.mStencilAttachment.isAttached() && |
| 1205 | mState.mStencilAttachment.getDepthSize() > 0) |
| 1206 | { |
| 1207 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1208 | } |
| 1209 | else if (mState.mDepthAttachment.isAttached() && |
| 1210 | mState.mDepthAttachment.getStencilSize() > 0) |
| 1211 | { |
| 1212 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 1213 | } |
| 1214 | } |
| 1215 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1216 | // ES3.1(section 9.4) requires that if no image is attached to the framebuffer, and either the |
| 1217 | // value of the framebuffer's FRAMEBUFFER_DEFAULT_WIDTH or FRAMEBUFFER_DEFAULT_HEIGHT parameters |
| 1218 | // is zero, the framebuffer is considered incomplete. |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 1219 | GLint defaultWidth = mState.getDefaultWidth(); |
| 1220 | GLint defaultHeight = mState.getDefaultHeight(); |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1221 | if (!hasAttachments && (defaultWidth == 0 || defaultHeight == 0)) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 1222 | { |
| 1223 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 1226 | // 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] | 1227 | // In ES 3.0, there is no such restriction. |
Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 1228 | if ((state.getClientMajorVersion() < 3 || state.getExtensions().webglCompatibility) && |
| 1229 | !mState.attachmentsHaveSameDimensions()) |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 1230 | { |
| 1231 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 1232 | } |
| 1233 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 1234 | // ES3.1(section 9.4) requires that if the attached images are a mix of renderbuffers and |
| 1235 | // 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] | 1236 | if (fixedSampleLocations.valid() && hasRenderbuffer && !fixedSampleLocations.value()) |
| 1237 | { |
| 1238 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| 1239 | } |
| 1240 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 1241 | // The WebGL conformance tests implicitly define that all framebuffer |
| 1242 | // attachments must be unique. For example, the same level of a texture can |
| 1243 | // not be attached to two different color attachments. |
| 1244 | if (state.getExtensions().webglCompatibility) |
| 1245 | { |
| 1246 | if (!mState.colorAttachmentsAreUniqueImages()) |
| 1247 | { |
| 1248 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 1249 | } |
| 1250 | } |
| 1251 | |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 1252 | return GL_FRAMEBUFFER_COMPLETE; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1253 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 1254 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1255 | 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] | 1256 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1257 | // Back-ends might make the contents of the FBO undefined. In WebGL 2.0, invalidate operations |
| 1258 | // can be no-ops, so we should probably do that to ensure consistency. |
| 1259 | // TODO(jmadill): WebGL behaviour, and robust resource init behaviour without WebGL. |
| 1260 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1261 | return mImpl->discard(context, count, attachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1264 | angle::Result Framebuffer::invalidate(const Context *context, |
| 1265 | size_t count, |
| 1266 | const GLenum *attachments) |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 1267 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1268 | // Back-ends might make the contents of the FBO undefined. In WebGL 2.0, invalidate operations |
| 1269 | // can be no-ops, so we should probably do that to ensure consistency. |
| 1270 | // TODO(jmadill): WebGL behaviour, and robust resource init behaviour without WebGL. |
| 1271 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1272 | return mImpl->invalidate(context, count, attachments); |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1275 | bool Framebuffer::partialClearNeedsInit(const Context *context, |
| 1276 | bool color, |
| 1277 | bool depth, |
| 1278 | bool stencil) |
| 1279 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1280 | const auto &glState = context->getState(); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1281 | |
| 1282 | if (!glState.isRobustResourceInitEnabled()) |
| 1283 | { |
| 1284 | return false; |
| 1285 | } |
| 1286 | |
| 1287 | // Scissors can affect clearing. |
| 1288 | // TODO(jmadill): Check for complete scissor overlap. |
| 1289 | if (glState.isScissorTestEnabled()) |
| 1290 | { |
| 1291 | return true; |
| 1292 | } |
| 1293 | |
| 1294 | // If colors masked, we must clear before we clear. Do a simple check. |
| 1295 | // TODO(jmadill): Filter out unused color channels from the test. |
| 1296 | if (color) |
| 1297 | { |
| 1298 | const auto &blend = glState.getBlendState(); |
| 1299 | if (!(blend.colorMaskRed && blend.colorMaskGreen && blend.colorMaskBlue && |
| 1300 | blend.colorMaskAlpha)) |
| 1301 | { |
| 1302 | return true; |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | const auto &depthStencil = glState.getDepthStencilState(); |
Yuly Novikov | 21edf3d | 2018-07-23 16:44:16 -0400 | [diff] [blame] | 1307 | if (stencil && (depthStencil.stencilMask != depthStencil.stencilWritemask || |
| 1308 | depthStencil.stencilBackMask != depthStencil.stencilBackWritemask)) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1309 | { |
| 1310 | return true; |
| 1311 | } |
| 1312 | |
| 1313 | return false; |
| 1314 | } |
| 1315 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1316 | angle::Result Framebuffer::invalidateSub(const Context *context, |
| 1317 | size_t count, |
| 1318 | const GLenum *attachments, |
| 1319 | const Rectangle &area) |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 1320 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1321 | // Back-ends might make the contents of the FBO undefined. In WebGL 2.0, invalidate operations |
| 1322 | // can be no-ops, so we should probably do that to ensure consistency. |
| 1323 | // TODO(jmadill): Make a invalidate no-op in WebGL 2.0. |
| 1324 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1325 | return mImpl->invalidateSub(context, count, attachments, area); |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 1326 | } |
| 1327 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1328 | angle::Result Framebuffer::clear(const Context *context, GLbitfield mask) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1329 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1330 | const auto &glState = context->getState(); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1331 | if (glState.isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1332 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1333 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1334 | } |
| 1335 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1336 | // Remove clear bits that are ineffective. An effective clear changes at least one fragment. If |
| 1337 | // color/depth/stencil masks make the clear ineffective we skip it altogether. |
| 1338 | |
| 1339 | // If all color channels are masked, don't attempt to clear color. |
| 1340 | if (context->getState().getBlendState().allChannelsMasked()) |
| 1341 | { |
| 1342 | mask &= ~GL_COLOR_BUFFER_BIT; |
| 1343 | } |
| 1344 | |
| 1345 | // If depth write is disabled, don't attempt to clear depth. |
| 1346 | if (!context->getState().getDepthStencilState().depthMask) |
| 1347 | { |
| 1348 | mask &= ~GL_DEPTH_BUFFER_BIT; |
| 1349 | } |
| 1350 | |
| 1351 | // If all stencil bits are masked, don't attempt to clear stencil. |
| 1352 | if (context->getState().getDepthStencilState().stencilWritemask == 0) |
| 1353 | { |
| 1354 | mask &= ~GL_STENCIL_BUFFER_BIT; |
| 1355 | } |
| 1356 | |
| 1357 | if (mask != 0) |
| 1358 | { |
| 1359 | ANGLE_TRY(mImpl->clear(context, mask)); |
| 1360 | } |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1361 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1362 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1363 | } |
| 1364 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1365 | angle::Result Framebuffer::clearBufferfv(const Context *context, |
| 1366 | GLenum buffer, |
| 1367 | GLint drawbuffer, |
| 1368 | const GLfloat *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1369 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1370 | if (context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1371 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1372 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1373 | } |
| 1374 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1375 | if (buffer == GL_DEPTH) |
| 1376 | { |
| 1377 | // If depth write is disabled, don't attempt to clear depth. |
| 1378 | if (!context->getState().getDepthStencilState().depthMask) |
| 1379 | { |
| 1380 | return angle::Result::Continue; |
| 1381 | } |
| 1382 | } |
| 1383 | else |
| 1384 | { |
| 1385 | // If all color channels are masked, don't attempt to clear color. |
| 1386 | if (context->getState().getBlendState().allChannelsMasked()) |
| 1387 | { |
| 1388 | return angle::Result::Continue; |
| 1389 | } |
| 1390 | } |
| 1391 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1392 | ANGLE_TRY(mImpl->clearBufferfv(context, buffer, drawbuffer, values)); |
| 1393 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1394 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1395 | } |
| 1396 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1397 | angle::Result Framebuffer::clearBufferuiv(const Context *context, |
| 1398 | GLenum buffer, |
| 1399 | GLint drawbuffer, |
| 1400 | const GLuint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1401 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1402 | if (context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1403 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1404 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1405 | } |
| 1406 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1407 | // If all color channels are masked, don't attempt to clear color. |
| 1408 | if (context->getState().getBlendState().allChannelsMasked()) |
| 1409 | { |
| 1410 | return angle::Result::Continue; |
| 1411 | } |
| 1412 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1413 | ANGLE_TRY(mImpl->clearBufferuiv(context, buffer, drawbuffer, values)); |
| 1414 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1415 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1416 | } |
| 1417 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1418 | angle::Result Framebuffer::clearBufferiv(const Context *context, |
| 1419 | GLenum buffer, |
| 1420 | GLint drawbuffer, |
| 1421 | const GLint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1422 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1423 | if (context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1424 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1425 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1426 | } |
| 1427 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1428 | if (buffer == GL_STENCIL) |
| 1429 | { |
| 1430 | // If all stencil bits are masked, don't attempt to clear stencil. |
| 1431 | if (context->getState().getDepthStencilState().stencilWritemask == 0) |
| 1432 | { |
| 1433 | return angle::Result::Continue; |
| 1434 | } |
| 1435 | } |
| 1436 | else |
| 1437 | { |
| 1438 | // If all color channels are masked, don't attempt to clear color. |
| 1439 | if (context->getState().getBlendState().allChannelsMasked()) |
| 1440 | { |
| 1441 | return angle::Result::Continue; |
| 1442 | } |
| 1443 | } |
| 1444 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1445 | ANGLE_TRY(mImpl->clearBufferiv(context, buffer, drawbuffer, values)); |
| 1446 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1447 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1448 | } |
| 1449 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1450 | angle::Result Framebuffer::clearBufferfi(const Context *context, |
| 1451 | GLenum buffer, |
| 1452 | GLint drawbuffer, |
| 1453 | GLfloat depth, |
| 1454 | GLint stencil) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1455 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1456 | if (context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1457 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1458 | return angle::Result::Continue; |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1459 | } |
| 1460 | |
Shahbaz Youssefi | f6c937f | 2019-04-02 17:04:08 -0400 | [diff] [blame] | 1461 | bool clearDepth = context->getState().getDepthStencilState().depthMask; |
| 1462 | bool clearStencil = context->getState().getDepthStencilState().stencilWritemask != 0; |
| 1463 | |
| 1464 | if (clearDepth && clearStencil) |
| 1465 | { |
| 1466 | ASSERT(buffer == GL_DEPTH_STENCIL); |
| 1467 | ANGLE_TRY(mImpl->clearBufferfi(context, GL_DEPTH_STENCIL, drawbuffer, depth, stencil)); |
| 1468 | } |
| 1469 | else if (clearDepth && !clearStencil) |
| 1470 | { |
| 1471 | ANGLE_TRY(mImpl->clearBufferfv(context, GL_DEPTH, drawbuffer, &depth)); |
| 1472 | } |
| 1473 | else if (!clearDepth && clearStencil) |
| 1474 | { |
| 1475 | ANGLE_TRY(mImpl->clearBufferiv(context, GL_STENCIL, drawbuffer, &stencil)); |
| 1476 | } |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1477 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1478 | return angle::Result::Continue; |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1479 | } |
| 1480 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1481 | angle::Result Framebuffer::getImplementationColorReadFormat(const Context *context, |
| 1482 | GLenum *formatOut) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1483 | { |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 1484 | ANGLE_TRY(syncState(context)); |
| 1485 | *formatOut = mImpl->getImplementationColorReadFormat(context); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1486 | return angle::Result::Continue; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1487 | } |
| 1488 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1489 | angle::Result Framebuffer::getImplementationColorReadType(const Context *context, GLenum *typeOut) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1490 | { |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 1491 | ANGLE_TRY(syncState(context)); |
| 1492 | *typeOut = mImpl->getImplementationColorReadType(context); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1493 | return angle::Result::Continue; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1494 | } |
| 1495 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1496 | angle::Result Framebuffer::readPixels(const Context *context, |
| 1497 | const Rectangle &area, |
| 1498 | GLenum format, |
| 1499 | GLenum type, |
| 1500 | void *pixels) |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1501 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1502 | ANGLE_TRY(mImpl->readPixels(context, area, format, type, pixels)); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1503 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1504 | Buffer *unpackBuffer = context->getState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1505 | if (unpackBuffer) |
| 1506 | { |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 1507 | unpackBuffer->onPixelPack(context); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1508 | } |
| 1509 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1510 | return angle::Result::Continue; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1511 | } |
| 1512 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1513 | angle::Result Framebuffer::blit(const Context *context, |
| 1514 | const Rectangle &sourceArea, |
| 1515 | const Rectangle &destArea, |
| 1516 | GLbitfield mask, |
| 1517 | GLenum filter) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 1518 | { |
He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 1519 | GLbitfield blitMask = mask; |
| 1520 | |
| 1521 | // Note that blitting is called against draw framebuffer. |
| 1522 | // See the code in gl::Context::blitFramebuffer. |
| 1523 | if ((mask & GL_COLOR_BUFFER_BIT) && !hasEnabledDrawBuffer()) |
| 1524 | { |
| 1525 | blitMask &= ~GL_COLOR_BUFFER_BIT; |
| 1526 | } |
| 1527 | |
| 1528 | if ((mask & GL_STENCIL_BUFFER_BIT) && mState.getStencilAttachment() == nullptr) |
| 1529 | { |
| 1530 | blitMask &= ~GL_STENCIL_BUFFER_BIT; |
| 1531 | } |
| 1532 | |
| 1533 | if ((mask & GL_DEPTH_BUFFER_BIT) && mState.getDepthAttachment() == nullptr) |
| 1534 | { |
| 1535 | blitMask &= ~GL_DEPTH_BUFFER_BIT; |
| 1536 | } |
| 1537 | |
| 1538 | if (!blitMask) |
| 1539 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1540 | return angle::Result::Continue; |
He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | return mImpl->blit(context, sourceArea, destArea, blitMask, filter); |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 1544 | } |
| 1545 | |
Luc Ferron | bf6dc37 | 2018-06-28 15:24:19 -0400 | [diff] [blame] | 1546 | bool Framebuffer::isDefault() const |
| 1547 | { |
| 1548 | return id() == 0; |
| 1549 | } |
| 1550 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1551 | int Framebuffer::getSamples(const Context *context) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1552 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1553 | return (isComplete(context) ? getCachedSamples(context) : 0); |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 1556 | int Framebuffer::getCachedSamples(const Context *context) |
| 1557 | { |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1558 | ASSERT(mCachedStatus.valid() && mCachedStatus.value() == GL_FRAMEBUFFER_COMPLETE); |
| 1559 | |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame] | 1560 | // For a complete framebuffer, all attachments must have the same sample count. |
| 1561 | // In this case return the first nonzero sample size. |
| 1562 | const auto *firstNonNullAttachment = mState.getFirstNonNullAttachment(); |
| 1563 | if (firstNonNullAttachment) |
| 1564 | { |
| 1565 | ASSERT(firstNonNullAttachment->isAttached()); |
| 1566 | return firstNonNullAttachment->getSamples(); |
| 1567 | } |
| 1568 | |
| 1569 | // No attachments found. |
| 1570 | return 0; |
| 1571 | } |
| 1572 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 1573 | angle::Result Framebuffer::getSamplePosition(const Context *context, |
| 1574 | size_t index, |
| 1575 | GLfloat *xy) const |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1576 | { |
Geoff Lang | 1345507 | 2018-05-09 11:24:43 -0400 | [diff] [blame] | 1577 | ANGLE_TRY(mImpl->getSamplePosition(context, index, xy)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1578 | return angle::Result::Continue; |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1579 | } |
| 1580 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 1581 | bool Framebuffer::hasValidDepthStencil() const |
| 1582 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1583 | return mState.getDepthStencilAttachment() != nullptr; |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 1584 | } |
| 1585 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1586 | void Framebuffer::setAttachment(const Context *context, |
| 1587 | GLenum type, |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1588 | GLenum binding, |
| 1589 | const ImageIndex &textureIndex, |
| 1590 | FramebufferAttachmentObject *resource) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 1591 | { |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1592 | setAttachment(context, type, binding, textureIndex, resource, |
| 1593 | FramebufferAttachment::kDefaultNumViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1594 | FramebufferAttachment::kDefaultBaseViewIndex, false); |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | void Framebuffer::setAttachment(const Context *context, |
| 1598 | GLenum type, |
| 1599 | GLenum binding, |
| 1600 | const ImageIndex &textureIndex, |
| 1601 | FramebufferAttachmentObject *resource, |
| 1602 | GLsizei numViews, |
| 1603 | GLuint baseViewIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1604 | bool isMultiview) |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1605 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1606 | // Context may be null in unit tests. |
| 1607 | if (!context || !context->isWebGL1()) |
| 1608 | { |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1609 | setAttachmentImpl(context, type, binding, textureIndex, resource, numViews, baseViewIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1610 | isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1611 | return; |
| 1612 | } |
| 1613 | |
| 1614 | switch (binding) |
| 1615 | { |
| 1616 | case GL_DEPTH_STENCIL: |
| 1617 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1618 | mState.mWebGLDepthStencilAttachment.attach(context, type, binding, textureIndex, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1619 | resource, numViews, baseViewIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1620 | isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1621 | break; |
| 1622 | case GL_DEPTH: |
| 1623 | case GL_DEPTH_ATTACHMENT: |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1624 | mState.mWebGLDepthAttachment.attach(context, type, binding, textureIndex, resource, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1625 | numViews, baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1626 | break; |
| 1627 | case GL_STENCIL: |
| 1628 | case GL_STENCIL_ATTACHMENT: |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1629 | mState.mWebGLStencilAttachment.attach(context, type, binding, textureIndex, resource, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1630 | numViews, baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1631 | break; |
| 1632 | default: |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1633 | setAttachmentImpl(context, type, binding, textureIndex, resource, numViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1634 | baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1635 | return; |
| 1636 | } |
| 1637 | |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1638 | commitWebGL1DepthStencilIfConsistent(context, numViews, baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1639 | } |
| 1640 | |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1641 | void Framebuffer::setAttachmentMultiview(const Context *context, |
| 1642 | GLenum type, |
| 1643 | GLenum binding, |
| 1644 | const ImageIndex &textureIndex, |
| 1645 | FramebufferAttachmentObject *resource, |
| 1646 | GLsizei numViews, |
| 1647 | GLint baseViewIndex) |
Martin Radev | 82ef774 | 2017-08-08 17:44:58 +0300 | [diff] [blame] | 1648 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1649 | setAttachment(context, type, binding, textureIndex, resource, numViews, baseViewIndex, true); |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | void Framebuffer::commitWebGL1DepthStencilIfConsistent(const Context *context, |
| 1653 | GLsizei numViews, |
| 1654 | GLuint baseViewIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1655 | bool isMultiview) |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1656 | { |
| 1657 | int count = 0; |
| 1658 | |
| 1659 | std::array<FramebufferAttachment *, 3> attachments = {{&mState.mWebGLDepthStencilAttachment, |
| 1660 | &mState.mWebGLDepthAttachment, |
| 1661 | &mState.mWebGLStencilAttachment}}; |
| 1662 | for (FramebufferAttachment *attachment : attachments) |
| 1663 | { |
| 1664 | if (attachment->isAttached()) |
| 1665 | { |
| 1666 | count++; |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | mState.mWebGLDepthStencilConsistent = (count <= 1); |
| 1671 | if (!mState.mWebGLDepthStencilConsistent) |
| 1672 | { |
| 1673 | // Inconsistent. |
| 1674 | return; |
| 1675 | } |
| 1676 | |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1677 | auto getImageIndexIfTextureAttachment = [](const FramebufferAttachment &attachment) { |
| 1678 | if (attachment.type() == GL_TEXTURE) |
| 1679 | { |
| 1680 | return attachment.getTextureImageIndex(); |
| 1681 | } |
| 1682 | else |
| 1683 | { |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1684 | return ImageIndex(); |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1685 | } |
| 1686 | }; |
| 1687 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1688 | if (mState.mWebGLDepthAttachment.isAttached()) |
| 1689 | { |
| 1690 | const auto &depth = mState.mWebGLDepthAttachment; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1691 | setAttachmentImpl(context, depth.type(), GL_DEPTH_ATTACHMENT, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1692 | getImageIndexIfTextureAttachment(depth), depth.getResource(), numViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1693 | baseViewIndex, isMultiview); |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1694 | setAttachmentImpl(context, GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex(), nullptr, numViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1695 | baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1696 | } |
| 1697 | else if (mState.mWebGLStencilAttachment.isAttached()) |
| 1698 | { |
| 1699 | const auto &stencil = mState.mWebGLStencilAttachment; |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1700 | setAttachmentImpl(context, GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex(), nullptr, numViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1701 | baseViewIndex, isMultiview); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1702 | setAttachmentImpl(context, stencil.type(), GL_STENCIL_ATTACHMENT, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1703 | getImageIndexIfTextureAttachment(stencil), stencil.getResource(), |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1704 | numViews, baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1705 | } |
| 1706 | else if (mState.mWebGLDepthStencilAttachment.isAttached()) |
| 1707 | { |
| 1708 | const auto &depthStencil = mState.mWebGLDepthStencilAttachment; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1709 | setAttachmentImpl(context, depthStencil.type(), GL_DEPTH_ATTACHMENT, |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1710 | getImageIndexIfTextureAttachment(depthStencil), |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1711 | depthStencil.getResource(), numViews, baseViewIndex, isMultiview); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1712 | setAttachmentImpl(context, depthStencil.type(), GL_STENCIL_ATTACHMENT, |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1713 | getImageIndexIfTextureAttachment(depthStencil), |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1714 | depthStencil.getResource(), numViews, baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1715 | } |
| 1716 | else |
| 1717 | { |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1718 | setAttachmentImpl(context, GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex(), nullptr, numViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1719 | baseViewIndex, isMultiview); |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1720 | setAttachmentImpl(context, GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex(), nullptr, numViews, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1721 | baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1722 | } |
| 1723 | } |
| 1724 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1725 | void Framebuffer::setAttachmentImpl(const Context *context, |
| 1726 | GLenum type, |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1727 | GLenum binding, |
| 1728 | const ImageIndex &textureIndex, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1729 | FramebufferAttachmentObject *resource, |
| 1730 | GLsizei numViews, |
| 1731 | GLuint baseViewIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1732 | bool isMultiview) |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1733 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1734 | switch (binding) |
| 1735 | { |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1736 | case GL_DEPTH_STENCIL: |
| 1737 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1738 | { |
| 1739 | // ensure this is a legitimate depth+stencil format |
| 1740 | FramebufferAttachmentObject *attachmentObj = resource; |
| 1741 | if (resource) |
| 1742 | { |
Jamie Madill | 4fd95d5 | 2017-04-05 11:22:18 -0400 | [diff] [blame] | 1743 | const Format &format = resource->getAttachmentFormat(binding, textureIndex); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1744 | if (format.info->depthBits == 0 || format.info->stencilBits == 0) |
| 1745 | { |
| 1746 | // Attaching nullptr detaches the current attachment. |
| 1747 | attachmentObj = nullptr; |
| 1748 | } |
| 1749 | } |
| 1750 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1751 | updateAttachment(context, &mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1752 | &mDirtyDepthAttachmentBinding, type, binding, textureIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1753 | attachmentObj, numViews, baseViewIndex, isMultiview); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1754 | updateAttachment(context, &mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1755 | &mDirtyStencilAttachmentBinding, type, binding, textureIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1756 | attachmentObj, numViews, baseViewIndex, isMultiview); |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 1757 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1758 | } |
| 1759 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1760 | case GL_DEPTH: |
| 1761 | case GL_DEPTH_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1762 | updateAttachment(context, &mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1763 | &mDirtyDepthAttachmentBinding, type, binding, textureIndex, resource, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1764 | numViews, baseViewIndex, isMultiview); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1765 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1766 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1767 | case GL_STENCIL: |
| 1768 | case GL_STENCIL_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1769 | updateAttachment(context, &mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1770 | &mDirtyStencilAttachmentBinding, type, binding, textureIndex, resource, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1771 | numViews, baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1772 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1773 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1774 | case GL_BACK: |
Geoff Lang | 8170eab | 2017-09-21 13:59:04 -0400 | [diff] [blame] | 1775 | updateAttachment(context, &mState.mColorAttachments[0], DIRTY_BIT_COLOR_ATTACHMENT_0, |
| 1776 | &mDirtyColorAttachmentBindings[0], type, binding, textureIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1777 | resource, numViews, baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1778 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1779 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1780 | default: |
| 1781 | { |
| 1782 | size_t colorIndex = binding - GL_COLOR_ATTACHMENT0; |
| 1783 | ASSERT(colorIndex < mState.mColorAttachments.size()); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1784 | size_t dirtyBit = DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1785 | updateAttachment(context, &mState.mColorAttachments[colorIndex], dirtyBit, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1786 | &mDirtyColorAttachmentBindings[colorIndex], type, binding, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1787 | textureIndex, resource, numViews, baseViewIndex, isMultiview); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1788 | |
shrekshao | c87e005 | 2019-02-21 11:40:28 -0800 | [diff] [blame] | 1789 | if (!resource) |
| 1790 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1791 | mColorAttachmentBits.reset(colorIndex); |
shrekshao | c87e005 | 2019-02-21 11:40:28 -0800 | [diff] [blame] | 1792 | mFloat32ColorAttachmentBits.reset(colorIndex); |
| 1793 | } |
| 1794 | else |
| 1795 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1796 | mColorAttachmentBits.set(colorIndex); |
shrekshao | c87e005 | 2019-02-21 11:40:28 -0800 | [diff] [blame] | 1797 | updateFloat32ColorAttachmentBits( |
| 1798 | colorIndex, resource->getAttachmentFormat(binding, textureIndex).info); |
| 1799 | } |
| 1800 | |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 1801 | // TODO(jmadill): ASSERT instead of checking the attachment exists in |
| 1802 | // formsRenderingFeedbackLoopWith |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1803 | bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE); |
| 1804 | mState.mEnabledDrawBuffers.set(colorIndex, enabled); |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame] | 1805 | SetComponentTypeMask(getDrawbufferWriteType(colorIndex), colorIndex, |
| 1806 | &mState.mDrawBufferTypeMask); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1807 | } |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1808 | break; |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1812 | void Framebuffer::updateAttachment(const Context *context, |
| 1813 | FramebufferAttachment *attachment, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1814 | size_t dirtyBit, |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1815 | angle::ObserverBinding *onDirtyBinding, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1816 | GLenum type, |
| 1817 | GLenum binding, |
| 1818 | const ImageIndex &textureIndex, |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1819 | FramebufferAttachmentObject *resource, |
| 1820 | GLsizei numViews, |
| 1821 | GLuint baseViewIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1822 | bool isMultiview) |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1823 | { |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 1824 | attachment->attach(context, type, binding, textureIndex, resource, numViews, baseViewIndex, |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 1825 | isMultiview); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1826 | mDirtyBits.set(dirtyBit); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1827 | mState.mResourceNeedsInit.set(dirtyBit, attachment->initState() == InitState::MayNeedInit); |
Jamie Madill | 66f0d2c | 2018-11-30 15:25:36 -0500 | [diff] [blame] | 1828 | onDirtyBinding->bind(resource); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1829 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 1830 | invalidateCompletenessCache(context); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1831 | } |
| 1832 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1833 | void Framebuffer::resetAttachment(const Context *context, GLenum binding) |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1834 | { |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1835 | setAttachment(context, GL_NONE, binding, ImageIndex(), nullptr); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1836 | } |
| 1837 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 1838 | angle::Result Framebuffer::syncState(const Context *context) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1839 | { |
| 1840 | if (mDirtyBits.any()) |
| 1841 | { |
Jamie Madill | 888081d | 2018-02-27 00:24:46 -0500 | [diff] [blame] | 1842 | mDirtyBitsGuard = mDirtyBits; |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 1843 | ANGLE_TRY(mImpl->syncState(context, mDirtyBits)); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1844 | mDirtyBits.reset(); |
Jamie Madill | 888081d | 2018-02-27 00:24:46 -0500 | [diff] [blame] | 1845 | mDirtyBitsGuard.reset(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1846 | } |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1847 | return angle::Result::Continue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1848 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1849 | |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1850 | void Framebuffer::onSubjectStateChange(const Context *context, |
| 1851 | angle::SubjectIndex index, |
| 1852 | angle::SubjectMessage message) |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1853 | { |
Jamie Madill | e4faae2 | 2019-05-10 08:27:00 -0400 | [diff] [blame] | 1854 | if (message != angle::SubjectMessage::SubjectChanged) |
Jamie Madill | f668a4b | 2018-09-23 17:01:20 -0400 | [diff] [blame] | 1855 | { |
Jamie Madill | 6722009 | 2019-05-20 11:12:53 -0400 | [diff] [blame^] | 1856 | // This can be triggered by SubImage calls for Textures. |
| 1857 | if (message == angle::SubjectMessage::ContentsChanged) |
| 1858 | { |
| 1859 | mDirtyBits.set(DIRTY_BIT_COLOR_BUFFER_CONTENTS_0 + index); |
| 1860 | onStateChange(context, angle::SubjectMessage::DirtyBitsFlagged); |
| 1861 | return; |
| 1862 | } |
| 1863 | |
Jamie Madill | f668a4b | 2018-09-23 17:01:20 -0400 | [diff] [blame] | 1864 | // This can be triggered by the GL back-end TextureGL class. |
Jamie Madill | e4faae2 | 2019-05-10 08:27:00 -0400 | [diff] [blame] | 1865 | ASSERT(message == angle::SubjectMessage::DirtyBitsFlagged); |
Jamie Madill | f668a4b | 2018-09-23 17:01:20 -0400 | [diff] [blame] | 1866 | return; |
| 1867 | } |
Jamie Madill | 55e57f9 | 2018-09-18 11:32:43 -0400 | [diff] [blame] | 1868 | |
| 1869 | ASSERT(!mDirtyBitsGuard.valid() || mDirtyBitsGuard.value().test(index)); |
| 1870 | mDirtyBits.set(index); |
Jamie Madill | 888081d | 2018-02-27 00:24:46 -0500 | [diff] [blame] | 1871 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 1872 | invalidateCompletenessCache(context); |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1873 | |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1874 | FramebufferAttachment *attachment = getAttachmentFromSubjectIndex(index); |
| 1875 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1876 | // Mark the appropriate init flag. |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1877 | mState.mResourceNeedsInit.set(index, attachment->initState() == InitState::MayNeedInit); |
shrekshao | c87e005 | 2019-02-21 11:40:28 -0800 | [diff] [blame] | 1878 | |
| 1879 | // Update mFloat32ColorAttachmentBits Cache |
| 1880 | if (index < DIRTY_BIT_COLOR_ATTACHMENT_MAX) |
| 1881 | { |
| 1882 | ASSERT(index != DIRTY_BIT_DEPTH_ATTACHMENT); |
| 1883 | ASSERT(index != DIRTY_BIT_STENCIL_ATTACHMENT); |
| 1884 | updateFloat32ColorAttachmentBits(index - DIRTY_BIT_COLOR_ATTACHMENT_0, |
| 1885 | attachment->getFormat().info); |
| 1886 | } |
Jamie Madill | d444255 | 2018-02-27 22:03:47 -0500 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | FramebufferAttachment *Framebuffer::getAttachmentFromSubjectIndex(angle::SubjectIndex index) |
| 1890 | { |
| 1891 | switch (index) |
| 1892 | { |
| 1893 | case DIRTY_BIT_DEPTH_ATTACHMENT: |
| 1894 | return &mState.mDepthAttachment; |
| 1895 | case DIRTY_BIT_STENCIL_ATTACHMENT: |
| 1896 | return &mState.mStencilAttachment; |
| 1897 | default: |
| 1898 | size_t colorIndex = (index - DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 1899 | ASSERT(colorIndex < mState.mColorAttachments.size()); |
| 1900 | return &mState.mColorAttachments[colorIndex]; |
| 1901 | } |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1902 | } |
| 1903 | |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1904 | bool Framebuffer::formsRenderingFeedbackLoopWith(const Context *context) const |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1905 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1906 | const State &state = context->getState(); |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1907 | const Program *program = state.getProgram(); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1908 | |
| 1909 | // TODO(jmadill): Default framebuffer feedback loops. |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 1910 | if (mState.mId == 0) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1911 | { |
| 1912 | return false; |
| 1913 | } |
| 1914 | |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1915 | const FramebufferAttachment *depth = getDepthbuffer(); |
| 1916 | const FramebufferAttachment *stencil = getStencilbuffer(); |
| 1917 | |
| 1918 | const bool checkDepth = depth && depth->type() == GL_TEXTURE; |
| 1919 | // Skip the feedback loop check for stencil if depth/stencil point to the same resource. |
| 1920 | const bool checkStencil = |
| 1921 | (stencil && stencil->type() == GL_TEXTURE) && (!depth || *stencil != *depth); |
| 1922 | |
| 1923 | const gl::ActiveTextureMask &activeTextures = program->getActiveSamplersMask(); |
| 1924 | const gl::ActiveTexturePointerArray &textures = state.getActiveTexturesCache(); |
| 1925 | |
| 1926 | for (size_t textureUnit : activeTextures) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1927 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1928 | Texture *texture = textures[textureUnit]; |
| 1929 | |
| 1930 | if (texture == nullptr) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1931 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1932 | continue; |
| 1933 | } |
| 1934 | |
| 1935 | // Depth and stencil attachment form feedback loops |
| 1936 | // Regardless of if enabled or masked. |
| 1937 | if (checkDepth) |
| 1938 | { |
| 1939 | if (texture->id() == depth->id()) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1940 | { |
| 1941 | return true; |
| 1942 | } |
| 1943 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1944 | |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1945 | if (checkStencil) |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1946 | { |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1947 | if (texture->id() == stencil->id()) |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1948 | { |
Jamie Madill | 38fe684 | 2018-09-19 07:20:00 -0400 | [diff] [blame] | 1949 | return true; |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1950 | } |
| 1951 | } |
shrekshao | 8413fab | 2019-04-04 17:13:18 -0700 | [diff] [blame] | 1952 | |
| 1953 | // Check if any color attachment forms a feedback loop. |
| 1954 | for (size_t drawIndex : mColorAttachmentBits) |
| 1955 | { |
| 1956 | const FramebufferAttachment &attachment = mState.mColorAttachments[drawIndex]; |
| 1957 | ASSERT(attachment.isAttached()); |
| 1958 | |
| 1959 | if (attachment.isTextureWithId(texture->id())) |
| 1960 | { |
| 1961 | // TODO(jmadill): Check for appropriate overlap. |
| 1962 | return true; |
| 1963 | } |
| 1964 | } |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1965 | } |
| 1966 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1967 | return false; |
| 1968 | } |
| 1969 | |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1970 | bool Framebuffer::formsCopyingFeedbackLoopWith(GLuint copyTextureID, |
| 1971 | GLint copyTextureLevel, |
| 1972 | GLint copyTextureLayer) const |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1973 | { |
Jamie Madill | 2274b65 | 2018-05-31 10:56:08 -0400 | [diff] [blame] | 1974 | if (mState.mId == 0) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1975 | { |
| 1976 | // It seems impossible to form a texture copying feedback loop with the default FBO. |
| 1977 | return false; |
| 1978 | } |
| 1979 | |
| 1980 | const FramebufferAttachment *readAttachment = getReadColorbuffer(); |
| 1981 | ASSERT(readAttachment); |
| 1982 | |
| 1983 | if (readAttachment->isTextureWithId(copyTextureID)) |
| 1984 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1985 | const auto &imageIndex = readAttachment->getTextureImageIndex(); |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1986 | if (imageIndex.getLevelIndex() == copyTextureLevel) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1987 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1988 | // Check 3D/Array texture layers. |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 1989 | return !imageIndex.hasLayer() || copyTextureLayer == ImageIndex::kEntireLevel || |
| 1990 | imageIndex.getLayerIndex() == copyTextureLayer; |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1991 | } |
| 1992 | } |
| 1993 | return false; |
| 1994 | } |
| 1995 | |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1996 | GLint Framebuffer::getDefaultWidth() const |
| 1997 | { |
| 1998 | return mState.getDefaultWidth(); |
| 1999 | } |
| 2000 | |
| 2001 | GLint Framebuffer::getDefaultHeight() const |
| 2002 | { |
| 2003 | return mState.getDefaultHeight(); |
| 2004 | } |
| 2005 | |
| 2006 | GLint Framebuffer::getDefaultSamples() const |
| 2007 | { |
| 2008 | return mState.getDefaultSamples(); |
| 2009 | } |
| 2010 | |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2011 | bool Framebuffer::getDefaultFixedSampleLocations() const |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2012 | { |
| 2013 | return mState.getDefaultFixedSampleLocations(); |
| 2014 | } |
| 2015 | |
Jiawei Shao | b1e9138 | 2018-05-17 14:33:55 +0800 | [diff] [blame] | 2016 | GLint Framebuffer::getDefaultLayers() const |
| 2017 | { |
| 2018 | return mState.getDefaultLayers(); |
| 2019 | } |
| 2020 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2021 | void Framebuffer::setDefaultWidth(const Context *context, GLint defaultWidth) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2022 | { |
| 2023 | mState.mDefaultWidth = defaultWidth; |
| 2024 | mDirtyBits.set(DIRTY_BIT_DEFAULT_WIDTH); |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2025 | invalidateCompletenessCache(context); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2026 | } |
| 2027 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2028 | void Framebuffer::setDefaultHeight(const Context *context, GLint defaultHeight) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2029 | { |
| 2030 | mState.mDefaultHeight = defaultHeight; |
| 2031 | mDirtyBits.set(DIRTY_BIT_DEFAULT_HEIGHT); |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2032 | invalidateCompletenessCache(context); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2033 | } |
| 2034 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2035 | void Framebuffer::setDefaultSamples(const Context *context, GLint defaultSamples) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2036 | { |
| 2037 | mState.mDefaultSamples = defaultSamples; |
| 2038 | mDirtyBits.set(DIRTY_BIT_DEFAULT_SAMPLES); |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2039 | invalidateCompletenessCache(context); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2040 | } |
| 2041 | |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2042 | void Framebuffer::setDefaultFixedSampleLocations(const Context *context, |
| 2043 | bool defaultFixedSampleLocations) |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2044 | { |
| 2045 | mState.mDefaultFixedSampleLocations = defaultFixedSampleLocations; |
| 2046 | mDirtyBits.set(DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS); |
Jamie Madill | b983a4b | 2018-08-01 11:34:51 -0400 | [diff] [blame] | 2047 | invalidateCompletenessCache(context); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 2048 | } |
| 2049 | |
Jiawei Shao | b1e9138 | 2018-05-17 14:33:55 +0800 | [diff] [blame] | 2050 | void Framebuffer::setDefaultLayers(GLint defaultLayers) |
| 2051 | { |
| 2052 | mState.mDefaultLayers = defaultLayers; |
| 2053 | mDirtyBits.set(DIRTY_BIT_DEFAULT_LAYERS); |
| 2054 | } |
| 2055 | |
Martin Radev | 14a26ae | 2017-07-24 15:56:29 +0300 | [diff] [blame] | 2056 | GLsizei Framebuffer::getNumViews() const |
| 2057 | { |
Martin Radev | 5c00d0d | 2017-08-07 10:06:59 +0300 | [diff] [blame] | 2058 | return mState.getNumViews(); |
Martin Radev | 14a26ae | 2017-07-24 15:56:29 +0300 | [diff] [blame] | 2059 | } |
| 2060 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 2061 | GLint Framebuffer::getBaseViewIndex() const |
| 2062 | { |
| 2063 | return mState.getBaseViewIndex(); |
| 2064 | } |
| 2065 | |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 2066 | bool Framebuffer::isMultiview() const |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 2067 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 2068 | return mState.isMultiview(); |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 2069 | } |
| 2070 | |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 2071 | bool Framebuffer::readDisallowedByMultiview() const |
| 2072 | { |
Mingyu Hu | 7d64c48 | 2019-03-12 14:27:40 -0700 | [diff] [blame] | 2073 | return (mState.isMultiview() && mState.getNumViews() > 1); |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 2074 | } |
| 2075 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 2076 | angle::Result Framebuffer::ensureClearAttachmentsInitialized(const Context *context, |
| 2077 | GLbitfield mask) |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2078 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2079 | const auto &glState = context->getState(); |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2080 | if (!context->isRobustResourceInitEnabled() || glState.isRasterizerDiscardEnabled()) |
| 2081 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2082 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2083 | } |
| 2084 | |
Geoff Lang | a36483f | 2018-03-09 16:11:21 -0500 | [diff] [blame] | 2085 | const BlendState &blend = glState.getBlendState(); |
| 2086 | const DepthStencilState &depthStencil = glState.getDepthStencilState(); |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2087 | |
| 2088 | bool color = (mask & GL_COLOR_BUFFER_BIT) != 0 && !IsColorMaskedOut(blend); |
| 2089 | bool depth = (mask & GL_DEPTH_BUFFER_BIT) != 0 && !IsDepthMaskedOut(depthStencil); |
| 2090 | bool stencil = (mask & GL_STENCIL_BUFFER_BIT) != 0 && !IsStencilMaskedOut(depthStencil); |
| 2091 | |
| 2092 | if (!color && !depth && !stencil) |
| 2093 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2094 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | if (partialClearNeedsInit(context, color, depth, stencil)) |
| 2098 | { |
| 2099 | ANGLE_TRY(ensureDrawAttachmentsInitialized(context)); |
| 2100 | } |
| 2101 | |
| 2102 | // If the impl encounters an error during a a full (non-partial) clear, the attachments will |
| 2103 | // still be marked initialized. This simplifies design, allowing this method to be called before |
| 2104 | // the clear. |
| 2105 | markDrawAttachmentsInitialized(color, depth, stencil); |
| 2106 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2107 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2108 | } |
| 2109 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 2110 | angle::Result Framebuffer::ensureClearBufferAttachmentsInitialized(const Context *context, |
| 2111 | GLenum buffer, |
| 2112 | GLint drawbuffer) |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2113 | { |
| 2114 | if (!context->isRobustResourceInitEnabled() || |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2115 | context->getState().isRasterizerDiscardEnabled() || IsClearBufferMaskedOut(context, buffer)) |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 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 | |
| 2120 | if (partialBufferClearNeedsInit(context, buffer)) |
| 2121 | { |
| 2122 | ANGLE_TRY(ensureBufferInitialized(context, buffer, drawbuffer)); |
| 2123 | } |
| 2124 | |
| 2125 | // If the impl encounters an error during a a full (non-partial) clear, the attachments will |
| 2126 | // still be marked initialized. This simplifies design, allowing this method to be called before |
| 2127 | // the clear. |
| 2128 | markBufferInitialized(buffer, drawbuffer); |
| 2129 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2130 | return angle::Result::Continue; |
Geoff Lang | d4fff50 | 2017-09-22 11:28:28 -0400 | [diff] [blame] | 2131 | } |
| 2132 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 2133 | angle::Result Framebuffer::ensureDrawAttachmentsInitialized(const Context *context) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2134 | { |
| 2135 | if (!context->isRobustResourceInitEnabled()) |
| 2136 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2137 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | // Note: we don't actually filter by the draw attachment enum. Just init everything. |
| 2141 | for (size_t bit : mState.mResourceNeedsInit) |
| 2142 | { |
| 2143 | switch (bit) |
| 2144 | { |
| 2145 | case DIRTY_BIT_DEPTH_ATTACHMENT: |
| 2146 | ANGLE_TRY(InitAttachment(context, &mState.mDepthAttachment)); |
| 2147 | break; |
| 2148 | case DIRTY_BIT_STENCIL_ATTACHMENT: |
| 2149 | ANGLE_TRY(InitAttachment(context, &mState.mStencilAttachment)); |
| 2150 | break; |
| 2151 | default: |
| 2152 | ANGLE_TRY(InitAttachment(context, &mState.mColorAttachments[bit])); |
| 2153 | break; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | mState.mResourceNeedsInit.reset(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2158 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2159 | } |
| 2160 | |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2161 | angle::Result Framebuffer::ensureReadAttachmentsInitialized(const Context *context) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2162 | { |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2163 | ASSERT(context->isRobustResourceInitEnabled()); |
| 2164 | |
| 2165 | if (mState.mResourceNeedsInit.none()) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2166 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2167 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2168 | } |
| 2169 | |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2170 | if (mState.mReadBufferState != GL_NONE) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2171 | { |
| 2172 | size_t readIndex = mState.getReadIndex(); |
| 2173 | if (mState.mResourceNeedsInit[readIndex]) |
| 2174 | { |
| 2175 | ANGLE_TRY(InitAttachment(context, &mState.mColorAttachments[readIndex])); |
| 2176 | mState.mResourceNeedsInit.reset(readIndex); |
| 2177 | } |
| 2178 | } |
| 2179 | |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2180 | // Conservatively init depth since it can be read by BlitFramebuffer. |
| 2181 | if (hasDepth()) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2182 | { |
| 2183 | if (mState.mResourceNeedsInit[DIRTY_BIT_DEPTH_ATTACHMENT]) |
| 2184 | { |
| 2185 | ANGLE_TRY(InitAttachment(context, &mState.mDepthAttachment)); |
| 2186 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2187 | } |
| 2188 | } |
| 2189 | |
Jamie Madill | 0a1eeb8 | 2019-05-13 13:53:18 -0400 | [diff] [blame] | 2190 | // Conservatively init stencil since it can be read by BlitFramebuffer. |
| 2191 | if (hasStencil()) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2192 | { |
| 2193 | if (mState.mResourceNeedsInit[DIRTY_BIT_STENCIL_ATTACHMENT]) |
| 2194 | { |
| 2195 | ANGLE_TRY(InitAttachment(context, &mState.mStencilAttachment)); |
| 2196 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2197 | } |
| 2198 | } |
| 2199 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2200 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | void Framebuffer::markDrawAttachmentsInitialized(bool color, bool depth, bool stencil) |
| 2204 | { |
| 2205 | // Mark attachments as initialized. |
| 2206 | if (color) |
| 2207 | { |
| 2208 | for (auto colorIndex : mState.mEnabledDrawBuffers) |
| 2209 | { |
| 2210 | auto &colorAttachment = mState.mColorAttachments[colorIndex]; |
| 2211 | ASSERT(colorAttachment.isAttached()); |
| 2212 | colorAttachment.setInitState(InitState::Initialized); |
| 2213 | mState.mResourceNeedsInit.reset(colorIndex); |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | if (depth && mState.mDepthAttachment.isAttached()) |
| 2218 | { |
| 2219 | mState.mDepthAttachment.setInitState(InitState::Initialized); |
| 2220 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2221 | } |
| 2222 | |
| 2223 | if (stencil && mState.mStencilAttachment.isAttached()) |
| 2224 | { |
| 2225 | mState.mStencilAttachment.setInitState(InitState::Initialized); |
| 2226 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | void Framebuffer::markBufferInitialized(GLenum bufferType, GLint bufferIndex) |
| 2231 | { |
| 2232 | switch (bufferType) |
| 2233 | { |
| 2234 | case GL_COLOR: |
| 2235 | { |
| 2236 | ASSERT(bufferIndex < static_cast<GLint>(mState.mColorAttachments.size())); |
| 2237 | if (mState.mColorAttachments[bufferIndex].isAttached()) |
| 2238 | { |
| 2239 | mState.mColorAttachments[bufferIndex].setInitState(InitState::Initialized); |
| 2240 | mState.mResourceNeedsInit.reset(bufferIndex); |
| 2241 | } |
| 2242 | break; |
| 2243 | } |
| 2244 | case GL_DEPTH: |
| 2245 | { |
| 2246 | if (mState.mDepthAttachment.isAttached()) |
| 2247 | { |
| 2248 | mState.mDepthAttachment.setInitState(InitState::Initialized); |
| 2249 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2250 | } |
| 2251 | break; |
| 2252 | } |
| 2253 | case GL_STENCIL: |
| 2254 | { |
| 2255 | if (mState.mStencilAttachment.isAttached()) |
| 2256 | { |
| 2257 | mState.mStencilAttachment.setInitState(InitState::Initialized); |
| 2258 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2259 | } |
| 2260 | break; |
| 2261 | } |
| 2262 | case GL_DEPTH_STENCIL: |
| 2263 | { |
| 2264 | if (mState.mDepthAttachment.isAttached()) |
| 2265 | { |
| 2266 | mState.mDepthAttachment.setInitState(InitState::Initialized); |
| 2267 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2268 | } |
| 2269 | if (mState.mStencilAttachment.isAttached()) |
| 2270 | { |
| 2271 | mState.mStencilAttachment.setInitState(InitState::Initialized); |
| 2272 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2273 | } |
| 2274 | break; |
| 2275 | } |
| 2276 | default: |
| 2277 | UNREACHABLE(); |
| 2278 | break; |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | Box Framebuffer::getDimensions() const |
| 2283 | { |
| 2284 | return mState.getDimensions(); |
| 2285 | } |
| 2286 | |
Jamie Madill | 64b7c4f | 2018-10-19 11:38:04 -0400 | [diff] [blame] | 2287 | angle::Result Framebuffer::ensureBufferInitialized(const Context *context, |
| 2288 | GLenum bufferType, |
| 2289 | GLint bufferIndex) |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2290 | { |
| 2291 | ASSERT(context->isRobustResourceInitEnabled()); |
| 2292 | |
| 2293 | if (mState.mResourceNeedsInit.none()) |
| 2294 | { |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2295 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | switch (bufferType) |
| 2299 | { |
| 2300 | case GL_COLOR: |
| 2301 | { |
| 2302 | ASSERT(bufferIndex < static_cast<GLint>(mState.mColorAttachments.size())); |
| 2303 | if (mState.mResourceNeedsInit[bufferIndex]) |
| 2304 | { |
| 2305 | ANGLE_TRY(InitAttachment(context, &mState.mColorAttachments[bufferIndex])); |
| 2306 | mState.mResourceNeedsInit.reset(bufferIndex); |
| 2307 | } |
| 2308 | break; |
| 2309 | } |
| 2310 | case GL_DEPTH: |
| 2311 | { |
| 2312 | if (mState.mResourceNeedsInit[DIRTY_BIT_DEPTH_ATTACHMENT]) |
| 2313 | { |
| 2314 | ANGLE_TRY(InitAttachment(context, &mState.mDepthAttachment)); |
| 2315 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2316 | } |
| 2317 | break; |
| 2318 | } |
| 2319 | case GL_STENCIL: |
| 2320 | { |
| 2321 | if (mState.mResourceNeedsInit[DIRTY_BIT_STENCIL_ATTACHMENT]) |
| 2322 | { |
| 2323 | ANGLE_TRY(InitAttachment(context, &mState.mStencilAttachment)); |
| 2324 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2325 | } |
| 2326 | break; |
| 2327 | } |
| 2328 | case GL_DEPTH_STENCIL: |
| 2329 | { |
| 2330 | if (mState.mResourceNeedsInit[DIRTY_BIT_DEPTH_ATTACHMENT]) |
| 2331 | { |
| 2332 | ANGLE_TRY(InitAttachment(context, &mState.mDepthAttachment)); |
| 2333 | mState.mResourceNeedsInit.reset(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 2334 | } |
| 2335 | if (mState.mResourceNeedsInit[DIRTY_BIT_STENCIL_ATTACHMENT]) |
| 2336 | { |
| 2337 | ANGLE_TRY(InitAttachment(context, &mState.mStencilAttachment)); |
| 2338 | mState.mResourceNeedsInit.reset(DIRTY_BIT_STENCIL_ATTACHMENT); |
| 2339 | } |
| 2340 | break; |
| 2341 | } |
| 2342 | default: |
| 2343 | UNREACHABLE(); |
| 2344 | break; |
| 2345 | } |
| 2346 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2347 | return angle::Result::Continue; |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | bool Framebuffer::partialBufferClearNeedsInit(const Context *context, GLenum bufferType) |
| 2351 | { |
| 2352 | if (!context->isRobustResourceInitEnabled() || mState.mResourceNeedsInit.none()) |
| 2353 | { |
| 2354 | return false; |
| 2355 | } |
| 2356 | |
| 2357 | switch (bufferType) |
| 2358 | { |
| 2359 | case GL_COLOR: |
| 2360 | return partialClearNeedsInit(context, true, false, false); |
| 2361 | case GL_DEPTH: |
| 2362 | return partialClearNeedsInit(context, false, true, false); |
| 2363 | case GL_STENCIL: |
| 2364 | return partialClearNeedsInit(context, false, false, true); |
| 2365 | case GL_DEPTH_STENCIL: |
| 2366 | return partialClearNeedsInit(context, false, true, true); |
| 2367 | default: |
| 2368 | UNREACHABLE(); |
| 2369 | return false; |
| 2370 | } |
| 2371 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2372 | } // namespace gl |