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