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