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" |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 19 | #include "libANGLE/renderer/gl/BlitGL.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 20 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
Jacek Caban | fa60f69 | 2015-04-27 18:23:44 +0200 | [diff] [blame] | 21 | #include "libANGLE/renderer/gl/RenderbufferGL.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 22 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
| 23 | #include "libANGLE/renderer/gl/TextureGL.h" |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 24 | #include "libANGLE/renderer/gl/WorkaroundsGL.h" |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 25 | #include "libANGLE/renderer/gl/formatutilsgl.h" |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 26 | #include "libANGLE/renderer/gl/renderergl_utils.h" |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 27 | #include "platform/Platform.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 28 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 29 | using namespace gl; |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 30 | using angle::CheckedNumeric; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 31 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 32 | namespace rx |
| 33 | { |
| 34 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 35 | FramebufferGL::FramebufferGL(const FramebufferState &state, |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 36 | const FunctionsGL *functions, |
| 37 | StateManagerGL *stateManager, |
| 38 | const WorkaroundsGL &workarounds, |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 39 | BlitGL *blitter, |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 40 | bool isDefault) |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 41 | : FramebufferImpl(state), |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 42 | mFunctions(functions), |
| 43 | mStateManager(stateManager), |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 44 | mWorkarounds(workarounds), |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 45 | mBlitter(blitter), |
Corentin Wallez | 6ab01b9 | 2015-08-03 10:16:36 -0700 | [diff] [blame] | 46 | mFramebufferID(0), |
| 47 | mIsDefault(isDefault) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 48 | { |
Corentin Wallez | 6ab01b9 | 2015-08-03 10:16:36 -0700 | [diff] [blame] | 49 | if (!mIsDefault) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 50 | { |
| 51 | mFunctions->genFramebuffers(1, &mFramebufferID); |
| 52 | } |
| 53 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 54 | |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 55 | FramebufferGL::FramebufferGL(GLuint id, |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 56 | const FramebufferState &state, |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 57 | const FunctionsGL *functions, |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 58 | const WorkaroundsGL &workarounds, |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 59 | BlitGL *blitter, |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 60 | StateManagerGL *stateManager) |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 61 | : FramebufferImpl(state), |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 62 | mFunctions(functions), |
| 63 | mStateManager(stateManager), |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 64 | mWorkarounds(workarounds), |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 65 | mBlitter(blitter), |
Corentin Wallez | 86f8dd7 | 2015-08-12 12:37:48 -0700 | [diff] [blame] | 66 | mFramebufferID(id), |
| 67 | mIsDefault(true) |
| 68 | { |
| 69 | } |
| 70 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 71 | FramebufferGL::~FramebufferGL() |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 72 | { |
Geoff Lang | 1eb708e | 2015-05-04 14:58:23 -0400 | [diff] [blame] | 73 | mStateManager->deleteFramebuffer(mFramebufferID); |
| 74 | mFramebufferID = 0; |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 75 | } |
| 76 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 77 | static void BindFramebufferAttachment(const FunctionsGL *functions, |
| 78 | GLenum attachmentPoint, |
| 79 | const FramebufferAttachment *attachment) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 80 | { |
| 81 | if (attachment) |
| 82 | { |
| 83 | if (attachment->type() == GL_TEXTURE) |
| 84 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 85 | const Texture *texture = attachment->getTexture(); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 86 | const TextureGL *textureGL = GetImplAs<TextureGL>(texture); |
| 87 | |
| 88 | if (texture->getTarget() == GL_TEXTURE_2D) |
| 89 | { |
| 90 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, |
| 91 | textureGL->getTextureID(), attachment->mipLevel()); |
| 92 | } |
| 93 | else if (texture->getTarget() == GL_TEXTURE_CUBE_MAP) |
| 94 | { |
| 95 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, attachment->cubeMapFace(), |
| 96 | textureGL->getTextureID(), attachment->mipLevel()); |
| 97 | } |
| 98 | else if (texture->getTarget() == GL_TEXTURE_2D_ARRAY || texture->getTarget() == GL_TEXTURE_3D) |
| 99 | { |
| 100 | functions->framebufferTextureLayer(GL_FRAMEBUFFER, attachmentPoint, textureGL->getTextureID(), |
| 101 | attachment->mipLevel(), attachment->layer()); |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | UNREACHABLE(); |
| 106 | } |
| 107 | } |
| 108 | else if (attachment->type() == GL_RENDERBUFFER) |
| 109 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 110 | const Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 111 | const RenderbufferGL *renderbufferGL = GetImplAs<RenderbufferGL>(renderbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 112 | |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 113 | functions->framebufferRenderbuffer(GL_FRAMEBUFFER, attachmentPoint, GL_RENDERBUFFER, |
| 114 | renderbufferGL->getRenderbufferID()); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 115 | } |
| 116 | else |
| 117 | { |
| 118 | UNREACHABLE(); |
| 119 | } |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | // Unbind this attachment |
| 124 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, 0, 0); |
| 125 | } |
| 126 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 127 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 128 | Error FramebufferGL::discard(size_t count, const GLenum *attachments) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 129 | { |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 130 | // glInvalidateFramebuffer accepts the same enums as glDiscardFramebufferEXT |
| 131 | return invalidate(count, attachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 134 | Error FramebufferGL::invalidate(size_t count, const GLenum *attachments) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 135 | { |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 136 | // Since this function is just a hint, only call a native function if it exists. |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 137 | if (mFunctions->invalidateFramebuffer) |
| 138 | { |
| 139 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 140 | mFunctions->invalidateFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), attachments); |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 141 | } |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 142 | else if (mFunctions->discardFramebuffer) |
| 143 | { |
| 144 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 145 | mFunctions->discardFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), attachments); |
| 146 | } |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 147 | |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 148 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 149 | } |
| 150 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 151 | Error FramebufferGL::invalidateSub(size_t count, |
| 152 | const GLenum *attachments, |
| 153 | const gl::Rectangle &area) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 154 | { |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 155 | // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is available. |
| 156 | if (mFunctions->invalidateSubFramebuffer) |
| 157 | { |
| 158 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 159 | mFunctions->invalidateSubFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), |
| 160 | attachments, area.x, area.y, area.width, area.height); |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 163 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 164 | } |
| 165 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 166 | Error FramebufferGL::clear(ContextImpl *context, GLbitfield mask) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 167 | { |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 168 | syncClearState(mask); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 169 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 170 | mFunctions->clear(mask); |
| 171 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 172 | return Error(GL_NO_ERROR); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 173 | } |
| 174 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 175 | Error FramebufferGL::clearBufferfv(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 176 | GLenum buffer, |
| 177 | GLint drawbuffer, |
| 178 | const GLfloat *values) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 179 | { |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 180 | syncClearBufferState(buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 181 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 182 | mFunctions->clearBufferfv(buffer, drawbuffer, values); |
| 183 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 184 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 185 | } |
| 186 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 187 | Error FramebufferGL::clearBufferuiv(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 188 | GLenum buffer, |
| 189 | GLint drawbuffer, |
| 190 | const GLuint *values) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 191 | { |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 192 | syncClearBufferState(buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 193 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 194 | mFunctions->clearBufferuiv(buffer, drawbuffer, values); |
| 195 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 196 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 199 | Error FramebufferGL::clearBufferiv(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 200 | GLenum buffer, |
| 201 | GLint drawbuffer, |
| 202 | const GLint *values) |
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->clearBufferiv(buffer, drawbuffer, values); |
| 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 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 211 | Error FramebufferGL::clearBufferfi(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 212 | GLenum buffer, |
| 213 | GLint drawbuffer, |
| 214 | GLfloat depth, |
| 215 | GLint stencil) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 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->clearBufferfi(buffer, drawbuffer, depth, stencil); |
| 220 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 221 | return Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | GLenum FramebufferGL::getImplementationColorReadFormat() const |
| 225 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 226 | const auto *readAttachment = mState.getReadAttachment(); |
| 227 | const Format &format = readAttachment->getFormat(); |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 228 | return format.info->getReadPixelsFormat(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | GLenum FramebufferGL::getImplementationColorReadType() const |
| 232 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 233 | const auto *readAttachment = mState.getReadAttachment(); |
| 234 | const Format &format = readAttachment->getFormat(); |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 235 | return format.info->getReadPixelsType(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 236 | } |
| 237 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 238 | Error FramebufferGL::readPixels(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 239 | const gl::Rectangle &area, |
| 240 | GLenum format, |
| 241 | GLenum type, |
| 242 | GLvoid *pixels) const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 243 | { |
Geoff Lang | da34d00 | 2015-09-04 11:08:59 -0400 | [diff] [blame] | 244 | // TODO: don't sync the pixel pack state here once the dirty bits contain the pixel pack buffer |
| 245 | // binding |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 246 | const PixelPackState &packState = context->getGLState().getPackState(); |
Geoff Lang | da34d00 | 2015-09-04 11:08:59 -0400 | [diff] [blame] | 247 | mStateManager->setPixelPackState(packState); |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 248 | |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 249 | nativegl::ReadPixelsFormat readPixelsFormat = |
| 250 | nativegl::GetReadPixelsFormat(mFunctions, mWorkarounds, format, type); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 251 | GLenum readFormat = readPixelsFormat.format; |
| 252 | GLenum readType = readPixelsFormat.type; |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 253 | |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 254 | mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, mFramebufferID); |
| 255 | |
| 256 | if (mWorkarounds.packOverlappingRowsSeparatelyPackBuffer && packState.pixelBuffer.get() && |
| 257 | packState.rowLength != 0 && packState.rowLength < area.width) |
| 258 | { |
| 259 | return readPixelsRowByRowWorkaround(area, readFormat, readType, packState, pixels); |
| 260 | } |
| 261 | |
| 262 | if (mWorkarounds.packLastRowSeparatelyForPaddingInclusion) |
| 263 | { |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 264 | gl::Extents size(area.width, area.height, 1); |
| 265 | |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 266 | bool apply; |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 267 | ANGLE_TRY_RESULT(ShouldApplyLastRowPaddingWorkaround(size, packState, readFormat, readType, |
| 268 | false, pixels), |
| 269 | apply); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 270 | |
| 271 | if (apply) |
| 272 | { |
| 273 | return readPixelsPaddingWorkaround(area, readFormat, readType, packState, pixels); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | mFunctions->readPixels(area.x, area.y, area.width, area.height, readFormat, readType, pixels); |
| 278 | |
| 279 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 280 | } |
| 281 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 282 | Error FramebufferGL::blit(ContextImpl *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 283 | const gl::Rectangle &sourceArea, |
| 284 | const gl::Rectangle &destArea, |
| 285 | GLbitfield mask, |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 286 | GLenum filter) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 287 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 288 | const Framebuffer *sourceFramebuffer = context->getGLState().getReadFramebuffer(); |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 289 | const Framebuffer *destFramebuffer = context->getGLState().getDrawFramebuffer(); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 290 | |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 291 | const FramebufferAttachment *colorReadAttachment = sourceFramebuffer->getReadColorbuffer(); |
Corentin Wallez | 4596a76 | 2016-12-20 14:50:18 -0500 | [diff] [blame] | 292 | |
| 293 | GLsizei readAttachmentSamples = 0; |
| 294 | if (colorReadAttachment != nullptr) |
| 295 | { |
| 296 | readAttachmentSamples = colorReadAttachment->getSamples(); |
| 297 | } |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 298 | |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 299 | bool needManualColorBlit = false; |
| 300 | |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 301 | // TODO(cwallez) when the filter is LINEAR and both source and destination are SRGB, we |
| 302 | // could avoid doing a manual blit. |
| 303 | |
| 304 | // Prior to OpenGL 4.4 BlitFramebuffer (section 18.3.1 of GL 4.3 core profile) reads: |
| 305 | // When values are taken from the read buffer, no linearization is performed, even |
| 306 | // if the format of the buffer is SRGB. |
| 307 | // Starting from OpenGL 4.4 (section 18.3.1) it reads: |
| 308 | // When values are taken from the read buffer, if FRAMEBUFFER_SRGB is enabled and the |
| 309 | // value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the framebuffer attachment |
| 310 | // corresponding to the read buffer is SRGB, the red, green, and blue components are |
| 311 | // converted from the non-linear sRGB color space according [...]. |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 312 | { |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 313 | bool sourceSRGB = colorReadAttachment != nullptr && |
| 314 | colorReadAttachment->getColorEncoding() == GL_SRGB; |
| 315 | needManualColorBlit = |
| 316 | needManualColorBlit || (sourceSRGB && mFunctions->isAtMostGL(gl::Version(4, 3))); |
| 317 | } |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 318 | |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 319 | // Prior to OpenGL 4.2 BlitFramebuffer (section 4.3.2 of GL 4.1 core profile) reads: |
| 320 | // Blit operations bypass the fragment pipeline. The only fragment operations which |
| 321 | // affect a blit are the pixel ownership test and scissor test. |
| 322 | // Starting from OpenGL 4.2 (section 4.3.2) it reads: |
| 323 | // When values are written to the draw buffers, blit operations bypass the fragment |
| 324 | // pipeline. The only fragment operations which affect a blit are the pixel ownership |
| 325 | // test, the scissor test and sRGB conversion. |
| 326 | if (!needManualColorBlit) |
| 327 | { |
| 328 | bool destSRGB = false; |
| 329 | for (size_t i = 0; i < destFramebuffer->getDrawbufferStateCount(); ++i) |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 330 | { |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 331 | const FramebufferAttachment *attachment = destFramebuffer->getDrawBuffer(i); |
| 332 | if (attachment && attachment->getColorEncoding() == GL_SRGB) |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 333 | { |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 334 | destSRGB = true; |
| 335 | break; |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 336 | } |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 337 | } |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 338 | |
| 339 | needManualColorBlit = |
| 340 | needManualColorBlit || (destSRGB && mFunctions->isAtMostGL(gl::Version(4, 1))); |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | // Enable FRAMEBUFFER_SRGB if needed |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 344 | mStateManager->setFramebufferSRGBEnabledForFramebuffer(true, this); |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 345 | |
| 346 | GLenum blitMask = mask; |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 347 | if (needManualColorBlit && (mask & GL_COLOR_BUFFER_BIT) && readAttachmentSamples <= 1) |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 348 | { |
| 349 | ANGLE_TRY(mBlitter->blitColorBufferWithShader(sourceFramebuffer, destFramebuffer, |
| 350 | sourceArea, destArea, filter)); |
| 351 | blitMask &= ~GL_COLOR_BUFFER_BIT; |
| 352 | } |
| 353 | |
| 354 | if (blitMask == 0) |
| 355 | { |
| 356 | return gl::NoError(); |
| 357 | } |
| 358 | |
| 359 | const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(sourceFramebuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 360 | mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID()); |
| 361 | mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebufferID); |
| 362 | |
Jamie Madill | 2da819e | 2015-12-03 15:53:19 -0500 | [diff] [blame] | 363 | mFunctions->blitFramebuffer(sourceArea.x, sourceArea.y, sourceArea.x1(), sourceArea.y1(), |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 364 | destArea.x, destArea.y, destArea.x1(), destArea.y1(), blitMask, |
| 365 | filter); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 366 | |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 367 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 368 | } |
| 369 | |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 370 | bool FramebufferGL::checkStatus() const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 371 | { |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 372 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 373 | GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER); |
| 374 | if (status != GL_FRAMEBUFFER_COMPLETE) |
| 375 | { |
| 376 | ANGLEPlatformCurrent()->logWarning("GL framebuffer returned incomplete."); |
| 377 | } |
| 378 | return (status == GL_FRAMEBUFFER_COMPLETE); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 379 | } |
| 380 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 381 | void FramebufferGL::syncState(const Framebuffer::DirtyBits &dirtyBits) |
| 382 | { |
| 383 | // Don't need to sync state for the default FBO. |
| 384 | if (mIsDefault) |
| 385 | { |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 390 | |
| 391 | for (auto dirtyBit : angle::IterateBitSet(dirtyBits)) |
| 392 | { |
| 393 | switch (dirtyBit) |
| 394 | { |
| 395 | case Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT: |
| 396 | BindFramebufferAttachment(mFunctions, GL_DEPTH_ATTACHMENT, |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 397 | mState.getDepthAttachment()); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 398 | break; |
| 399 | case Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT: |
| 400 | BindFramebufferAttachment(mFunctions, GL_STENCIL_ATTACHMENT, |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 401 | mState.getStencilAttachment()); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 402 | break; |
| 403 | case Framebuffer::DIRTY_BIT_DRAW_BUFFERS: |
| 404 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 405 | const auto &drawBuffers = mState.getDrawBufferStates(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 406 | mFunctions->drawBuffers(static_cast<GLsizei>(drawBuffers.size()), |
| 407 | drawBuffers.data()); |
| 408 | break; |
| 409 | } |
| 410 | case Framebuffer::DIRTY_BIT_READ_BUFFER: |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 411 | mFunctions->readBuffer(mState.getReadBufferState()); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 412 | break; |
| 413 | default: |
| 414 | { |
| 415 | ASSERT(Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 && |
| 416 | dirtyBit < Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX); |
| 417 | size_t index = |
| 418 | static_cast<size_t>(dirtyBit - Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0); |
| 419 | BindFramebufferAttachment(mFunctions, |
| 420 | static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + index), |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 421 | mState.getColorAttachment(index)); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 422 | break; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 428 | GLuint FramebufferGL::getFramebufferID() const |
| 429 | { |
| 430 | return mFramebufferID; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 431 | } |
| 432 | |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 433 | bool FramebufferGL::isDefault() const |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 434 | { |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 435 | return mIsDefault; |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void FramebufferGL::syncClearState(GLbitfield mask) |
| 439 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 440 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 441 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 442 | if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && |
| 443 | (mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 444 | { |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 445 | bool hasSRGBAttachment = false; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 446 | for (const auto &attachment : mState.getColorAttachments()) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 447 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 448 | if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB) |
| 449 | { |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 450 | hasSRGBAttachment = true; |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 451 | break; |
| 452 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 453 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 454 | |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 455 | mStateManager->setFramebufferSRGBEnabled(hasSRGBAttachment); |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 456 | } |
| 457 | else |
| 458 | { |
| 459 | mStateManager->setFramebufferSRGBEnabled(!mIsDefault); |
| 460 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
| 464 | void FramebufferGL::syncClearBufferState(GLenum buffer, GLint drawBuffer) |
| 465 | { |
| 466 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
| 467 | { |
| 468 | if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && buffer == GL_COLOR && |
| 469 | !mIsDefault) |
| 470 | { |
| 471 | // If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer |
| 472 | // is an SRGB format. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 473 | const auto &drawbufferState = mState.getDrawBufferStates(); |
| 474 | const auto &colorAttachments = mState.getColorAttachments(); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 475 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 476 | const FramebufferAttachment *attachment = nullptr; |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 477 | if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 && |
| 478 | drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size()) |
| 479 | { |
| 480 | size_t attachmentIdx = |
| 481 | static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0); |
| 482 | attachment = &colorAttachments[attachmentIdx]; |
| 483 | } |
| 484 | |
| 485 | if (attachment != nullptr) |
| 486 | { |
| 487 | mStateManager->setFramebufferSRGBEnabled(attachment->getColorEncoding() == GL_SRGB); |
| 488 | } |
| 489 | } |
| 490 | else |
| 491 | { |
| 492 | mStateManager->setFramebufferSRGBEnabled(!mIsDefault); |
| 493 | } |
| 494 | } |
| 495 | } |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 496 | gl::Error FramebufferGL::readPixelsRowByRowWorkaround(const gl::Rectangle &area, |
| 497 | GLenum format, |
| 498 | GLenum type, |
| 499 | const gl::PixelPackState &pack, |
| 500 | GLvoid *pixels) const |
| 501 | { |
| 502 | intptr_t offset = reinterpret_cast<intptr_t>(pixels); |
| 503 | |
| 504 | const gl::InternalFormat &glFormat = |
| 505 | gl::GetInternalFormatInfo(gl::GetSizedInternalFormat(format, type)); |
| 506 | GLuint rowBytes = 0; |
| 507 | ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength), |
| 508 | rowBytes); |
| 509 | GLuint skipBytes = 0; |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 510 | ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, pack, false), skipBytes); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 511 | |
| 512 | gl::PixelPackState directPack; |
| 513 | directPack.pixelBuffer = pack.pixelBuffer; |
| 514 | directPack.alignment = 1; |
| 515 | mStateManager->setPixelPackState(directPack); |
| 516 | directPack.pixelBuffer.set(nullptr); |
| 517 | |
| 518 | offset += skipBytes; |
| 519 | for (GLint row = 0; row < area.height; ++row) |
| 520 | { |
| 521 | mFunctions->readPixels(area.x, row + area.y, area.width, 1, format, type, |
| 522 | reinterpret_cast<GLvoid *>(offset)); |
| 523 | offset += row * rowBytes; |
| 524 | } |
| 525 | |
| 526 | return gl::NoError(); |
| 527 | } |
| 528 | |
| 529 | gl::Error FramebufferGL::readPixelsPaddingWorkaround(const gl::Rectangle &area, |
| 530 | GLenum format, |
| 531 | GLenum type, |
| 532 | const gl::PixelPackState &pack, |
| 533 | GLvoid *pixels) const |
| 534 | { |
| 535 | const gl::InternalFormat &glFormat = |
| 536 | gl::GetInternalFormatInfo(gl::GetSizedInternalFormat(format, type)); |
| 537 | GLuint rowBytes = 0; |
| 538 | ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength), |
| 539 | rowBytes); |
| 540 | GLuint skipBytes = 0; |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 541 | ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, pack, false), skipBytes); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 542 | |
| 543 | // Get all by the last row |
| 544 | if (area.height > 1) |
| 545 | { |
| 546 | mFunctions->readPixels(area.x, area.y, area.width, area.height - 1, format, type, pixels); |
| 547 | } |
| 548 | |
| 549 | // Get the last row manually |
| 550 | gl::PixelPackState directPack; |
| 551 | directPack.pixelBuffer = pack.pixelBuffer; |
| 552 | directPack.alignment = 1; |
| 553 | mStateManager->setPixelPackState(directPack); |
| 554 | directPack.pixelBuffer.set(nullptr); |
| 555 | |
| 556 | intptr_t lastRowOffset = |
| 557 | reinterpret_cast<intptr_t>(pixels) + skipBytes + (area.height - 1) * rowBytes; |
| 558 | mFunctions->readPixels(area.x, area.y + area.height - 1, area.width, 1, format, type, |
| 559 | reinterpret_cast<GLvoid *>(lastRowOffset)); |
| 560 | |
| 561 | return gl::NoError(); |
| 562 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 563 | } // namespace rx |