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