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