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