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 | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 13 | #include "common/utilities.h" |
| 14 | #include "libANGLE/Config.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 15 | #include "libANGLE/Context.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/FramebufferAttachment.h" |
Jamie Madill | c46f45d | 2015-03-31 13:20:55 -0400 | [diff] [blame] | 17 | #include "libANGLE/Renderbuffer.h" |
| 18 | #include "libANGLE/Surface.h" |
| 19 | #include "libANGLE/Texture.h" |
| 20 | #include "libANGLE/formatutils.h" |
Geoff Lang | b5d8f23 | 2014-12-04 15:43:01 -0500 | [diff] [blame] | 21 | #include "libANGLE/renderer/FramebufferImpl.h" |
Jamie Madill | 48115b6 | 2015-03-16 10:46:57 -0400 | [diff] [blame] | 22 | #include "libANGLE/renderer/ImplFactory.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 23 | #include "libANGLE/renderer/RenderbufferImpl.h" |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 24 | #include "libANGLE/renderer/SurfaceImpl.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 25 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 26 | namespace gl |
| 27 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 28 | |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 29 | namespace |
| 30 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 31 | void DetachMatchingAttachment(FramebufferAttachment *attachment, GLenum matchType, GLuint matchId) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 32 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 33 | if (attachment->isAttached() && |
| 34 | attachment->type() == matchType && |
| 35 | attachment->id() == matchId) |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 36 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 37 | attachment->detach(); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 42 | Framebuffer::Data::Data() |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 43 | : mLabel(), |
| 44 | mColorAttachments(1), |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 45 | mDrawBufferStates(1, GL_NONE), |
| 46 | mReadBufferState(GL_COLOR_ATTACHMENT0_EXT) |
| 47 | { |
| 48 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
| 49 | } |
| 50 | |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 51 | Framebuffer::Data::Data(const Caps &caps) |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 52 | : mLabel(), |
| 53 | mColorAttachments(caps.maxColorAttachments), |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 54 | mDrawBufferStates(caps.maxDrawBuffers, GL_NONE), |
| 55 | mReadBufferState(GL_COLOR_ATTACHMENT0_EXT) |
| 56 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 57 | ASSERT(mDrawBufferStates.size() > 0); |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 58 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
| 59 | } |
| 60 | |
| 61 | Framebuffer::Data::~Data() |
| 62 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 63 | } |
| 64 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 65 | const std::string &Framebuffer::Data::getLabel() |
| 66 | { |
| 67 | return mLabel; |
| 68 | } |
| 69 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 70 | const FramebufferAttachment *Framebuffer::Data::getReadAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 71 | { |
| 72 | ASSERT(mReadBufferState == GL_BACK || (mReadBufferState >= GL_COLOR_ATTACHMENT0 && mReadBufferState <= GL_COLOR_ATTACHMENT15)); |
| 73 | size_t readIndex = (mReadBufferState == GL_BACK ? 0 : static_cast<size_t>(mReadBufferState - GL_COLOR_ATTACHMENT0)); |
| 74 | ASSERT(readIndex < mColorAttachments.size()); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 75 | return mColorAttachments[readIndex].isAttached() ? &mColorAttachments[readIndex] : nullptr; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 78 | const FramebufferAttachment *Framebuffer::Data::getFirstColorAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 79 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 80 | for (const FramebufferAttachment &colorAttachment : mColorAttachments) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 81 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 82 | if (colorAttachment.isAttached()) |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 83 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 84 | return &colorAttachment; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | return nullptr; |
| 89 | } |
| 90 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 91 | const FramebufferAttachment *Framebuffer::Data::getDepthOrStencilAttachment() const |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 92 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 93 | if (mDepthAttachment.isAttached()) |
| 94 | { |
| 95 | return &mDepthAttachment; |
| 96 | } |
| 97 | if (mStencilAttachment.isAttached()) |
| 98 | { |
| 99 | return &mStencilAttachment; |
| 100 | } |
| 101 | return nullptr; |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 104 | const FramebufferAttachment *Framebuffer::Data::getColorAttachment(size_t colorAttachment) const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 105 | { |
| 106 | ASSERT(colorAttachment < mColorAttachments.size()); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 107 | return mColorAttachments[colorAttachment].isAttached() ? |
| 108 | &mColorAttachments[colorAttachment] : |
| 109 | nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 112 | const FramebufferAttachment *Framebuffer::Data::getDepthAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 113 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 114 | return mDepthAttachment.isAttached() ? &mDepthAttachment : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 117 | const FramebufferAttachment *Framebuffer::Data::getStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 118 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 119 | return mStencilAttachment.isAttached() ? &mStencilAttachment : nullptr; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 120 | } |
| 121 | |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 122 | const FramebufferAttachment *Framebuffer::Data::getDepthStencilAttachment() const |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 123 | { |
| 124 | // A valid depth-stencil attachment has the same resource bound to both the |
| 125 | // depth and stencil attachment points. |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 126 | if (mDepthAttachment.isAttached() && mStencilAttachment.isAttached() && |
| 127 | mDepthAttachment.type() == mStencilAttachment.type() && |
| 128 | mDepthAttachment.id() == mStencilAttachment.id()) |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 129 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 130 | return &mDepthAttachment; |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | return nullptr; |
| 134 | } |
| 135 | |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 136 | bool Framebuffer::Data::attachmentsHaveSameDimensions() const |
| 137 | { |
| 138 | Optional<Extents> attachmentSize; |
| 139 | |
| 140 | auto hasMismatchedSize = [&attachmentSize](const FramebufferAttachment &attachment) |
| 141 | { |
| 142 | if (!attachment.isAttached()) |
| 143 | { |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | if (!attachmentSize.valid()) |
| 148 | { |
| 149 | attachmentSize = attachment.getSize(); |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | return (attachment.getSize() != attachmentSize.value()); |
| 154 | }; |
| 155 | |
| 156 | for (const auto &attachment : mColorAttachments) |
| 157 | { |
| 158 | if (hasMismatchedSize(attachment)) |
| 159 | { |
| 160 | return false; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | if (hasMismatchedSize(mDepthAttachment)) |
| 165 | { |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | return !hasMismatchedSize(mStencilAttachment); |
| 170 | } |
| 171 | |
Jamie Madill | 48115b6 | 2015-03-16 10:46:57 -0400 | [diff] [blame] | 172 | Framebuffer::Framebuffer(const Caps &caps, rx::ImplFactory *factory, GLuint id) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 173 | : mData(caps), mImpl(factory->createFramebuffer(mData)), mId(id) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 174 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 175 | ASSERT(mId != 0); |
| 176 | ASSERT(mImpl != nullptr); |
| 177 | } |
| 178 | |
| 179 | Framebuffer::Framebuffer(rx::SurfaceImpl *surface) |
| 180 | : mData(), mImpl(surface->createDefaultFramebuffer(mData)), mId(0) |
| 181 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 182 | ASSERT(mImpl != nullptr); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | Framebuffer::~Framebuffer() |
| 186 | { |
Geoff Lang | da88add | 2014-12-01 10:22:01 -0500 | [diff] [blame] | 187 | SafeDelete(mImpl); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 190 | void Framebuffer::setLabel(const std::string &label) |
| 191 | { |
| 192 | mData.mLabel = label; |
| 193 | } |
| 194 | |
| 195 | const std::string &Framebuffer::getLabel() const |
| 196 | { |
| 197 | return mData.mLabel; |
| 198 | } |
| 199 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 200 | void Framebuffer::detachTexture(GLuint textureId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 201 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 202 | detachResourceById(GL_TEXTURE, textureId); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 205 | void Framebuffer::detachRenderbuffer(GLuint renderbufferId) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 206 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 207 | detachResourceById(GL_RENDERBUFFER, renderbufferId); |
| 208 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 209 | |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 210 | void Framebuffer::detachResourceById(GLenum resourceType, GLuint resourceId) |
| 211 | { |
| 212 | for (auto &colorAttachment : mData.mColorAttachments) |
| 213 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 214 | DetachMatchingAttachment(&colorAttachment, resourceType, resourceId); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 217 | DetachMatchingAttachment(&mData.mDepthAttachment, resourceType, resourceId); |
| 218 | DetachMatchingAttachment(&mData.mStencilAttachment, resourceType, resourceId); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 221 | const FramebufferAttachment *Framebuffer::getColorbuffer(size_t colorAttachment) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 222 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 223 | return mData.getColorAttachment(colorAttachment); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 226 | const FramebufferAttachment *Framebuffer::getDepthbuffer() const |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 227 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 228 | return mData.getDepthAttachment(); |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 229 | } |
| 230 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 231 | const FramebufferAttachment *Framebuffer::getStencilbuffer() const |
| 232 | { |
| 233 | return mData.getStencilAttachment(); |
| 234 | } |
| 235 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 236 | const FramebufferAttachment *Framebuffer::getDepthStencilBuffer() const |
| 237 | { |
| 238 | return mData.getDepthStencilAttachment(); |
| 239 | } |
| 240 | |
| 241 | const FramebufferAttachment *Framebuffer::getDepthOrStencilbuffer() const |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 242 | { |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 243 | return mData.getDepthOrStencilAttachment(); |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 246 | const FramebufferAttachment *Framebuffer::getReadColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 247 | { |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 248 | return mData.getReadAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 249 | } |
| 250 | |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 251 | GLenum Framebuffer::getReadColorbufferType() const |
| 252 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 253 | const FramebufferAttachment *readAttachment = mData.getReadAttachment(); |
| 254 | return (readAttachment != nullptr ? readAttachment->type() : GL_NONE); |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 257 | const FramebufferAttachment *Framebuffer::getFirstColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 258 | { |
Jamie Madill | 7147f01 | 2015-03-05 15:41:40 -0500 | [diff] [blame] | 259 | return mData.getFirstColorAttachment(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 262 | const FramebufferAttachment *Framebuffer::getAttachment(GLenum attachment) const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 263 | { |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 264 | if (attachment >= GL_COLOR_ATTACHMENT0 && attachment <= GL_COLOR_ATTACHMENT15) |
| 265 | { |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 266 | return mData.getColorAttachment(attachment - GL_COLOR_ATTACHMENT0); |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 267 | } |
| 268 | else |
| 269 | { |
| 270 | switch (attachment) |
| 271 | { |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 272 | case GL_COLOR: |
| 273 | case GL_BACK: |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 274 | return mData.getColorAttachment(0); |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 275 | case GL_DEPTH: |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 276 | case GL_DEPTH_ATTACHMENT: |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 277 | return mData.getDepthAttachment(); |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 278 | case GL_STENCIL: |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 279 | case GL_STENCIL_ATTACHMENT: |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 280 | return mData.getStencilAttachment(); |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 281 | case GL_DEPTH_STENCIL: |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 282 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 283 | return getDepthStencilBuffer(); |
| 284 | default: |
| 285 | UNREACHABLE(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 286 | return nullptr; |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 287 | } |
| 288 | } |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 291 | size_t Framebuffer::getDrawbufferStateCount() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 292 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 293 | return mData.mDrawBufferStates.size(); |
| 294 | } |
| 295 | |
| 296 | GLenum Framebuffer::getDrawBufferState(size_t drawBuffer) const |
| 297 | { |
| 298 | ASSERT(drawBuffer < mData.mDrawBufferStates.size()); |
| 299 | return mData.mDrawBufferStates[drawBuffer]; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Jamie Madill | 1fbc59f | 2016-02-24 15:25:51 -0500 | [diff] [blame^] | 302 | const std::vector<GLenum> &Framebuffer::getDrawBufferStates() const |
| 303 | { |
| 304 | return mData.getDrawBufferStates(); |
| 305 | } |
| 306 | |
Geoff Lang | 164d54e | 2014-12-01 10:55:33 -0500 | [diff] [blame] | 307 | 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] | 308 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 309 | auto &drawStates = mData.mDrawBufferStates; |
| 310 | |
| 311 | ASSERT(count <= drawStates.size()); |
| 312 | std::copy(buffers, buffers + count, drawStates.begin()); |
| 313 | std::fill(drawStates.begin() + count, drawStates.end(), GL_NONE); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 314 | mDirtyBits.set(DIRTY_BIT_DRAW_BUFFERS); |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 315 | } |
| 316 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 317 | const FramebufferAttachment *Framebuffer::getDrawBuffer(size_t drawBuffer) const |
| 318 | { |
| 319 | ASSERT(drawBuffer < mData.mDrawBufferStates.size()); |
| 320 | if (mData.mDrawBufferStates[drawBuffer] != GL_NONE) |
| 321 | { |
| 322 | // ES3 spec: "If the GL is bound to a draw framebuffer object, the ith buffer listed in bufs |
| 323 | // must be COLOR_ATTACHMENTi or NONE" |
| 324 | ASSERT(mData.mDrawBufferStates[drawBuffer] == GL_COLOR_ATTACHMENT0 + drawBuffer || |
| 325 | (drawBuffer == 0 && mData.mDrawBufferStates[drawBuffer] == GL_BACK)); |
| 326 | return getAttachment(mData.mDrawBufferStates[drawBuffer]); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | return nullptr; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | bool Framebuffer::hasEnabledDrawBuffer() const |
| 335 | { |
| 336 | for (size_t drawbufferIdx = 0; drawbufferIdx < mData.mDrawBufferStates.size(); ++drawbufferIdx) |
| 337 | { |
| 338 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
| 339 | { |
| 340 | return true; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | return false; |
| 345 | } |
| 346 | |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 347 | GLenum Framebuffer::getReadBufferState() const |
| 348 | { |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 349 | return mData.mReadBufferState; |
Geoff Lang | 9dd9580 | 2014-12-01 11:12:59 -0500 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | void Framebuffer::setReadBuffer(GLenum buffer) |
| 353 | { |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 354 | ASSERT(buffer == GL_BACK || buffer == GL_NONE || |
| 355 | (buffer >= GL_COLOR_ATTACHMENT0 && |
Jamie Madill | d1405e5 | 2015-03-05 15:41:39 -0500 | [diff] [blame] | 356 | (buffer - GL_COLOR_ATTACHMENT0) < mData.mColorAttachments.size())); |
| 357 | mData.mReadBufferState = buffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 358 | mDirtyBits.set(DIRTY_BIT_READ_BUFFER); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 361 | size_t Framebuffer::getNumColorBuffers() const |
| 362 | { |
| 363 | return mData.mColorAttachments.size(); |
| 364 | } |
| 365 | |
Jamie Madill | 0df8fe4 | 2015-11-24 16:10:24 -0500 | [diff] [blame] | 366 | bool Framebuffer::hasDepth() const |
| 367 | { |
| 368 | return (mData.mDepthAttachment.isAttached() && mData.mDepthAttachment.getDepthSize() > 0); |
| 369 | } |
| 370 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 371 | bool Framebuffer::hasStencil() const |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 372 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 373 | return (mData.mStencilAttachment.isAttached() && mData.mStencilAttachment.getStencilSize() > 0); |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 374 | } |
| 375 | |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 376 | bool Framebuffer::usingExtendedDrawBuffers() const |
| 377 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 378 | for (size_t drawbufferIdx = 1; drawbufferIdx < mData.mDrawBufferStates.size(); ++drawbufferIdx) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 379 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 380 | if (getDrawBuffer(drawbufferIdx) != nullptr) |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 381 | { |
| 382 | return true; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | return false; |
| 387 | } |
| 388 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 389 | GLenum Framebuffer::checkStatus(const gl::Data &data) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 390 | { |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame] | 391 | // The default framebuffer *must* always be complete, though it may not be |
| 392 | // subject to the same rules as application FBOs. ie, it could have 0x0 size. |
| 393 | if (mId == 0) |
| 394 | { |
| 395 | return GL_FRAMEBUFFER_COMPLETE; |
| 396 | } |
| 397 | |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 398 | unsigned int colorbufferSize = 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 399 | int samples = -1; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 400 | bool missingAttachment = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 401 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 402 | for (const FramebufferAttachment &colorAttachment : mData.mColorAttachments) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 403 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 404 | if (colorAttachment.isAttached()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 405 | { |
Jamie Madill | 6b120b9 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 406 | const Extents &size = colorAttachment.getSize(); |
| 407 | if (size.width == 0 || size.height == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 408 | { |
| 409 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 410 | } |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 411 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 412 | GLenum internalformat = colorAttachment.getInternalFormat(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 413 | const TextureCaps &formatCaps = data.textureCaps->get(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 414 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 415 | if (colorAttachment.type() == GL_TEXTURE) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 416 | { |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 417 | if (!formatCaps.renderable) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 418 | { |
Jamie Madill | 8117678 | 2015-11-24 16:10:23 -0500 | [diff] [blame] | 419 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 422 | if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 423 | { |
| 424 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 425 | } |
Jamie Madill | 6b120b9 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 426 | |
| 427 | if (colorAttachment.layer() >= size.depth) |
| 428 | { |
| 429 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 430 | } |
Jamie Madill | 3215b20 | 2015-12-15 16:41:39 -0500 | [diff] [blame] | 431 | |
| 432 | // ES3 specifies that cube map texture attachments must be cube complete. |
| 433 | // This language is missing from the ES2 spec, but we enforce it here because some |
| 434 | // desktop OpenGL drivers also enforce this validation. |
| 435 | // TODO(jmadill): Check if OpenGL ES2 drivers enforce cube completeness. |
| 436 | const Texture *texture = colorAttachment.getTexture(); |
| 437 | ASSERT(texture); |
| 438 | if (texture->getTarget() == GL_TEXTURE_CUBE_MAP && !texture->isCubeComplete()) |
| 439 | { |
| 440 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 441 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 442 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 443 | else if (colorAttachment.type() == GL_RENDERBUFFER) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 444 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 445 | if (!formatCaps.renderable || formatInfo.depthBits > 0 || formatInfo.stencilBits > 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 446 | { |
| 447 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 448 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | if (!missingAttachment) |
| 452 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 453 | // APPLE_framebuffer_multisample, which EXT_draw_buffers refers to, requires that |
| 454 | // 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] | 455 | if (colorAttachment.getSamples() != samples) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 456 | { |
| 457 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT; |
| 458 | } |
| 459 | |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 460 | // in GLES 2.0, all color attachments attachments must have the same number of bitplanes |
| 461 | // in GLES 3.0, there is no such restriction |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 462 | if (data.clientVersion < 3) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 463 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 464 | if (formatInfo.pixelBytes != colorbufferSize) |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 465 | { |
| 466 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 467 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 468 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 469 | } |
| 470 | else |
| 471 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 472 | samples = colorAttachment.getSamples(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 473 | colorbufferSize = formatInfo.pixelBytes; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 474 | missingAttachment = false; |
| 475 | } |
| 476 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 479 | const FramebufferAttachment &depthAttachment = mData.mDepthAttachment; |
| 480 | if (depthAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 481 | { |
Jamie Madill | 6b120b9 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 482 | const Extents &size = depthAttachment.getSize(); |
| 483 | if (size.width == 0 || size.height == 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 484 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 485 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 488 | GLenum internalformat = depthAttachment.getInternalFormat(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 489 | const TextureCaps &formatCaps = data.textureCaps->get(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 490 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 491 | if (depthAttachment.type() == GL_TEXTURE) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 492 | { |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 493 | // depth texture attachments require OES/ANGLE_depth_texture |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 494 | if (!data.extensions->depthTextures) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 495 | { |
| 496 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 497 | } |
| 498 | |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 499 | if (!formatCaps.renderable) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 500 | { |
Jamie Madill | 8117678 | 2015-11-24 16:10:23 -0500 | [diff] [blame] | 501 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 504 | if (formatInfo.depthBits == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 505 | { |
| 506 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 507 | } |
| 508 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 509 | else if (depthAttachment.type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 510 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 511 | if (!formatCaps.renderable || formatInfo.depthBits == 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 512 | { |
| 513 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 514 | } |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | if (missingAttachment) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 518 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 519 | samples = depthAttachment.getSamples(); |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 520 | missingAttachment = false; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 521 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 522 | else if (samples != depthAttachment.getSamples()) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 523 | { |
| 524 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
| 525 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 528 | const FramebufferAttachment &stencilAttachment = mData.mStencilAttachment; |
| 529 | if (stencilAttachment.isAttached()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 530 | { |
Jamie Madill | 6b120b9 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 531 | const Extents &size = stencilAttachment.getSize(); |
| 532 | if (size.width == 0 || size.height == 0) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 533 | { |
| 534 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 535 | } |
| 536 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 537 | GLenum internalformat = stencilAttachment.getInternalFormat(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 538 | const TextureCaps &formatCaps = data.textureCaps->get(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 539 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 540 | if (stencilAttachment.type() == GL_TEXTURE) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 541 | { |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 542 | // texture stencil attachments come along as part |
| 543 | // of OES_packed_depth_stencil + OES/ANGLE_depth_texture |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 544 | if (!data.extensions->depthTextures) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 545 | { |
| 546 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 547 | } |
| 548 | |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 549 | if (!formatCaps.renderable) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 550 | { |
Jamie Madill | 8117678 | 2015-11-24 16:10:23 -0500 | [diff] [blame] | 551 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 552 | } |
| 553 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 554 | if (formatInfo.stencilBits == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 555 | { |
| 556 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 557 | } |
| 558 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 559 | else if (stencilAttachment.type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 560 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 561 | if (!formatCaps.renderable || formatInfo.stencilBits == 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 562 | { |
| 563 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 564 | } |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | if (missingAttachment) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 568 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 569 | samples = stencilAttachment.getSamples(); |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 570 | missingAttachment = false; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 571 | } |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 572 | else if (samples != stencilAttachment.getSamples()) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 573 | { |
| 574 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
| 575 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 576 | } |
| 577 | |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 578 | // we need to have at least one attachment to be complete |
| 579 | if (missingAttachment) |
| 580 | { |
| 581 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 584 | // In ES 2.0, all color attachments must have the same width and height. |
| 585 | // In ES 3.0, there is no such restriction. |
| 586 | if (data.clientVersion < 3 && !mData.attachmentsHaveSameDimensions()) |
| 587 | { |
| 588 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 589 | } |
| 590 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 591 | syncState(); |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 592 | if (!mImpl->checkStatus()) |
| 593 | { |
| 594 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 595 | } |
| 596 | |
| 597 | return GL_FRAMEBUFFER_COMPLETE; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 598 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 599 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 600 | Error Framebuffer::discard(size_t count, const GLenum *attachments) |
| 601 | { |
| 602 | return mImpl->discard(count, attachments); |
| 603 | } |
| 604 | |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 605 | Error Framebuffer::invalidate(size_t count, const GLenum *attachments) |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 606 | { |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 607 | return mImpl->invalidate(count, attachments); |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 610 | 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] | 611 | { |
Geoff Lang | 9ad4bda | 2014-12-01 11:03:09 -0500 | [diff] [blame] | 612 | return mImpl->invalidateSub(count, attachments, area); |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 613 | } |
| 614 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 615 | Error Framebuffer::clear(const gl::Data &data, GLbitfield mask) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 616 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 617 | if (data.state->isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 618 | { |
| 619 | return gl::Error(GL_NO_ERROR); |
| 620 | } |
| 621 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 622 | return mImpl->clear(data, mask); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 623 | } |
| 624 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 625 | Error Framebuffer::clearBufferfv(const gl::Data &data, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 626 | GLenum buffer, |
| 627 | GLint drawbuffer, |
| 628 | const GLfloat *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 629 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 630 | if (data.state->isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 631 | { |
| 632 | return gl::Error(GL_NO_ERROR); |
| 633 | } |
| 634 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 635 | return mImpl->clearBufferfv(data, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 636 | } |
| 637 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 638 | Error Framebuffer::clearBufferuiv(const gl::Data &data, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 639 | GLenum buffer, |
| 640 | GLint drawbuffer, |
| 641 | const GLuint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 642 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 643 | if (data.state->isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 644 | { |
| 645 | return gl::Error(GL_NO_ERROR); |
| 646 | } |
| 647 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 648 | return mImpl->clearBufferuiv(data, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 649 | } |
| 650 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 651 | Error Framebuffer::clearBufferiv(const gl::Data &data, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 652 | GLenum buffer, |
| 653 | GLint drawbuffer, |
| 654 | const GLint *values) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 655 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 656 | if (data.state->isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 657 | { |
| 658 | return gl::Error(GL_NO_ERROR); |
| 659 | } |
| 660 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 661 | return mImpl->clearBufferiv(data, buffer, drawbuffer, values); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 662 | } |
| 663 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 664 | Error Framebuffer::clearBufferfi(const gl::Data &data, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 665 | GLenum buffer, |
| 666 | GLint drawbuffer, |
| 667 | GLfloat depth, |
| 668 | GLint stencil) |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 669 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 670 | if (data.state->isRasterizerDiscardEnabled()) |
Jamie Madill | 984ef41 | 2015-11-24 16:10:21 -0500 | [diff] [blame] | 671 | { |
| 672 | return gl::Error(GL_NO_ERROR); |
| 673 | } |
| 674 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 675 | return mImpl->clearBufferfi(data, buffer, drawbuffer, depth, stencil); |
Geoff Lang | b04dc82 | 2014-12-01 12:02:02 -0500 | [diff] [blame] | 676 | } |
| 677 | |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 678 | GLenum Framebuffer::getImplementationColorReadFormat() const |
| 679 | { |
| 680 | return mImpl->getImplementationColorReadFormat(); |
| 681 | } |
| 682 | |
| 683 | GLenum Framebuffer::getImplementationColorReadType() const |
| 684 | { |
| 685 | return mImpl->getImplementationColorReadType(); |
| 686 | } |
| 687 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 688 | Error Framebuffer::readPixels(const State &state, |
| 689 | const Rectangle &area, |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 690 | GLenum format, |
| 691 | GLenum type, |
| 692 | GLvoid *pixels) const |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 693 | { |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 694 | Error error = mImpl->readPixels(state, area, format, type, pixels); |
| 695 | if (error.isError()) |
| 696 | { |
| 697 | return error; |
| 698 | } |
| 699 | |
| 700 | Buffer *unpackBuffer = state.getUnpackState().pixelBuffer.get(); |
| 701 | if (unpackBuffer) |
| 702 | { |
| 703 | unpackBuffer->onPixelUnpack(); |
| 704 | } |
| 705 | |
| 706 | return Error(GL_NO_ERROR); |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 707 | } |
| 708 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 709 | Error Framebuffer::blit(const State &state, |
| 710 | const Rectangle &sourceArea, |
| 711 | const Rectangle &destArea, |
Geoff Lang | 242468f | 2015-09-24 14:15:41 -0400 | [diff] [blame] | 712 | GLbitfield mask, |
| 713 | GLenum filter, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 714 | const Framebuffer *sourceFramebuffer) |
Geoff Lang | 54bd5a4 | 2014-12-01 12:51:04 -0500 | [diff] [blame] | 715 | { |
| 716 | return mImpl->blit(state, sourceArea, destArea, mask, filter, sourceFramebuffer); |
| 717 | } |
| 718 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 719 | int Framebuffer::getSamples(const gl::Data &data) const |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 720 | { |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 721 | if (checkStatus(data) == GL_FRAMEBUFFER_COMPLETE) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 722 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 723 | // for a complete framebuffer, all attachments must have the same sample count |
| 724 | // in this case return the first nonzero sample size |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 725 | for (const FramebufferAttachment &colorAttachment : mData.mColorAttachments) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 726 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 727 | if (colorAttachment.isAttached()) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 728 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 729 | return colorAttachment.getSamples(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 730 | } |
| 731 | } |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 732 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 733 | |
| 734 | return 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 737 | bool Framebuffer::hasValidDepthStencil() const |
| 738 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 739 | return mData.getDepthStencilAttachment() != nullptr; |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 740 | } |
| 741 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 742 | void Framebuffer::setAttachment(GLenum type, |
| 743 | GLenum binding, |
| 744 | const ImageIndex &textureIndex, |
| 745 | FramebufferAttachmentObject *resource) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 746 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 747 | if (binding == GL_DEPTH_STENCIL || binding == GL_DEPTH_STENCIL_ATTACHMENT) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 748 | { |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 749 | // ensure this is a legitimate depth+stencil format |
Jamie Madill | 375c37c | 2015-07-21 15:14:08 -0400 | [diff] [blame] | 750 | FramebufferAttachmentObject *attachmentObj = resource; |
| 751 | if (resource) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 752 | { |
Jamie Madill | 375c37c | 2015-07-21 15:14:08 -0400 | [diff] [blame] | 753 | FramebufferAttachment::Target target(binding, textureIndex); |
| 754 | GLenum internalFormat = resource->getAttachmentInternalFormat(target); |
| 755 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat); |
| 756 | if (formatInfo.depthBits == 0 || formatInfo.stencilBits == 0) |
| 757 | { |
| 758 | // Attaching nullptr detaches the current attachment. |
| 759 | attachmentObj = nullptr; |
| 760 | } |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 761 | } |
Jamie Madill | 375c37c | 2015-07-21 15:14:08 -0400 | [diff] [blame] | 762 | |
| 763 | mData.mDepthAttachment.attach(type, binding, textureIndex, attachmentObj); |
| 764 | mData.mStencilAttachment.attach(type, binding, textureIndex, attachmentObj); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 765 | mDirtyBits.set(DIRTY_BIT_DEPTH_ATTACHMENT); |
| 766 | mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT); |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 767 | } |
| 768 | else |
| 769 | { |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 770 | switch (binding) |
| 771 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 772 | case GL_DEPTH: |
| 773 | case GL_DEPTH_ATTACHMENT: |
| 774 | mData.mDepthAttachment.attach(type, binding, textureIndex, resource); |
| 775 | mDirtyBits.set(DIRTY_BIT_DEPTH_ATTACHMENT); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 776 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 777 | case GL_STENCIL: |
| 778 | case GL_STENCIL_ATTACHMENT: |
| 779 | mData.mStencilAttachment.attach(type, binding, textureIndex, resource); |
| 780 | mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 781 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 782 | case GL_BACK: |
| 783 | mData.mColorAttachments[0].attach(type, binding, textureIndex, resource); |
| 784 | mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 785 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 786 | default: |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 787 | { |
| 788 | size_t colorIndex = binding - GL_COLOR_ATTACHMENT0; |
| 789 | ASSERT(colorIndex < mData.mColorAttachments.size()); |
Jamie Madill | 7d75e2b | 2015-04-30 09:42:18 -0400 | [diff] [blame] | 790 | mData.mColorAttachments[colorIndex].attach(type, binding, textureIndex, resource); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 791 | mDirtyBits.set(DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 792 | } |
| 793 | break; |
| 794 | } |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
Jamie Madill | 2d06b73 | 2015-04-20 12:53:28 -0400 | [diff] [blame] | 798 | void Framebuffer::resetAttachment(GLenum binding) |
| 799 | { |
| 800 | setAttachment(GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr); |
| 801 | } |
| 802 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 803 | void Framebuffer::syncState() const |
| 804 | { |
| 805 | if (mDirtyBits.any()) |
| 806 | { |
| 807 | mImpl->syncState(mDirtyBits); |
| 808 | mDirtyBits.reset(); |
| 809 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 810 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 811 | |
| 812 | } // namespace gl |