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