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