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 | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 11 | #include "common/bitset_utils.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 12 | #include "common/debug.h" |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 13 | #include "libANGLE/Context.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 14 | #include "libANGLE/FramebufferAttachment.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 15 | #include "libANGLE/State.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 16 | #include "libANGLE/angletypes.h" |
| 17 | #include "libANGLE/formatutils.h" |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 18 | #include "libANGLE/queryconversions.h" |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 19 | #include "libANGLE/renderer/ContextImpl.h" |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 20 | #include "libANGLE/renderer/gl/BlitGL.h" |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 21 | #include "libANGLE/renderer/gl/ClearMultiviewGL.h" |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 22 | #include "libANGLE/renderer/gl/ContextGL.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 23 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
Jacek Caban | fa60f69 | 2015-04-27 18:23:44 +0200 | [diff] [blame] | 24 | #include "libANGLE/renderer/gl/RenderbufferGL.h" |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 25 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
| 26 | #include "libANGLE/renderer/gl/TextureGL.h" |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 27 | #include "libANGLE/renderer/gl/WorkaroundsGL.h" |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 28 | #include "libANGLE/renderer/gl/formatutilsgl.h" |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 29 | #include "libANGLE/renderer/gl/renderergl_utils.h" |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 30 | #include "platform/Platform.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 31 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 32 | using namespace gl; |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 33 | using angle::CheckedNumeric; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 34 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 35 | namespace rx |
| 36 | { |
| 37 | |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 38 | namespace |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 39 | { |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 40 | |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 41 | void BindFramebufferAttachment(const FunctionsGL *functions, |
| 42 | GLenum attachmentPoint, |
| 43 | const FramebufferAttachment *attachment) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 44 | { |
| 45 | if (attachment) |
| 46 | { |
| 47 | if (attachment->type() == GL_TEXTURE) |
| 48 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 49 | const Texture *texture = attachment->getTexture(); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 50 | const TextureGL *textureGL = GetImplAs<TextureGL>(texture); |
| 51 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 52 | if (texture->getType() == TextureType::_2D || |
| 53 | texture->getType() == TextureType::_2DMultisample || |
| 54 | texture->getType() == TextureType::Rectangle) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 55 | { |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 56 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 57 | ToGLenum(texture->getType()), |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 58 | textureGL->getTextureID(), attachment->mipLevel()); |
| 59 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 60 | else if (texture->getType() == TextureType::CubeMap) |
| 61 | { |
| 62 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, |
| 63 | ToGLenum(attachment->cubeMapFace()), |
| 64 | textureGL->getTextureID(), attachment->mipLevel()); |
| 65 | } |
| 66 | else if (texture->getType() == TextureType::_2DArray || |
| 67 | texture->getType() == TextureType::_3D) |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 68 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 69 | if (attachment->getMultiviewLayout() == GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE) |
| 70 | { |
| 71 | ASSERT(functions->framebufferTexture); |
| 72 | functions->framebufferTexture(GL_FRAMEBUFFER, attachmentPoint, |
| 73 | textureGL->getTextureID(), |
| 74 | attachment->mipLevel()); |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | functions->framebufferTextureLayer(GL_FRAMEBUFFER, attachmentPoint, |
| 79 | textureGL->getTextureID(), |
| 80 | attachment->mipLevel(), attachment->layer()); |
| 81 | } |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 82 | } |
| 83 | else |
| 84 | { |
| 85 | UNREACHABLE(); |
| 86 | } |
| 87 | } |
| 88 | else if (attachment->type() == GL_RENDERBUFFER) |
| 89 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 90 | const Renderbuffer *renderbuffer = attachment->getRenderbuffer(); |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 91 | const RenderbufferGL *renderbufferGL = GetImplAs<RenderbufferGL>(renderbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 92 | |
Geoff Lang | cd69f1c | 2015-03-18 14:33:23 -0400 | [diff] [blame] | 93 | functions->framebufferRenderbuffer(GL_FRAMEBUFFER, attachmentPoint, GL_RENDERBUFFER, |
| 94 | renderbufferGL->getRenderbufferID()); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 95 | } |
| 96 | else |
| 97 | { |
| 98 | UNREACHABLE(); |
| 99 | } |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | // Unbind this attachment |
| 104 | functions->framebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, 0, 0); |
| 105 | } |
| 106 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 107 | |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 108 | bool AreAllLayersActive(const FramebufferAttachment &attachment) |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 109 | { |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 110 | int baseViewIndex = attachment.getBaseViewIndex(); |
| 111 | if (baseViewIndex != 0) |
| 112 | { |
| 113 | return false; |
| 114 | } |
| 115 | const ImageIndex &imageIndex = attachment.getTextureImageIndex(); |
Jamie Madill | cc12937 | 2018-04-12 09:13:18 -0400 | [diff] [blame] | 116 | int numLayers = static_cast<int>( |
| 117 | attachment.getTexture()->getDepth(imageIndex.getTarget(), imageIndex.getLevelIndex())); |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 118 | return (attachment.getNumViews() == numLayers); |
| 119 | } |
| 120 | |
| 121 | bool RequiresMultiviewClear(const FramebufferState &state, bool scissorTestEnabled) |
| 122 | { |
| 123 | // Get one attachment and check whether all layers are attached. |
| 124 | const FramebufferAttachment *attachment = nullptr; |
| 125 | bool allTextureArraysAreFullyAttached = true; |
| 126 | for (const FramebufferAttachment &colorAttachment : state.getColorAttachments()) |
| 127 | { |
| 128 | if (colorAttachment.isAttached()) |
| 129 | { |
| 130 | if (colorAttachment.getMultiviewLayout() == GL_NONE) |
| 131 | { |
| 132 | return false; |
| 133 | } |
| 134 | attachment = &colorAttachment; |
| 135 | allTextureArraysAreFullyAttached = |
| 136 | allTextureArraysAreFullyAttached && AreAllLayersActive(*attachment); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | const FramebufferAttachment *depthAttachment = state.getDepthAttachment(); |
| 141 | if (depthAttachment) |
| 142 | { |
| 143 | if (depthAttachment->getMultiviewLayout() == GL_NONE) |
| 144 | { |
| 145 | return false; |
| 146 | } |
| 147 | attachment = depthAttachment; |
| 148 | allTextureArraysAreFullyAttached = |
| 149 | allTextureArraysAreFullyAttached && AreAllLayersActive(*attachment); |
| 150 | } |
| 151 | const FramebufferAttachment *stencilAttachment = state.getStencilAttachment(); |
| 152 | if (stencilAttachment) |
| 153 | { |
| 154 | if (stencilAttachment->getMultiviewLayout() == GL_NONE) |
| 155 | { |
| 156 | return false; |
| 157 | } |
| 158 | attachment = stencilAttachment; |
| 159 | allTextureArraysAreFullyAttached = |
| 160 | allTextureArraysAreFullyAttached && AreAllLayersActive(*attachment); |
| 161 | } |
| 162 | |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 163 | if (attachment == nullptr) |
| 164 | { |
| 165 | return false; |
| 166 | } |
| 167 | switch (attachment->getMultiviewLayout()) |
| 168 | { |
| 169 | case GL_FRAMEBUFFER_MULTIVIEW_LAYERED_ANGLE: |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 170 | // If all layers of each texture array are active, then there is no need to issue a |
| 171 | // special multiview clear. |
| 172 | return !allTextureArraysAreFullyAttached; |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 173 | case GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE: |
| 174 | return (scissorTestEnabled == true); |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 175 | default: |
| 176 | UNREACHABLE(); |
| 177 | } |
| 178 | return false; |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 179 | } |
| 180 | |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 181 | } // namespace |
| 182 | |
| 183 | FramebufferGL::FramebufferGL(const FramebufferState &state, |
| 184 | const FunctionsGL *functions, |
| 185 | StateManagerGL *stateManager, |
| 186 | const WorkaroundsGL &workarounds, |
| 187 | BlitGL *blitter, |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 188 | ClearMultiviewGL *multiviewClearer, |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 189 | bool isDefault) |
| 190 | : FramebufferImpl(state), |
| 191 | mFunctions(functions), |
| 192 | mStateManager(stateManager), |
| 193 | mWorkarounds(workarounds), |
| 194 | mBlitter(blitter), |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 195 | mMultiviewClearer(multiviewClearer), |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 196 | mFramebufferID(0), |
| 197 | mIsDefault(isDefault), |
| 198 | mAppliedEnabledDrawBuffers(1) |
| 199 | { |
| 200 | if (!mIsDefault) |
| 201 | { |
| 202 | mFunctions->genFramebuffers(1, &mFramebufferID); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | FramebufferGL::FramebufferGL(GLuint id, |
| 207 | const FramebufferState &state, |
| 208 | const FunctionsGL *functions, |
| 209 | const WorkaroundsGL &workarounds, |
| 210 | BlitGL *blitter, |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 211 | ClearMultiviewGL *multiviewClearer, |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 212 | StateManagerGL *stateManager) |
| 213 | : FramebufferImpl(state), |
| 214 | mFunctions(functions), |
| 215 | mStateManager(stateManager), |
| 216 | mWorkarounds(workarounds), |
| 217 | mBlitter(blitter), |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 218 | mMultiviewClearer(multiviewClearer), |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 219 | mFramebufferID(id), |
| 220 | mIsDefault(true), |
| 221 | mAppliedEnabledDrawBuffers(1) |
| 222 | { |
| 223 | } |
| 224 | |
| 225 | FramebufferGL::~FramebufferGL() |
| 226 | { |
| 227 | mStateManager->deleteFramebuffer(mFramebufferID); |
| 228 | mFramebufferID = 0; |
| 229 | } |
| 230 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 231 | Error FramebufferGL::discard(const gl::Context *context, size_t count, const GLenum *attachments) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 232 | { |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 233 | // glInvalidateFramebuffer accepts the same enums as glDiscardFramebufferEXT |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 234 | return invalidate(context, count, attachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 237 | Error FramebufferGL::invalidate(const gl::Context *context, size_t count, const GLenum *attachments) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 238 | { |
Geoff Lang | 005a701 | 2017-03-27 13:17:34 -0400 | [diff] [blame] | 239 | const GLenum *finalAttachmentsPtr = attachments; |
| 240 | |
| 241 | std::vector<GLenum> modifiedAttachments; |
| 242 | if (modifyInvalidateAttachmentsForEmulatedDefaultFBO(count, attachments, &modifiedAttachments)) |
| 243 | { |
| 244 | finalAttachmentsPtr = modifiedAttachments.data(); |
| 245 | } |
| 246 | |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 247 | // 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] | 248 | if (mFunctions->invalidateFramebuffer) |
| 249 | { |
| 250 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Geoff Lang | 005a701 | 2017-03-27 13:17:34 -0400 | [diff] [blame] | 251 | mFunctions->invalidateFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), |
| 252 | finalAttachmentsPtr); |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 253 | } |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame] | 254 | else if (mFunctions->discardFramebufferEXT) |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 255 | { |
| 256 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame] | 257 | mFunctions->discardFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLsizei>(count), |
| 258 | finalAttachmentsPtr); |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 259 | } |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 260 | |
Geoff Lang | 57ce9ea | 2016-11-24 12:03:14 -0500 | [diff] [blame] | 261 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 262 | } |
| 263 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 264 | Error FramebufferGL::invalidateSub(const gl::Context *context, |
| 265 | size_t count, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 266 | const GLenum *attachments, |
| 267 | const gl::Rectangle &area) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 268 | { |
Geoff Lang | 005a701 | 2017-03-27 13:17:34 -0400 | [diff] [blame] | 269 | |
| 270 | const GLenum *finalAttachmentsPtr = attachments; |
| 271 | |
| 272 | std::vector<GLenum> modifiedAttachments; |
| 273 | if (modifyInvalidateAttachmentsForEmulatedDefaultFBO(count, attachments, &modifiedAttachments)) |
| 274 | { |
| 275 | finalAttachmentsPtr = modifiedAttachments.data(); |
| 276 | } |
| 277 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 278 | // Since this function is just a hint and not available until OpenGL 4.3, only call it if it is |
| 279 | // available. |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 280 | if (mFunctions->invalidateSubFramebuffer) |
| 281 | { |
| 282 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 283 | mFunctions->invalidateSubFramebuffer(GL_FRAMEBUFFER, static_cast<GLsizei>(count), |
Geoff Lang | 005a701 | 2017-03-27 13:17:34 -0400 | [diff] [blame] | 284 | finalAttachmentsPtr, area.x, area.y, area.width, |
| 285 | area.height); |
Geoff Lang | 64a7244 | 2015-04-01 14:43:11 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 288 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 289 | } |
| 290 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 291 | Error FramebufferGL::clear(const gl::Context *context, GLbitfield mask) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 292 | { |
Frank Henigman | 308d745 | 2017-02-15 22:51:21 -0500 | [diff] [blame] | 293 | syncClearState(context, mask); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 294 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 295 | |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 296 | if (!RequiresMultiviewClear(mState, context->getGLState().isScissorTestEnabled())) |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 297 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 298 | mFunctions->clear(mask); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 299 | } |
| 300 | else |
| 301 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 302 | mMultiviewClearer->clearMultiviewFBO(mState, context->getGLState().getScissor(), |
| 303 | ClearMultiviewGL::ClearCommandType::Clear, mask, |
| 304 | GL_NONE, 0, nullptr, 0.0f, 0); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 305 | } |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 306 | |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 307 | return gl::NoError(); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 308 | } |
| 309 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 310 | Error FramebufferGL::clearBufferfv(const gl::Context *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 311 | GLenum buffer, |
| 312 | GLint drawbuffer, |
| 313 | const GLfloat *values) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 314 | { |
Frank Henigman | 308d745 | 2017-02-15 22:51:21 -0500 | [diff] [blame] | 315 | syncClearBufferState(context, buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 316 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 317 | |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 318 | if (!RequiresMultiviewClear(mState, context->getGLState().isScissorTestEnabled())) |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 319 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 320 | mFunctions->clearBufferfv(buffer, drawbuffer, values); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 321 | } |
| 322 | else |
| 323 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 324 | mMultiviewClearer->clearMultiviewFBO(mState, context->getGLState().getScissor(), |
| 325 | ClearMultiviewGL::ClearCommandType::ClearBufferfv, |
| 326 | static_cast<GLbitfield>(0u), buffer, drawbuffer, |
| 327 | reinterpret_cast<const uint8_t *>(values), 0.0f, 0); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 328 | } |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 329 | |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 330 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 333 | Error FramebufferGL::clearBufferuiv(const gl::Context *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 334 | GLenum buffer, |
| 335 | GLint drawbuffer, |
| 336 | const GLuint *values) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 337 | { |
Frank Henigman | 308d745 | 2017-02-15 22:51:21 -0500 | [diff] [blame] | 338 | syncClearBufferState(context, buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 339 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 340 | |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 341 | if (!RequiresMultiviewClear(mState, context->getGLState().isScissorTestEnabled())) |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 342 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 343 | mFunctions->clearBufferuiv(buffer, drawbuffer, values); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 344 | } |
| 345 | else |
| 346 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 347 | mMultiviewClearer->clearMultiviewFBO(mState, context->getGLState().getScissor(), |
| 348 | ClearMultiviewGL::ClearCommandType::ClearBufferuiv, |
| 349 | static_cast<GLbitfield>(0u), buffer, drawbuffer, |
| 350 | reinterpret_cast<const uint8_t *>(values), 0.0f, 0); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 351 | } |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 352 | |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 353 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 354 | } |
| 355 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 356 | Error FramebufferGL::clearBufferiv(const gl::Context *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 357 | GLenum buffer, |
| 358 | GLint drawbuffer, |
| 359 | const GLint *values) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 360 | { |
Frank Henigman | 308d745 | 2017-02-15 22:51:21 -0500 | [diff] [blame] | 361 | syncClearBufferState(context, buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 362 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 363 | |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 364 | if (!RequiresMultiviewClear(mState, context->getGLState().isScissorTestEnabled())) |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 365 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 366 | mFunctions->clearBufferiv(buffer, drawbuffer, values); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 367 | } |
| 368 | else |
| 369 | { |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 370 | mMultiviewClearer->clearMultiviewFBO(mState, context->getGLState().getScissor(), |
| 371 | ClearMultiviewGL::ClearCommandType::ClearBufferiv, |
| 372 | static_cast<GLbitfield>(0u), buffer, drawbuffer, |
| 373 | reinterpret_cast<const uint8_t *>(values), 0.0f, 0); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 374 | } |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 375 | |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 376 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 377 | } |
| 378 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 379 | Error FramebufferGL::clearBufferfi(const gl::Context *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 380 | GLenum buffer, |
| 381 | GLint drawbuffer, |
| 382 | GLfloat depth, |
| 383 | GLint stencil) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 384 | { |
Frank Henigman | 308d745 | 2017-02-15 22:51:21 -0500 | [diff] [blame] | 385 | syncClearBufferState(context, buffer, drawbuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 386 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 387 | |
Martin Radev | 61e710b | 2017-09-05 11:59:52 +0300 | [diff] [blame] | 388 | if (!RequiresMultiviewClear(mState, context->getGLState().isScissorTestEnabled())) |
Martin Radev | b076193 | 2017-07-25 17:42:25 +0300 | [diff] [blame] | 389 | { |
| 390 | mFunctions->clearBufferfi(buffer, drawbuffer, depth, stencil); |
| 391 | } |
Martin Radev | 5e424fa | 2017-08-09 16:25:36 +0300 | [diff] [blame] | 392 | else |
| 393 | { |
| 394 | mMultiviewClearer->clearMultiviewFBO(mState, context->getGLState().getScissor(), |
| 395 | ClearMultiviewGL::ClearCommandType::ClearBufferfi, |
| 396 | static_cast<GLbitfield>(0u), buffer, drawbuffer, |
| 397 | nullptr, depth, stencil); |
| 398 | } |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 399 | |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 400 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 401 | } |
| 402 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 403 | GLenum FramebufferGL::getImplementationColorReadFormat(const gl::Context *context) const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 404 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 405 | const auto *readAttachment = mState.getReadAttachment(); |
| 406 | const Format &format = readAttachment->getFormat(); |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 407 | return format.info->getReadPixelsFormat(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 408 | } |
| 409 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 410 | GLenum FramebufferGL::getImplementationColorReadType(const gl::Context *context) const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 411 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 412 | const auto *readAttachment = mState.getReadAttachment(); |
| 413 | const Format &format = readAttachment->getFormat(); |
Geoff Lang | c71ea66 | 2017-09-26 17:06:02 -0400 | [diff] [blame] | 414 | return format.info->getReadPixelsType(context->getClientVersion()); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 415 | } |
| 416 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 417 | Error FramebufferGL::readPixels(const gl::Context *context, |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 418 | const gl::Rectangle &origArea, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 419 | GLenum format, |
| 420 | GLenum type, |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 421 | void *ptrOrOffset) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 422 | { |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 423 | // Clip read area to framebuffer. |
| 424 | const gl::Extents fbSize = getState().getReadAttachment()->getSize(); |
| 425 | const gl::Rectangle fbRect(0, 0, fbSize.width, fbSize.height); |
| 426 | gl::Rectangle area; |
| 427 | if (!ClipRectangle(origArea, fbRect, &area)) |
| 428 | { |
| 429 | // nothing to read |
| 430 | return gl::NoError(); |
| 431 | } |
| 432 | |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 433 | PixelPackState packState = context->getGLState().getPackState(); |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 434 | const gl::Buffer *packBuffer = |
| 435 | context->getGLState().getTargetBuffer(gl::BufferBinding::PixelPack); |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 436 | |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 437 | nativegl::ReadPixelsFormat readPixelsFormat = |
| 438 | nativegl::GetReadPixelsFormat(mFunctions, mWorkarounds, format, type); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 439 | GLenum readFormat = readPixelsFormat.format; |
| 440 | GLenum readType = readPixelsFormat.type; |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 441 | |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 442 | mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, mFramebufferID); |
| 443 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 444 | bool useOverlappingRowsWorkaround = mWorkarounds.packOverlappingRowsSeparatelyPackBuffer && |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 445 | packBuffer && packState.rowLength != 0 && |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 446 | packState.rowLength < area.width; |
| 447 | |
| 448 | GLubyte *pixels = reinterpret_cast<GLubyte *>(ptrOrOffset); |
| 449 | int leftClip = area.x - origArea.x; |
| 450 | int topClip = area.y - origArea.y; |
| 451 | if (leftClip || topClip) |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 452 | { |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 453 | // Adjust destination to match portion clipped off left and/or top. |
| 454 | const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(readFormat, readType); |
| 455 | |
| 456 | GLuint rowBytes = 0; |
| 457 | ANGLE_TRY_RESULT(glFormat.computeRowPitch(readType, origArea.width, packState.alignment, |
| 458 | packState.rowLength), |
| 459 | rowBytes); |
| 460 | pixels += leftClip * glFormat.pixelBytes + topClip * rowBytes; |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 461 | } |
| 462 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 463 | if (packState.rowLength == 0 && area.width != origArea.width) |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 464 | { |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 465 | // No rowLength was specified so it will derive from read width, but clipping changed the |
| 466 | // read width. Use the original width so we fill the user's buffer as they intended. |
| 467 | packState.rowLength = origArea.width; |
| 468 | } |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 469 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 470 | // We want to use rowLength, but that might not be supported. |
| 471 | bool cannotSetDesiredRowLength = |
| 472 | packState.rowLength && !GetImplAs<ContextGL>(context)->getNativeExtensions().packSubimage; |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 473 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 474 | gl::Error retVal = gl::NoError(); |
| 475 | if (cannotSetDesiredRowLength || useOverlappingRowsWorkaround) |
| 476 | { |
| 477 | retVal = readPixelsRowByRow(context, area, readFormat, readType, packState, pixels); |
| 478 | } |
| 479 | else |
| 480 | { |
| 481 | gl::ErrorOrResult<bool> useLastRowPaddingWorkaround = false; |
| 482 | if (mWorkarounds.packLastRowSeparatelyForPaddingInclusion) |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 483 | { |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 484 | useLastRowPaddingWorkaround = ShouldApplyLastRowPaddingWorkaround( |
| 485 | gl::Extents(area.width, area.height, 1), packState, packBuffer, readFormat, |
| 486 | readType, false, pixels); |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | if (useLastRowPaddingWorkaround.isError()) |
| 490 | { |
| 491 | retVal = useLastRowPaddingWorkaround.getError(); |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | retVal = readPixelsAllAtOnce(context, area, readFormat, readType, packState, pixels, |
| 496 | useLastRowPaddingWorkaround.getResult()); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 500 | return retVal; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 501 | } |
| 502 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 503 | Error FramebufferGL::blit(const gl::Context *context, |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 504 | const gl::Rectangle &sourceArea, |
| 505 | const gl::Rectangle &destArea, |
| 506 | GLbitfield mask, |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 507 | GLenum filter) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 508 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 509 | const Framebuffer *sourceFramebuffer = context->getGLState().getReadFramebuffer(); |
| 510 | const Framebuffer *destFramebuffer = context->getGLState().getDrawFramebuffer(); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 511 | |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 512 | const FramebufferAttachment *colorReadAttachment = sourceFramebuffer->getReadColorbuffer(); |
Corentin Wallez | 4596a76 | 2016-12-20 14:50:18 -0500 | [diff] [blame] | 513 | |
| 514 | GLsizei readAttachmentSamples = 0; |
| 515 | if (colorReadAttachment != nullptr) |
| 516 | { |
| 517 | readAttachmentSamples = colorReadAttachment->getSamples(); |
| 518 | } |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 519 | |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 520 | bool needManualColorBlit = false; |
| 521 | |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 522 | // TODO(cwallez) when the filter is LINEAR and both source and destination are SRGB, we |
| 523 | // could avoid doing a manual blit. |
| 524 | |
| 525 | // Prior to OpenGL 4.4 BlitFramebuffer (section 18.3.1 of GL 4.3 core profile) reads: |
| 526 | // When values are taken from the read buffer, no linearization is performed, even |
| 527 | // if the format of the buffer is SRGB. |
| 528 | // Starting from OpenGL 4.4 (section 18.3.1) it reads: |
| 529 | // When values are taken from the read buffer, if FRAMEBUFFER_SRGB is enabled and the |
| 530 | // value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the framebuffer attachment |
| 531 | // corresponding to the read buffer is SRGB, the red, green, and blue components are |
| 532 | // converted from the non-linear sRGB color space according [...]. |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 533 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 534 | bool sourceSRGB = |
| 535 | colorReadAttachment != nullptr && colorReadAttachment->getColorEncoding() == GL_SRGB; |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 536 | needManualColorBlit = |
| 537 | needManualColorBlit || (sourceSRGB && mFunctions->isAtMostGL(gl::Version(4, 3))); |
| 538 | } |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 539 | |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 540 | // Prior to OpenGL 4.2 BlitFramebuffer (section 4.3.2 of GL 4.1 core profile) reads: |
| 541 | // Blit operations bypass the fragment pipeline. The only fragment operations which |
| 542 | // affect a blit are the pixel ownership test and scissor test. |
| 543 | // Starting from OpenGL 4.2 (section 4.3.2) it reads: |
| 544 | // When values are written to the draw buffers, blit operations bypass the fragment |
| 545 | // pipeline. The only fragment operations which affect a blit are the pixel ownership |
| 546 | // test, the scissor test and sRGB conversion. |
| 547 | if (!needManualColorBlit) |
| 548 | { |
| 549 | bool destSRGB = false; |
| 550 | for (size_t i = 0; i < destFramebuffer->getDrawbufferStateCount(); ++i) |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 551 | { |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 552 | const FramebufferAttachment *attachment = destFramebuffer->getDrawBuffer(i); |
| 553 | if (attachment && attachment->getColorEncoding() == GL_SRGB) |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 554 | { |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 555 | destSRGB = true; |
| 556 | break; |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 557 | } |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 558 | } |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 559 | |
| 560 | needManualColorBlit = |
| 561 | needManualColorBlit || (destSRGB && mFunctions->isAtMostGL(gl::Version(4, 1))); |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | // Enable FRAMEBUFFER_SRGB if needed |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 565 | mStateManager->setFramebufferSRGBEnabledForFramebuffer(context, true, this); |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 566 | |
| 567 | GLenum blitMask = mask; |
Corentin Wallez | 6898b35 | 2016-11-10 11:41:15 -0500 | [diff] [blame] | 568 | if (needManualColorBlit && (mask & GL_COLOR_BUFFER_BIT) && readAttachmentSamples <= 1) |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 569 | { |
| 570 | ANGLE_TRY(mBlitter->blitColorBufferWithShader(sourceFramebuffer, destFramebuffer, |
| 571 | sourceArea, destArea, filter)); |
| 572 | blitMask &= ~GL_COLOR_BUFFER_BIT; |
| 573 | } |
| 574 | |
| 575 | if (blitMask == 0) |
| 576 | { |
| 577 | return gl::NoError(); |
| 578 | } |
| 579 | |
| 580 | const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(sourceFramebuffer); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 581 | mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID()); |
| 582 | mStateManager->bindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebufferID); |
| 583 | |
Jamie Madill | 2da819e | 2015-12-03 15:53:19 -0500 | [diff] [blame] | 584 | mFunctions->blitFramebuffer(sourceArea.x, sourceArea.y, sourceArea.x1(), sourceArea.y1(), |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 585 | destArea.x, destArea.y, destArea.x1(), destArea.y1(), blitMask, |
| 586 | filter); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 587 | |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 588 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 589 | } |
| 590 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 591 | gl::Error FramebufferGL::getSamplePosition(size_t index, GLfloat *xy) const |
| 592 | { |
| 593 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 594 | mFunctions->getMultisamplefv(GL_SAMPLE_POSITION, static_cast<GLuint>(index), xy); |
| 595 | return gl::NoError(); |
| 596 | } |
| 597 | |
Kenneth Russell | ce8602a | 2017-10-03 18:23:08 -0700 | [diff] [blame] | 598 | bool FramebufferGL::checkStatus(const gl::Context *context) const |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 599 | { |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 600 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 601 | GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER); |
| 602 | if (status != GL_FRAMEBUFFER_COMPLETE) |
| 603 | { |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 604 | WARN() << "GL framebuffer returned incomplete."; |
Jamie Madill | cc86d64 | 2015-11-24 13:00:07 -0500 | [diff] [blame] | 605 | } |
| 606 | return (status == GL_FRAMEBUFFER_COMPLETE); |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 609 | gl::Error FramebufferGL::syncState(const gl::Context *context, |
| 610 | const Framebuffer::DirtyBits &dirtyBits) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 611 | { |
| 612 | // Don't need to sync state for the default FBO. |
| 613 | if (mIsDefault) |
| 614 | { |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 615 | return gl::NoError(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mFramebufferID); |
| 619 | |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 620 | // A pointer to one of the attachments for which the texture or the render buffer is not zero. |
| 621 | const FramebufferAttachment *attachment = nullptr; |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 622 | |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 623 | for (auto dirtyBit : dirtyBits) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 624 | { |
| 625 | switch (dirtyBit) |
| 626 | { |
| 627 | case Framebuffer::DIRTY_BIT_DEPTH_ATTACHMENT: |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 628 | { |
| 629 | const FramebufferAttachment *newAttachment = mState.getDepthAttachment(); |
| 630 | BindFramebufferAttachment(mFunctions, GL_DEPTH_ATTACHMENT, newAttachment); |
| 631 | if (newAttachment) |
| 632 | { |
| 633 | attachment = newAttachment; |
| 634 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 635 | break; |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 636 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 637 | case Framebuffer::DIRTY_BIT_STENCIL_ATTACHMENT: |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 638 | { |
| 639 | const FramebufferAttachment *newAttachment = mState.getStencilAttachment(); |
| 640 | BindFramebufferAttachment(mFunctions, GL_STENCIL_ATTACHMENT, newAttachment); |
| 641 | if (newAttachment) |
| 642 | { |
| 643 | attachment = newAttachment; |
| 644 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 645 | break; |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 646 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 647 | case Framebuffer::DIRTY_BIT_DRAW_BUFFERS: |
| 648 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 649 | const auto &drawBuffers = mState.getDrawBufferStates(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 650 | mFunctions->drawBuffers(static_cast<GLsizei>(drawBuffers.size()), |
| 651 | drawBuffers.data()); |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 652 | mAppliedEnabledDrawBuffers = mState.getEnabledDrawBuffers(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 653 | break; |
| 654 | } |
| 655 | case Framebuffer::DIRTY_BIT_READ_BUFFER: |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 656 | mFunctions->readBuffer(mState.getReadBufferState()); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 657 | break; |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 658 | case Framebuffer::DIRTY_BIT_DEFAULT_WIDTH: |
| 659 | mFunctions->framebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, |
| 660 | mState.getDefaultWidth()); |
| 661 | break; |
| 662 | case Framebuffer::DIRTY_BIT_DEFAULT_HEIGHT: |
| 663 | mFunctions->framebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, |
| 664 | mState.getDefaultHeight()); |
| 665 | break; |
| 666 | case Framebuffer::DIRTY_BIT_DEFAULT_SAMPLES: |
| 667 | mFunctions->framebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, |
| 668 | mState.getDefaultSamples()); |
| 669 | break; |
| 670 | case Framebuffer::DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS: |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 671 | mFunctions->framebufferParameteri( |
| 672 | GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS, |
| 673 | gl::ConvertToGLBoolean(mState.getDefaultFixedSampleLocations())); |
JiangYizhou | f7bbc8a | 2016-11-16 09:57:22 +0800 | [diff] [blame] | 674 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 675 | default: |
| 676 | { |
| 677 | ASSERT(Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0 == 0 && |
| 678 | dirtyBit < Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_MAX); |
| 679 | size_t index = |
| 680 | static_cast<size_t>(dirtyBit - Framebuffer::DIRTY_BIT_COLOR_ATTACHMENT_0); |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 681 | const FramebufferAttachment *newAttachment = mState.getColorAttachment(index); |
| 682 | BindFramebufferAttachment( |
| 683 | mFunctions, static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + index), newAttachment); |
| 684 | if (newAttachment) |
| 685 | { |
| 686 | attachment = newAttachment; |
| 687 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 688 | break; |
| 689 | } |
| 690 | } |
| 691 | } |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 692 | |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 693 | if (attachment) |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 694 | { |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 695 | const bool isSideBySide = |
| 696 | (attachment->getMultiviewLayout() == GL_FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE); |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 697 | mStateManager->setSideBySide(isSideBySide); |
Martin Radev | 7c2e6a9 | 2017-08-28 11:13:16 +0300 | [diff] [blame] | 698 | mStateManager->setViewportOffsets(attachment->getMultiviewViewportOffsets()); |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 699 | mStateManager->updateMultiviewBaseViewLayerIndexUniform(context->getGLState().getProgram(), |
| 700 | getState()); |
Martin Radev | 878c8b1 | 2017-07-28 09:51:04 +0300 | [diff] [blame] | 701 | } |
Jamie Madill | 19fa1c6 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 702 | |
| 703 | return gl::NoError(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 704 | } |
| 705 | |
Geoff Lang | 4ad1709 | 2015-03-10 16:47:44 -0400 | [diff] [blame] | 706 | GLuint FramebufferGL::getFramebufferID() const |
| 707 | { |
| 708 | return mFramebufferID; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 709 | } |
| 710 | |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 711 | bool FramebufferGL::isDefault() const |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 712 | { |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 713 | return mIsDefault; |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 714 | } |
| 715 | |
Geoff Lang | 809b13e | 2017-11-07 15:33:46 -0500 | [diff] [blame] | 716 | void FramebufferGL::maskOutInactiveOutputDrawBuffers(GLenum binding, DrawBufferMask maxSet) |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 717 | { |
| 718 | auto targetAppliedDrawBuffers = mState.getEnabledDrawBuffers() & maxSet; |
| 719 | if (mAppliedEnabledDrawBuffers != targetAppliedDrawBuffers) |
| 720 | { |
| 721 | mAppliedEnabledDrawBuffers = targetAppliedDrawBuffers; |
| 722 | |
| 723 | const auto &stateDrawBuffers = mState.getDrawBufferStates(); |
| 724 | GLsizei drawBufferCount = static_cast<GLsizei>(stateDrawBuffers.size()); |
| 725 | ASSERT(drawBufferCount <= IMPLEMENTATION_MAX_DRAW_BUFFERS); |
| 726 | |
| 727 | GLenum drawBuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS]; |
| 728 | for (GLenum i = 0; static_cast<int>(i) < drawBufferCount; ++i) |
| 729 | { |
| 730 | drawBuffers[i] = targetAppliedDrawBuffers[i] ? stateDrawBuffers[i] : GL_NONE; |
| 731 | } |
| 732 | |
Geoff Lang | 809b13e | 2017-11-07 15:33:46 -0500 | [diff] [blame] | 733 | mStateManager->bindFramebuffer(binding, mFramebufferID); |
Corentin Wallez | e755774 | 2017-06-01 13:09:57 -0400 | [diff] [blame] | 734 | mFunctions->drawBuffers(drawBufferCount, drawBuffers); |
| 735 | } |
| 736 | } |
| 737 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 738 | void FramebufferGL::syncClearState(const gl::Context *context, GLbitfield mask) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 739 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 740 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 741 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 742 | if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && |
| 743 | (mask & GL_COLOR_BUFFER_BIT) != 0 && !mIsDefault) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 744 | { |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 745 | bool hasSRGBAttachment = false; |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 746 | for (const auto &attachment : mState.getColorAttachments()) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 747 | { |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 748 | if (attachment.isAttached() && attachment.getColorEncoding() == GL_SRGB) |
| 749 | { |
Corentin Wallez | 26a717b | 2016-09-27 08:45:42 -0700 | [diff] [blame] | 750 | hasSRGBAttachment = true; |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 751 | break; |
| 752 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 753 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 754 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 755 | mStateManager->setFramebufferSRGBEnabled(context, hasSRGBAttachment); |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 756 | } |
| 757 | else |
| 758 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 759 | mStateManager->setFramebufferSRGBEnabled(context, !mIsDefault); |
Frank Henigman | a3d333c | 2016-03-22 22:09:14 -0400 | [diff] [blame] | 760 | } |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 764 | void FramebufferGL::syncClearBufferState(const gl::Context *context, |
| 765 | GLenum buffer, |
| 766 | GLint drawBuffer) |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 767 | { |
| 768 | if (mFunctions->standard == STANDARD_GL_DESKTOP) |
| 769 | { |
| 770 | if (mWorkarounds.doesSRGBClearsOnLinearFramebufferAttachments && buffer == GL_COLOR && |
| 771 | !mIsDefault) |
| 772 | { |
| 773 | // If doing a clear on a color buffer, set SRGB blend enabled only if the color buffer |
| 774 | // is an SRGB format. |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 775 | const auto &drawbufferState = mState.getDrawBufferStates(); |
| 776 | const auto &colorAttachments = mState.getColorAttachments(); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 777 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 778 | const FramebufferAttachment *attachment = nullptr; |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 779 | if (drawbufferState[drawBuffer] >= GL_COLOR_ATTACHMENT0 && |
| 780 | drawbufferState[drawBuffer] < GL_COLOR_ATTACHMENT0 + colorAttachments.size()) |
| 781 | { |
| 782 | size_t attachmentIdx = |
| 783 | static_cast<size_t>(drawbufferState[drawBuffer] - GL_COLOR_ATTACHMENT0); |
| 784 | attachment = &colorAttachments[attachmentIdx]; |
| 785 | } |
| 786 | |
| 787 | if (attachment != nullptr) |
| 788 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 789 | mStateManager->setFramebufferSRGBEnabled(context, |
Frank Henigman | 308d745 | 2017-02-15 22:51:21 -0500 | [diff] [blame] | 790 | attachment->getColorEncoding() == GL_SRGB); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | else |
| 794 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 795 | mStateManager->setFramebufferSRGBEnabled(context, !mIsDefault); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | } |
Geoff Lang | 005a701 | 2017-03-27 13:17:34 -0400 | [diff] [blame] | 799 | |
| 800 | bool FramebufferGL::modifyInvalidateAttachmentsForEmulatedDefaultFBO( |
| 801 | size_t count, |
| 802 | const GLenum *attachments, |
| 803 | std::vector<GLenum> *modifiedAttachments) const |
| 804 | { |
| 805 | bool needsModification = mIsDefault && mFramebufferID != 0; |
| 806 | if (!needsModification) |
| 807 | { |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | modifiedAttachments->resize(count); |
| 812 | for (size_t i = 0; i < count; i++) |
| 813 | { |
| 814 | switch (attachments[i]) |
| 815 | { |
| 816 | case GL_COLOR: |
| 817 | (*modifiedAttachments)[i] = GL_COLOR_ATTACHMENT0; |
| 818 | break; |
| 819 | |
| 820 | case GL_DEPTH: |
| 821 | (*modifiedAttachments)[i] = GL_DEPTH_ATTACHMENT; |
| 822 | break; |
| 823 | |
| 824 | case GL_STENCIL: |
| 825 | (*modifiedAttachments)[i] = GL_STENCIL_ATTACHMENT; |
| 826 | break; |
| 827 | |
| 828 | default: |
| 829 | UNREACHABLE(); |
| 830 | break; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | return true; |
| 835 | } |
| 836 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 837 | gl::Error FramebufferGL::readPixelsRowByRow(const gl::Context *context, |
| 838 | const gl::Rectangle &area, |
| 839 | GLenum format, |
| 840 | GLenum type, |
| 841 | const gl::PixelPackState &pack, |
| 842 | GLubyte *pixels) const |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 843 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 844 | const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type); |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 845 | |
| 846 | GLuint rowBytes = 0; |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 847 | ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength), |
| 848 | rowBytes); |
| 849 | GLuint skipBytes = 0; |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 850 | ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, pack, false), skipBytes); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 851 | |
| 852 | gl::PixelPackState directPack; |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 853 | directPack.alignment = 1; |
| 854 | mStateManager->setPixelPackState(directPack); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 855 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 856 | pixels += skipBytes; |
| 857 | for (GLint y = area.y; y < area.y + area.height; ++y) |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 858 | { |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 859 | mFunctions->readPixels(area.x, y, area.width, 1, format, type, pixels); |
| 860 | pixels += rowBytes; |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | return gl::NoError(); |
| 864 | } |
| 865 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 866 | gl::Error FramebufferGL::readPixelsAllAtOnce(const gl::Context *context, |
| 867 | const gl::Rectangle &area, |
| 868 | GLenum format, |
| 869 | GLenum type, |
| 870 | const gl::PixelPackState &pack, |
| 871 | GLubyte *pixels, |
| 872 | bool readLastRowSeparately) const |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 873 | { |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 874 | GLint height = area.height - readLastRowSeparately; |
| 875 | if (height > 0) |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 876 | { |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 877 | mStateManager->setPixelPackState(pack); |
| 878 | mFunctions->readPixels(area.x, area.y, area.width, height, format, type, pixels); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 879 | } |
| 880 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 881 | if (readLastRowSeparately) |
| 882 | { |
| 883 | const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type); |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 884 | |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 885 | GLuint rowBytes = 0; |
| 886 | ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength), |
| 887 | rowBytes); |
| 888 | GLuint skipBytes = 0; |
| 889 | ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, pack, false), skipBytes); |
| 890 | |
| 891 | gl::PixelPackState directPack; |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 892 | directPack.alignment = 1; |
| 893 | mStateManager->setPixelPackState(directPack); |
Frank Henigman | fa36c33 | 2017-06-09 18:44:45 -0400 | [diff] [blame] | 894 | |
| 895 | pixels += skipBytes + (area.height - 1) * rowBytes; |
| 896 | mFunctions->readPixels(area.x, area.y + area.height - 1, area.width, 1, format, type, |
| 897 | pixels); |
| 898 | } |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 899 | |
| 900 | return gl::NoError(); |
| 901 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 902 | } // namespace rx |