Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // FramebufferGL.cpp: Implements the class methods for FramebufferGL. |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/FramebufferGL.h" |
| 10 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 11 | #include "common/BitSetIterator.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 12 | #include "common/debug.h" |
Jamie Madill | 9082b98 | 2016-04-27 15:21:51 -0400 | [diff] [blame] | 13 | #include "libANGLE/ContextState.h" |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 14 | #include "libANGLE/State.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 15 | #include "libANGLE/FramebufferAttachment.h" |
| 16 | #include "libANGLE/angletypes.h" |
| 17 | #include "libANGLE/formatutils.h" |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 18 | #include "libANGLE/renderer/ContextImpl.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 19 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
Jacek Caban | fa60f69 | 2015-04-27 18:23:44 +0200 | [diff] [blame] | 20 | #include "libANGLE/renderer/gl/RenderbufferGL.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 21 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
| 22 | #include "libANGLE/renderer/gl/TextureGL.h" |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 23 | #include "libANGLE/renderer/gl/WorkaroundsGL.h" |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 24 | #include "platform/Platform.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 25 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 26 | using namespace gl; |
| 27 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 28 | namespace rx |
| 29 | { |
| 30 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 31 | FramebufferGL::FramebufferGL(const FramebufferState &state, |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 32 | const FunctionsGL *functions, |
| 33 | StateManagerGL *stateManager, |
| 34 | const WorkaroundsGL &workarounds, |
| 35 | bool isDefault) |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 36 | : FramebufferImpl(state), |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 37 | mFunctions(functions), |
| 38 | mStateManager(stateManager), |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 39 | mWorkarounds(workarounds), |
Corentin Wallez | 6ab01b9 | 2015-08-03 10:16:36 -0700 | [diff] [blame] | 40 | mFramebufferID(0), |
| 41 | mIsDefault(isDefault) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 42 | { |
Corentin Wallez | 6ab01b9 | 2015-08-03 10:16:36 -0700 | [diff] [blame] | 43 | if (!mIsDefault) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 44 | { |
| 45 | mFunctions->genFramebuffers(1, &mFramebufferID); |
| 46 | } |
| 47 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 48 | |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 49 | FramebufferGL::FramebufferGL(GLuint id, |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 50 | const FramebufferState &state, |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 51 | const FunctionsGL *functions, |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 52 | const WorkaroundsGL &workarounds, |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 53 | StateManagerGL *stateManager) |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 54 | : FramebufferImpl(state), |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 55 | mFunctions(functions), |
| 56 | mStateManager(stateManager), |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 57 | mWorkarounds(workarounds), |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 58 | mFramebufferID(id), |
| 59 | mIsDefault(true) |
| 60 | { |
| 61 | } |
| 62 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 63 | FramebufferGL::~FramebufferGL() |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 64 | { |
Geoff Lang | 1eb708e | 2015-05-04 14:58:23 -0400 | [diff] [blame] | 65 | mStateManager->deleteFramebuffer(mFramebufferID); |
| 66 | mFramebufferID = 0; |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 69 | static void BindFramebufferAttachment(const FunctionsGL *functions, |
| 70 | GLenum attachmentPoint, |
| 71 | const FramebufferAttachment *attachment) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 72 | { |
| 73 | if (attachment) |
| 74 | { |
| 75 | if (attachment->type() == GL_TEXTURE) |
| 76 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 77 | const Texture *texture = attachment->getTexture(); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 78 | const TextureGL *textureGL = GetImplAs<TextureGL>(texture); |
| 79 | |
| 80 | if (texture->getTarget() == GL_TEXTURE_2D) |
| 81 | { |
| 82 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, |
| 83 | textureGL->getTextureID(), attachment->mipLevel()); |
| 84 | } |
| 85 | else if (texture->getTarget() == GL_TEXTURE_CUBE_MAP) |
| 86 | { |
| 87 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, attachment->cubeMapFace(), |
| 88 | textureGL->getTextureID(), attachment->mipLevel()); |
| 89 | } |
| 90 | else if (texture->getTarget() == GL_TEXTURE_2D_ARRAY || texture->getTarget() == GL_TEXTURE_3D) |
| 91 | { |
| 92 | functions->framebufferTextureLayer(GL_FRAMEBUFFER, attachmentPoint, textureGL->getTextureID(), |
| 93 | attachment->mipLevel(), attachment->layer()); |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | UNREACHABLE(); |
| 98 | } |
| 99 | } |
| 100 | else if (attachment->type() == GL_RENDERBUFFER) |
| 101 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 102 | const Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 103 | const RenderbufferGL *renderbufferGL = GetImplAs<RenderbufferGL>(renderbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 104 | |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 105 | functions->framebufferRenderbuffer(GL_FRAMEBUFFER, attachmentPoint, GL_RENDERBUFFER, |
| 106 | renderbufferGL->getRenderbufferID()); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 107 | } |
| 108 | else |
| 109 | { |
| 110 | UNREACHABLE(); |
| 111 | } |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | // Unbind this attachment |
| 116 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, 0, 0); |
| 117 | } |
| 118 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 119 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 120 | Error FramebufferGL::discard(size_t count, const GLenum *attachments) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 121 | { |
| 122 | UNIMPLEMENTED(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 123 | return Error(GL_INVALID_OPERATION); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 126 | Error FramebufferGL::invalidate(size_t count, const GLenum *attachments) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 127 | { |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 128 | // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available. |
| 129 | if (mFunctions->invalidateFramebuffer) |
| 130 | { |
| 131 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 132 | mFunctions->invalidateFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), attachments); |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 135 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 136 | } |
| 137 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 138 | Error FramebufferGL::invalidateSub(size_t count, |
| 139 | const GLenum *attachments, |
| 140 | const gl::Rectangle &area) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 141 | { |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 142 | // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available. |
| 143 | if (mFunctions->invalidateSubFramebuffer) |
| 144 | { |
| 145 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 146 | mFunctions->invalidateSubFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), |
| 147 | attachments, area.x, area.y, area.width, area.height); |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 150 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 153 | Error FramebufferGL::clear(ContextImpl *context, GLbitfield mask) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 154 | { |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 155 | syncClearState(mask); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 156 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 157 | mFunctions->clear(mask); |
| 158 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 159 | return Error(GL_NO_ERROR); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 160 | } |
| 161 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 162 | Error FramebufferGL::clearBufferfv(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 163 | GLenum buffer, |
| 164 | GLint drawbuffer, |
| 165 | const GLfloat *values) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 166 | { |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 167 | syncClearBufferState(buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 168 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 169 | mFunctions->clearBufferfv(buffer, drawbuffer, values); |
| 170 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 171 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 172 | } |
| 173 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 174 | Error FramebufferGL::clearBufferuiv(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 175 | GLenum buffer, |
| 176 | GLint drawbuffer, |
| 177 | const GLuint *values) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 178 | { |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 179 | syncClearBufferState(buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 180 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 181 | mFunctions->clearBufferuiv(buffer, drawbuffer, values); |
| 182 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 183 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 184 | } |
| 185 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 186 | Error FramebufferGL::clearBufferiv(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 187 | GLenum buffer, |
| 188 | GLint drawbuffer, |
| 189 | const GLint *values) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 190 | { |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 191 | syncClearBufferState(buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 192 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 193 | mFunctions->clearBufferiv(buffer, drawbuffer, values); |
| 194 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 195 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 196 | } |
| 197 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 198 | Error FramebufferGL::clearBufferfi(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 199 | GLenum buffer, |
| 200 | GLint drawbuffer, |
| 201 | GLfloat depth, |
| 202 | GLint stencil) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 203 | { |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 204 | syncClearBufferState(buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 205 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 206 | mFunctions->clearBufferfi(buffer, drawbuffer, depth, stencil); |
| 207 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 208 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | GLenum FramebufferGL::getImplementationColorReadFormat() const |
| 212 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame^] | 213 | const auto *readAttachment = mState.getReadAttachment(); |
| 214 | const Format &format = readAttachment->getFormat(); |
| 215 | return format.info->format; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | GLenum FramebufferGL::getImplementationColorReadType() const |
| 219 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame^] | 220 | const auto *readAttachment = mState.getReadAttachment(); |
| 221 | const Format &format = readAttachment->getFormat(); |
| 222 | return format.info->type; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 225 | Error FramebufferGL::readPixels(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 226 | const gl::Rectangle &area, |
| 227 | GLenum format, |
| 228 | GLenum type, |
| 229 | GLvoid *pixels) const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 230 | { |
Geoff Lang | da34d00 | 2015-09-04 11:08:59 -0400 | [diff] [blame] | 231 | // TODO: don't sync the pixel pack state here once the dirty bits contain the pixel pack buffer |
| 232 | // binding |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 233 | const PixelPackState &packState = context->getGLState().getPackState(); |
Geoff Lang | da34d00 | 2015-09-04 11:08:59 -0400 | [diff] [blame] | 234 | mStateManager->setPixelPackState(packState); |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 235 | |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 236 | mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, mFramebufferID); |
| 237 | mFunctions->readPixels(area.x, area.y, area.width, area.height, format, type, pixels); |
| 238 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 239 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 240 | } |
| 241 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 242 | Error FramebufferGL::blit(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 243 | const gl::Rectangle &sourceArea, |
| 244 | const gl::Rectangle &destArea, |
| 245 | GLbitfield mask, |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 246 | GLenum filter) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 247 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 248 | const Framebuffer *sourceFramebuffer = context->getGLState().getReadFramebuffer(); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 249 | const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(sourceFramebuffer); |
| 250 | |
| 251 | mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID()); |
| 252 | mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebufferID); |
| 253 | |
Jamie Madill | 2da819e | 2015-12-03 15:53:19 -0500 | [diff] [blame] | 254 | mFunctions->blitFramebuffer(sourceArea.x, sourceArea.y, sourceArea.x1(), sourceArea.y1(), |
| 255 | destArea.x, destArea.y, destArea.x1(), destArea.y1(), mask, filter); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 256 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 257 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 258 | } |
| 259 | |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 260 | bool FramebufferGL::checkStatus() const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 261 | { |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 262 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 263 | GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER); |
| 264 | if (status != GL_FRAMEBUFFER_COMPLETE) |
| 265 | { |
| 266 | ANGLEPlatformCurrent()->logWarning("GL framebuffer returned incomplete."); |
| 267 | } |
| 268 | return (status == GL_FRAMEBUFFER_COMPLETE); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 269 | } |
| 270 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 271 | void FramebufferGL::syncState(const Framebuffer::DirtyBits &dirtyBits) |
| 272 | { |
| 273 | // Don't need to sync state for the default FBO. |
| 274 | if (mIsDefault) |
| 275 | { |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 280 | |
| 281 | for (auto dirtyBit : angle::IterateBitSet(dirtyBits)) |
| 282 | { |
| 283 | switch (dirtyBit) |
| 284 | { |
| 285 | case Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT: |
| 286 | BindFramebufferAttachment(mFunctions, GL_DEPTH_ATTACHMENT, |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 287 | mState.getDepthAttachment()); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 288 | break; |
| 289 | case Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT: |
| 290 | BindFramebufferAttachment(mFunctions, GL_STENCIL_ATTACHMENT, |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 291 | mState.getStencilAttachment()); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 292 | break; |
| 293 | case Framebuffer::DIRTY_BIT_DRAW_BUFFERS: |
| 294 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 295 | const auto &drawBuffers = mState.getDrawBufferStates(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 296 | mFunctions->drawBuffers(static_cast<GLsizei>(drawBuffers.size()), |
| 297 | drawBuffers.data()); |
| 298 | break; |
| 299 | } |
| 300 | case Framebuffer::DIRTY_BIT_READ_BUFFER: |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 301 | mFunctions->readBuffer(mState.getReadBufferState()); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 302 | break; |
| 303 | default: |
| 304 | { |
| 305 | ASSERT(Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 && |
| 306 | dirtyBit < Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX); |
| 307 | size_t index = |
| 308 | static_cast<size_t>(dirtyBit - Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 309 | BindFramebufferAttachment(mFunctions, |
| 310 | static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + index), |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 311 | mState.getColorAttachment(index)); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 312 | break; |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 318 | GLuint FramebufferGL::getFramebufferID() const |
| 319 | { |
| 320 | return mFramebufferID; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 321 | } |
| 322 | |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 323 | void FramebufferGL::syncDrawState() const |
| 324 | { |
| 325 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
| 326 | { |
| 327 | // Enable SRGB blending for all framebuffers except the default framebuffer on Desktop |
| 328 | // OpenGL. |
| 329 | // When SRGB blending is enabled, only SRGB capable formats will use it but the default |
| 330 | // framebuffer will always use it if it is enabled. |
| 331 | // TODO(geofflang): Update this when the framebuffer binding dirty changes, when it exists. |
| 332 | mStateManager->setFramebufferSRGBEnabled(!mIsDefault); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void FramebufferGL::syncClearState(GLbitfield mask) |
| 337 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 338 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 339 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 340 | if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && |
| 341 | (mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 342 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 343 | bool hasSRBAttachment = false; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 344 | for (const auto &attachment : mState.getColorAttachments()) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 345 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 346 | if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB) |
| 347 | { |
| 348 | hasSRBAttachment = true; |
| 349 | break; |
| 350 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 351 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 352 | |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 353 | mStateManager->setFramebufferSRGBEnabled(hasSRBAttachment); |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | mStateManager->setFramebufferSRGBEnabled(!mIsDefault); |
| 358 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer) |
| 363 | { |
| 364 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
| 365 | { |
| 366 | if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && buffer == GL_COLOR && |
| 367 | !mIsDefault) |
| 368 | { |
| 369 | // If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer |
| 370 | // is an SRGB format. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 371 | const auto &drawbufferState = mState.getDrawBufferStates(); |
| 372 | const auto &colorAttachments = mState.getColorAttachments(); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 373 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 374 | const FramebufferAttachment *attachment = nullptr; |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 375 | if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 && |
| 376 | drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size()) |
| 377 | { |
| 378 | size_t attachmentIdx = |
| 379 | static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0); |
| 380 | attachment = &colorAttachments[attachmentIdx]; |
| 381 | } |
| 382 | |
| 383 | if (attachment != nullptr) |
| 384 | { |
| 385 | mStateManager->setFramebufferSRGBEnabled(attachment->getColorEncoding() == GL_SRGB); |
| 386 | } |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | mStateManager->setFramebufferSRGBEnabled(!mIsDefault); |
| 391 | } |
| 392 | } |
| 393 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 394 | } // namespace rx |