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