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