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