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 | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 12 | #include "common/BitSetIterator.h" |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 13 | #include "common/Optional.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" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 17 | #include "libANGLE/FramebufferAttachment.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 18 | #include "libANGLE/Renderbuffer.h" |
| 19 | #include "libANGLE/Surface.h" |
| 20 | #include "libANGLE/Texture.h" |
| 21 | #include "libANGLE/formatutils.h" |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 22 | #include "libANGLE/renderer/ContextImpl.h" |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 23 | #include "libANGLE/renderer/FramebufferImpl.h" |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 24 | #include "libANGLE/renderer/GLImplFactory.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 25 | #include "libANGLE/renderer/RenderbufferImpl.h" |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 26 | #include "libANGLE/renderer/SurfaceImpl.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 27 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 28 | using namespace angle; |
| 29 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 30 | namespace gl |
| 31 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 32 | |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 33 | namespace |
| 34 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 35 | |
| 36 | void BindResourceChannel(ChannelBinding *binding, FramebufferAttachmentObject *resource) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 37 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 38 | binding->bind(resource ? resource->getDirtyChannel() : nullptr); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 39 | } |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 40 | |
| 41 | } // anonymous namespace |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 42 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 43 | FramebufferState::FramebufferState() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 44 | : mLabel(), |
| 45 | mColorAttachments(1), |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 46 | mDrawBufferStates(1, GL_NONE), |
| 47 | mReadBufferState(GL_COLOR_ATTACHMENT0_EXT) |
| 48 | { |
| 49 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 50 | mEnabledDrawBuffers.set(0); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 51 | } |
| 52 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 53 | FramebufferState::FramebufferState(const Caps &caps) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 54 | : mLabel(), |
| 55 | mColorAttachments(caps.maxColorAttachments), |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 56 | mDrawBufferStates(caps.maxDrawBuffers, GL_NONE), |
| 57 | mReadBufferState(GL_COLOR_ATTACHMENT0_EXT) |
| 58 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 59 | ASSERT(mDrawBufferStates.size() > 0); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 60 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
| 61 | } |
| 62 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 63 | FramebufferState::~FramebufferState() |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 64 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 67 | const std::string &FramebufferState::getLabel() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 68 | { |
| 69 | return mLabel; |
| 70 | } |
| 71 | |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 72 | const FramebufferAttachment *FramebufferState::getAttachment(GLenum attachment) const |
| 73 | { |
| 74 | if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15) |
| 75 | { |
| 76 | return getColorAttachment(attachment - GL_COLOR_ATTACHMENT0); |
| 77 | } |
| 78 | |
| 79 | switch (attachment) |
| 80 | { |
| 81 | case GL_COLOR: |
| 82 | case GL_BACK: |
| 83 | return getColorAttachment(0); |
| 84 | case GL_DEPTH: |
| 85 | case GL_DEPTH_ATTACHMENT: |
| 86 | return getDepthAttachment(); |
| 87 | case GL_STENCIL: |
| 88 | case GL_STENCIL_ATTACHMENT: |
| 89 | return getStencilAttachment(); |
| 90 | case GL_DEPTH_STENCIL: |
| 91 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 92 | return getDepthStencilAttachment(); |
| 93 | default: |
| 94 | UNREACHABLE(); |
| 95 | return nullptr; |
| 96 | } |
| 97 | } |
| 98 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 99 | const FramebufferAttachment *FramebufferState::getReadAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 100 | { |
Antoine Labour | 2ec65dc | 2016-11-30 16:28:58 -0800 | [diff] [blame] | 101 | if (mReadBufferState == GL_NONE) |
| 102 | { |
| 103 | return nullptr; |
| 104 | } |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 105 | ASSERT(mReadBufferState == GL_BACK || (mReadBufferState >= GL_COLOR_ATTACHMENT0 && mReadBufferState <= GL_COLOR_ATTACHMENT15)); |
| 106 | size_t readIndex = (mReadBufferState == GL_BACK ? 0 : static_cast<size_t>(mReadBufferState - GL_COLOR_ATTACHMENT0)); |
| 107 | ASSERT(readIndex < mColorAttachments.size()); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 108 | return mColorAttachments[readIndex].isAttached() ? &mColorAttachments[readIndex] : nullptr; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 109 | } |
| 110 | |
Jamie Madill | 7b57b9d | 2017-01-13 09:33:38 -0500 | [diff] [blame] | 111 | const FramebufferAttachment *FramebufferState::getFirstNonNullAttachment() const |
| 112 | { |
| 113 | auto *colorAttachment = getFirstColorAttachment(); |
| 114 | if (colorAttachment) |
| 115 | { |
| 116 | return colorAttachment; |
| 117 | } |
| 118 | return getDepthOrStencilAttachment(); |
| 119 | } |
| 120 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 121 | const FramebufferAttachment *FramebufferState::getFirstColorAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 122 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 123 | for (const FramebufferAttachment &colorAttachment : mColorAttachments) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 124 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 125 | if (colorAttachment.isAttached()) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 126 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 127 | return &colorAttachment; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | return nullptr; |
| 132 | } |
| 133 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 134 | const FramebufferAttachment *FramebufferState::getDepthOrStencilAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 135 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 136 | if (mDepthAttachment.isAttached()) |
| 137 | { |
| 138 | return &mDepthAttachment; |
| 139 | } |
| 140 | if (mStencilAttachment.isAttached()) |
| 141 | { |
| 142 | return &mStencilAttachment; |
| 143 | } |
| 144 | return nullptr; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 145 | } |
| 146 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 147 | const FramebufferAttachment *FramebufferState::getStencilOrDepthStencilAttachment() const |
| 148 | { |
| 149 | if (mStencilAttachment.isAttached()) |
| 150 | { |
| 151 | return &mStencilAttachment; |
| 152 | } |
| 153 | return getDepthStencilAttachment(); |
| 154 | } |
| 155 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 156 | const FramebufferAttachment *FramebufferState::getColorAttachment(size_t colorAttachment) const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 157 | { |
| 158 | ASSERT(colorAttachment < mColorAttachments.size()); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 159 | return mColorAttachments[colorAttachment].isAttached() ? |
| 160 | &mColorAttachments[colorAttachment] : |
| 161 | nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 162 | } |
| 163 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 164 | const FramebufferAttachment *FramebufferState::getDepthAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 165 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 166 | return mDepthAttachment.isAttached() ? &mDepthAttachment : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 167 | } |
| 168 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 169 | const FramebufferAttachment *FramebufferState::getStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 170 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 171 | return mStencilAttachment.isAttached() ? &mStencilAttachment : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 174 | const FramebufferAttachment *FramebufferState::getDepthStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 175 | { |
| 176 | // A valid depth-stencil attachment has the same resource bound to both the |
| 177 | // depth and stencil attachment points. |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 178 | if (mDepthAttachment.isAttached() && mStencilAttachment.isAttached() && |
Jamie Madill | 44f2648 | 2016-11-18 12:49:15 -0500 | [diff] [blame] | 179 | mDepthAttachment == mStencilAttachment) |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 180 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 181 | return &mDepthAttachment; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | return nullptr; |
| 185 | } |
| 186 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 187 | bool FramebufferState::attachmentsHaveSameDimensions() const |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 188 | { |
| 189 | Optional<Extents> attachmentSize; |
| 190 | |
| 191 | auto hasMismatchedSize = [&attachmentSize](const FramebufferAttachment &attachment) |
| 192 | { |
| 193 | if (!attachment.isAttached()) |
| 194 | { |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | if (!attachmentSize.valid()) |
| 199 | { |
| 200 | attachmentSize = attachment.getSize(); |
| 201 | return false; |
| 202 | } |
| 203 | |
| 204 | return (attachment.getSize() != attachmentSize.value()); |
| 205 | }; |
| 206 | |
| 207 | for (const auto &attachment : mColorAttachments) |
| 208 | { |
| 209 | if (hasMismatchedSize(attachment)) |
| 210 | { |
| 211 | return false; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if (hasMismatchedSize(mDepthAttachment)) |
| 216 | { |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | return !hasMismatchedSize(mStencilAttachment); |
| 221 | } |
| 222 | |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 223 | const gl::FramebufferAttachment *FramebufferState::getDrawBuffer(size_t drawBufferIdx) const |
| 224 | { |
| 225 | ASSERT(drawBufferIdx < mDrawBufferStates.size()); |
| 226 | if (mDrawBufferStates[drawBufferIdx] != GL_NONE) |
| 227 | { |
| 228 | // ES3 spec: "If the GL is bound to a draw framebuffer object, the ith buffer listed in bufs |
| 229 | // must be COLOR_ATTACHMENTi or NONE" |
| 230 | ASSERT(mDrawBufferStates[drawBufferIdx] == GL_COLOR_ATTACHMENT0 + drawBufferIdx || |
| 231 | (drawBufferIdx == 0 && mDrawBufferStates[drawBufferIdx] == GL_BACK)); |
| 232 | return getAttachment(mDrawBufferStates[drawBufferIdx]); |
| 233 | } |
| 234 | else |
| 235 | { |
| 236 | return nullptr; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | size_t FramebufferState::getDrawBufferCount() const |
| 241 | { |
| 242 | return mDrawBufferStates.size(); |
| 243 | } |
| 244 | |
Geoff Lang | b21e20d | 2016-07-19 15:35:41 -0400 | [diff] [blame] | 245 | bool FramebufferState::colorAttachmentsAreUniqueImages() const |
| 246 | { |
| 247 | for (size_t firstAttachmentIdx = 0; firstAttachmentIdx < mColorAttachments.size(); |
| 248 | firstAttachmentIdx++) |
| 249 | { |
| 250 | const gl::FramebufferAttachment &firstAttachment = mColorAttachments[firstAttachmentIdx]; |
| 251 | if (!firstAttachment.isAttached()) |
| 252 | { |
| 253 | continue; |
| 254 | } |
| 255 | |
| 256 | for (size_t secondAttachmentIdx = firstAttachmentIdx + 1; |
| 257 | secondAttachmentIdx < mColorAttachments.size(); secondAttachmentIdx++) |
| 258 | { |
| 259 | const gl::FramebufferAttachment &secondAttachment = |
| 260 | mColorAttachments[secondAttachmentIdx]; |
| 261 | if (!secondAttachment.isAttached()) |
| 262 | { |
| 263 | continue; |
| 264 | } |
| 265 | |
| 266 | if (firstAttachment == secondAttachment) |
| 267 | { |
| 268 | return false; |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | return true; |
| 274 | } |
| 275 | |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 276 | Framebuffer::Framebuffer(const Caps &caps, rx::GLImplFactory *factory, GLuint id) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 277 | : mState(caps), |
| 278 | mImpl(factory->createFramebuffer(mState)), |
| 279 | mId(id), |
| 280 | mCachedStatus(), |
| 281 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 282 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 283 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 284 | ASSERT(mId != 0); |
| 285 | ASSERT(mImpl != nullptr); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 286 | ASSERT(mState.mColorAttachments.size() == static_cast<size_t>(caps.maxColorAttachments)); |
| 287 | |
| 288 | for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex) |
| 289 | { |
| 290 | mDirtyColorAttachmentBindings.push_back(ChannelBinding( |
| 291 | this, static_cast<SignalToken>(DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex))); |
| 292 | } |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | Framebuffer::Framebuffer(rx::SurfaceImpl *surface) |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 296 | : mState(), |
| 297 | mImpl(surface->createDefaultFramebuffer(mState)), |
| 298 | mId(0), |
| 299 | mCachedStatus(GL_FRAMEBUFFER_COMPLETE), |
| 300 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 301 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 302 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 303 | ASSERT(mImpl != nullptr); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 304 | mDirtyColorAttachmentBindings.push_back( |
| 305 | ChannelBinding(this, static_cast<SignalToken>(DIRTY_BIT_COLOR_ATTACHMENT_0))); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 308 | Framebuffer::Framebuffer(rx::GLImplFactory *factory) |
| 309 | : mState(), |
| 310 | mImpl(factory->createFramebuffer(mState)), |
| 311 | mId(0), |
| 312 | mCachedStatus(GL_FRAMEBUFFER_UNDEFINED_OES), |
| 313 | mDirtyDepthAttachmentBinding(this, DIRTY_BIT_DEPTH_ATTACHMENT), |
| 314 | mDirtyStencilAttachmentBinding(this, DIRTY_BIT_STENCIL_ATTACHMENT) |
| 315 | { |
| 316 | mDirtyColorAttachmentBindings.push_back( |
| 317 | ChannelBinding(this, static_cast<SignalToken>(DIRTY_BIT_COLOR_ATTACHMENT_0))); |
| 318 | } |
| 319 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 320 | Framebuffer::~Framebuffer() |
| 321 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 322 | SafeDelete(mImpl); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 325 | void Framebuffer::setLabel(const std::string &label) |
| 326 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 327 | mState.mLabel = label; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | const std::string &Framebuffer::getLabel() const |
| 331 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 332 | return mState.mLabel; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 333 | } |
| 334 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 335 | void Framebuffer::detachTexture(GLuint textureId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 336 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 337 | detachResourceById(GL_TEXTURE, textureId); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 340 | void Framebuffer::detachRenderbuffer(GLuint renderbufferId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 341 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 342 | detachResourceById(GL_RENDERBUFFER, renderbufferId); |
| 343 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 344 | |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 345 | void Framebuffer::detachResourceById(GLenum resourceType, GLuint resourceId) |
| 346 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 347 | for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 348 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 349 | detachMatchingAttachment(&mState.mColorAttachments[colorIndex], resourceType, resourceId, |
| 350 | DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 353 | detachMatchingAttachment(&mState.mDepthAttachment, resourceType, resourceId, |
| 354 | DIRTY_BIT_DEPTH_ATTACHMENT); |
| 355 | detachMatchingAttachment(&mState.mStencilAttachment, resourceType, resourceId, |
| 356 | DIRTY_BIT_STENCIL_ATTACHMENT); |
| 357 | } |
| 358 | |
| 359 | void Framebuffer::detachMatchingAttachment(FramebufferAttachment *attachment, |
| 360 | GLenum matchType, |
| 361 | GLuint matchId, |
| 362 | size_t dirtyBit) |
| 363 | { |
| 364 | if (attachment->isAttached() && attachment->type() == matchType && attachment->id() == matchId) |
| 365 | { |
| 366 | attachment->detach(); |
| 367 | mDirtyBits.set(dirtyBit); |
| 368 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 371 | const FramebufferAttachment *Framebuffer::getColorbuffer(size_t colorAttachment) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 372 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 373 | return mState.getColorAttachment(colorAttachment); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 376 | const FramebufferAttachment *Framebuffer::getDepthbuffer() const |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 377 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 378 | return mState.getDepthAttachment(); |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 379 | } |
| 380 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 381 | const FramebufferAttachment *Framebuffer::getStencilbuffer() const |
| 382 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 383 | return mState.getStencilAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 384 | } |
| 385 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 386 | const FramebufferAttachment *Framebuffer::getDepthStencilBuffer() const |
| 387 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 388 | return mState.getDepthStencilAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | const FramebufferAttachment *Framebuffer::getDepthOrStencilbuffer() const |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 392 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 393 | return mState.getDepthOrStencilAttachment(); |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 396 | const FramebufferAttachment *Framebuffer::getStencilOrDepthStencilAttachment() const |
| 397 | { |
| 398 | return mState.getStencilOrDepthStencilAttachment(); |
| 399 | } |
| 400 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 401 | const FramebufferAttachment *Framebuffer::getReadColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 402 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 403 | return mState.getReadAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 404 | } |
| 405 | |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 406 | GLenum Framebuffer::getReadColorbufferType() const |
| 407 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 408 | const FramebufferAttachment *readAttachment = mState.getReadAttachment(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 409 | return (readAttachment != nullptr ? readAttachment->type() : GL_NONE); |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 412 | const FramebufferAttachment *Framebuffer::getFirstColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 413 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 414 | return mState.getFirstColorAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 417 | const FramebufferAttachment *Framebuffer::getAttachment(GLenum attachment) const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 418 | { |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 419 | return mState.getAttachment(attachment); |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 420 | } |
| 421 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 422 | size_t Framebuffer::getDrawbufferStateCount() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 423 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 424 | return mState.mDrawBufferStates.size(); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | GLenum Framebuffer::getDrawBufferState(size_t drawBuffer) const |
| 428 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 429 | ASSERT(drawBuffer < mState.mDrawBufferStates.size()); |
| 430 | return mState.mDrawBufferStates[drawBuffer]; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 433 | const std::vector<GLenum> &Framebuffer::getDrawBufferStates() const |
| 434 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 435 | return mState.getDrawBufferStates(); |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Geoff Lang | 164d54e | 2014-12-01 10:55:33 -0500 | [diff] [blame] | 438 | 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] | 439 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 440 | auto &drawStates = mState.mDrawBufferStates; |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 441 | |
| 442 | ASSERT(count <= drawStates.size()); |
| 443 | std::copy(buffers, buffers + count, drawStates.begin()); |
| 444 | std::fill(drawStates.begin() + count, drawStates.end(), GL_NONE); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 445 | mDirtyBits.set(DIRTY_BIT_DRAW_BUFFERS); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 446 | |
| 447 | mState.mEnabledDrawBuffers.reset(); |
| 448 | for (size_t index = 0; index < count; ++index) |
| 449 | { |
| 450 | if (drawStates[index] != GL_NONE && mState.mColorAttachments[index].isAttached()) |
| 451 | { |
| 452 | mState.mEnabledDrawBuffers.set(index); |
| 453 | } |
| 454 | } |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 455 | } |
| 456 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 457 | const FramebufferAttachment *Framebuffer::getDrawBuffer(size_t drawBuffer) const |
| 458 | { |
Geoff Lang | 4b7f12b | 2016-06-21 16:47:07 -0400 | [diff] [blame] | 459 | return mState.getDrawBuffer(drawBuffer); |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | bool Framebuffer::hasEnabledDrawBuffer() const |
| 463 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 464 | for (size_t drawbufferIdx = 0; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 465 | { |
| 466 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
| 467 | { |
| 468 | return true; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | return false; |
| 473 | } |
| 474 | |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 475 | GLenum Framebuffer::getReadBufferState() const |
| 476 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 477 | return mState.mReadBufferState; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | void Framebuffer::setReadBuffer(GLenum buffer) |
| 481 | { |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 482 | ASSERT(buffer == GL_BACK || buffer == GL_NONE || |
| 483 | (buffer >= GL_COLOR_ATTACHMENT0 && |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 484 | (buffer - GL_COLOR_ATTACHMENT0) < mState.mColorAttachments.size())); |
| 485 | mState.mReadBufferState = buffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 486 | mDirtyBits.set(DIRTY_BIT_READ_BUFFER); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 489 | size_t Framebuffer::getNumColorBuffers() const |
| 490 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 491 | return mState.mColorAttachments.size(); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 492 | } |
| 493 | |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 494 | bool Framebuffer::hasDepth() const |
| 495 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 496 | return (mState.mDepthAttachment.isAttached() && mState.mDepthAttachment.getDepthSize() > 0); |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 497 | } |
| 498 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 499 | bool Framebuffer::hasStencil() const |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 500 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 501 | return (mState.mStencilAttachment.isAttached() && |
| 502 | mState.mStencilAttachment.getStencilSize() > 0); |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 503 | } |
| 504 | |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 505 | bool Framebuffer::usingExtendedDrawBuffers() const |
| 506 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 507 | for (size_t drawbufferIdx = 1; drawbufferIdx < mState.mDrawBufferStates.size(); ++drawbufferIdx) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 508 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 509 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 510 | { |
| 511 | return true; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | return false; |
| 516 | } |
| 517 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 518 | GLenum Framebuffer::checkStatus(const ContextState &state) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 519 | { |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 520 | // The default framebuffer is always complete except when it is surfaceless in which |
| 521 | // case it is always unsupported. We return early because the default framebuffer may |
| 522 | // 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] | 523 | if (mId == 0) |
| 524 | { |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 525 | ASSERT(mCachedStatus.valid()); |
| 526 | ASSERT(mCachedStatus.value() == GL_FRAMEBUFFER_COMPLETE || |
| 527 | mCachedStatus.value() == GL_FRAMEBUFFER_UNDEFINED_OES); |
| 528 | return mCachedStatus.value(); |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 529 | } |
| 530 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 531 | if (hasAnyDirtyBit() || !mCachedStatus.valid()) |
| 532 | { |
| 533 | mCachedStatus = checkStatusImpl(state); |
| 534 | } |
| 535 | |
| 536 | return mCachedStatus.value(); |
| 537 | } |
| 538 | |
| 539 | GLenum Framebuffer::checkStatusImpl(const ContextState &state) |
| 540 | { |
| 541 | ASSERT(mId != 0); |
| 542 | |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 543 | unsigned int colorbufferSize = 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 544 | int samples = -1; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 545 | bool missingAttachment = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 546 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 547 | for (const FramebufferAttachment &colorAttachment : mState.mColorAttachments) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 548 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 549 | if (colorAttachment.isAttached()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 550 | { |
Jamie Madill | 6b120b9 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 551 | const Extents &size = colorAttachment.getSize(); |
| 552 | if (size.width == 0 || size.height == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 553 | { |
| 554 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 555 | } |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 556 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 557 | const Format &format = colorAttachment.getFormat(); |
| 558 | const TextureCaps &formatCaps = state.getTextureCap(format.asSized()); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 559 | if (colorAttachment.type() == GL_TEXTURE) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 560 | { |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 561 | if (!formatCaps.renderable) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 562 | { |
Jamie Madill | 8117678 | 2015-11-24 16:10:23 -0500 | [diff] [blame] | 563 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 566 | if (format.info->depthBits > 0 || format.info->stencilBits > 0) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 567 | { |
| 568 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 569 | } |
Jamie Madill | 6b120b9 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 570 | |
| 571 | if (colorAttachment.layer() >= size.depth) |
| 572 | { |
| 573 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 574 | } |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 575 | |
| 576 | // ES3 specifies that cube map texture attachments must be cube complete. |
| 577 | // This language is missing from the ES2 spec, but we enforce it here because some |
| 578 | // desktop OpenGL drivers also enforce this validation. |
| 579 | // TODO(jmadill): Check if OpenGL ES2 drivers enforce cube completeness. |
| 580 | const Texture *texture = colorAttachment.getTexture(); |
| 581 | ASSERT(texture); |
Olli Etuaho | e8528d8 | 2016-05-16 17:50:52 +0300 | [diff] [blame] | 582 | if (texture->getTarget() == GL_TEXTURE_CUBE_MAP && |
| 583 | !texture->getTextureState().isCubeComplete()) |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 584 | { |
| 585 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 586 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 587 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 588 | else if (colorAttachment.type() == GL_RENDERBUFFER) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 589 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 590 | if (!formatCaps.renderable || format.info->depthBits > 0 || |
| 591 | format.info->stencilBits > 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 592 | { |
| 593 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 594 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | if (!missingAttachment) |
| 598 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 599 | // APPLE_framebuffer_multisample, which EXT_draw_buffers refers to, requires that |
| 600 | // all color attachments have the same number of samples for the FBO to be complete. |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 601 | if (colorAttachment.getSamples() != samples) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 602 | { |
| 603 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT; |
| 604 | } |
| 605 | |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 606 | // in GLES 2.0, all color attachments attachments must have the same number of bitplanes |
| 607 | // in GLES 3.0, there is no such restriction |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 608 | if (state.getClientMajorVersion() < 3) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 609 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 610 | if (format.info->pixelBytes != colorbufferSize) |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 611 | { |
| 612 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 613 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 614 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 615 | } |
| 616 | else |
| 617 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 618 | samples = colorAttachment.getSamples(); |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 619 | colorbufferSize = format.info->pixelBytes; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 620 | missingAttachment = false; |
| 621 | } |
| 622 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 625 | const FramebufferAttachment &depthAttachment = mState.mDepthAttachment; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 626 | if (depthAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 627 | { |
Jamie Madill | 6b120b9 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 628 | const Extents &size = depthAttachment.getSize(); |
| 629 | if (size.width == 0 || size.height == 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 630 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 631 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 634 | const Format &format = depthAttachment.getFormat(); |
| 635 | const TextureCaps &formatCaps = state.getTextureCap(format.asSized()); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 636 | if (depthAttachment.type() == GL_TEXTURE) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 637 | { |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 638 | if (!formatCaps.renderable) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 639 | { |
Jamie Madill | 8117678 | 2015-11-24 16:10:23 -0500 | [diff] [blame] | 640 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 641 | } |
| 642 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 643 | if (format.info->depthBits == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 644 | { |
| 645 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 646 | } |
| 647 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 648 | else if (depthAttachment.type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 649 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 650 | if (!formatCaps.renderable || format.info->depthBits == 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 651 | { |
| 652 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 653 | } |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | if (missingAttachment) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 657 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 658 | samples = depthAttachment.getSamples(); |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 659 | missingAttachment = false; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 660 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 661 | else if (samples != depthAttachment.getSamples()) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 662 | { |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 663 | // CHROMIUM_framebuffer_mixed_samples allows a framebuffer to be |
| 664 | // considered complete when its depth or stencil samples are a |
| 665 | // multiple of the number of color samples. |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 666 | const bool mixedSamples = state.getExtensions().framebufferMixedSamples; |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 667 | if (!mixedSamples) |
| 668 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
| 669 | |
| 670 | const int colorSamples = samples ? samples : 1; |
| 671 | const int depthSamples = depthAttachment.getSamples(); |
| 672 | if ((depthSamples % colorSamples) != 0) |
| 673 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 674 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 677 | const FramebufferAttachment &stencilAttachment = mState.mStencilAttachment; |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 678 | if (stencilAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 679 | { |
Jamie Madill | 6b120b9 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 680 | const Extents &size = stencilAttachment.getSize(); |
| 681 | if (size.width == 0 || size.height == 0) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 682 | { |
| 683 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 684 | } |
| 685 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 686 | const Format &format = stencilAttachment.getFormat(); |
| 687 | const TextureCaps &formatCaps = state.getTextureCap(format.asSized()); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 688 | if (stencilAttachment.type() == GL_TEXTURE) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 689 | { |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 690 | if (!formatCaps.renderable) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 691 | { |
Jamie Madill | 8117678 | 2015-11-24 16:10:23 -0500 | [diff] [blame] | 692 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 693 | } |
| 694 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 695 | if (format.info->stencilBits == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 696 | { |
| 697 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 698 | } |
| 699 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 700 | else if (stencilAttachment.type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 701 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 702 | if (!formatCaps.renderable || format.info->stencilBits == 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 703 | { |
| 704 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 705 | } |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | if (missingAttachment) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 709 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 710 | samples = stencilAttachment.getSamples(); |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 711 | missingAttachment = false; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 712 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 713 | else if (samples != stencilAttachment.getSamples()) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 714 | { |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 715 | // see the comments in depth attachment check. |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 716 | const bool mixedSamples = state.getExtensions().framebufferMixedSamples; |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 717 | if (!mixedSamples) |
| 718 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
| 719 | |
| 720 | const int colorSamples = samples ? samples : 1; |
| 721 | const int stencilSamples = stencilAttachment.getSamples(); |
| 722 | if ((stencilSamples % colorSamples) != 0) |
| 723 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 724 | } |
Corentin Wallez | 086d59a | 2016-04-29 09:06:49 -0400 | [diff] [blame] | 725 | |
| 726 | // Starting from ES 3.0 stencil and depth, if present, should be the same image |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 727 | if (state.getClientMajorVersion() >= 3 && depthAttachment.isAttached() && |
Corentin Wallez | 086d59a | 2016-04-29 09:06:49 -0400 | [diff] [blame] | 728 | stencilAttachment != depthAttachment) |
| 729 | { |
| 730 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 731 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 732 | } |
| 733 | |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 734 | // we need to have at least one attachment to be complete |
| 735 | if (missingAttachment) |
| 736 | { |
| 737 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 740 | // In ES 2.0, all color attachments must have the same width and height. |
| 741 | // In ES 3.0, there is no such restriction. |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 742 | if (state.getClientMajorVersion() < 3 && !mState.attachmentsHaveSameDimensions()) |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 743 | { |
| 744 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 745 | } |
| 746 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 747 | syncState(); |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 748 | if (!mImpl->checkStatus()) |
| 749 | { |
| 750 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 751 | } |
| 752 | |
| 753 | return GL_FRAMEBUFFER_COMPLETE; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 754 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 755 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 756 | Error Framebuffer::discard(size_t count, const GLenum *attachments) |
| 757 | { |
| 758 | return mImpl->discard(count, attachments); |
| 759 | } |
| 760 | |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 761 | Error Framebuffer::invalidate(size_t count, const GLenum *attachments) |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 762 | { |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 763 | return mImpl->invalidate(count, attachments); |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 764 | } |
| 765 | |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 766 | Error Framebuffer::invalidateSub(size_t count, const GLenum *attachments, const gl::Rectangle &area) |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 767 | { |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 768 | return mImpl->invalidateSub(count, attachments, area); |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 769 | } |
| 770 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 771 | Error Framebuffer::clear(rx::ContextImpl *context, GLbitfield mask) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 772 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 773 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 774 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 775 | return gl::NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 776 | } |
| 777 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 778 | return mImpl->clear(context, mask); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 779 | } |
| 780 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 781 | Error Framebuffer::clearBufferfv(rx::ContextImpl *context, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 782 | GLenum buffer, |
| 783 | GLint drawbuffer, |
| 784 | const GLfloat *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 785 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 786 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 787 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 788 | return gl::NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 789 | } |
| 790 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 791 | return mImpl->clearBufferfv(context, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 792 | } |
| 793 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 794 | Error Framebuffer::clearBufferuiv(rx::ContextImpl *context, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 795 | GLenum buffer, |
| 796 | GLint drawbuffer, |
| 797 | const GLuint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 798 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 799 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 800 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 801 | return gl::NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 802 | } |
| 803 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 804 | return mImpl->clearBufferuiv(context, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 805 | } |
| 806 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 807 | Error Framebuffer::clearBufferiv(rx::ContextImpl *context, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 808 | GLenum buffer, |
| 809 | GLint drawbuffer, |
| 810 | const GLint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 811 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 812 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 813 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 814 | return gl::NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 815 | } |
| 816 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 817 | return mImpl->clearBufferiv(context, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 818 | } |
| 819 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 820 | Error Framebuffer::clearBufferfi(rx::ContextImpl *context, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 821 | GLenum buffer, |
| 822 | GLint drawbuffer, |
| 823 | GLfloat depth, |
| 824 | GLint stencil) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 825 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 826 | if (context->getGLState().isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 827 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 828 | return gl::NoError(); |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 829 | } |
| 830 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 831 | return mImpl->clearBufferfi(context, buffer, drawbuffer, depth, stencil); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 832 | } |
| 833 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 834 | GLenum Framebuffer::getImplementationColorReadFormat() const |
| 835 | { |
| 836 | return mImpl->getImplementationColorReadFormat(); |
| 837 | } |
| 838 | |
| 839 | GLenum Framebuffer::getImplementationColorReadType() const |
| 840 | { |
| 841 | return mImpl->getImplementationColorReadType(); |
| 842 | } |
| 843 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 844 | Error Framebuffer::readPixels(rx::ContextImpl *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 845 | const Rectangle &area, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 846 | GLenum format, |
| 847 | GLenum type, |
| 848 | GLvoid *pixels) const |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 849 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 850 | ANGLE_TRY(mImpl->readPixels(context, area, format, type, pixels)); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 851 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 852 | Buffer *unpackBuffer = context->getGLState().getUnpackState().pixelBuffer.get(); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 853 | if (unpackBuffer) |
| 854 | { |
| 855 | unpackBuffer->onPixelUnpack(); |
| 856 | } |
| 857 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 858 | return NoError(); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 859 | } |
| 860 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 861 | Error Framebuffer::blit(rx::ContextImpl *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 862 | const Rectangle &sourceArea, |
| 863 | const Rectangle &destArea, |
Geoff Lang | 242468f | 2015-09-24 14:15:41 -0400 | [diff] [blame] | 864 | GLbitfield mask, |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 865 | GLenum filter) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 866 | { |
He Yunchao | 6be602d | 2016-12-22 14:33:07 +0800 | [diff] [blame] | 867 | GLbitfield blitMask = mask; |
| 868 | |
| 869 | // Note that blitting is called against draw framebuffer. |
| 870 | // See the code in gl::Context::blitFramebuffer. |
| 871 | if ((mask & GL_COLOR_BUFFER_BIT) && !hasEnabledDrawBuffer()) |
| 872 | { |
| 873 | blitMask &= ~GL_COLOR_BUFFER_BIT; |
| 874 | } |
| 875 | |
| 876 | if ((mask & GL_STENCIL_BUFFER_BIT) && mState.getStencilAttachment() == nullptr) |
| 877 | { |
| 878 | blitMask &= ~GL_STENCIL_BUFFER_BIT; |
| 879 | } |
| 880 | |
| 881 | if ((mask & GL_DEPTH_BUFFER_BIT) && mState.getDepthAttachment() == nullptr) |
| 882 | { |
| 883 | blitMask &= ~GL_DEPTH_BUFFER_BIT; |
| 884 | } |
| 885 | |
| 886 | if (!blitMask) |
| 887 | { |
| 888 | return NoError(); |
| 889 | } |
| 890 | |
| 891 | return mImpl->blit(context, sourceArea, destArea, blitMask, filter); |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 892 | } |
| 893 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 894 | int Framebuffer::getSamples(const ContextState &state) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 895 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 896 | if (complete(state)) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 897 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 898 | // For a complete framebuffer, all attachments must have the same sample count. |
| 899 | // In this case return the first nonzero sample size. |
| 900 | const auto *firstColorAttachment = mState.getFirstColorAttachment(); |
| 901 | if (firstColorAttachment) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 902 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 903 | ASSERT(firstColorAttachment->isAttached()); |
| 904 | return firstColorAttachment->getSamples(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 905 | } |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 906 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 907 | |
| 908 | return 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 911 | Error Framebuffer::getSamplePosition(size_t index, GLfloat *xy) const |
| 912 | { |
| 913 | ANGLE_TRY(mImpl->getSamplePosition(index, xy)); |
| 914 | return gl::NoError(); |
| 915 | } |
| 916 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 917 | bool Framebuffer::hasValidDepthStencil() const |
| 918 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 919 | return mState.getDepthStencilAttachment() != nullptr; |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 920 | } |
| 921 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 922 | void Framebuffer::setAttachment(GLenum type, |
| 923 | GLenum binding, |
| 924 | const ImageIndex &textureIndex, |
| 925 | FramebufferAttachmentObject *resource) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 926 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 927 | if (binding == GL_DEPTH_STENCIL || binding == GL_DEPTH_STENCIL_ATTACHMENT) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 928 | { |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 929 | // ensure this is a legitimate depth+stencil format |
Jamie Madill | 375c37c | 2015-07-21 15:14:08 -0400 | [diff] [blame] | 930 | FramebufferAttachmentObject *attachmentObj = resource; |
| 931 | if (resource) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 932 | { |
Jamie Madill | 375c37c | 2015-07-21 15:14:08 -0400 | [diff] [blame] | 933 | FramebufferAttachment::Target target(binding, textureIndex); |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 934 | const Format &format = resource->getAttachmentFormat(target); |
| 935 | if (format.info->depthBits == 0 || format.info->stencilBits == 0) |
Jamie Madill | 375c37c | 2015-07-21 15:14:08 -0400 | [diff] [blame] | 936 | { |
| 937 | // Attaching nullptr detaches the current attachment. |
| 938 | attachmentObj = nullptr; |
| 939 | } |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 940 | } |
Jamie Madill | 375c37c | 2015-07-21 15:14:08 -0400 | [diff] [blame] | 941 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 942 | mState.mDepthAttachment.attach(type, binding, textureIndex, attachmentObj); |
| 943 | mState.mStencilAttachment.attach(type, binding, textureIndex, attachmentObj); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 944 | mDirtyBits.set(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 945 | mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 946 | BindResourceChannel(&mDirtyDepthAttachmentBinding, resource); |
| 947 | BindResourceChannel(&mDirtyStencilAttachmentBinding, resource); |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 948 | } |
| 949 | else |
| 950 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 951 | switch (binding) |
| 952 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 953 | case GL_DEPTH: |
| 954 | case GL_DEPTH_ATTACHMENT: |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 955 | mState.mDepthAttachment.attach(type, binding, textureIndex, resource); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 956 | mDirtyBits.set(DIRTY_BIT_DEPTH_ATTACHMENT); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 957 | BindResourceChannel(&mDirtyDepthAttachmentBinding, resource); |
| 958 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 959 | case GL_STENCIL: |
| 960 | case GL_STENCIL_ATTACHMENT: |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 961 | mState.mStencilAttachment.attach(type, binding, textureIndex, resource); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 962 | mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 963 | BindResourceChannel(&mDirtyStencilAttachmentBinding, resource); |
| 964 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 965 | case GL_BACK: |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 966 | mState.mColorAttachments[0].attach(type, binding, textureIndex, resource); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 967 | mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 968 | // No need for a resource binding for the default FBO, it's always complete. |
| 969 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 970 | default: |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 971 | { |
| 972 | size_t colorIndex = binding - GL_COLOR_ATTACHMENT0; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 973 | ASSERT(colorIndex < mState.mColorAttachments.size()); |
| 974 | mState.mColorAttachments[colorIndex].attach(type, binding, textureIndex, resource); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 975 | mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 976 | BindResourceChannel(&mDirtyColorAttachmentBindings[colorIndex], resource); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 977 | |
| 978 | bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE); |
| 979 | mState.mEnabledDrawBuffers.set(colorIndex, enabled); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 980 | } |
| 981 | break; |
| 982 | } |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 986 | void Framebuffer::resetAttachment(GLenum binding) |
| 987 | { |
| 988 | setAttachment(GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr); |
| 989 | } |
| 990 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 991 | void Framebuffer::syncState() |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 992 | { |
| 993 | if (mDirtyBits.any()) |
| 994 | { |
| 995 | mImpl->syncState(mDirtyBits); |
| 996 | mDirtyBits.reset(); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 997 | if (mId != 0) |
| 998 | { |
| 999 | mCachedStatus.reset(); |
| 1000 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1001 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1002 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1003 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1004 | void Framebuffer::signal(SignalToken token) |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1005 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1006 | // TOOD(jmadill): Make this only update individual attachments to do less work. |
| 1007 | mCachedStatus.reset(); |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1008 | } |
| 1009 | |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1010 | bool Framebuffer::complete(const ContextState &state) |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1011 | { |
Jamie Madill | 362876b | 2016-06-16 14:46:59 -0400 | [diff] [blame] | 1012 | return (checkStatus(state) == GL_FRAMEBUFFER_COMPLETE); |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1015 | bool Framebuffer::formsRenderingFeedbackLoopWith(const State &state) const |
| 1016 | { |
| 1017 | const Program *program = state.getProgram(); |
| 1018 | |
| 1019 | // TODO(jmadill): Default framebuffer feedback loops. |
| 1020 | if (mId == 0) |
| 1021 | { |
| 1022 | return false; |
| 1023 | } |
| 1024 | |
| 1025 | // The bitset will skip inactive draw buffers. |
| 1026 | for (GLuint drawIndex : angle::IterateBitSet(mState.mEnabledDrawBuffers)) |
| 1027 | { |
| 1028 | const FramebufferAttachment *attachment = getDrawBuffer(drawIndex); |
| 1029 | if (attachment && attachment->type() == GL_TEXTURE) |
| 1030 | { |
| 1031 | // Validate the feedback loop. |
| 1032 | if (program->samplesFromTexture(state, attachment->id())) |
| 1033 | { |
| 1034 | return true; |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame^] | 1039 | // Validate depth-stencil feedback loop. |
| 1040 | const auto &dsState = state.getDepthStencilState(); |
| 1041 | |
| 1042 | // We can skip the feedback loop checks if depth/stencil is masked out or disabled. |
| 1043 | const FramebufferAttachment *depth = getDepthbuffer(); |
| 1044 | if (depth && depth->type() == GL_TEXTURE && dsState.depthTest && dsState.depthMask) |
| 1045 | { |
| 1046 | if (program->samplesFromTexture(state, depth->id())) |
| 1047 | { |
| 1048 | return true; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | // Note: we assume the front and back masks are the same for WebGL. |
| 1053 | const FramebufferAttachment *stencil = getStencilbuffer(); |
| 1054 | ASSERT(dsState.stencilBackWritemask == dsState.stencilWritemask); |
| 1055 | if (stencil && stencil->type() == GL_TEXTURE && dsState.stencilTest && |
| 1056 | dsState.stencilWritemask != 0) |
| 1057 | { |
| 1058 | // Skip the feedback loop check if depth/stencil point to the same resource. |
| 1059 | if (!depth || *stencil != *depth) |
| 1060 | { |
| 1061 | if (program->samplesFromTexture(state, stencil->id())) |
| 1062 | { |
| 1063 | return true; |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1068 | return false; |
| 1069 | } |
| 1070 | |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 1071 | bool Framebuffer::formsCopyingFeedbackLoopWith(GLuint copyTextureID, GLint copyTextureLevel) const |
| 1072 | { |
| 1073 | if (mId == 0) |
| 1074 | { |
| 1075 | // It seems impossible to form a texture copying feedback loop with the default FBO. |
| 1076 | return false; |
| 1077 | } |
| 1078 | |
| 1079 | const FramebufferAttachment *readAttachment = getReadColorbuffer(); |
| 1080 | ASSERT(readAttachment); |
| 1081 | |
| 1082 | if (readAttachment->isTextureWithId(copyTextureID)) |
| 1083 | { |
| 1084 | // TODO(jmadill): 3D/Array texture layers. |
| 1085 | if (readAttachment->getTextureImageIndex().mipIndex == copyTextureLevel) |
| 1086 | { |
| 1087 | return true; |
| 1088 | } |
| 1089 | } |
| 1090 | return false; |
| 1091 | } |
| 1092 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1093 | } // namespace gl |