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