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 | |
| 269 | void Framebuffer::setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer) |
| 270 | { |
| 271 | mDrawBufferStates[colorAttachment] = drawBuffer; |
| 272 | } |
| 273 | |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 274 | bool Framebuffer::isEnabledColorAttachment(unsigned int colorAttachment) const |
| 275 | { |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 276 | return (mColorbuffers[colorAttachment] && mDrawBufferStates[colorAttachment] != GL_NONE); |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | bool Framebuffer::hasEnabledColorAttachment() const |
| 280 | { |
| 281 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 282 | { |
| 283 | if (isEnabledColorAttachment(colorAttachment)) |
| 284 | { |
| 285 | return true; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | return false; |
| 290 | } |
| 291 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 292 | bool Framebuffer::hasStencil() const |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 293 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 294 | return (mStencilbuffer && mStencilbuffer->getStencilSize() > 0); |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 295 | } |
| 296 | |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 297 | bool Framebuffer::usingExtendedDrawBuffers() const |
| 298 | { |
| 299 | for (unsigned int colorAttachment = 1; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 300 | { |
| 301 | if (isEnabledColorAttachment(colorAttachment)) |
| 302 | { |
| 303 | return true; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | return false; |
| 308 | } |
| 309 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 310 | GLenum Framebuffer::completeness(const gl::Data &data) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 311 | { |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 312 | // The default framebuffer *must* always be complete, though it may not be |
| 313 | // subject to the same rules as application FBOs. ie, it could have 0x0 size. |
| 314 | if (mId == 0) |
| 315 | { |
| 316 | return GL_FRAMEBUFFER_COMPLETE; |
| 317 | } |
| 318 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 319 | int width = 0; |
| 320 | int height = 0; |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 321 | unsigned int colorbufferSize = 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 322 | int samples = -1; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 323 | bool missingAttachment = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 324 | |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 325 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 326 | { |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 327 | const FramebufferAttachment *colorbuffer = mColorbuffers[colorAttachment]; |
| 328 | |
| 329 | if (colorbuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 330 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 331 | if (colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 332 | { |
| 333 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 334 | } |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 335 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 336 | GLenum internalformat = colorbuffer->getInternalFormat(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 337 | const TextureCaps &formatCaps = data.textureCaps->get(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 338 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 339 | if (colorbuffer->type() == GL_TEXTURE) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 340 | { |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 341 | if (!formatCaps.renderable) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 342 | { |
| 343 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 344 | } |
| 345 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 346 | if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 347 | { |
| 348 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 349 | } |
| 350 | } |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 351 | else if (colorbuffer->type() == GL_RENDERBUFFER) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 352 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 353 | if (!formatCaps.renderable || formatInfo.depthBits > 0 || formatInfo.stencilBits > 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 354 | { |
| 355 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 356 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | if (!missingAttachment) |
| 360 | { |
| 361 | // all color attachments must have the same width and height |
| 362 | if (colorbuffer->getWidth() != width || colorbuffer->getHeight() != height) |
| 363 | { |
| 364 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 365 | } |
| 366 | |
| 367 | // APPLE_framebuffer_multisample, which EXT_draw_buffers refers to, requires that |
| 368 | // all color attachments have the same number of samples for the FBO to be complete. |
| 369 | if (colorbuffer->getSamples() != samples) |
| 370 | { |
| 371 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT; |
| 372 | } |
| 373 | |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 374 | // in GLES 2.0, all color attachments attachments must have the same number of bitplanes |
| 375 | // in GLES 3.0, there is no such restriction |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 376 | if (data.clientVersion < 3) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 377 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 378 | if (formatInfo.pixelBytes != colorbufferSize) |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 379 | { |
| 380 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 381 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | // D3D11 does not allow for overlapping RenderTargetViews, so ensure uniqueness |
| 385 | for (unsigned int previousColorAttachment = 0; previousColorAttachment < colorAttachment; previousColorAttachment++) |
| 386 | { |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 387 | const FramebufferAttachment *previousAttachment = mColorbuffers[previousColorAttachment]; |
| 388 | |
| 389 | if (previousAttachment && |
| 390 | (colorbuffer->id() == previousAttachment->id() && |
| 391 | colorbuffer->type() == previousAttachment->type())) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 392 | { |
| 393 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | else |
| 398 | { |
| 399 | width = colorbuffer->getWidth(); |
| 400 | height = colorbuffer->getHeight(); |
| 401 | samples = colorbuffer->getSamples(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 402 | colorbufferSize = formatInfo.pixelBytes; |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 403 | missingAttachment = false; |
| 404 | } |
| 405 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 408 | if (mDepthbuffer) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 409 | { |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 410 | if (mDepthbuffer->getWidth() == 0 || mDepthbuffer->getHeight() == 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 411 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 412 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 415 | GLenum internalformat = mDepthbuffer->getInternalFormat(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 416 | const TextureCaps &formatCaps = data.textureCaps->get(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 417 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 418 | if (mDepthbuffer->type() == GL_TEXTURE) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 419 | { |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 420 | // depth texture attachments require OES/ANGLE_depth_texture |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 421 | if (!data.extensions->depthTextures) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 422 | { |
| 423 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 424 | } |
| 425 | |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 426 | if (!formatCaps.renderable) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 427 | { |
| 428 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 429 | } |
| 430 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 431 | if (formatInfo.depthBits == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 432 | { |
| 433 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 434 | } |
| 435 | } |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 436 | else if (mDepthbuffer->type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 437 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 438 | if (!formatCaps.renderable || formatInfo.depthBits == 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 439 | { |
| 440 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 441 | } |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | if (missingAttachment) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 445 | { |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 446 | width = mDepthbuffer->getWidth(); |
| 447 | height = mDepthbuffer->getHeight(); |
| 448 | samples = mDepthbuffer->getSamples(); |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 449 | missingAttachment = false; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 450 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 451 | else if (width != mDepthbuffer->getWidth() || height != mDepthbuffer->getHeight()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 452 | { |
| 453 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 454 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 455 | else if (samples != mDepthbuffer->getSamples()) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 456 | { |
| 457 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
| 458 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 461 | if (mStencilbuffer) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 462 | { |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 463 | if (mStencilbuffer->getWidth() == 0 || mStencilbuffer->getHeight() == 0) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 464 | { |
| 465 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 466 | } |
| 467 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 468 | GLenum internalformat = mStencilbuffer->getInternalFormat(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 469 | const TextureCaps &formatCaps = data.textureCaps->get(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 470 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 471 | if (mStencilbuffer->type() == GL_TEXTURE) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 472 | { |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 473 | // texture stencil attachments come along as part |
| 474 | // of OES_packed_depth_stencil + OES/ANGLE_depth_texture |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 475 | if (!data.extensions->depthTextures) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 476 | { |
| 477 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 478 | } |
| 479 | |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 480 | if (!formatCaps.renderable) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 481 | { |
| 482 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 483 | } |
| 484 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 485 | if (formatInfo.stencilBits == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 486 | { |
| 487 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 488 | } |
| 489 | } |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 490 | else if (mStencilbuffer->type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 491 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 492 | if (!formatCaps.renderable || formatInfo.stencilBits == 0) |
Jamie Madill | bb94f34 | 2014-06-23 15:23:02 -0400 | [diff] [blame] | 493 | { |
| 494 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 495 | } |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | if (missingAttachment) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 499 | { |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 500 | width = mStencilbuffer->getWidth(); |
| 501 | height = mStencilbuffer->getHeight(); |
| 502 | samples = mStencilbuffer->getSamples(); |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 503 | missingAttachment = false; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 504 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 505 | else if (width != mStencilbuffer->getWidth() || height != mStencilbuffer->getHeight()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 506 | { |
| 507 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 508 | } |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 509 | else if (samples != mStencilbuffer->getSamples()) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 510 | { |
| 511 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
| 512 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 513 | } |
| 514 | |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 515 | // if we have both a depth and stencil buffer, they must refer to the same object |
| 516 | // 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] | 517 | if (mDepthbuffer && mStencilbuffer && !hasValidDepthStencil()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 518 | { |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 519 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 520 | } |
| 521 | |
| 522 | // we need to have at least one attachment to be complete |
| 523 | if (missingAttachment) |
| 524 | { |
| 525 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 526 | } |
| 527 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 528 | return GL_FRAMEBUFFER_COMPLETE; |
| 529 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 530 | |
Geoff Lang | 64f23f6 | 2014-09-10 14:40:12 -0400 | [diff] [blame] | 531 | Error Framebuffer::invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments) |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 532 | { |
| 533 | GLuint maxDimension = caps.maxRenderbufferSize; |
Geoff Lang | 64f23f6 | 2014-09-10 14:40:12 -0400 | [diff] [blame] | 534 | return invalidateSub(numAttachments, attachments, 0, 0, maxDimension, maxDimension); |
Jamie Madill | 2d96b9e | 2014-08-29 15:46:47 -0400 | [diff] [blame] | 535 | } |
| 536 | |
Geoff Lang | 64f23f6 | 2014-09-10 14:40:12 -0400 | [diff] [blame] | 537 | Error Framebuffer::invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height) |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 538 | { |
Jamie Madill | 6d70826 | 2014-09-03 15:07:13 -0400 | [diff] [blame] | 539 | for (GLsizei attachIndex = 0; attachIndex < numAttachments; ++attachIndex) |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 540 | { |
Jamie Madill | 6d70826 | 2014-09-03 15:07:13 -0400 | [diff] [blame] | 541 | GLenum attachmentTarget = attachments[attachIndex]; |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 542 | |
Geoff Lang | 64f23f6 | 2014-09-10 14:40:12 -0400 | [diff] [blame] | 543 | FramebufferAttachment *attachment = (attachmentTarget == GL_DEPTH_STENCIL_ATTACHMENT) ? getDepthOrStencilbuffer() |
| 544 | : getAttachment(attachmentTarget); |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 545 | |
Jamie Madill | 6d70826 | 2014-09-03 15:07:13 -0400 | [diff] [blame] | 546 | if (attachment) |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 547 | { |
Geoff Lang | 64f23f6 | 2014-09-10 14:40:12 -0400 | [diff] [blame] | 548 | rx::RenderTarget *renderTarget = NULL; |
| 549 | Error error = rx::GetAttachmentRenderTarget(attachment, &renderTarget); |
| 550 | if (error.isError()) |
Jamie Madill | 6d70826 | 2014-09-03 15:07:13 -0400 | [diff] [blame] | 551 | { |
Geoff Lang | 64f23f6 | 2014-09-10 14:40:12 -0400 | [diff] [blame] | 552 | return error; |
Jamie Madill | 6d70826 | 2014-09-03 15:07:13 -0400 | [diff] [blame] | 553 | } |
Geoff Lang | 64f23f6 | 2014-09-10 14:40:12 -0400 | [diff] [blame] | 554 | |
| 555 | renderTarget->invalidate(x, y, width, height); |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 556 | } |
| 557 | } |
Geoff Lang | 64f23f6 | 2014-09-10 14:40:12 -0400 | [diff] [blame] | 558 | |
| 559 | return Error(GL_NO_ERROR); |
Jamie Madill | 400a441 | 2014-08-29 15:46:45 -0400 | [diff] [blame] | 560 | } |
| 561 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 562 | int Framebuffer::getSamples(const gl::Data &data) const |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 563 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 564 | if (completeness(data) == GL_FRAMEBUFFER_COMPLETE) |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 565 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 566 | // for a complete framebuffer, all attachments must have the same sample count |
| 567 | // in this case return the first nonzero sample size |
| 568 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 569 | { |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 570 | if (mColorbuffers[colorAttachment]) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 571 | { |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 572 | return mColorbuffers[colorAttachment]->getSamples(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 573 | } |
| 574 | } |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 575 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 576 | |
| 577 | return 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 580 | bool Framebuffer::hasValidDepthStencil() const |
| 581 | { |
| 582 | // A valid depth-stencil attachment has the same resource bound to both the |
| 583 | // depth and stencil attachment points. |
| 584 | return (mDepthbuffer && mStencilbuffer && |
| 585 | mDepthbuffer->type() == mStencilbuffer->type() && |
| 586 | mDepthbuffer->id() == mStencilbuffer->id()); |
| 587 | } |
| 588 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 589 | ColorbufferInfo Framebuffer::getColorbuffersForRender(const rx::Workarounds &workarounds) const |
Jamie Madill | ce20c7f | 2014-09-03 11:56:29 -0400 | [diff] [blame] | 590 | { |
| 591 | ColorbufferInfo colorbuffersForRender; |
| 592 | |
| 593 | for (size_t colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; ++colorAttachment) |
| 594 | { |
| 595 | GLenum drawBufferState = mDrawBufferStates[colorAttachment]; |
| 596 | FramebufferAttachment *colorbuffer = mColorbuffers[colorAttachment]; |
| 597 | |
| 598 | if (colorbuffer != NULL && drawBufferState != GL_NONE) |
| 599 | { |
| 600 | ASSERT(drawBufferState == GL_BACK || drawBufferState == (GL_COLOR_ATTACHMENT0_EXT + colorAttachment)); |
| 601 | colorbuffersForRender.push_back(colorbuffer); |
| 602 | } |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 603 | else if (!workarounds.mrtPerfWorkaround) |
Jamie Madill | ce20c7f | 2014-09-03 11:56:29 -0400 | [diff] [blame] | 604 | { |
| 605 | colorbuffersForRender.push_back(NULL); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | return colorbuffersForRender; |
| 610 | } |
| 611 | |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 612 | void Framebuffer::setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex) |
| 613 | { |
| 614 | setAttachment(attachment, new TextureAttachment(attachment, texture, imageIndex)); |
| 615 | } |
| 616 | |
| 617 | void Framebuffer::setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer) |
| 618 | { |
| 619 | setAttachment(attachment, new RenderbufferAttachment(attachment, renderbuffer)); |
| 620 | } |
| 621 | |
| 622 | void Framebuffer::setNULLAttachment(GLenum attachment) |
| 623 | { |
| 624 | setAttachment(attachment, NULL); |
| 625 | } |
| 626 | |
| 627 | void Framebuffer::setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj) |
| 628 | { |
| 629 | if (attachment >= GL_COLOR_ATTACHMENT0 && attachment < (GL_COLOR_ATTACHMENT0 + IMPLEMENTATION_MAX_DRAW_BUFFERS)) |
| 630 | { |
| 631 | size_t colorAttachment = attachment - GL_COLOR_ATTACHMENT0; |
| 632 | SafeDelete(mColorbuffers[colorAttachment]); |
| 633 | mColorbuffers[colorAttachment] = attachmentObj; |
| 634 | } |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 635 | else if (attachment == GL_BACK) |
| 636 | { |
| 637 | SafeDelete(mColorbuffers[0]); |
| 638 | mColorbuffers[0] = attachmentObj; |
| 639 | } |
| 640 | else if (attachment == GL_DEPTH_ATTACHMENT || attachment == GL_DEPTH) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 641 | { |
| 642 | SafeDelete(mDepthbuffer); |
| 643 | mDepthbuffer = attachmentObj; |
| 644 | } |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 645 | else if (attachment == GL_STENCIL_ATTACHMENT || attachment == GL_STENCIL) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 646 | { |
| 647 | SafeDelete(mStencilbuffer); |
| 648 | mStencilbuffer = attachmentObj; |
| 649 | } |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 650 | else if (attachment == GL_DEPTH_STENCIL_ATTACHMENT || attachment == GL_DEPTH_STENCIL) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 651 | { |
| 652 | SafeDelete(mDepthbuffer); |
| 653 | SafeDelete(mStencilbuffer); |
| 654 | |
| 655 | // ensure this is a legitimate depth+stencil format |
| 656 | if (attachmentObj && attachmentObj->getDepthSize() > 0 && attachmentObj->getStencilSize() > 0) |
| 657 | { |
| 658 | mDepthbuffer = attachmentObj; |
| 659 | |
| 660 | // Make a new attachment object to ensure we do not double-delete |
| 661 | // See angle issue 686 |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 662 | if (attachmentObj->type() == GL_TEXTURE) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 663 | { |
| 664 | mStencilbuffer = new TextureAttachment(GL_DEPTH_STENCIL_ATTACHMENT, attachmentObj->getTexture(), |
| 665 | *attachmentObj->getTextureImageIndex()); |
| 666 | } |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 667 | else if (attachmentObj->type() == GL_RENDERBUFFER) |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 668 | { |
| 669 | mStencilbuffer = new RenderbufferAttachment(GL_DEPTH_STENCIL_ATTACHMENT, attachmentObj->getRenderbuffer()); |
| 670 | } |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 671 | else |
| 672 | { |
| 673 | UNREACHABLE(); |
| 674 | } |
Geoff Lang | ab75a05 | 2014-10-15 12:56:37 -0400 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | else |
| 678 | { |
| 679 | UNREACHABLE(); |
| 680 | } |
| 681 | } |
| 682 | |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 683 | DefaultFramebuffer::DefaultFramebuffer(rx::FramebufferImpl *impl, rx::DefaultAttachmentImpl *colorAttachment, |
| 684 | rx::DefaultAttachmentImpl *depthAttachment, rx::DefaultAttachmentImpl *stencilAttachment) |
| 685 | : Framebuffer(impl, 0) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 686 | { |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 687 | ASSERT(colorAttachment); |
| 688 | setAttachment(GL_BACK, new DefaultAttachment(GL_BACK, colorAttachment)); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 689 | |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 690 | if (depthAttachment) |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 691 | { |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 692 | setAttachment(GL_DEPTH, new DefaultAttachment(GL_DEPTH, depthAttachment)); |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 693 | } |
Geoff Lang | 528ce3c | 2014-12-01 10:44:07 -0500 | [diff] [blame^] | 694 | if (stencilAttachment) |
| 695 | { |
| 696 | setAttachment(GL_STENCIL, new DefaultAttachment(GL_STENCIL, stencilAttachment)); |
| 697 | } |
| 698 | |
| 699 | mDrawBufferStates[0] = GL_BACK; |
| 700 | mReadBufferState = GL_BACK; |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 701 | } |
| 702 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 703 | } |