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