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