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" |
| 22 | #include "libANGLE/formatutils.h" |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 23 | #include "libANGLE/renderer/ContextImpl.h" |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 24 | #include "libANGLE/renderer/FramebufferImpl.h" |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 25 | #include "libANGLE/renderer/GLImplFactory.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 26 | #include "libANGLE/renderer/RenderbufferImpl.h" |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 27 | #include "libANGLE/renderer/SurfaceImpl.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 28 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 29 | using namespace angle; |
| 30 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 31 | namespace gl |
| 32 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 33 | |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 34 | namespace |
| 35 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 36 | |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 37 | void BindResourceChannel(OnAttachmentDirtyBinding *binding, FramebufferAttachmentObject *resource) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 38 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 39 | binding->bind(resource ? resource->getDirtyChannel() : nullptr); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 40 | } |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 41 | |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 42 | bool CheckAttachmentCompleteness(const Context *context, const FramebufferAttachment &attachment) |
| 43 | { |
| 44 | ASSERT(attachment.isAttached()); |
| 45 | |
| 46 | const Extents &size = attachment.getSize(); |
| 47 | if (size.width == 0 || size.height == 0) |
| 48 | { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | const InternalFormat &format = *attachment.getFormat().info; |
| 53 | if (!format.renderSupport(context->getClientVersion(), context->getExtensions())) |
| 54 | { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | if (attachment.type() == GL_TEXTURE) |
| 59 | { |
| 60 | if (attachment.layer() >= size.depth) |
| 61 | { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | // ES3 specifies that cube map texture attachments must be cube complete. |
| 66 | // This language is missing from the ES2 spec, but we enforce it here because some |
| 67 | // desktop OpenGL drivers also enforce this validation. |
| 68 | // TODO(jmadill): Check if OpenGL ES2 drivers enforce cube completeness. |
| 69 | const Texture *texture = attachment.getTexture(); |
| 70 | ASSERT(texture); |
| 71 | if (texture->getTarget() == GL_TEXTURE_CUBE_MAP && |
| 72 | !texture->getTextureState().isCubeComplete()) |
| 73 | { |
| 74 | return false; |
| 75 | } |
Geoff Lang | 857c09d | 2017-05-16 15:55:04 -0400 | [diff] [blame] | 76 | |
| 77 | if (!texture->getImmutableFormat()) |
| 78 | { |
| 79 | GLuint attachmentMipLevel = static_cast<GLuint>(attachment.mipLevel()); |
| 80 | |
| 81 | // From the ES 3.0 spec, pg 213: |
| 82 | // If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is TEXTURE and the value of |
| 83 | // FRAMEBUFFER_ATTACHMENT_OBJECT_NAME does not name an immutable-format texture, |
| 84 | // then the value of FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL must be in the |
| 85 | // range[levelbase, q], where levelbase is the value of TEXTURE_BASE_LEVEL and q is |
| 86 | // the effective maximum texture level defined in the Mipmapping discussion of |
| 87 | // section 3.8.10.4. |
| 88 | if (attachmentMipLevel < texture->getBaseLevel() || |
| 89 | attachmentMipLevel > texture->getMipmapMaxLevel()) |
| 90 | { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | // Form the ES 3.0 spec, pg 213/214: |
| 95 | // If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is TEXTURE and the value of |
| 96 | // FRAMEBUFFER_ATTACHMENT_OBJECT_NAME does not name an immutable-format texture and |
| 97 | // the value of FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL is not levelbase, then the |
| 98 | // texture must be mipmap complete, and if FRAMEBUFFER_ATTACHMENT_OBJECT_NAME names |
| 99 | // a cubemap texture, the texture must also be cube complete. |
| 100 | if (attachmentMipLevel != texture->getBaseLevel() && !texture->isMipmapComplete()) |
| 101 | { |
| 102 | return false; |
| 103 | } |
| 104 | } |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | return true; |
| 108 | }; |
| 109 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 110 | bool CheckAttachmentSampleCompleteness(const Context *context, |
| 111 | const FramebufferAttachment &attachment, |
| 112 | bool colorAttachment, |
| 113 | Optional<int> *samples, |
| 114 | Optional<GLboolean> *fixedSampleLocations) |
| 115 | { |
| 116 | ASSERT(attachment.isAttached()); |
| 117 | |
| 118 | if (attachment.type() == GL_TEXTURE) |
| 119 | { |
| 120 | const Texture *texture = attachment.getTexture(); |
| 121 | ASSERT(texture); |
| 122 | |
| 123 | const ImageIndex &attachmentImageIndex = attachment.getTextureImageIndex(); |
| 124 | |
| 125 | // ES3.1 (section 9.4) requires that the value of TEXTURE_FIXED_SAMPLE_LOCATIONS should be |
| 126 | // the same for all attached textures. |
| 127 | GLboolean fixedSampleloc = texture->getFixedSampleLocations(attachmentImageIndex.type, |
| 128 | attachmentImageIndex.mipIndex); |
| 129 | if (fixedSampleLocations->valid() && fixedSampleloc != fixedSampleLocations->value()) |
| 130 | { |
| 131 | return false; |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | *fixedSampleLocations = fixedSampleloc; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (samples->valid()) |
| 140 | { |
| 141 | if (attachment.getSamples() != samples->value()) |
| 142 | { |
| 143 | if (colorAttachment) |
| 144 | { |
| 145 | // APPLE_framebuffer_multisample, which EXT_draw_buffers refers to, requires that |
| 146 | // all color attachments have the same number of samples for the FBO to be complete. |
| 147 | return false; |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | // CHROMIUM_framebuffer_mixed_samples allows a framebuffer to be considered complete |
| 152 | // when its depth or stencil samples are a multiple of the number of color samples. |
| 153 | if (!context->getExtensions().framebufferMixedSamples) |
| 154 | { |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | if ((attachment.getSamples() % std::max(samples->value(), 1)) != 0) |
| 159 | { |
| 160 | return false; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | *samples = attachment.getSamples(); |
| 168 | } |
| 169 | |
| 170 | return true; |
| 171 | } |
| 172 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 173 | } // anonymous namespace |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 174 | |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 175 | // This constructor is only used for default framebuffers. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 176 | FramebufferState::FramebufferState() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 177 | : mLabel(), |
| 178 | mColorAttachments(1), |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 179 | mDrawBufferStates(1, GL_BACK), |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 180 | mReadBufferState(GL_BACK), |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 181 | mDefaultWidth(0), |
| 182 | mDefaultHeight(0), |
| 183 | mDefaultSamples(0), |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 184 | mDefaultFixedSampleLocations(GL_FALSE), |
| 185 | mWebGLDepthStencilConsistent(true) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 186 | { |
Geoff Lang | d90d388 | 2017-03-21 10:49:54 -0400 | [diff] [blame] | 187 | ASSERT(mDrawBufferStates.size() > 0); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 188 | mEnabledDrawBuffers.set(0); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 189 | } |
| 190 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 191 | FramebufferState::FramebufferState(const Caps &caps) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 192 | : mLabel(), |
| 193 | mColorAttachments(caps.maxColorAttachments), |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 194 | mDrawBufferStates(caps.maxDrawBuffers, GL_NONE), |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 195 | mReadBufferState(GL_COLOR_ATTACHMENT0_EXT), |
| 196 | mDefaultWidth(0), |
| 197 | mDefaultHeight(0), |
| 198 | mDefaultSamples(0), |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 199 | mDefaultFixedSampleLocations(GL_FALSE), |
| 200 | mWebGLDepthStencilConsistent(true) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 201 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 202 | ASSERT(mDrawBufferStates.size() > 0); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 203 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 204 | mEnabledDrawBuffers.set(0); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 205 | } |
| 206 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 207 | FramebufferState::~FramebufferState() |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 208 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 209 | } |
| 210 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 211 | const std::string &FramebufferState::getLabel() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 212 | { |
| 213 | return mLabel; |
| 214 | } |
| 215 | |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 216 | const FramebufferAttachment *FramebufferState::getAttachment(GLenum attachment) const |
| 217 | { |
| 218 | if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15) |
| 219 | { |
| 220 | return getColorAttachment(attachment - GL_COLOR_ATTACHMENT0); |
| 221 | } |
| 222 | |
| 223 | switch (attachment) |
| 224 | { |
| 225 | case GL_COLOR: |
| 226 | case GL_BACK: |
| 227 | return getColorAttachment(0); |
| 228 | case GL_DEPTH: |
| 229 | case GL_DEPTH_ATTACHMENT: |
| 230 | return getDepthAttachment(); |
| 231 | case GL_STENCIL: |
| 232 | case GL_STENCIL_ATTACHMENT: |
| 233 | return getStencilAttachment(); |
| 234 | case GL_DEPTH_STENCIL: |
| 235 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 236 | return getDepthStencilAttachment(); |
| 237 | default: |
| 238 | UNREACHABLE(); |
| 239 | return nullptr; |
| 240 | } |
| 241 | } |
| 242 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 243 | const FramebufferAttachment *FramebufferState::getReadAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 244 | { |
Antoine Labour | 2ec65dc | 2016-11-30 16:28:58 -0800 | [diff] [blame] | 245 | if (mReadBufferState == GL_NONE) |
| 246 | { |
| 247 | return nullptr; |
| 248 | } |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 249 | ASSERT(mReadBufferState == GL_BACK || |
| 250 | (mReadBufferState >= GL_COLOR_ATTACHMENT0 && mReadBufferState <= GL_COLOR_ATTACHMENT15)); |
| 251 | size_t readIndex = (mReadBufferState == GL_BACK |
| 252 | ? 0 |
| 253 | : static_cast<size_t>(mReadBufferState - GL_COLOR_ATTACHMENT0)); |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 254 | ASSERT(readIndex < mColorAttachments.size()); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 255 | return mColorAttachments[readIndex].isAttached() ? &mColorAttachments[readIndex] : nullptr; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 256 | } |
| 257 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 258 | const FramebufferAttachment *FramebufferState::getFirstNonNullAttachment() const |
| 259 | { |
| 260 | auto *colorAttachment = getFirstColorAttachment(); |
| 261 | if (colorAttachment) |
| 262 | { |
| 263 | return colorAttachment; |
| 264 | } |
| 265 | return getDepthOrStencilAttachment(); |
| 266 | } |
| 267 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 268 | const FramebufferAttachment *FramebufferState::getFirstColorAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 269 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 270 | for (const FramebufferAttachment &colorAttachment : mColorAttachments) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 271 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 272 | if (colorAttachment.isAttached()) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 273 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 274 | return &colorAttachment; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
| 278 | return nullptr; |
| 279 | } |
| 280 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 281 | const FramebufferAttachment *FramebufferState::getDepthOrStencilAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 282 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 283 | if (mDepthAttachment.isAttached()) |
| 284 | { |
| 285 | return &mDepthAttachment; |
| 286 | } |
| 287 | if (mStencilAttachment.isAttached()) |
| 288 | { |
| 289 | return &mStencilAttachment; |
| 290 | } |
| 291 | return nullptr; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 292 | } |
| 293 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 294 | const FramebufferAttachment *FramebufferState::getStencilOrDepthStencilAttachment() const |
| 295 | { |
| 296 | if (mStencilAttachment.isAttached()) |
| 297 | { |
| 298 | return &mStencilAttachment; |
| 299 | } |
| 300 | return getDepthStencilAttachment(); |
| 301 | } |
| 302 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 303 | const FramebufferAttachment *FramebufferState::getColorAttachment(size_t colorAttachment) const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 304 | { |
| 305 | ASSERT(colorAttachment < mColorAttachments.size()); |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 306 | return mColorAttachments[colorAttachment].isAttached() ? &mColorAttachments[colorAttachment] |
| 307 | : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 308 | } |
| 309 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 310 | const FramebufferAttachment *FramebufferState::getDepthAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 311 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 312 | return mDepthAttachment.isAttached() ? &mDepthAttachment : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 315 | const FramebufferAttachment *FramebufferState::getStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 316 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 317 | return mStencilAttachment.isAttached() ? &mStencilAttachment : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 320 | const FramebufferAttachment *FramebufferState::getDepthStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 321 | { |
| 322 | // A valid depth-stencil attachment has the same resource bound to both the |
| 323 | // depth and stencil attachment points. |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 324 | if (mDepthAttachment.isAttached() && mStencilAttachment.isAttached() && |
Jamie Madill | 44f2648 | 2016-11-18 12:49:15 -0500 | [diff] [blame] | 325 | mDepthAttachment == mStencilAttachment) |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 326 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 327 | return &mDepthAttachment; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | return nullptr; |
| 331 | } |
| 332 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 333 | bool FramebufferState::attachmentsHaveSameDimensions() const |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 334 | { |
| 335 | Optional<Extents> attachmentSize; |
| 336 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 337 | auto hasMismatchedSize = [&attachmentSize](const FramebufferAttachment &attachment) { |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 338 | if (!attachment.isAttached()) |
| 339 | { |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | if (!attachmentSize.valid()) |
| 344 | { |
| 345 | attachmentSize = attachment.getSize(); |
| 346 | return false; |
| 347 | } |
| 348 | |
| 349 | return (attachment.getSize() != attachmentSize.value()); |
| 350 | }; |
| 351 | |
| 352 | for (const auto &attachment : mColorAttachments) |
| 353 | { |
| 354 | if (hasMismatchedSize(attachment)) |
| 355 | { |
| 356 | return false; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | if (hasMismatchedSize(mDepthAttachment)) |
| 361 | { |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | return !hasMismatchedSize(mStencilAttachment); |
| 366 | } |
| 367 | |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 368 | const gl::FramebufferAttachment *FramebufferState::getDrawBuffer(size_t drawBufferIdx) const |
| 369 | { |
| 370 | ASSERT(drawBufferIdx < mDrawBufferStates.size()); |
| 371 | if (mDrawBufferStates[drawBufferIdx] != GL_NONE) |
| 372 | { |
| 373 | // ES3 spec: "If the GL is bound to a draw framebuffer object, the ith buffer listed in bufs |
| 374 | // must be COLOR_ATTACHMENTi or NONE" |
| 375 | ASSERT(mDrawBufferStates[drawBufferIdx] == GL_COLOR_ATTACHMENT0 + drawBufferIdx || |
| 376 | (drawBufferIdx == 0 && mDrawBufferStates[drawBufferIdx] == GL_BACK)); |
| 377 | return getAttachment(mDrawBufferStates[drawBufferIdx]); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | return nullptr; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | size_t FramebufferState::getDrawBufferCount() const |
| 386 | { |
| 387 | return mDrawBufferStates.size(); |
| 388 | } |
| 389 | |
Geoff Lang | b21e20d | 2016-07-19 15:35:41 -0400 | [diff] [blame] | 390 | bool FramebufferState::colorAttachmentsAreUniqueImages() const |
| 391 | { |
| 392 | for (size_t firstAttachmentIdx = 0; firstAttachmentIdx < mColorAttachments.size(); |
| 393 | firstAttachmentIdx++) |
| 394 | { |
| 395 | const gl::FramebufferAttachment &firstAttachment = mColorAttachments[firstAttachmentIdx]; |
| 396 | if (!firstAttachment.isAttached()) |
| 397 | { |
| 398 | continue; |
| 399 | } |
| 400 | |
| 401 | for (size_t secondAttachmentIdx = firstAttachmentIdx + 1; |
| 402 | secondAttachmentIdx < mColorAttachments.size(); secondAttachmentIdx++) |
| 403 | { |
| 404 | const gl::FramebufferAttachment &secondAttachment = |
| 405 | mColorAttachments[secondAttachmentIdx]; |
| 406 | if (!secondAttachment.isAttached()) |
| 407 | { |
| 408 | continue; |
| 409 | } |
| 410 | |
| 411 | if (firstAttachment == secondAttachment) |
| 412 | { |
| 413 | return false; |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | return true; |
| 419 | } |
| 420 | |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame^] | 421 | bool FramebufferState::hasDepth() const |
| 422 | { |
| 423 | return (mDepthAttachment.isAttached() && mDepthAttachment.getDepthSize() > 0); |
| 424 | } |
| 425 | |
| 426 | bool FramebufferState::hasStencil() const |
| 427 | { |
| 428 | return (mStencilAttachment.isAttached() && mStencilAttachment.getStencilSize() > 0); |
| 429 | } |
| 430 | |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 431 | Framebuffer::Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 432 | : mState(caps), |
| 433 | mImpl(factory->createFramebuffer(mState)), |
| 434 | mId(id), |
| 435 | mCachedStatus(), |
| 436 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 437 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 438 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 439 | ASSERT(mId != 0); |
| 440 | ASSERT(mImpl != nullptr); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 441 | ASSERT(mState.mColorAttachments.size() == static_cast<size_t>(caps.maxColorAttachments)); |
| 442 | |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 443 | for (uint32_t colorIndex = 0; |
| 444 | colorIndex < static_cast<uint32_t>(mState.mColorAttachments.size()); ++colorIndex) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 445 | { |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 446 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 447 | } |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 448 | } |
| 449 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 450 | Framebuffer::Framebuffer(const egl::Display *display, egl::Surface *surface) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 451 | : mState(), |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 452 | mImpl(surface->getImplementation()->createDefaultFramebuffer(mState)), |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 453 | mId(0), |
| 454 | mCachedStatus(GL_FRAMEBUFFER_COMPLETE), |
| 455 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 456 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 457 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 458 | ASSERT(mImpl != nullptr); |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 459 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 460 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 461 | const Context *proxyContext = display->getProxyContext(); |
| 462 | |
| 463 | setAttachmentImpl(proxyContext, GL_FRAMEBUFFER_DEFAULT, GL_BACK, gl::ImageIndex::MakeInvalid(), |
| 464 | surface); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 465 | |
| 466 | if (surface->getConfig()->depthSize > 0) |
| 467 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 468 | setAttachmentImpl(proxyContext, GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, |
| 469 | gl::ImageIndex::MakeInvalid(), surface); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | if (surface->getConfig()->stencilSize > 0) |
| 473 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 474 | setAttachmentImpl(proxyContext, GL_FRAMEBUFFER_DEFAULT, GL_STENCIL, |
| 475 | gl::ImageIndex::MakeInvalid(), surface); |
Jamie Madill | 6f60d05 | 2017-02-22 15:20:11 -0500 | [diff] [blame] | 476 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 479 | Framebuffer::Framebuffer(rx::GLImplFactory *factory) |
| 480 | : mState(), |
| 481 | mImpl(factory->createFramebuffer(mState)), |
| 482 | mId(0), |
| 483 | mCachedStatus(GL_FRAMEBUFFER_UNDEFINED_OES), |
| 484 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 485 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
| 486 | { |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 487 | mDirtyColorAttachmentBindings.emplace_back(this, DIRTY_BIT_COLOR_ATTACHMENT_0); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 488 | } |
| 489 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 490 | Framebuffer::~Framebuffer() |
| 491 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 492 | SafeDelete(mImpl); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 493 | } |
| 494 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 495 | void Framebuffer::onDestroy(const Context *context) |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 496 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 497 | for (auto &attachment : mState.mColorAttachments) |
| 498 | { |
| 499 | attachment.detach(context); |
| 500 | } |
| 501 | mState.mDepthAttachment.detach(context); |
| 502 | mState.mStencilAttachment.detach(context); |
| 503 | mState.mWebGLDepthAttachment.detach(context); |
| 504 | mState.mWebGLStencilAttachment.detach(context); |
| 505 | mState.mWebGLDepthStencilAttachment.detach(context); |
| 506 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 507 | mImpl->destroy(context); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void Framebuffer::destroyDefault(const egl::Display *display) |
| 511 | { |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 512 | mImpl->destroyDefault(display); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 515 | void Framebuffer::setLabel(const std::string &label) |
| 516 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 517 | mState.mLabel = label; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | const std::string &Framebuffer::getLabel() const |
| 521 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 522 | return mState.mLabel; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 523 | } |
| 524 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 525 | void Framebuffer::detachTexture(const Context *context, GLuint textureId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 526 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 527 | detachResourceById(context, GL_TEXTURE, textureId); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 530 | void Framebuffer::detachRenderbuffer(const Context *context, GLuint renderbufferId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 531 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 532 | detachResourceById(context, GL_RENDERBUFFER, renderbufferId); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 533 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 534 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 535 | void Framebuffer::detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 536 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 537 | for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 538 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 539 | detachMatchingAttachment(context, &mState.mColorAttachments[colorIndex], resourceType, |
| 540 | resourceId, DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 543 | if (context->isWebGL1()) |
| 544 | { |
| 545 | const std::array<FramebufferAttachment *, 3> attachments = { |
| 546 | {&mState.mWebGLDepthStencilAttachment, &mState.mWebGLDepthAttachment, |
| 547 | &mState.mWebGLStencilAttachment}}; |
| 548 | for (FramebufferAttachment *attachment : attachments) |
| 549 | { |
| 550 | if (attachment->isAttached() && attachment->type() == resourceType && |
| 551 | attachment->id() == resourceId) |
| 552 | { |
| 553 | resetAttachment(context, attachment->getBinding()); |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | else |
| 558 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 559 | detachMatchingAttachment(context, &mState.mDepthAttachment, resourceType, resourceId, |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 560 | DIRTY_BIT_DEPTH_ATTACHMENT); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 561 | detachMatchingAttachment(context, &mState.mStencilAttachment, resourceType, resourceId, |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 562 | DIRTY_BIT_STENCIL_ATTACHMENT); |
| 563 | } |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 564 | } |
| 565 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 566 | void Framebuffer::detachMatchingAttachment(const Context *context, |
| 567 | FramebufferAttachment *attachment, |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 568 | GLenum matchType, |
| 569 | GLuint matchId, |
| 570 | size_t dirtyBit) |
| 571 | { |
| 572 | if (attachment->isAttached() && attachment->type() == matchType && attachment->id() == matchId) |
| 573 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 574 | attachment->detach(context); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 575 | mDirtyBits.set(dirtyBit); |
| 576 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 579 | const FramebufferAttachment *Framebuffer::getColorbuffer(size_t colorAttachment) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 580 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 581 | return mState.getColorAttachment(colorAttachment); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 584 | const FramebufferAttachment *Framebuffer::getDepthbuffer() const |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 585 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 586 | return mState.getDepthAttachment(); |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 587 | } |
| 588 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 589 | const FramebufferAttachment *Framebuffer::getStencilbuffer() const |
| 590 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 591 | return mState.getStencilAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 592 | } |
| 593 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 594 | const FramebufferAttachment *Framebuffer::getDepthStencilBuffer() const |
| 595 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 596 | return mState.getDepthStencilAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | const FramebufferAttachment *Framebuffer::getDepthOrStencilbuffer() const |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 600 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 601 | return mState.getDepthOrStencilAttachment(); |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 604 | const FramebufferAttachment *Framebuffer::getStencilOrDepthStencilAttachment() const |
| 605 | { |
| 606 | return mState.getStencilOrDepthStencilAttachment(); |
| 607 | } |
| 608 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 609 | const FramebufferAttachment *Framebuffer::getReadColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 610 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 611 | return mState.getReadAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 612 | } |
| 613 | |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 614 | GLenum Framebuffer::getReadColorbufferType() const |
| 615 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 616 | const FramebufferAttachment *readAttachment = mState.getReadAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 617 | return (readAttachment != nullptr ? readAttachment->type() : GL_NONE); |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 620 | const FramebufferAttachment *Framebuffer::getFirstColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 621 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 622 | return mState.getFirstColorAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 625 | const FramebufferAttachment *Framebuffer::getAttachment(GLenum attachment) const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 626 | { |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 627 | return mState.getAttachment(attachment); |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 628 | } |
| 629 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 630 | size_t Framebuffer::getDrawbufferStateCount() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 631 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 632 | return mState.mDrawBufferStates.size(); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | GLenum Framebuffer::getDrawBufferState(size_t drawBuffer) const |
| 636 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 637 | ASSERT(drawBuffer < mState.mDrawBufferStates.size()); |
| 638 | return mState.mDrawBufferStates[drawBuffer]; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 641 | const std::vector<GLenum> &Framebuffer::getDrawBufferStates() const |
| 642 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 643 | return mState.getDrawBufferStates(); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 644 | } |
| 645 | |
Geoff Lang | 164d54e | 2014-12-01 10:55:33 -0500 | [diff] [blame] | 646 | 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] | 647 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 648 | auto &drawStates = mState.mDrawBufferStates; |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 649 | |
| 650 | ASSERT(count <= drawStates.size()); |
| 651 | std::copy(buffers, buffers + count, drawStates.begin()); |
| 652 | std::fill(drawStates.begin() + count, drawStates.end(), GL_NONE); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 653 | mDirtyBits.set(DIRTY_BIT_DRAW_BUFFERS); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 654 | |
| 655 | mState.mEnabledDrawBuffers.reset(); |
| 656 | for (size_t index = 0; index < count; ++index) |
| 657 | { |
| 658 | if (drawStates[index] != GL_NONE && mState.mColorAttachments[index].isAttached()) |
| 659 | { |
| 660 | mState.mEnabledDrawBuffers.set(index); |
| 661 | } |
| 662 | } |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 663 | } |
| 664 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 665 | const FramebufferAttachment *Framebuffer::getDrawBuffer(size_t drawBuffer) const |
| 666 | { |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 667 | return mState.getDrawBuffer(drawBuffer); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 668 | } |
| 669 | |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 670 | GLenum Framebuffer::getDrawbufferWriteType(size_t drawBuffer) const |
| 671 | { |
| 672 | const FramebufferAttachment *attachment = mState.getDrawBuffer(drawBuffer); |
| 673 | if (attachment == nullptr) |
| 674 | { |
| 675 | return GL_NONE; |
| 676 | } |
| 677 | |
| 678 | GLenum componentType = attachment->getFormat().info->componentType; |
| 679 | switch (componentType) |
| 680 | { |
| 681 | case GL_INT: |
| 682 | case GL_UNSIGNED_INT: |
| 683 | return componentType; |
| 684 | |
| 685 | default: |
| 686 | return GL_FLOAT; |
| 687 | } |
| 688 | } |
| 689 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 690 | bool Framebuffer::hasEnabledDrawBuffer() const |
| 691 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 692 | for (size_t drawbufferIdx = 0; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 693 | { |
| 694 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
| 695 | { |
| 696 | return true; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | return false; |
| 701 | } |
| 702 | |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 703 | GLenum Framebuffer::getReadBufferState() const |
| 704 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 705 | return mState.mReadBufferState; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | void Framebuffer::setReadBuffer(GLenum buffer) |
| 709 | { |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 710 | ASSERT(buffer == GL_BACK || buffer == GL_NONE || |
| 711 | (buffer >= GL_COLOR_ATTACHMENT0 && |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 712 | (buffer - GL_COLOR_ATTACHMENT0) < mState.mColorAttachments.size())); |
| 713 | mState.mReadBufferState = buffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 714 | mDirtyBits.set(DIRTY_BIT_READ_BUFFER); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 717 | size_t Framebuffer::getNumColorBuffers() const |
| 718 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 719 | return mState.mColorAttachments.size(); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 720 | } |
| 721 | |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 722 | bool Framebuffer::hasDepth() const |
| 723 | { |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame^] | 724 | return mState.hasDepth(); |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 725 | } |
| 726 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 727 | bool Framebuffer::hasStencil() const |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 728 | { |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame^] | 729 | return mState.hasStencil(); |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 730 | } |
| 731 | |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 732 | bool Framebuffer::usingExtendedDrawBuffers() const |
| 733 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 734 | for (size_t drawbufferIdx = 1; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 735 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 736 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 737 | { |
| 738 | return true; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return false; |
| 743 | } |
| 744 | |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 745 | void Framebuffer::invalidateCompletenessCache() |
| 746 | { |
| 747 | if (mId != 0) |
| 748 | { |
| 749 | mCachedStatus.reset(); |
| 750 | } |
| 751 | } |
| 752 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 753 | GLenum Framebuffer::checkStatus(const Context *context) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 754 | { |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 755 | // The default framebuffer is always complete except when it is surfaceless in which |
| 756 | // case it is always unsupported. We return early because the default framebuffer may |
| 757 | // not be subject to the same rules as application FBOs. ie, it could have 0x0 size. |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 758 | if (mId == 0) |
| 759 | { |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 760 | ASSERT(mCachedStatus.valid()); |
| 761 | ASSERT(mCachedStatus.value() == GL_FRAMEBUFFER_COMPLETE || |
| 762 | mCachedStatus.value() == GL_FRAMEBUFFER_UNDEFINED_OES); |
| 763 | return mCachedStatus.value(); |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 764 | } |
| 765 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 766 | if (hasAnyDirtyBit() || !mCachedStatus.valid()) |
| 767 | { |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 768 | mCachedStatus = checkStatusImpl(context); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | return mCachedStatus.value(); |
| 772 | } |
| 773 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 774 | GLenum Framebuffer::checkStatusImpl(const Context *context) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 775 | { |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 776 | const ContextState &state = context->getContextState(); |
| 777 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 778 | ASSERT(mId != 0); |
| 779 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 780 | bool hasAttachments = false; |
| 781 | Optional<unsigned int> colorbufferSize; |
| 782 | Optional<int> samples; |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 783 | Optional<GLboolean> fixedSampleLocations; |
| 784 | bool hasRenderbuffer = false; |
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 | for (const FramebufferAttachment &colorAttachment : mState.mColorAttachments) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 787 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 788 | if (colorAttachment.isAttached()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 789 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 790 | if (!CheckAttachmentCompleteness(context, colorAttachment)) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 791 | { |
| 792 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 793 | } |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 794 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 795 | const InternalFormat &format = *colorAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 796 | if (format.depthBits > 0 || format.stencilBits > 0) |
| 797 | { |
| 798 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 799 | } |
| 800 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 801 | if (!CheckAttachmentSampleCompleteness(context, colorAttachment, true, &samples, |
| 802 | &fixedSampleLocations)) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 803 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 804 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 807 | // in GLES 2.0, all color attachments attachments must have the same number of bitplanes |
| 808 | // in GLES 3.0, there is no such restriction |
| 809 | if (state.getClientMajorVersion() < 3) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 810 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 811 | if (colorbufferSize.valid()) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 812 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 813 | if (format.pixelBytes != colorbufferSize.value()) |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 814 | { |
| 815 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 816 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 817 | } |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 818 | else |
| 819 | { |
| 820 | colorbufferSize = format.pixelBytes; |
| 821 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 822 | } |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 823 | |
| 824 | hasRenderbuffer = hasRenderbuffer || (colorAttachment.type() == GL_RENDERBUFFER); |
| 825 | hasAttachments = true; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 826 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 827 | } |
| 828 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 829 | const FramebufferAttachment &depthAttachment = mState.mDepthAttachment; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 830 | if (depthAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 831 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 832 | if (!CheckAttachmentCompleteness(context, depthAttachment)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 833 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 834 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 835 | } |
| 836 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 837 | const InternalFormat &format = *depthAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 838 | if (format.depthBits == 0) |
| 839 | { |
| 840 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 841 | } |
| 842 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 843 | if (!CheckAttachmentSampleCompleteness(context, depthAttachment, false, &samples, |
| 844 | &fixedSampleLocations)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 845 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 846 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 847 | } |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 848 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 849 | hasRenderbuffer = hasRenderbuffer || (depthAttachment.type() == GL_RENDERBUFFER); |
| 850 | hasAttachments = true; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 853 | const FramebufferAttachment &stencilAttachment = mState.mStencilAttachment; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 854 | if (stencilAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 855 | { |
Geoff Lang | 9f10b77 | 2017-05-16 15:51:03 -0400 | [diff] [blame] | 856 | if (!CheckAttachmentCompleteness(context, stencilAttachment)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 857 | { |
| 858 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 859 | } |
| 860 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 861 | const InternalFormat &format = *stencilAttachment.getFormat().info; |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 862 | if (format.stencilBits == 0) |
| 863 | { |
| 864 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 865 | } |
| 866 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 867 | if (!CheckAttachmentSampleCompleteness(context, stencilAttachment, false, &samples, |
| 868 | &fixedSampleLocations)) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 869 | { |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 870 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 871 | } |
Corentin Wallez | 086d59a | 2016-04-29 09:06:49 -0400 | [diff] [blame] | 872 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 873 | hasRenderbuffer = hasRenderbuffer || (stencilAttachment.type() == GL_RENDERBUFFER); |
| 874 | hasAttachments = true; |
| 875 | } |
| 876 | |
| 877 | // Starting from ES 3.0 stencil and depth, if present, should be the same image |
| 878 | if (state.getClientMajorVersion() >= 3 && depthAttachment.isAttached() && |
| 879 | stencilAttachment.isAttached() && stencilAttachment != depthAttachment) |
| 880 | { |
| 881 | return GL_FRAMEBUFFER_UNSUPPORTED; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 884 | // Special additional validation for WebGL 1 DEPTH/STENCIL/DEPTH_STENCIL. |
| 885 | if (state.isWebGL1()) |
| 886 | { |
| 887 | if (!mState.mWebGLDepthStencilConsistent) |
| 888 | { |
| 889 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 890 | } |
| 891 | |
| 892 | if (mState.mWebGLDepthStencilAttachment.isAttached()) |
| 893 | { |
| 894 | if (mState.mWebGLDepthStencilAttachment.getDepthSize() == 0 || |
| 895 | mState.mWebGLDepthStencilAttachment.getStencilSize() == 0) |
| 896 | { |
| 897 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 898 | } |
| 899 | } |
| 900 | else if (mState.mStencilAttachment.isAttached() && |
| 901 | mState.mStencilAttachment.getDepthSize() > 0) |
| 902 | { |
| 903 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 904 | } |
| 905 | else if (mState.mDepthAttachment.isAttached() && |
| 906 | mState.mDepthAttachment.getStencilSize() > 0) |
| 907 | { |
| 908 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 909 | } |
| 910 | } |
| 911 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 912 | // ES3.1(section 9.4) requires that if no image is attached to the framebuffer, and either the |
| 913 | // value of the framebuffer's FRAMEBUFFER_DEFAULT_WIDTH or FRAMEBUFFER_DEFAULT_HEIGHT parameters |
| 914 | // is zero, the framebuffer is considered incomplete. |
JiangYizhou | 461d9a3 | 2017-01-04 16:37:26 +0800 | [diff] [blame] | 915 | GLint defaultWidth = mState.getDefaultWidth(); |
| 916 | GLint defaultHeight = mState.getDefaultHeight(); |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 917 | if (!hasAttachments && (defaultWidth == 0 || defaultHeight == 0)) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 918 | { |
| 919 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 922 | // 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] | 923 | // In ES 3.0, there is no such restriction. |
Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 924 | if ((state.getClientMajorVersion() < 3 || state.getExtensions().webglCompatibility) && |
| 925 | !mState.attachmentsHaveSameDimensions()) |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 926 | { |
| 927 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 928 | } |
| 929 | |
Geoff Lang | a1b9d5a | 2017-05-18 11:22:27 -0400 | [diff] [blame] | 930 | // ES3.1(section 9.4) requires that if the attached images are a mix of renderbuffers and |
| 931 | // 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] | 932 | if (fixedSampleLocations.valid() && hasRenderbuffer && !fixedSampleLocations.value()) |
| 933 | { |
| 934 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE; |
| 935 | } |
| 936 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 937 | syncState(context); |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 938 | if (!mImpl->checkStatus()) |
| 939 | { |
| 940 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 941 | } |
| 942 | |
| 943 | return GL_FRAMEBUFFER_COMPLETE; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 944 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 945 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 946 | Error Framebuffer::discard(const Context *context, size_t count, const GLenum *attachments) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 947 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 948 | return mImpl->discard(context, count, attachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 951 | Error Framebuffer::invalidate(const Context *context, size_t count, const GLenum *attachments) |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 952 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 953 | return mImpl->invalidate(context, count, attachments); |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 954 | } |
| 955 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 956 | Error Framebuffer::invalidateSub(const Context *context, |
| 957 | size_t count, |
| 958 | const GLenum *attachments, |
| 959 | const gl::Rectangle &area) |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 960 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 961 | return mImpl->invalidateSub(context, count, attachments, area); |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 962 | } |
| 963 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 964 | Error Framebuffer::clear(const gl::Context *context, GLbitfield mask) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 965 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 966 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 967 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 968 | return NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 969 | } |
| 970 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 971 | return mImpl->clear(context, mask); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 972 | } |
| 973 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 974 | Error Framebuffer::clearBufferfv(const gl::Context *context, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 975 | GLenum buffer, |
| 976 | GLint drawbuffer, |
| 977 | const GLfloat *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 978 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 979 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 980 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 981 | return NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 982 | } |
| 983 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 984 | return mImpl->clearBufferfv(context, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 985 | } |
| 986 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 987 | Error Framebuffer::clearBufferuiv(const gl::Context *context, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 988 | GLenum buffer, |
| 989 | GLint drawbuffer, |
| 990 | const GLuint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 991 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 992 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 993 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 994 | return NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 995 | } |
| 996 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 997 | return mImpl->clearBufferuiv(context, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 998 | } |
| 999 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1000 | Error Framebuffer::clearBufferiv(const gl::Context *context, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1001 | GLenum buffer, |
| 1002 | GLint drawbuffer, |
| 1003 | const GLint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1004 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1005 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1006 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1007 | return NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1008 | } |
| 1009 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1010 | return mImpl->clearBufferiv(context, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1011 | } |
| 1012 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1013 | Error Framebuffer::clearBufferfi(const gl::Context *context, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1014 | GLenum buffer, |
| 1015 | GLint drawbuffer, |
| 1016 | GLfloat depth, |
| 1017 | GLint stencil) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1018 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1019 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1020 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1021 | return NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 1022 | } |
| 1023 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1024 | return mImpl->clearBufferfi(context, buffer, drawbuffer, depth, stencil); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 1025 | } |
| 1026 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1027 | GLenum Framebuffer::getImplementationColorReadFormat(const Context *context) const |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1028 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1029 | return mImpl->getImplementationColorReadFormat(context); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1030 | } |
| 1031 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1032 | GLenum Framebuffer::getImplementationColorReadType(const Context *context) const |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1033 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1034 | return mImpl->getImplementationColorReadType(context); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1035 | } |
| 1036 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1037 | Error Framebuffer::readPixels(const gl::Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1038 | const Rectangle &area, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1039 | GLenum format, |
| 1040 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1041 | void *pixels) const |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1042 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1043 | ANGLE_TRY(mImpl->readPixels(context, area, format, type, pixels)); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1044 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1045 | Buffer *unpackBuffer = context->getGLState().getUnpackState().pixelBuffer.get(); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 1046 | if (unpackBuffer) |
| 1047 | { |
| 1048 | unpackBuffer->onPixelUnpack(); |
| 1049 | } |
| 1050 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1051 | return NoError(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1052 | } |
| 1053 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1054 | Error Framebuffer::blit(const gl::Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1055 | const Rectangle &sourceArea, |
| 1056 | const Rectangle &destArea, |
Geoff Lang | 242468f | 2015-09-24 14:15:41 -0400 | [diff] [blame] | 1057 | GLbitfield mask, |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 1058 | GLenum filter) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 1059 | { |
He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 1060 | GLbitfield blitMask = mask; |
| 1061 | |
| 1062 | // Note that blitting is called against draw framebuffer. |
| 1063 | // See the code in gl::Context::blitFramebuffer. |
| 1064 | if ((mask & GL_COLOR_BUFFER_BIT) && !hasEnabledDrawBuffer()) |
| 1065 | { |
| 1066 | blitMask &= ~GL_COLOR_BUFFER_BIT; |
| 1067 | } |
| 1068 | |
| 1069 | if ((mask & GL_STENCIL_BUFFER_BIT) && mState.getStencilAttachment() == nullptr) |
| 1070 | { |
| 1071 | blitMask &= ~GL_STENCIL_BUFFER_BIT; |
| 1072 | } |
| 1073 | |
| 1074 | if ((mask & GL_DEPTH_BUFFER_BIT) && mState.getDepthAttachment() == nullptr) |
| 1075 | { |
| 1076 | blitMask &= ~GL_DEPTH_BUFFER_BIT; |
| 1077 | } |
| 1078 | |
| 1079 | if (!blitMask) |
| 1080 | { |
| 1081 | return NoError(); |
| 1082 | } |
| 1083 | |
| 1084 | return mImpl->blit(context, sourceArea, destArea, blitMask, filter); |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 1085 | } |
| 1086 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1087 | int Framebuffer::getSamples(const Context *context) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1088 | { |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1089 | if (complete(context)) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1090 | { |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame^] | 1091 | return getCachedSamples(context); |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1092 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 1093 | |
| 1094 | return 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Jamie Madill | 9c33586 | 2017-07-18 11:51:38 -0400 | [diff] [blame^] | 1097 | int Framebuffer::getCachedSamples(const Context *context) |
| 1098 | { |
| 1099 | // For a complete framebuffer, all attachments must have the same sample count. |
| 1100 | // In this case return the first nonzero sample size. |
| 1101 | const auto *firstNonNullAttachment = mState.getFirstNonNullAttachment(); |
| 1102 | if (firstNonNullAttachment) |
| 1103 | { |
| 1104 | ASSERT(firstNonNullAttachment->isAttached()); |
| 1105 | return firstNonNullAttachment->getSamples(); |
| 1106 | } |
| 1107 | |
| 1108 | // No attachments found. |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1112 | Error Framebuffer::getSamplePosition(size_t index, GLfloat *xy) const |
| 1113 | { |
| 1114 | ANGLE_TRY(mImpl->getSamplePosition(index, xy)); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1115 | return NoError(); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1116 | } |
| 1117 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 1118 | bool Framebuffer::hasValidDepthStencil() const |
| 1119 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 1120 | return mState.getDepthStencilAttachment() != nullptr; |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 1121 | } |
| 1122 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1123 | void Framebuffer::setAttachment(const Context *context, |
| 1124 | GLenum type, |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1125 | GLenum binding, |
| 1126 | const ImageIndex &textureIndex, |
| 1127 | FramebufferAttachmentObject *resource) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 1128 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1129 | // Context may be null in unit tests. |
| 1130 | if (!context || !context->isWebGL1()) |
| 1131 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1132 | setAttachmentImpl(context, type, binding, textureIndex, resource); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1133 | return; |
| 1134 | } |
| 1135 | |
| 1136 | switch (binding) |
| 1137 | { |
| 1138 | case GL_DEPTH_STENCIL: |
| 1139 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1140 | mState.mWebGLDepthStencilAttachment.attach(context, type, binding, textureIndex, |
| 1141 | resource); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1142 | break; |
| 1143 | case GL_DEPTH: |
| 1144 | case GL_DEPTH_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1145 | mState.mWebGLDepthAttachment.attach(context, type, binding, textureIndex, resource); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1146 | break; |
| 1147 | case GL_STENCIL: |
| 1148 | case GL_STENCIL_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1149 | mState.mWebGLStencilAttachment.attach(context, type, binding, textureIndex, resource); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1150 | break; |
| 1151 | default: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1152 | setAttachmentImpl(context, type, binding, textureIndex, resource); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1153 | return; |
| 1154 | } |
| 1155 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1156 | commitWebGL1DepthStencilIfConsistent(context); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1157 | } |
| 1158 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1159 | void Framebuffer::commitWebGL1DepthStencilIfConsistent(const Context *context) |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1160 | { |
| 1161 | int count = 0; |
| 1162 | |
| 1163 | std::array<FramebufferAttachment *, 3> attachments = {{&mState.mWebGLDepthStencilAttachment, |
| 1164 | &mState.mWebGLDepthAttachment, |
| 1165 | &mState.mWebGLStencilAttachment}}; |
| 1166 | for (FramebufferAttachment *attachment : attachments) |
| 1167 | { |
| 1168 | if (attachment->isAttached()) |
| 1169 | { |
| 1170 | count++; |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | mState.mWebGLDepthStencilConsistent = (count <= 1); |
| 1175 | if (!mState.mWebGLDepthStencilConsistent) |
| 1176 | { |
| 1177 | // Inconsistent. |
| 1178 | return; |
| 1179 | } |
| 1180 | |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1181 | auto getImageIndexIfTextureAttachment = [](const FramebufferAttachment &attachment) { |
| 1182 | if (attachment.type() == GL_TEXTURE) |
| 1183 | { |
| 1184 | return attachment.getTextureImageIndex(); |
| 1185 | } |
| 1186 | else |
| 1187 | { |
| 1188 | return ImageIndex::MakeInvalid(); |
| 1189 | } |
| 1190 | }; |
| 1191 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1192 | if (mState.mWebGLDepthAttachment.isAttached()) |
| 1193 | { |
| 1194 | const auto &depth = mState.mWebGLDepthAttachment; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1195 | setAttachmentImpl(context, depth.type(), GL_DEPTH_ATTACHMENT, |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1196 | getImageIndexIfTextureAttachment(depth), depth.getResource()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1197 | setAttachmentImpl(context, GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), |
| 1198 | nullptr); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1199 | } |
| 1200 | else if (mState.mWebGLStencilAttachment.isAttached()) |
| 1201 | { |
| 1202 | const auto &stencil = mState.mWebGLStencilAttachment; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1203 | setAttachmentImpl(context, GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), |
| 1204 | nullptr); |
| 1205 | setAttachmentImpl(context, stencil.type(), GL_STENCIL_ATTACHMENT, |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1206 | getImageIndexIfTextureAttachment(stencil), stencil.getResource()); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1207 | } |
| 1208 | else if (mState.mWebGLDepthStencilAttachment.isAttached()) |
| 1209 | { |
| 1210 | const auto &depthStencil = mState.mWebGLDepthStencilAttachment; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1211 | setAttachmentImpl(context, depthStencil.type(), GL_DEPTH_ATTACHMENT, |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1212 | getImageIndexIfTextureAttachment(depthStencil), |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1213 | depthStencil.getResource()); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1214 | setAttachmentImpl(context, depthStencil.type(), GL_STENCIL_ATTACHMENT, |
Geoff Lang | e466c55 | 2017-03-17 15:24:12 -0400 | [diff] [blame] | 1215 | getImageIndexIfTextureAttachment(depthStencil), |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1216 | depthStencil.getResource()); |
| 1217 | } |
| 1218 | else |
| 1219 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1220 | setAttachmentImpl(context, GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), |
| 1221 | nullptr); |
| 1222 | setAttachmentImpl(context, GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), |
| 1223 | nullptr); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1227 | void Framebuffer::setAttachmentImpl(const Context *context, |
| 1228 | GLenum type, |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1229 | GLenum binding, |
| 1230 | const ImageIndex &textureIndex, |
| 1231 | FramebufferAttachmentObject *resource) |
| 1232 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1233 | switch (binding) |
| 1234 | { |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1235 | case GL_DEPTH_STENCIL: |
| 1236 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1237 | { |
| 1238 | // ensure this is a legitimate depth+stencil format |
| 1239 | FramebufferAttachmentObject *attachmentObj = resource; |
| 1240 | if (resource) |
| 1241 | { |
Jamie Madill | 4fd95d5 | 2017-04-05 11:22:18 -0400 | [diff] [blame] | 1242 | const Format &format = resource->getAttachmentFormat(binding, textureIndex); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1243 | if (format.info->depthBits == 0 || format.info->stencilBits == 0) |
| 1244 | { |
| 1245 | // Attaching nullptr detaches the current attachment. |
| 1246 | attachmentObj = nullptr; |
| 1247 | } |
| 1248 | } |
| 1249 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1250 | updateAttachment(context, &mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1251 | &mDirtyDepthAttachmentBinding, type, binding, textureIndex, |
| 1252 | attachmentObj); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1253 | updateAttachment(context, &mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1254 | &mDirtyStencilAttachmentBinding, type, binding, textureIndex, |
| 1255 | attachmentObj); |
| 1256 | return; |
| 1257 | } |
| 1258 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1259 | case GL_DEPTH: |
| 1260 | case GL_DEPTH_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1261 | updateAttachment(context, &mState.mDepthAttachment, DIRTY_BIT_DEPTH_ATTACHMENT, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1262 | &mDirtyDepthAttachmentBinding, type, binding, textureIndex, resource); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1263 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1264 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1265 | case GL_STENCIL: |
| 1266 | case GL_STENCIL_ATTACHMENT: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1267 | updateAttachment(context, &mState.mStencilAttachment, DIRTY_BIT_STENCIL_ATTACHMENT, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1268 | &mDirtyStencilAttachmentBinding, type, binding, textureIndex, |
| 1269 | resource); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1270 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1271 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1272 | case GL_BACK: |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1273 | mState.mColorAttachments[0].attach(context, type, binding, textureIndex, resource); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1274 | mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 1275 | // No need for a resource binding for the default FBO, it's always complete. |
| 1276 | break; |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1277 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1278 | default: |
| 1279 | { |
| 1280 | size_t colorIndex = binding - GL_COLOR_ATTACHMENT0; |
| 1281 | ASSERT(colorIndex < mState.mColorAttachments.size()); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1282 | size_t dirtyBit = DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1283 | updateAttachment(context, &mState.mColorAttachments[colorIndex], dirtyBit, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1284 | &mDirtyColorAttachmentBindings[colorIndex], type, binding, |
| 1285 | textureIndex, resource); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1286 | |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 1287 | // TODO(jmadill): ASSERT instead of checking the attachment exists in |
| 1288 | // formsRenderingFeedbackLoopWith |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1289 | bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE); |
| 1290 | mState.mEnabledDrawBuffers.set(colorIndex, enabled); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1291 | } |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1292 | break; |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 1293 | } |
| 1294 | } |
| 1295 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1296 | void Framebuffer::updateAttachment(const Context *context, |
| 1297 | FramebufferAttachment *attachment, |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1298 | size_t dirtyBit, |
| 1299 | OnAttachmentDirtyBinding *onDirtyBinding, |
| 1300 | GLenum type, |
| 1301 | GLenum binding, |
| 1302 | const ImageIndex &textureIndex, |
| 1303 | FramebufferAttachmentObject *resource) |
| 1304 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1305 | attachment->attach(context, type, binding, textureIndex, resource); |
Jamie Madill | b812669 | 2017-04-05 11:22:17 -0400 | [diff] [blame] | 1306 | mDirtyBits.set(dirtyBit); |
| 1307 | BindResourceChannel(onDirtyBinding, resource); |
| 1308 | } |
| 1309 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1310 | void Framebuffer::resetAttachment(const Context *context, GLenum binding) |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1311 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1312 | setAttachment(context, GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 1313 | } |
| 1314 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1315 | void Framebuffer::syncState(const Context *context) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1316 | { |
| 1317 | if (mDirtyBits.any()) |
| 1318 | { |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 1319 | mImpl->syncState(context, mDirtyBits); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1320 | mDirtyBits.reset(); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 1321 | if (mId != 0) |
| 1322 | { |
| 1323 | mCachedStatus.reset(); |
| 1324 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1325 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1326 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1327 | |
Jamie Madill | 1e5499d | 2017-04-05 11:22:16 -0400 | [diff] [blame] | 1328 | void Framebuffer::signal(uint32_t token) |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1329 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1330 | // TOOD(jmadill): Make this only update individual attachments to do less work. |
| 1331 | mCachedStatus.reset(); |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1332 | } |
| 1333 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1334 | bool Framebuffer::complete(const Context *context) |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1335 | { |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1336 | return (checkStatus(context) == GL_FRAMEBUFFER_COMPLETE); |
| 1337 | } |
| 1338 | |
| 1339 | bool Framebuffer::cachedComplete() const |
| 1340 | { |
| 1341 | return (mCachedStatus.valid() && mCachedStatus == GL_FRAMEBUFFER_COMPLETE); |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1342 | } |
| 1343 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1344 | bool Framebuffer::formsRenderingFeedbackLoopWith(const State &state) const |
| 1345 | { |
| 1346 | const Program *program = state.getProgram(); |
| 1347 | |
| 1348 | // TODO(jmadill): Default framebuffer feedback loops. |
| 1349 | if (mId == 0) |
| 1350 | { |
| 1351 | return false; |
| 1352 | } |
| 1353 | |
| 1354 | // The bitset will skip inactive draw buffers. |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1355 | for (size_t drawIndex : mState.mEnabledDrawBuffers) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1356 | { |
| 1357 | const FramebufferAttachment *attachment = getDrawBuffer(drawIndex); |
| 1358 | if (attachment && attachment->type() == GL_TEXTURE) |
| 1359 | { |
| 1360 | // Validate the feedback loop. |
| 1361 | if (program->samplesFromTexture(state, attachment->id())) |
| 1362 | { |
| 1363 | return true; |
| 1364 | } |
| 1365 | } |
| 1366 | } |
| 1367 | |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1368 | // Validate depth-stencil feedback loop. |
| 1369 | const auto &dsState = state.getDepthStencilState(); |
| 1370 | |
| 1371 | // We can skip the feedback loop checks if depth/stencil is masked out or disabled. |
| 1372 | const FramebufferAttachment *depth = getDepthbuffer(); |
| 1373 | if (depth && depth->type() == GL_TEXTURE && dsState.depthTest && dsState.depthMask) |
| 1374 | { |
| 1375 | if (program->samplesFromTexture(state, depth->id())) |
| 1376 | { |
| 1377 | return true; |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | // Note: we assume the front and back masks are the same for WebGL. |
| 1382 | const FramebufferAttachment *stencil = getStencilbuffer(); |
| 1383 | ASSERT(dsState.stencilBackWritemask == dsState.stencilWritemask); |
| 1384 | if (stencil && stencil->type() == GL_TEXTURE && dsState.stencilTest && |
| 1385 | dsState.stencilWritemask != 0) |
| 1386 | { |
| 1387 | // Skip the feedback loop check if depth/stencil point to the same resource. |
| 1388 | if (!depth || *stencil != *depth) |
| 1389 | { |
| 1390 | if (program->samplesFromTexture(state, stencil->id())) |
| 1391 | { |
| 1392 | return true; |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1397 | return false; |
| 1398 | } |
| 1399 | |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1400 | bool Framebuffer::formsCopyingFeedbackLoopWith(GLuint copyTextureID, |
| 1401 | GLint copyTextureLevel, |
| 1402 | GLint copyTextureLayer) const |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1403 | { |
| 1404 | if (mId == 0) |
| 1405 | { |
| 1406 | // It seems impossible to form a texture copying feedback loop with the default FBO. |
| 1407 | return false; |
| 1408 | } |
| 1409 | |
| 1410 | const FramebufferAttachment *readAttachment = getReadColorbuffer(); |
| 1411 | ASSERT(readAttachment); |
| 1412 | |
| 1413 | if (readAttachment->isTextureWithId(copyTextureID)) |
| 1414 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1415 | const auto &imageIndex = readAttachment->getTextureImageIndex(); |
| 1416 | if (imageIndex.mipIndex == copyTextureLevel) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1417 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1418 | // Check 3D/Array texture layers. |
| 1419 | return imageIndex.layerIndex == ImageIndex::ENTIRE_LEVEL || |
| 1420 | copyTextureLayer == ImageIndex::ENTIRE_LEVEL || |
| 1421 | imageIndex.layerIndex == copyTextureLayer; |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1422 | } |
| 1423 | } |
| 1424 | return false; |
| 1425 | } |
| 1426 | |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 1427 | GLint Framebuffer::getDefaultWidth() const |
| 1428 | { |
| 1429 | return mState.getDefaultWidth(); |
| 1430 | } |
| 1431 | |
| 1432 | GLint Framebuffer::getDefaultHeight() const |
| 1433 | { |
| 1434 | return mState.getDefaultHeight(); |
| 1435 | } |
| 1436 | |
| 1437 | GLint Framebuffer::getDefaultSamples() const |
| 1438 | { |
| 1439 | return mState.getDefaultSamples(); |
| 1440 | } |
| 1441 | |
| 1442 | GLboolean Framebuffer::getDefaultFixedSampleLocations() const |
| 1443 | { |
| 1444 | return mState.getDefaultFixedSampleLocations(); |
| 1445 | } |
| 1446 | |
| 1447 | void Framebuffer::setDefaultWidth(GLint defaultWidth) |
| 1448 | { |
| 1449 | mState.mDefaultWidth = defaultWidth; |
| 1450 | mDirtyBits.set(DIRTY_BIT_DEFAULT_WIDTH); |
| 1451 | } |
| 1452 | |
| 1453 | void Framebuffer::setDefaultHeight(GLint defaultHeight) |
| 1454 | { |
| 1455 | mState.mDefaultHeight = defaultHeight; |
| 1456 | mDirtyBits.set(DIRTY_BIT_DEFAULT_HEIGHT); |
| 1457 | } |
| 1458 | |
| 1459 | void Framebuffer::setDefaultSamples(GLint defaultSamples) |
| 1460 | { |
| 1461 | mState.mDefaultSamples = defaultSamples; |
| 1462 | mDirtyBits.set(DIRTY_BIT_DEFAULT_SAMPLES); |
| 1463 | } |
| 1464 | |
| 1465 | void Framebuffer::setDefaultFixedSampleLocations(GLboolean defaultFixedSampleLocations) |
| 1466 | { |
| 1467 | mState.mDefaultFixedSampleLocations = defaultFixedSampleLocations; |
| 1468 | mDirtyBits.set(DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS); |
| 1469 | } |
| 1470 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1471 | // TODO(jmadill): Remove this kludge. |
| 1472 | GLenum Framebuffer::checkStatus(const ValidationContext *context) |
| 1473 | { |
| 1474 | return checkStatus(static_cast<const Context *>(context)); |
| 1475 | } |
| 1476 | |
| 1477 | int Framebuffer::getSamples(const ValidationContext *context) |
| 1478 | { |
| 1479 | return getSamples(static_cast<const Context *>(context)); |
| 1480 | } |
| 1481 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1482 | } // namespace gl |