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