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