shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 3 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // Framebuffer.cpp: Implements the gl::Framebuffer class. Implements GL framebuffer |
| 9 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105. |
| 10 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 11 | #include "libGLESv2/Framebuffer.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 12 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 13 | #include "libGLESv2/main.h" |
shannonwoods@chromium.org | a2ecfcc | 2013-05-30 00:11:59 +0000 | [diff] [blame] | 14 | #include "common/utilities.h" |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 15 | #include "libGLESv2/formatutils.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 16 | #include "libGLESv2/Texture.h" |
| 17 | #include "libGLESv2/Context.h" |
| 18 | #include "libGLESv2/renderer/Renderer.h" |
| 19 | #include "libGLESv2/Renderbuffer.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 20 | |
| 21 | namespace gl |
| 22 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 23 | |
daniel@transgaming.com | 16418b1 | 2012-11-28 19:32:22 +0000 | [diff] [blame] | 24 | Framebuffer::Framebuffer(rx::Renderer *renderer) |
| 25 | : mRenderer(renderer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 26 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 27 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 28 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 29 | mDrawBufferStates[colorAttachment] = GL_NONE; |
| 30 | } |
| 31 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
| 32 | mReadBufferState = GL_COLOR_ATTACHMENT0_EXT; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | Framebuffer::~Framebuffer() |
| 36 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 37 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 38 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 39 | mColorbuffers[colorAttachment].set(NULL, GL_NONE, 0, 0); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 40 | } |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 41 | mDepthbuffer.set(NULL, GL_NONE, 0, 0); |
| 42 | mStencilbuffer.set(NULL, GL_NONE, 0, 0); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 45 | FramebufferAttachmentImpl *Framebuffer::createAttachmentImpl(GLenum type, GLuint handle, GLint level, GLint layer) const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 46 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 47 | if (handle == 0) |
| 48 | { |
| 49 | return NULL; |
| 50 | } |
| 51 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 52 | gl::Context *context = gl::getContext(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 53 | |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 54 | switch (type) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 55 | { |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 56 | case GL_NONE: |
| 57 | return NULL; |
| 58 | |
| 59 | case GL_RENDERBUFFER: |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 60 | return new RenderbufferAttachment(context->getRenderbuffer(handle)); |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 61 | |
| 62 | case GL_TEXTURE_2D: |
| 63 | { |
| 64 | Texture *texture = context->getTexture(handle); |
| 65 | if (texture && texture->getTarget() == GL_TEXTURE_2D) |
| 66 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 67 | Texture2D *tex2D = static_cast<Texture2D*>(texture); |
| 68 | return new Texture2DAttachment(tex2D, level); |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 69 | } |
| 70 | else |
| 71 | { |
| 72 | return NULL; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 77 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 78 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 79 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 80 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 81 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 82 | { |
| 83 | Texture *texture = context->getTexture(handle); |
| 84 | if (texture && texture->getTarget() == GL_TEXTURE_CUBE_MAP) |
| 85 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 86 | TextureCubeMap *texCube = static_cast<TextureCubeMap*>(texture); |
| 87 | return new TextureCubeMapAttachment(texCube, type, level); |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 88 | } |
| 89 | else |
| 90 | { |
| 91 | return NULL; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | case GL_TEXTURE_3D: |
| 96 | { |
| 97 | Texture *texture = context->getTexture(handle); |
| 98 | if (texture && texture->getTarget() == GL_TEXTURE_3D) |
| 99 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 100 | Texture3D *tex3D = static_cast<Texture3D*>(texture); |
| 101 | return new Texture3DAttachment(tex3D, level, layer); |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 102 | } |
| 103 | else |
| 104 | { |
| 105 | return NULL; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | case GL_TEXTURE_2D_ARRAY: |
| 110 | { |
| 111 | Texture *texture = context->getTexture(handle); |
| 112 | if (texture && texture->getTarget() == GL_TEXTURE_2D_ARRAY) |
| 113 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 114 | Texture2DArray *tex2DArray = static_cast<Texture2DArray*>(texture); |
| 115 | return new Texture2DArrayAttachment(tex2DArray, level, layer); |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 116 | } |
| 117 | else |
| 118 | { |
| 119 | return NULL; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | default: |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 124 | UNREACHABLE(); |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 125 | return NULL; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 126 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 129 | void Framebuffer::setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer, GLint level, GLint layer) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 130 | { |
| 131 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 132 | FramebufferAttachmentImpl *attachmentImpl = createAttachmentImpl(type, colorbuffer, level, layer); |
| 133 | if (attachmentImpl) |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 134 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 135 | FramebufferAttachment *newAttachment = new FramebufferAttachment(mRenderer, colorbuffer, attachmentImpl); |
| 136 | mColorbuffers[colorAttachment].set(newAttachment, type, level, layer); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 137 | } |
| 138 | else |
| 139 | { |
| 140 | mColorbuffers[colorAttachment].set(NULL, GL_NONE, 0, 0); |
| 141 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 144 | void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 145 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 146 | FramebufferAttachmentImpl *attachmentImpl = createAttachmentImpl(type, depthbuffer, level, layer); |
| 147 | if (attachmentImpl) |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 148 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 149 | FramebufferAttachment *newAttachment = new FramebufferAttachment(mRenderer, depthbuffer, attachmentImpl); |
| 150 | mDepthbuffer.set(newAttachment, type, level, layer); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 151 | } |
| 152 | else |
| 153 | { |
| 154 | mDepthbuffer.set(NULL, GL_NONE, 0, 0); |
| 155 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 158 | void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 159 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 160 | FramebufferAttachmentImpl *attachmentImpl = createAttachmentImpl(type, stencilbuffer, level, layer); |
| 161 | if (attachmentImpl) |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 162 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 163 | FramebufferAttachment *newAttachment = new FramebufferAttachment(mRenderer, stencilbuffer, attachmentImpl); |
| 164 | mStencilbuffer.set(newAttachment, type, level, layer); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 165 | } |
| 166 | else |
| 167 | { |
| 168 | mStencilbuffer.set(NULL, GL_NONE, 0, 0); |
| 169 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 172 | void Framebuffer::setDepthStencilBuffer(GLenum type, GLuint depthStencilBuffer, GLint level, GLint layer) |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 173 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 174 | mDepthbuffer.set(NULL, GL_NONE, 0, 0); |
| 175 | mStencilbuffer.set(NULL, GL_NONE, 0, 0); |
| 176 | |
| 177 | FramebufferAttachmentImpl *attachmentImpl = createAttachmentImpl(type, depthStencilBuffer, level, layer); |
| 178 | if (attachmentImpl) |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 179 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 180 | FramebufferAttachment *newAttachment = new FramebufferAttachment(mRenderer, depthStencilBuffer, attachmentImpl); |
| 181 | if (newAttachment->getDepthSize() > 0 && newAttachment->getStencilSize() > 0) |
| 182 | { |
| 183 | mDepthbuffer.set(newAttachment, type, level, layer); |
| 184 | mStencilbuffer.set(newAttachment, type, level, layer); |
| 185 | } |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 189 | void Framebuffer::detachTexture(GLuint texture) |
| 190 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 191 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 192 | { |
Geoff Lang | 309c92a | 2013-07-25 16:23:19 -0400 | [diff] [blame] | 193 | if (mColorbuffers[colorAttachment].id() == texture && |
Geoff Lang | 0fe1949 | 2013-07-25 17:04:31 -0400 | [diff] [blame] | 194 | IsInternalTextureTarget(mColorbuffers[colorAttachment].type(), mRenderer->getCurrentClientVersion())) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 195 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 196 | mColorbuffers[colorAttachment].set(NULL, GL_NONE, 0, 0); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 197 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 198 | } |
daniel@transgaming.com | fbc0953 | 2010-04-26 15:33:41 +0000 | [diff] [blame] | 199 | |
Geoff Lang | 0fe1949 | 2013-07-25 17:04:31 -0400 | [diff] [blame] | 200 | if (mDepthbuffer.id() == texture && IsInternalTextureTarget(mDepthbuffer.type(), mRenderer->getCurrentClientVersion())) |
daniel@transgaming.com | fbc0953 | 2010-04-26 15:33:41 +0000 | [diff] [blame] | 201 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 202 | mDepthbuffer.set(NULL, GL_NONE, 0, 0); |
daniel@transgaming.com | fbc0953 | 2010-04-26 15:33:41 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Geoff Lang | 0fe1949 | 2013-07-25 17:04:31 -0400 | [diff] [blame] | 205 | if (mStencilbuffer.id() == texture && IsInternalTextureTarget(mStencilbuffer.type(), mRenderer->getCurrentClientVersion())) |
daniel@transgaming.com | fbc0953 | 2010-04-26 15:33:41 +0000 | [diff] [blame] | 206 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 207 | mStencilbuffer.set(NULL, GL_NONE, 0, 0); |
daniel@transgaming.com | fbc0953 | 2010-04-26 15:33:41 +0000 | [diff] [blame] | 208 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void Framebuffer::detachRenderbuffer(GLuint renderbuffer) |
| 212 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 213 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 214 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 215 | if (mColorbuffers[colorAttachment].id() == renderbuffer && mColorbuffers[colorAttachment].type() == GL_RENDERBUFFER) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 216 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 217 | mColorbuffers[colorAttachment].set(NULL, GL_NONE, 0, 0); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 218 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 221 | if (mDepthbuffer.id() == renderbuffer && mDepthbuffer.type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 222 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 223 | mDepthbuffer.set(NULL, GL_NONE, 0, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 226 | if (mStencilbuffer.id() == renderbuffer && mStencilbuffer.type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 227 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 228 | mStencilbuffer.set(NULL, GL_NONE, 0, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 232 | unsigned int Framebuffer::getRenderTargetSerial(unsigned int colorAttachment) const |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 233 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 234 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
| 235 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 236 | FramebufferAttachment *colorbuffer = mColorbuffers[colorAttachment].get(); |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 237 | |
| 238 | if (colorbuffer) |
| 239 | { |
| 240 | return colorbuffer->getSerial(); |
| 241 | } |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 246 | unsigned int Framebuffer::getDepthbufferSerial() const |
daniel@transgaming.com | 339ae70 | 2010-05-12 03:40:20 +0000 | [diff] [blame] | 247 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 248 | FramebufferAttachment *depthbuffer = mDepthbuffer.get(); |
daniel@transgaming.com | 339ae70 | 2010-05-12 03:40:20 +0000 | [diff] [blame] | 249 | |
| 250 | if (depthbuffer) |
| 251 | { |
| 252 | return depthbuffer->getSerial(); |
| 253 | } |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 258 | unsigned int Framebuffer::getStencilbufferSerial() const |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 259 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 260 | FramebufferAttachment *stencilbuffer = mStencilbuffer.get(); |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 261 | |
| 262 | if (stencilbuffer) |
| 263 | { |
| 264 | return stencilbuffer->getSerial(); |
| 265 | } |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 270 | FramebufferAttachment *Framebuffer::getColorbuffer(unsigned int colorAttachment) const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 271 | { |
| 272 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 273 | return mColorbuffers[colorAttachment].get(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 276 | FramebufferAttachment *Framebuffer::getDepthbuffer() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 277 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 278 | return mDepthbuffer.get(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 281 | FramebufferAttachment *Framebuffer::getStencilbuffer() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 282 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 283 | return mStencilbuffer.get(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 286 | FramebufferAttachment *Framebuffer::getDepthStencilBuffer() const |
Geoff Lang | 646559f | 2013-08-15 11:08:15 -0400 | [diff] [blame] | 287 | { |
| 288 | return (mDepthbuffer.id() == mStencilbuffer.id()) ? mDepthbuffer.get() : NULL; |
| 289 | } |
| 290 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 291 | FramebufferAttachment *Framebuffer::getDepthOrStencilbuffer() const |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 292 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 293 | FramebufferAttachment *depthstencilbuffer = mDepthbuffer.get(); |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 294 | |
| 295 | if (!depthstencilbuffer) |
| 296 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 297 | depthstencilbuffer = mStencilbuffer.get(); |
daniel@transgaming.com | d2b4702 | 2012-11-28 19:40:10 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | return depthstencilbuffer; |
| 301 | } |
| 302 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 303 | FramebufferAttachment *Framebuffer::getReadColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 304 | { |
| 305 | // Will require more logic if glReadBuffers is supported |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 306 | return mColorbuffers[0].get(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 307 | } |
| 308 | |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 309 | GLenum Framebuffer::getReadColorbufferType() const |
| 310 | { |
| 311 | // Will require more logic if glReadBuffers is supported |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 312 | return mColorbuffers[0].type(); |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 315 | FramebufferAttachment *Framebuffer::getFirstColorbuffer() const |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 316 | { |
| 317 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 318 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 319 | if (mColorbuffers[colorAttachment].type() != GL_NONE) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 320 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 321 | return mColorbuffers[colorAttachment].get(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | return NULL; |
| 326 | } |
| 327 | |
| 328 | GLenum Framebuffer::getColorbufferType(unsigned int colorAttachment) const |
| 329 | { |
| 330 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 331 | return mColorbuffers[colorAttachment].type(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 332 | } |
| 333 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 334 | GLenum Framebuffer::getDepthbufferType() const |
daniel@transgaming.com | c46c9c0 | 2010-04-23 18:34:55 +0000 | [diff] [blame] | 335 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 336 | return mDepthbuffer.type(); |
daniel@transgaming.com | c46c9c0 | 2010-04-23 18:34:55 +0000 | [diff] [blame] | 337 | } |
| 338 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 339 | GLenum Framebuffer::getStencilbufferType() const |
daniel@transgaming.com | c46c9c0 | 2010-04-23 18:34:55 +0000 | [diff] [blame] | 340 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 341 | return mStencilbuffer.type(); |
daniel@transgaming.com | c46c9c0 | 2010-04-23 18:34:55 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 344 | GLenum Framebuffer::getDepthStencilbufferType() const |
| 345 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 346 | return (mDepthbuffer.id() == mStencilbuffer.id()) ? mDepthbuffer.type() : GL_NONE; |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 347 | } |
| 348 | |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 349 | GLuint Framebuffer::getColorbufferHandle(unsigned int colorAttachment) const |
| 350 | { |
| 351 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 352 | return mColorbuffers[colorAttachment].id(); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 353 | } |
| 354 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 355 | GLuint Framebuffer::getDepthbufferHandle() const |
daniel@transgaming.com | c46c9c0 | 2010-04-23 18:34:55 +0000 | [diff] [blame] | 356 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 357 | return mDepthbuffer.id(); |
daniel@transgaming.com | c46c9c0 | 2010-04-23 18:34:55 +0000 | [diff] [blame] | 358 | } |
| 359 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 360 | GLuint Framebuffer::getStencilbufferHandle() const |
daniel@transgaming.com | c46c9c0 | 2010-04-23 18:34:55 +0000 | [diff] [blame] | 361 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 362 | return mStencilbuffer.id(); |
daniel@transgaming.com | c46c9c0 | 2010-04-23 18:34:55 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 365 | GLenum Framebuffer::getDepthStencilbufferHandle() const |
| 366 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 367 | return (mDepthbuffer.id() == mStencilbuffer.id()) ? mDepthbuffer.id() : 0; |
| 368 | } |
| 369 | |
| 370 | GLenum Framebuffer::getColorbufferMipLevel(unsigned int colorAttachment) const |
| 371 | { |
| 372 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
| 373 | return mColorbuffers[colorAttachment].mipLevel(); |
| 374 | } |
| 375 | |
| 376 | GLenum Framebuffer::getDepthbufferMipLevel() const |
| 377 | { |
| 378 | return mDepthbuffer.mipLevel(); |
| 379 | } |
| 380 | |
| 381 | GLenum Framebuffer::getStencilbufferMipLevel() const |
| 382 | { |
| 383 | return mStencilbuffer.mipLevel(); |
| 384 | } |
| 385 | |
| 386 | GLenum Framebuffer::getDepthStencilbufferMipLevel() const |
| 387 | { |
| 388 | return (mDepthbuffer.id() == mStencilbuffer.id()) ? mDepthbuffer.mipLevel() : 0; |
| 389 | } |
| 390 | |
| 391 | GLenum Framebuffer::getColorbufferLayer(unsigned int colorAttachment) const |
| 392 | { |
| 393 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
| 394 | return mColorbuffers[colorAttachment].layer(); |
| 395 | } |
| 396 | |
| 397 | GLenum Framebuffer::getDepthbufferLayer() const |
| 398 | { |
| 399 | return mDepthbuffer.layer(); |
| 400 | } |
| 401 | |
| 402 | GLenum Framebuffer::getStencilbufferLayer() const |
| 403 | { |
| 404 | return mStencilbuffer.layer(); |
| 405 | } |
| 406 | |
| 407 | GLenum Framebuffer::getDepthStencilbufferLayer() const |
| 408 | { |
| 409 | return (mDepthbuffer.id() == mStencilbuffer.id()) ? mDepthbuffer.layer() : 0; |
Geoff Lang | 55ba29c | 2013-07-11 16:57:53 -0400 | [diff] [blame] | 410 | } |
| 411 | |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 412 | GLenum Framebuffer::getDrawBufferState(unsigned int colorAttachment) const |
| 413 | { |
| 414 | return mDrawBufferStates[colorAttachment]; |
| 415 | } |
| 416 | |
| 417 | void Framebuffer::setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer) |
| 418 | { |
| 419 | mDrawBufferStates[colorAttachment] = drawBuffer; |
| 420 | } |
| 421 | |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 422 | bool Framebuffer::isEnabledColorAttachment(unsigned int colorAttachment) const |
| 423 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 424 | return (mColorbuffers[colorAttachment].type() != GL_NONE && mDrawBufferStates[colorAttachment] != GL_NONE); |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | bool Framebuffer::hasEnabledColorAttachment() const |
| 428 | { |
| 429 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 430 | { |
| 431 | if (isEnabledColorAttachment(colorAttachment)) |
| 432 | { |
| 433 | return true; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | return false; |
| 438 | } |
| 439 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 440 | bool Framebuffer::hasStencil() const |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 441 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 442 | if (mStencilbuffer.type() != GL_NONE) |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 443 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 444 | const FramebufferAttachment *stencilbufferObject = getStencilbuffer(); |
daniel@transgaming.com | a27ff1e | 2010-08-24 19:20:11 +0000 | [diff] [blame] | 445 | |
| 446 | if (stencilbufferObject) |
| 447 | { |
| 448 | return stencilbufferObject->getStencilSize() > 0; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | return false; |
| 453 | } |
| 454 | |
shannonwoods@chromium.org | 24ac850 | 2013-05-30 00:01:37 +0000 | [diff] [blame] | 455 | bool Framebuffer::usingExtendedDrawBuffers() const |
| 456 | { |
| 457 | for (unsigned int colorAttachment = 1; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 458 | { |
| 459 | if (isEnabledColorAttachment(colorAttachment)) |
| 460 | { |
| 461 | return true; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | return false; |
| 466 | } |
| 467 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 468 | GLenum Framebuffer::completeness() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 469 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 470 | int width = 0; |
| 471 | int height = 0; |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 472 | unsigned int colorbufferSize = 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 473 | int samples = -1; |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 474 | bool missingAttachment = true; |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 475 | GLuint clientVersion = mRenderer->getCurrentClientVersion(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 476 | |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 477 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 478 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 479 | if (mColorbuffers[colorAttachment].type() != GL_NONE) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 480 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 481 | const FramebufferAttachment *colorbuffer = getColorbuffer(colorAttachment); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 482 | |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 483 | if (!colorbuffer) |
daniel@transgaming.com | edc1918 | 2010-10-15 17:57:55 +0000 | [diff] [blame] | 484 | { |
| 485 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 486 | } |
daniel@transgaming.com | d885df0 | 2012-05-31 01:14:36 +0000 | [diff] [blame] | 487 | |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 488 | if (colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 489 | { |
| 490 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 491 | } |
daniel@transgaming.com | 0186813 | 2010-08-24 19:21:17 +0000 | [diff] [blame] | 492 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 493 | GLenum internalformat = colorbuffer->getInternalFormat(); |
| 494 | const TextureCaps &formatCaps = mRenderer->getCaps().textureCaps.get(internalformat); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 495 | if (mColorbuffers[colorAttachment].type() == GL_RENDERBUFFER) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 496 | { |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 497 | if (!formatCaps.colorRendering) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 498 | { |
| 499 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 500 | } |
| 501 | } |
Geoff Lang | 0fe1949 | 2013-07-25 17:04:31 -0400 | [diff] [blame] | 502 | else if (IsInternalTextureTarget(mColorbuffers[colorAttachment].type(), mRenderer->getCurrentClientVersion())) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 503 | { |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 504 | if (!formatCaps.colorRendering) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 505 | { |
| 506 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 507 | } |
| 508 | |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 509 | if (gl::GetDepthBits(internalformat, clientVersion) > 0 || |
| 510 | gl::GetStencilBits(internalformat, clientVersion) > 0) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 511 | { |
| 512 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 513 | } |
| 514 | } |
| 515 | else |
| 516 | { |
| 517 | UNREACHABLE(); |
| 518 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 519 | } |
| 520 | |
| 521 | if (!missingAttachment) |
| 522 | { |
| 523 | // all color attachments must have the same width and height |
| 524 | if (colorbuffer->getWidth() != width || colorbuffer->getHeight() != height) |
| 525 | { |
| 526 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 527 | } |
| 528 | |
| 529 | // APPLE_framebuffer_multisample, which EXT_draw_buffers refers to, requires that |
| 530 | // all color attachments have the same number of samples for the FBO to be complete. |
| 531 | if (colorbuffer->getSamples() != samples) |
| 532 | { |
| 533 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT; |
| 534 | } |
| 535 | |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 536 | // in GLES 2.0, all color attachments attachments must have the same number of bitplanes |
| 537 | // in GLES 3.0, there is no such restriction |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 538 | if (clientVersion < 3) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 539 | { |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 540 | if (gl::GetPixelBytes(colorbuffer->getInternalFormat(), clientVersion) != colorbufferSize) |
shannon.woods%transgaming.com@gtempaccount.com | c347152 | 2013-04-13 03:34:52 +0000 | [diff] [blame] | 541 | { |
| 542 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 543 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | // D3D11 does not allow for overlapping RenderTargetViews, so ensure uniqueness |
| 547 | for (unsigned int previousColorAttachment = 0; previousColorAttachment < colorAttachment; previousColorAttachment++) |
| 548 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 549 | if (mColorbuffers[colorAttachment].get() == mColorbuffers[previousColorAttachment].get()) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 550 | { |
| 551 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | else |
| 556 | { |
| 557 | width = colorbuffer->getWidth(); |
| 558 | height = colorbuffer->getHeight(); |
| 559 | samples = colorbuffer->getSamples(); |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 560 | colorbufferSize = gl::GetPixelBytes(colorbuffer->getInternalFormat(), clientVersion); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 561 | missingAttachment = false; |
| 562 | } |
| 563 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 566 | const FramebufferAttachment *depthbuffer = NULL; |
| 567 | const FramebufferAttachment *stencilbuffer = NULL; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 568 | |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 569 | if (mDepthbuffer.type() != GL_NONE) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 570 | { |
| 571 | depthbuffer = getDepthbuffer(); |
| 572 | |
| 573 | if (!depthbuffer) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 574 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 575 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 576 | } |
| 577 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 578 | if (depthbuffer->getWidth() == 0 || depthbuffer->getHeight() == 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 579 | { |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 580 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 581 | } |
| 582 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 583 | GLenum internalformat = depthbuffer->getInternalFormat(); |
| 584 | const TextureCaps &formatCaps = mRenderer->getCaps().textureCaps.get(internalformat); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 585 | if (mDepthbuffer.type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 586 | { |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 587 | if (!formatCaps.depthRendering) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 588 | { |
| 589 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 590 | } |
| 591 | } |
Geoff Lang | 0fe1949 | 2013-07-25 17:04:31 -0400 | [diff] [blame] | 592 | else if (IsInternalTextureTarget(mDepthbuffer.type(), mRenderer->getCurrentClientVersion())) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 593 | { |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 594 | // depth texture attachments require OES/ANGLE_depth_texture |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 595 | if (!mRenderer->getCaps().extensions.depthTextures) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 596 | { |
| 597 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 598 | } |
| 599 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 600 | if (!formatCaps.depthRendering) |
| 601 | { |
| 602 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 603 | } |
| 604 | |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 605 | if (gl::GetDepthBits(internalformat, clientVersion) == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 606 | { |
| 607 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 608 | } |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | UNREACHABLE(); |
| 613 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 614 | } |
| 615 | |
| 616 | if (missingAttachment) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 617 | { |
| 618 | width = depthbuffer->getWidth(); |
| 619 | height = depthbuffer->getHeight(); |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 620 | samples = depthbuffer->getSamples(); |
| 621 | missingAttachment = false; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 622 | } |
| 623 | else if (width != depthbuffer->getWidth() || height != depthbuffer->getHeight()) |
| 624 | { |
| 625 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 626 | } |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 627 | else if (samples != depthbuffer->getSamples()) |
| 628 | { |
| 629 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
| 630 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 633 | if (mStencilbuffer.type() != GL_NONE) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 634 | { |
| 635 | stencilbuffer = getStencilbuffer(); |
| 636 | |
| 637 | if (!stencilbuffer) |
| 638 | { |
| 639 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 640 | } |
| 641 | |
| 642 | if (stencilbuffer->getWidth() == 0 || stencilbuffer->getHeight() == 0) |
| 643 | { |
| 644 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 645 | } |
| 646 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 647 | GLenum internalformat = stencilbuffer->getInternalFormat(); |
| 648 | const TextureCaps &formatCaps = mRenderer->getCaps().textureCaps.get(internalformat); |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 649 | if (mStencilbuffer.type() == GL_RENDERBUFFER) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 650 | { |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 651 | if (!formatCaps.stencilRendering) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 652 | { |
| 653 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 654 | } |
| 655 | } |
Geoff Lang | 0fe1949 | 2013-07-25 17:04:31 -0400 | [diff] [blame] | 656 | else if (IsInternalTextureTarget(mStencilbuffer.type(), mRenderer->getCurrentClientVersion())) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 657 | { |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 658 | // texture stencil attachments come along as part |
| 659 | // of OES_packed_depth_stencil + OES/ANGLE_depth_texture |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 660 | if (!mRenderer->getCaps().extensions.depthTextures) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 661 | { |
| 662 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 663 | } |
| 664 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 665 | if (!formatCaps.stencilRendering) |
| 666 | { |
| 667 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 668 | } |
| 669 | |
shannonwoods@chromium.org | f6fb959 | 2013-05-30 00:09:40 +0000 | [diff] [blame] | 670 | if (gl::GetStencilBits(internalformat, clientVersion) == 0) |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 671 | { |
| 672 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 673 | } |
| 674 | } |
| 675 | else |
| 676 | { |
| 677 | UNREACHABLE(); |
| 678 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
| 679 | } |
| 680 | |
| 681 | if (missingAttachment) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 682 | { |
| 683 | width = stencilbuffer->getWidth(); |
| 684 | height = stencilbuffer->getHeight(); |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 685 | samples = stencilbuffer->getSamples(); |
| 686 | missingAttachment = false; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 687 | } |
| 688 | else if (width != stencilbuffer->getWidth() || height != stencilbuffer->getHeight()) |
| 689 | { |
| 690 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
| 691 | } |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 692 | else if (samples != stencilbuffer->getSamples()) |
| 693 | { |
| 694 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
| 695 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 696 | } |
| 697 | |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 698 | // if we have both a depth and stencil buffer, they must refer to the same object |
| 699 | // since we only support packed_depth_stencil and not separate depth and stencil |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 700 | if (depthbuffer && stencilbuffer && |
| 701 | !(depthbuffer->id() == stencilbuffer->id() && |
| 702 | depthbuffer->isTexture() == stencilbuffer->isTexture())) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 703 | { |
daniel@transgaming.com | 6b7c84c | 2012-05-31 01:14:39 +0000 | [diff] [blame] | 704 | return GL_FRAMEBUFFER_UNSUPPORTED; |
| 705 | } |
| 706 | |
| 707 | // we need to have at least one attachment to be complete |
| 708 | if (missingAttachment) |
| 709 | { |
| 710 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 711 | } |
| 712 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 713 | return GL_FRAMEBUFFER_COMPLETE; |
| 714 | } |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 715 | |
daniel@transgaming.com | 16418b1 | 2012-11-28 19:32:22 +0000 | [diff] [blame] | 716 | DefaultFramebuffer::DefaultFramebuffer(rx::Renderer *renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil) |
| 717 | : Framebuffer(renderer) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 718 | { |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 719 | Renderbuffer *colorRenderbuffer = new Renderbuffer(mRenderer, 0, colorbuffer); |
| 720 | FramebufferAttachment *colorAttachment = new FramebufferAttachment(mRenderer, 0, new RenderbufferAttachment(colorRenderbuffer)); |
| 721 | mColorbuffers[0].set(colorAttachment, GL_RENDERBUFFER, 0, 0); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 722 | |
Jamie Madill | 6c7b4ad | 2014-06-16 10:33:59 -0400 | [diff] [blame^] | 723 | Renderbuffer *depthStencilRenderbuffer = new Renderbuffer(mRenderer, 0, depthStencil); |
| 724 | FramebufferAttachment *depthStencilAttachment = new FramebufferAttachment(mRenderer, 0, new RenderbufferAttachment(depthStencilRenderbuffer)); |
| 725 | mDepthbuffer.set(depthStencilAttachment, (depthStencilRenderbuffer->getDepthSize() != 0) ? GL_RENDERBUFFER : GL_NONE, 0, 0); |
| 726 | mStencilbuffer.set(depthStencilAttachment, (depthStencilRenderbuffer->getStencilSize() != 0) ? GL_RENDERBUFFER : GL_NONE, 0, 0); |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 727 | |
| 728 | mDrawBufferStates[0] = GL_BACK; |
| 729 | mReadBufferState = GL_BACK; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 730 | } |
| 731 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 732 | int Framebuffer::getSamples() const |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 733 | { |
| 734 | if (completeness() == GL_FRAMEBUFFER_COMPLETE) |
| 735 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 736 | // for a complete framebuffer, all attachments must have the same sample count |
| 737 | // in this case return the first nonzero sample size |
| 738 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 739 | { |
Geoff Lang | c90d73a | 2013-07-22 16:39:23 -0400 | [diff] [blame] | 740 | if (mColorbuffers[colorAttachment].type() != GL_NONE) |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 741 | { |
| 742 | return getColorbuffer(colorAttachment)->getSamples(); |
| 743 | } |
| 744 | } |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 745 | } |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 746 | |
| 747 | return 0; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 748 | } |
| 749 | |
shannon.woods%transgaming.com@gtempaccount.com | 3b57b4f | 2013-04-13 03:28:29 +0000 | [diff] [blame] | 750 | GLenum DefaultFramebuffer::completeness() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 751 | { |
shannon.woods@transgaming.com | 3e3da58 | 2013-02-28 23:09:03 +0000 | [diff] [blame] | 752 | // The default framebuffer *must* always be complete, though it may not be |
| 753 | // 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] | 754 | return GL_FRAMEBUFFER_COMPLETE; |
| 755 | } |
| 756 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 757 | } |