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